summaryrefslogtreecommitdiff
path: root/pkg
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2019-02-10 17:06:04 +0100
committerChristian Pointner <equinox@spreadspace.org>2019-02-10 17:06:04 +0100
commitc4bf287cc3991e4e52706d3cc73ecf4a577adeeb (patch)
treea2a5435dc3067c325bde1ae5bf6355973588207b /pkg
parentmixer: closer subscriber channel on unsubscribe (diff)
refactored fader levels and mute state
Diffstat (limited to 'pkg')
-rw-r--r--pkg/mixer/mixer.go76
1 files changed, 59 insertions, 17 deletions
diff --git a/pkg/mixer/mixer.go b/pkg/mixer/mixer.go
index 4db2c3a..a3348d9 100644
--- a/pkg/mixer/mixer.go
+++ b/pkg/mixer/mixer.go
@@ -32,9 +32,13 @@ import (
"github.com/scgolang/midi"
)
-type Channel uint8
-type FaderLevel uint8
+// TODO: make this configurable
+const (
+ CC_MUTE = byte(0xB1)
+ CC_FADER = byte(0xB0)
+)
+type Channel uint8
type EventType int
const (
@@ -53,14 +57,61 @@ func (et EventType) String() string {
}
}
+type FaderLevel uint8
+
+// TODO: make the values configurable
+const (
+ FaderLevelUnknown = FaderLevel(0xFF)
+ FaderLevelMax = FaderLevel(0x7F)
+ FaderLevel0db = FaderLevel(0x5F)
+ FaderLevelOff = FaderLevel(0x00)
+)
+
+func (fl FaderLevel) String() string {
+ if fl > FaderLevelMax {
+ return "unknown"
+ }
+ val := fmt.Sprintf("%3d", fl)
+ switch fl {
+ case FaderLevelMax:
+ return val + " (max)"
+ case FaderLevel0db:
+ return val + " (0db)"
+ case FaderLevelOff:
+ return val + " (off)"
+ default:
+ return val
+ }
+}
+
+type Mute int8
+
+const (
+ MuteUnknown = -1
+ MuteUnmuted = 0
+ MuteMuted = 1
+)
+
+func (m Mute) String() string {
+ switch m {
+ case MuteUnmuted:
+ return "unmuted"
+ case MuteMuted:
+ return "muted"
+ default:
+ return "unknown"
+ }
+}
+
type Event struct {
Channel Channel
Type EventType
- Value uint8
+ Level FaderLevel
+ Mute Mute
}
func (e Event) String() string {
- return fmt.Sprintf("Event(%s) for channel 0x%02X, value=%d", e.Type, e.Channel, e.Value)
+ return fmt.Sprintf("Event(%s) for channel %d: level=%s, muted=%s", e.Type, e.Channel, e.Level, e.Mute)
}
type Mixer struct {
@@ -69,16 +120,6 @@ type Mixer struct {
subscribers map[Channel]*list.List
}
-// TODO: make this configurable
-const (
- CC_MUTE = byte(0xB1)
- CC_FADER = byte(0xB0)
-
- FaderLevelMax = FaderLevel(0x7F)
- FaderLevel0db = FaderLevel(0x60)
- FaderLevelOff = FaderLevel(0x00)
-)
-
func openDevice(devices []*midi.Device, prefix string) (d *midi.Device, err error) {
for _, device := range devices {
if strings.HasPrefix(device.Name, prefix) {
@@ -136,16 +177,17 @@ func (m *Mixer) sendEvent(ev Event) {
}
func (m *Mixer) handleMidiPacket(p midi.Packet) {
- ev := Event{}
+ ev := Event{Level: FaderLevelUnknown, Mute: MuteUnknown}
ev.Channel = Channel(p.Data[1])
switch p.Data[0] {
case CC_FADER:
ev.Type = EventFaderChange
- ev.Value = p.Data[2]
+ ev.Level = FaderLevel(p.Data[2])
case CC_MUTE:
ev.Type = EventMute
+ ev.Mute = MuteUnmuted
if p.Data[2] > 0 {
- ev.Value = 1
+ ev.Mute = MuteMuted
}
default:
return