-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
93 lines (81 loc) · 2.1 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
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/bspaans/bleep/audio"
"github.com/bspaans/bleep/controller"
"github.com/bspaans/bleep/termbox"
"github.com/bspaans/bleep/ui/server"
)
var sequencer = flag.String("sequencer", "", "Load sequencer from file")
var enable8bit = flag.Bool("8bit", false, "Set bit depth to 8bit")
var enableMono = flag.Bool("mono", false, "Mono output")
var enableSequencer = flag.Bool("enable-sequencer", false, "Enable sequencer")
var record = flag.String("record", "", "Record .wav output")
var instruments = flag.String("instruments", "", "The instruments bank to load")
var percussion = flag.String("percussion", "", "The instruments bank to load for the percussion channel.")
var enableUI = flag.Bool("ui", false, "Enable terminal UI (experimental)")
var enableWS = flag.Bool("ws", false, "Enable web socket endpoint (experimental)")
func QuitWithError(err error) {
fmt.Println("Oh no:", err.Error())
os.Exit(1)
}
func main() {
flag.Parse()
fmt.Println("This is not a test.")
fmt.Println("You are now running bleep.")
cfg := audio.NewAudioConfig()
if *enable8bit {
cfg.BitDepth = 8
}
if *enableMono {
cfg.Stereo = false
}
ctrl := controller.NewController(cfg)
if *record != "" {
if err := ctrl.EnableWavSink(*record); err != nil {
QuitWithError(err)
}
}
if err := ctrl.EnableSDLSink(); err != nil {
QuitWithError(err)
}
if *instruments != "" {
if err := ctrl.LoadInstrumentBank(*instruments); err != nil {
QuitWithError(err)
}
}
if *percussion != "" {
if err := ctrl.LoadPercussionBank(*percussion); err != nil {
QuitWithError(err)
}
}
defer ctrl.Quit()
c := make(chan os.Signal)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
go func() {
<-c
fmt.Println("Quitting")
ctrl.Quit()
os.Exit(0)
}()
if *enableSequencer {
ctrl.LoadEmptySequencer()
}
if *sequencer != "" {
err := ctrl.LoadSequencerFromFile(*sequencer)
if err != nil {
QuitWithError(err)
}
}
if *enableUI {
ctrl.UI = termbox.NewTermBox().Start(ctrl)
}
if *enableWS {
ctrl.UI = server.NewServer().Start(ctrl)
}
ctrl.StartSynth()
}