From 05ef86e00ce120dabf297e7c8003eae8fad1b85e Mon Sep 17 00:00:00 2001 From: Xavier Godart Date: Fri, 9 Aug 2024 09:52:21 +0200 Subject: [PATCH] prevent note preview while playing --- sequencer/pattern.go | 1 + sequencer/sequencer.go | 1 + sequencer/step.go | 3 +++ sequencer/track.go | 7 ++++++- 4 files changed, 11 insertions(+), 1 deletion(-) diff --git a/sequencer/pattern.go b/sequencer/pattern.go index f3eb3d9..04c27a7 100644 --- a/sequencer/pattern.go +++ b/sequencer/pattern.go @@ -123,6 +123,7 @@ func (s *sequencer) Load(pattern int) { s.tracks = append(s.tracks, &track{ midi: s.midi, + seq: s, steps: []*step{}, chord: t.Chord, length: t.Length, diff --git a/sequencer/sequencer.go b/sequencer/sequencer.go index 1a2d515..259b7ba 100644 --- a/sequencer/sequencer.go +++ b/sequencer/sequencer.go @@ -126,6 +126,7 @@ func (s *sequencer) AddTrack() { channel := len(s.tracks) track := &track{ midi: s.midi, + seq: s, pulse: pulse, chord: []uint8{defaultNote}, length: pulsesPerStep, diff --git a/sequencer/step.go b/sequencer/step.go index 4f90a73..f8d60c2 100644 --- a/sequencer/step.go +++ b/sequencer/step.go @@ -182,6 +182,9 @@ func (s *step) SetChord(chord []uint8) { if note < minChordNote || note > maxChordNote { return } + if s.track.seq.isPlaying { + continue + } go func(note uint8) { s.midi.NoteOn(s.track.device, s.track.channel, note, s.Velocity()) time.Sleep(time.Second) diff --git a/sequencer/track.go b/sequencer/track.go index 98cfab6..e4e6c53 100644 --- a/sequencer/track.go +++ b/sequencer/track.go @@ -24,7 +24,9 @@ type Track interface { } type track struct { - midi midi.Midi + midi midi.Midi + seq *sequencer + steps []*step // The pulse defines the current position of the playhead in the track. @@ -214,6 +216,9 @@ func (t *track) SetChord(chord []uint8) { if note < minChordNote || note > maxChordNote { return } + if t.seq.isPlaying { + continue + } go func(note uint8) { t.midi.NoteOn(t.device, t.channel, note, t.Velocity()) time.Sleep(time.Second)