Clean up state tracking of raw MIDI.

This commit is contained in:
David Robillard 2014-11-30 18:33:22 -05:00
parent 0f72ea4a34
commit 008bfceb77
4 changed files with 22 additions and 39 deletions

View file

@ -57,25 +57,7 @@ public:
void flush (framepos_t start, framepos_t end);
void reset_tracker ();
void loop_resolve (MidiBuffer& dst, framepos_t);
protected:
inline bool is_channel_event(uint8_t event_type_byte) {
// mask out channel information
event_type_byte &= 0xF0;
// midi channel events range from 0x80 to 0xE0
return (0x80 <= event_type_byte) && (event_type_byte <= 0xE0);
}
inline bool is_note_on(uint8_t event_type_byte) {
// mask out channel information
return (event_type_byte & 0xF0) == MIDI_CMD_NOTE_ON;
}
inline bool is_note_off(uint8_t event_type_byte) {
// mask out channel information
return (event_type_byte & 0xF0) == MIDI_CMD_NOTE_OFF;
}
void loop_resolve (MidiBuffer& dst, framepos_t);
private:
MidiStateTracker _tracker;

View file

@ -39,6 +39,7 @@ public:
MidiStateTracker();
void track (const MidiBuffer::const_iterator& from, const MidiBuffer::const_iterator& to);
void track (const uint8_t* evbuf);
void add (uint8_t note, uint8_t chn);
void remove (uint8_t note, uint8_t chn);
void resolve_notes (MidiBuffer& buffer, framepos_t time);
@ -54,19 +55,7 @@ public:
template<typename Time>
void track (const Evoral::Event<Time>& ev) {
const uint8_t type = ev.buffer()[0] & 0xF0;
const uint8_t chan = ev.buffer()[0] & 0x0F;
switch (type) {
case MIDI_CTL_ALL_NOTES_OFF:
reset();
break;
case MIDI_CMD_NOTE_ON:
add(ev.buffer()[1], chan);
break;
case MIDI_CMD_NOTE_OFF:
remove(ev.buffer()[1], chan);
break;
}
track (ev.buffer());
}
private:

View file

@ -114,13 +114,7 @@ MidiRingBuffer<T>::read(MidiBuffer& dst, framepos_t start, framepos_t end, frame
#endif
if (success) {
if (is_note_on(write_loc[0]) ) {
_tracker.add (write_loc[1], write_loc[0] & 0xf);
} else if (is_note_off(write_loc[0])) {
_tracker.remove (write_loc[1], write_loc[0] & 0xf);
}
_tracker.track(write_loc);
++count;
} else {
cerr << "WARNING: error reading event contents from MIDI ring" << endl;

View file

@ -91,6 +91,24 @@ MidiStateTracker::track (const MidiBuffer::const_iterator &from, const MidiBuffe
}
}
void
MidiStateTracker::track (const uint8_t* evbuf)
{
const uint8_t type = evbuf[0] & 0xF0;
const uint8_t chan = evbuf[0] & 0x0F;
switch (type) {
case MIDI_CTL_ALL_NOTES_OFF:
reset();
break;
case MIDI_CMD_NOTE_ON:
add(evbuf[1], chan);
break;
case MIDI_CMD_NOTE_OFF:
remove(evbuf[1], chan);
break;
}
}
void
MidiStateTracker::resolve_notes (MidiBuffer &dst, framepos_t time)
{