Initial commit

This commit is contained in:
2025-08-03 16:21:33 +02:00
commit 0c0e1e985e
7 changed files with 163 additions and 0 deletions

53
controller.go Normal file
View File

@@ -0,0 +1,53 @@
package main
import (
"log"
"gitlab.com/gomidi/midi/v2"
)
type Controller struct {
midiInput *MidiInput
mappings []Mapping
abortChan chan interface{}
}
func NewController(portName string) (*Controller, error) {
midiInput, err := NewMidiInput(portName)
if err != nil {
return nil, err
}
abortChan := make(chan interface{})
controller := &Controller{midiInput, nil, abortChan}
go func() {
for {
select {
case midiMessage := <-midiInput.Messages:
controller.update(midiMessage)
case <-abortChan:
return
}
}
}()
return controller, nil
}
func (c *Controller) AddMapping(mapping Mapping) {
c.mappings = append(c.mappings, mapping)
}
func (c Controller) Stop() {
c.midiInput.Stop()
c.abortChan <- struct{}{}
}
func (c Controller) update(msg midi.Message) {
for _, mapping := range c.mappings {
if mapping.Is(msg) {
log.Println("Mapping triggered!\n")
}
}
}