-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
99 lines (86 loc) · 3.12 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"flag"
"log"
_ "net/http/pprof"
"os"
"strings"
"github.com/jrcichra/wfh-organist/internal/client"
"github.com/jrcichra/wfh-organist/internal/common"
"github.com/jrcichra/wfh-organist/internal/miditux"
"github.com/jrcichra/wfh-organist/internal/server"
"github.com/jrcichra/wfh-organist/internal/types"
)
func main() {
log.SetOutput(os.Stdout)
// get args
serverIP := flag.String("server", "localhost", "server IP")
serverPort := flag.Int("port", 3131, "server port")
midiPortIn := flag.Int("midi-in", 1, "midi port in")
midiPortOut := flag.Int("midi-out", 1, "midi port out")
list := flag.Bool("list", false, "list available ports")
mode := flag.String("mode", "local", "client, server, or local (runs both)")
protocol := flag.String("protocol", "tcp", "tcp only (udp not implemented yet)")
profile := flag.String("profile", "profiles/default/", "profiles path")
stdinMode := flag.Bool("stdin", false, "read from stdin")
delay := flag.Int("delay", 0, "artificial delay in ms")
dontControlVolume := flag.Bool("novolume", false, "have WFHO control client volume")
dontRecord := flag.Bool("norecord", false, "continuously record midi")
serialPath := flag.String("serialPath", "", "serial port path")
serialBaud := flag.Int("serialBaud", 115200, "serial port baud rate")
feedback := flag.Bool("feedback", false, "send notes back through the network")
readSerial := flag.Bool("serial", false, "read serial input for expression petal")
flag.Parse()
// make sure stdinMode is only true if mode is client
if *stdinMode && strings.ToLower(*mode) != "client" {
log.Println("stdin mode can only be used with client mode")
return
}
// delay only works on the client or local mode
if *delay > 0 && strings.ToLower(*mode) != "client" && strings.ToLower(*mode) != "local" {
log.Println("delay only works with client or local mode")
return
}
// print MIDI IO if requested
if *list {
common.GetLists()
return
}
switch *protocol {
case "tcp":
// do nothing
default:
log.Println("Invalid protocol", *protocol)
return
}
// register types to gob
common.RegisterGobTypes()
// spin up a midi-tux goroutine to handle message outputs
midiTuxChan := make(chan types.MidiTuxMessage, 100)
go miditux.MidiTux(midiTuxChan)
server := server.Server{
MidiPortIn: *midiPortIn,
MidiPortOut: *midiPortOut,
Port: *serverPort,
Profile: *profile,
DontRecord: *dontRecord,
MidiTuxChan: midiTuxChan,
Feedback: *feedback,
}
// operate in client or server mode
switch strings.ToLower(*mode) {
case "server":
go server.Run()
case "client":
go client.Client(*midiPortIn, *serverIP, *serverPort, *protocol, *stdinMode, *delay, midiTuxChan, *profile, *dontControlVolume, *readSerial, *serialPath, *serialBaud)
case "local":
// run both (unless serverIP is set, and sleep forever
if *serverIP == "localhost" {
go server.Run()
}
go client.Client(*midiPortIn, *serverIP, *serverPort, *protocol, *stdinMode, *delay, midiTuxChan, *profile, *dontControlVolume, *readSerial, *serialPath, *serialBaud)
default:
log.Fatalf("Unknown mode: %s. Must be 'server' or 'client'\n", *mode)
}
select {}
}