fix(sointu-vsti): VST crashed due to Model.MIDI being nil

This commit is contained in:
5684185+vsariola@users.noreply.github.com 2024-10-14 16:57:21 +03:00
parent c07d8000c6
commit f427eca1f4
3 changed files with 19 additions and 7 deletions

View File

@ -54,7 +54,8 @@ func main() {
recoveryFile = filepath.Join(configDir, "Sointu", "sointu-track-recovery") recoveryFile = filepath.Join(configDir, "Sointu", "sointu-track-recovery")
} }
model, player := tracker.NewModelPlayer(cmd.MainSynther, recoveryFile) model, player := tracker.NewModelPlayer(cmd.MainSynther, recoveryFile)
model.MIDI = gomidi.NewContext() midiContext := gomidi.NewContext()
model.MIDI = midiContext
defer model.MIDI.Close() defer model.MIDI.Close()
if a := flag.Args(); len(a) > 0 { if a := flag.Args(); len(a) > 0 {
f, err := os.Open(a[0]) f, err := os.Open(a[0])
@ -64,7 +65,7 @@ func main() {
f.Close() f.Close()
} }
tracker := gioui.NewTracker(model) tracker := gioui.NewTracker(model)
audioCloser := audioContext.Play(&PlayerAudioSource{player, model.MIDI}) audioCloser := audioContext.Play(&PlayerAudioSource{player, midiContext})
go func() { go func() {
tracker.Main() tracker.Main()
audioCloser.Close() audioCloser.Close()

View File

@ -17,12 +17,22 @@ import (
"pipelined.dev/audio/vst2" "pipelined.dev/audio/vst2"
) )
type VSTIProcessContext struct { type (
events []vst2.MIDIEvent VSTIProcessContext struct {
eventIndex int events []vst2.MIDIEvent
host vst2.Host eventIndex int
host vst2.Host
}
NullMIDIContext struct{}
)
func (m *NullMIDIContext) ListInputDevices() func(yield func(tracker.MIDIDevice) bool) {
return func(yield func(tracker.MIDIDevice) bool) {}
} }
func (m *NullMIDIContext) Close() {}
func (c *VSTIProcessContext) NextEvent() (event tracker.MIDINoteEvent, ok bool) { func (c *VSTIProcessContext) NextEvent() (event tracker.MIDINoteEvent, ok bool) {
for c.eventIndex < len(c.events) { for c.eventIndex < len(c.events) {
ev := c.events[c.eventIndex] ev := c.events[c.eventIndex]
@ -63,6 +73,8 @@ func init() {
recoveryFile = filepath.Join(configDir, "sointu", "sointu-vsti-recovery-"+hex.EncodeToString(randBytes)) recoveryFile = filepath.Join(configDir, "sointu", "sointu-vsti-recovery-"+hex.EncodeToString(randBytes))
} }
model, player := tracker.NewModelPlayer(cmd.MainSynther, recoveryFile) model, player := tracker.NewModelPlayer(cmd.MainSynther, recoveryFile)
model.MIDI = &NullMIDIContext{}
t := gioui.NewTracker(model) t := gioui.NewTracker(model)
tracker.Bool{BoolData: (*tracker.InstrEnlarged)(model)}.Set(true) tracker.Bool{BoolData: (*tracker.InstrEnlarged)(model)}.Set(true)
go t.Main() go t.Main()

View File

@ -126,7 +126,6 @@ type (
MIDIContext interface { MIDIContext interface {
ListInputDevices() func(yield func(MIDIDevice) bool) ListInputDevices() func(yield func(MIDIDevice) bool)
Close() Close()
PlayerProcessContext
} }
MIDIDevice interface { MIDIDevice interface {