Skip to content

Commit

Permalink
prevent note preview while playing
Browse files Browse the repository at this point in the history
  • Loading branch information
xaviergodart committed Aug 9, 2024
1 parent 117188d commit 05ef86e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions sequencer/pattern.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions sequencer/sequencer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions sequencer/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 6 additions & 1 deletion sequencer/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 05ef86e

Please sign in to comment.