-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmt-420.go
125 lines (109 loc) · 3.37 KB
/
mt-420.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package main
import (
"flag"
"github.com/coral/mt-420/config"
"github.com/coral/mt-420/display"
"github.com/coral/mt-420/display/terminal"
"github.com/coral/mt-420/panel/kb"
"github.com/coral/mt-420/panel/mtpanel"
"github.com/coral/mt-420/storage"
"github.com/coral/mt-420/controller"
"github.com/coral/mt-420/display/lcd"
"github.com/coral/mt-420/panel"
"github.com/coral/mt-420/player"
"github.com/coral/mt-420/storage/floppy"
"github.com/coral/mt-420/storage/mock"
"github.com/sirupsen/logrus"
"golang.org/x/exp/errors/fmt"
)
func main() {
///////////////////////////////////////////
//FLAGS
///////////////////////////////////////////
virtual := flag.Bool("virtual", false, "virtual")
terminalDisplay := flag.Bool("tdisp", false, "terminal display")
mockFS := flag.Bool("mock", false, "mock")
mockPath := flag.String("mockPath", "files/midi", "where to look for mock filesystem")
configPath := flag.String("config", "config.json", "path to configuration")
flag.Parse()
///////////////////////////////////////////
//LOAD CONFIG
///////////////////////////////////////////
lconfig, err := config.Load(*configPath)
if err != nil {
panic("could not load config : " + *configPath)
}
delay := lconfig.Lcd.BootDelay
log := logrus.New()
log.SetLevel(logrus.WarnLevel)
///////////////////////////////////////////
//DISPLAY
///////////////////////////////////////////
var dp display.Device
if *terminalDisplay {
dp = terminal.New()
} else {
dp = lcd.New(lconfig.Lcd.Device)
}
err = dp.Init()
if err != nil {
panic(fmt.Sprintln("Display Fail", lconfig.Lcd.Device, err))
}
dp.SetContrast(lconfig.Lcd.Contrast)
dp.SetBrightness(lconfig.Lcd.Brightness)
display.DelayMessage(dp, "Starting MT-420", delay)
///////////////////////////////////////////
// Panel
//////////////////////////////////////////
display.DelayMessage(dp, "Connecting to panel", delay)
var frontPanel panel.Panel
if *virtual {
frontPanel = kb.New()
err = frontPanel.Init()
if err != nil {
panic(fmt.Sprintln("Panel Fail", lconfig.Panel.Device, err))
}
} else {
frontPanel = mtpanel.New(lconfig.Panel.Device, lconfig.Panel.Baud, log)
err = frontPanel.Init()
if err != nil {
panic(fmt.Sprintln("Panel Fail", lconfig.Panel.Device, err))
}
for _, be := range lconfig.Panel.Buttons {
frontPanel.AddButton(be.Name, be.Message)
}
frontPanel.AddEncoder(panel.Encoder{
Left: byte(lconfig.Panel.Rotary.EncoderLeft),
Right: byte(lconfig.Panel.Rotary.EncoderRight),
})
}
///////////////////////////////////////////
// Fluidsynth
//////////////////////////////////////////
display.DelayMessage(dp, "Loading Fluidsynth", delay)
p, err := player.New(player.Configuration{
SoundBank: lconfig.Fluidsynth.Soundfonts,
DefaultSoundFont: lconfig.Fluidsynth.Default,
Gain: lconfig.Fluidsynth.Gain,
})
defer p.Close()
if err != nil {
panic(err)
}
///////////////////////////////////////////
// Floppy
//////////////////////////////////////////
display.DelayMessage(dp, "Warming up floppy", delay)
var storage storage.Storage
if *mockFS {
storage = mock.New(*mockPath)
} else {
storage = floppy.New(lconfig.Floppy.Device, lconfig.Floppy.Mountpoint)
}
storage.Init()
///////////////////////////////////////////
// Controller
//////////////////////////////////////////
controller := controller.New(p, frontPanel, storage, dp)
controller.Start()
}