-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
79 lines (69 loc) · 1.81 KB
/
main.go
File metadata and controls
79 lines (69 loc) · 1.81 KB
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
package main
import (
"digico-osc-passthru/osc"
"fmt"
"net"
"os"
"strconv"
"strings"
)
func main() {
fmt.Println("Starting DiGiCo OSC Passthru...")
consoleIp, consoleRx, consoleTx := os.Args[1], os.Args[2], os.Args[3]
clients := []osc.Client{}
fmt.Println("RX", consoleRx)
fmt.Println("TX", consoleTx)
txInt, err := strconv.Atoi(consoleTx)
if err != nil {
fmt.Println("Error converting tx port to int")
return
}
rxInt, err := strconv.Atoi(consoleRx)
if err != nil {
fmt.Println("Error converting rx port to int")
return
}
go initConsole(txInt, &clients)
initClients(consoleIp, rxInt, txInt, &clients)
}
func initConsole(txInt int, clients *[]osc.Client) {
d := osc.NewStandardDispatcher()
// From Console
d.AddMsgHandler("*", func(msg *osc.Message, _ *net.Addr) {
fmt.Println("From Console", msg.Address)
if len(*clients) == 0 {
fmt.Println("No Clients")
}
for _, client := range *clients {
fmt.Println("Sending to", client.IP())
client.Send(msg)
}
fmt.Println("")
})
fromConsole := &osc.Server{
Addr: "0.0.0.0:" + fmt.Sprint(txInt),
Dispatcher: d,
}
fromConsole.ListenAndServe()
defer fromConsole.CloseConnection()
}
func initClients(consoleIp string, rxInt int, txInt int, clients *[]osc.Client) {
toConsole := osc.NewClient(consoleIp, rxInt)
d := osc.NewStandardDispatcher()
// From Clients
d.AddMsgHandler("*", func(msg *osc.Message, addr *net.Addr) {
toConsole.Send(msg)
for _, client := range *clients {
if (strings.Split(client.IP(), ":")[0] == strings.Split((*addr).String(), ":")[0]) {
return
}
}
*clients = append(*clients, *osc.NewClient(strings.Split((*addr).String(), ":")[0], txInt))
})
fromClients := &osc.Server{
Addr: ":" + fmt.Sprint(rxInt),
Dispatcher: d,
}
fromClients.ListenAndServe()
defer fromClients.CloseConnection()
}