refactor(tracker): use strings to identify MIDI ports

This commit is contained in:
5684185+vsariola@users.noreply.github.com
2026-01-23 23:48:16 +02:00
parent 651ceb3cbb
commit 173648fbdb
5 changed files with 72 additions and 63 deletions

View File

@ -6,6 +6,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/vsariola/sointu"
)
@ -126,19 +127,14 @@ type (
Dialog int
MIDIContext interface {
InputDevices(yield func(MIDIDevice) bool)
InputDevices(yield func(string) bool)
Open(name string) error
Close()
HasDeviceOpen() bool
TryToOpenBy(name string, first bool)
IsOpen() bool
}
NullMIDIContext struct{}
MIDIDevice interface {
String() string
Open() error
}
InstrumentTab int
)
@ -221,6 +217,15 @@ func NewModel(broker *Broker, synthers []sointu.Synther, midiContext MIDIContext
return m
}
func FindMIDIDeviceByPrefix(c MIDIContext, prefix string) (input string, ok bool) {
for input := range c.InputDevices {
if strings.HasPrefix(input, prefix) {
return input, true
}
}
return "", false
}
func (m *Model) change(kind string, t ChangeType, severity ChangeSeverity) func() {
if m.changeLevel == 0 {
m.changeType = NoChange
@ -434,10 +439,10 @@ func (d *modelData) Copy() modelData {
return ret
}
func (m NullMIDIContext) InputDevices(yield func(MIDIDevice) bool) {}
func (m NullMIDIContext) Close() {}
func (m NullMIDIContext) HasDeviceOpen() bool { return false }
func (m NullMIDIContext) TryToOpenBy(name string, first bool) {}
func (m NullMIDIContext) InputDevices(yield func(string) bool) {}
func (m NullMIDIContext) Open(name string) error { return nil }
func (m NullMIDIContext) Close() {}
func (m NullMIDIContext) IsOpen() bool { return false }
func (m *Model) resetSong() {
m.d.Song = defaultSong.Copy()