feat(tracker): compile with midi support only when CGO is available

Also add the midi context to the VSTI, so VSTI can use MIDI if they
wish so.
This commit is contained in:
5684185+vsariola@users.noreply.github.com
2025-06-20 19:38:06 +03:00
parent 3881b8eb22
commit 602b3b05cc
7 changed files with 42 additions and 21 deletions

View File

@ -117,8 +117,11 @@ type (
InputDevices(yield func(MIDIDevice) bool)
Close()
HasDeviceOpen() bool
TryToOpenBy(name string, first bool)
}
NullMIDIContext struct{}
MIDIDevice interface {
String() string
Open() error
@ -385,6 +388,11 @@ 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 *Model) resetSong() {
m.d.Song = defaultSong.Copy()
for _, instr := range m.d.Song.Patch {

View File

@ -13,18 +13,10 @@ import (
type NullContext struct{}
func (NullContext) FinishBlock(frame int) {}
func (NullContext) BPM() (bpm float64, ok bool) {
return 0, false
}
func (NullContext) InputDevices(yield func(tracker.MIDIDevice) bool) {}
func (NullContext) HasDeviceOpen() bool { return false }
func (NullContext) Close() {}
type modelFuzzState struct {
model *tracker.Model
clipboard []byte
@ -261,7 +253,7 @@ func FuzzModel(f *testing.F) {
reader := bytes.NewReader(slice)
synther := vm.GoSynther{}
broker := tracker.NewBroker()
model := tracker.NewModel(broker, synther, NullContext{}, "")
model := tracker.NewModel(broker, synther, tracker.NullMIDIContext{}, "")
player := tracker.NewPlayer(broker, synther)
buf := make([][2]float32, 2048)
closeChan := make(chan struct{})

View File

@ -51,6 +51,8 @@ type (
BPM() (bpm float64, ok bool)
}
NullPlayerProcessContext struct{}
// NoteEvent describes triggering or releasing of a note. The timestamps are
// in frames, and relative to the clock of the event source. Different
// sources can use different clocks. Player tries to adjust the timestamps
@ -200,6 +202,10 @@ func (p *Player) advanceRow() {
p.send(nil) // just send volume and song row information
}
func (p NullPlayerProcessContext) BPM() (bpm float64, ok bool) {
return 0, false // no BPM available
}
func (p *Player) processMessages(context PlayerProcessContext) {
loop:
for { // process new message