Skip to content

Commit 1396000

Browse files
committed
Improved the logic of sequencer
1 parent 49dbced commit 1396000

1 file changed

Lines changed: 28 additions & 22 deletions

File tree

Applications/Sequencer/PatternPad.cpp

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,20 @@ bool PatternPad::KeyEvent(Point xy, KeyInfo* keyInfo)
198198
}
199199
}
200200

201-
// Populate noteActive with notes from this step and send MIDI NoteOn
202-
auto it = pattern->events.lower_bound(startTime);
203-
while (it != pattern->events.end() && it->first <= endTime)
201+
// Populate noteActive with notes from this step and send MIDI NoteOn - Only while not playing
202+
if(!sequencer->sequence.Playing())
204203
{
205-
if (it->second.eventType == SequenceEventType::NoteEvent)
204+
auto it = pattern->events.lower_bound(startTime);
205+
while (it != pattern->events.end() && it->first <= endTime)
206206
{
207-
const SequenceEventNote& noteData = std::get<SequenceEventNote>(it->second.data);
208-
sequencer->noteActive.insert(noteData.note);
209-
MatrixOS::MIDI::Send(MidiPacket::NoteOn(channel, noteData.note, noteData.velocity), MIDI_PORT_ALL);
207+
if (it->second.eventType == SequenceEventType::NoteEvent)
208+
{
209+
const SequenceEventNote& noteData = std::get<SequenceEventNote>(it->second.data);
210+
sequencer->noteActive.insert(noteData.note);
211+
MatrixOS::MIDI::Send(MidiPacket::NoteOn(channel, noteData.note, noteData.velocity), MIDI_PORT_ALL);
212+
}
213+
++it;
210214
}
211-
++it;
212215
}
213216
}
214217
else if(keyInfo->state == RELEASED)
@@ -220,26 +223,29 @@ bool PatternPad::KeyEvent(Point xy, KeyInfo* keyInfo)
220223
sequencer->stepSelected.erase(stepIt);
221224
}
222225

223-
// Clear noteActive from notes in this step and send MIDI NoteOff
224-
auto eventIt = pattern->events.lower_bound(startTime);
225-
while (eventIt != pattern->events.end() && eventIt->first <= endTime)
226+
// Clear noteActive from notes in this step and send MIDI NoteOff - Only while not playing
227+
if(!sequencer->sequence.Playing())
226228
{
227-
if (eventIt->second.eventType == SequenceEventType::NoteEvent)
229+
auto eventIt = pattern->events.lower_bound(startTime);
230+
while (eventIt != pattern->events.end() && eventIt->first <= endTime)
228231
{
229-
const SequenceEventNote& noteData = std::get<SequenceEventNote>(eventIt->second.data);
230-
auto noteIt = sequencer->noteActive.find(noteData.note);
231-
if (noteIt != sequencer->noteActive.end())
232+
if (eventIt->second.eventType == SequenceEventType::NoteEvent)
232233
{
233-
sequencer->noteActive.erase(noteIt);
234-
}
234+
const SequenceEventNote& noteData = std::get<SequenceEventNote>(eventIt->second.data);
235+
auto noteIt = sequencer->noteActive.find(noteData.note);
236+
if (noteIt != sequencer->noteActive.end())
237+
{
238+
sequencer->noteActive.erase(noteIt);
239+
}
235240

236-
// Only send NoteOff if note is not currently selected on NotePad
237-
if(sequencer->noteSelected.find(noteData.note) == sequencer->noteSelected.end())
238-
{
239-
MatrixOS::MIDI::Send(MidiPacket::NoteOff(channel, noteData.note, 0), MIDI_PORT_ALL);
241+
// Only send NoteOff if note is not currently selected on NotePad
242+
if(sequencer->noteSelected.find(noteData.note) == sequencer->noteSelected.end())
243+
{
244+
MatrixOS::MIDI::Send(MidiPacket::NoteOff(channel, noteData.note, 0), MIDI_PORT_ALL);
245+
}
240246
}
247+
++eventIt;
241248
}
242-
++eventIt;
243249
}
244250
}
245251

0 commit comments

Comments
 (0)