-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
66 lines (52 loc) · 1.17 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
package main
import (
"flag"
"log"
"os"
"github.com/cameliot/alpaca"
"github.com/cameliot/alpaca/meta"
)
var version = "unknown"
func usage() {
flag.PrintDefaults()
os.Exit(-1)
}
func main() {
log.Println("Starting klang3 v.", version)
// Initialize configuration
config := parseFlags()
if config.RepoPath == "" {
usage()
}
// Initialize MQTT connection
actions, dispatch := alpaca.DialMqtt(
config.Mqtt.BrokerUri(),
alpaca.Routes{
"sampler": config.Mqtt.BaseTopic,
"meta": "v1/_meta",
},
)
// Initialize repository
repo := NewRepository(config.RepoPath)
err := repo.Update()
if err != nil {
log.Fatal("Could not read samples from repository:", err)
}
samplerActions := make(alpaca.Actions)
metaActions := make(alpaca.Actions)
// Initialize Soundboard Service
samplerSvc := NewSamplerSvc(config.PlayCmd, repo)
go samplerSvc.Handle(samplerActions, dispatch)
// Hanlde meta actions for service discovery
metaSvc := meta.NewMetaSvc(
"sampler@mainhall",
"klang3",
version,
"Klang3 MQTT SoundBoard",
)
go metaSvc.Handle(metaActions, dispatch)
for action := range actions {
samplerActions <- action
metaActions <- action
}
}