From c421748db938f129c9f44800e3c16c14e7b178ea Mon Sep 17 00:00:00 2001 From: "5684185+vsariola@users.noreply.github.com" <5684185+vsariola@users.noreply.github.com> Date: Mon, 17 Jul 2023 21:56:17 +0300 Subject: [PATCH] fix: if fetching BPM from vsti host fails, keep the previous BPM as defined by the user --- cmd/sointu-vsti/main.go | 3 +++ tracker/model.go | 3 +++ tracker/player.go | 5 +---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/cmd/sointu-vsti/main.go b/cmd/sointu-vsti/main.go index c4893b5..a9ffa83 100644 --- a/cmd/sointu-vsti/main.go +++ b/cmd/sointu-vsti/main.go @@ -36,6 +36,9 @@ func (c *VSTIProcessContext) NextEvent() (event tracker.PlayerProcessEvent, ok b func (c *VSTIProcessContext) BPM() (bpm float64, ok bool) { timeInfo := c.host.GetTimeInfo() + if timeInfo == nil || timeInfo.Flags&vst2.TempoValid == 0 || timeInfo.Tempo == 0 { + return 0, false + } return timeInfo.Tempo, true } diff --git a/tracker/model.go b/tracker/model.go index 88fb985..bb06b7b 100644 --- a/tracker/model.go +++ b/tracker/model.go @@ -161,6 +161,9 @@ func (m *Model) ProcessPlayerMessage(msg PlayerMessage) { case PlayerCrashMessage: m.panic = true case PlayerRecordedMessage: + if e.BPM == 0 { + e.BPM = float64(m.song.BPM) + } song := RecordingToSong(m.song.Patch, m.song.RowsPerBeat, m.song.Score.RowsPerPattern, e) m.SetSong(song) m.instrEnlarged = false diff --git a/tracker/player.go b/tracker/player.go index 4bb4b18..2d2df56 100644 --- a/tracker/player.go +++ b/tracker/player.go @@ -277,10 +277,7 @@ loop: p.recordingNoteArrived = false } else { if p.recording && len(p.recordingEvents) > 0 { - bpm, ok := context.BPM() - if !ok { - bpm = 120 - } + bpm, _ := context.BPM() p.trySend(PlayerRecordedMessage{ BPM: bpm, Events: p.recordingEvents,