diff --git a/src/jack.cpp b/src/jack.cpp index 8c42676..e19a3eb 100644 --- a/src/jack.cpp +++ b/src/jack.cpp @@ -1,5 +1,6 @@ /* $Id$ */ +#include #include #include #include diff --git a/src/notecache.cpp b/src/notecache.cpp new file mode 100644 index 0000000..65a4ded --- /dev/null +++ b/src/notecache.cpp @@ -0,0 +1,42 @@ +/* $Id$ */ + +#include +#include +#include "notecache.h" + +NoteCache::NoteCache() +{ + memset(m_notes, 0, sizeof m_notes); +} + +NoteCache::~NoteCache() +{ +} + +void NoteCache::Reset() +{ + memset(m_notes, 0, sizeof m_notes); +} + +void NoteCache::HandleEvent(jack_midi_event_t &event) +{ + uint8_t *buffer = event.buffer; + uint8_t cmd = buffer[0]; + + /* Note on or off event */ + if ((cmd & 0xE0) == 0x80) { + int8_t channel = cmd & 0x0F; + + for (uint i = 1; i < event.size; i += 2) { + int8_t note = buffer[i] & 0x7F; + int8_t velocity = buffer[i] & 0x7F; + if ((cmd & 0xF0) == 0x80) velocity = 0; + m_notes[channel][note] = velocity; + } + } else if ((cmd & 0xF0) == 0xB0 && buffer[1] == 0x7B) { + /* All notes off */ + int8_t channel = cmd & 0x0F; + memset(m_notes[channel], 0, sizeof m_notes[channel]); + } +} + diff --git a/src/notecache.h b/src/notecache.h index 6b2c906..54b3b8b 100644 --- a/src/notecache.h +++ b/src/notecache.h @@ -3,54 +3,24 @@ #ifndef NOTECACHE_H #define NOTECACHE_H -#include -#include +#include class NoteCache { private: int8_t m_notes[16][128]; public: - NoteCache() - { - memset(m_notes, 0, sizeof m_notes); - } + NoteCache(); + ~NoteCache(); - ~NoteCache() - { - } - - void Reset() - { - memset(m_notes, 0, sizeof m_notes); - } + void Reset(); int8_t GetNote(int8_t channel, int8_t note) const { return m_notes[channel][note]; } - void HandleEvent(jack_midi_event_t &event) - { - uint8_t *buffer = event.buffer; - uint8_t cmd = buffer[0]; - - /* Note on or off event */ - if ((cmd & 0xE0) == 0x80) { - int8_t channel = cmd & 0x0F; - - for (uint i = 1; i < event.size; i += 2) { - int8_t note = buffer[i] & 0x7F; - int8_t velocity = buffer[i] & 0x7F; - if ((cmd & 0xF0) == 0x80) velocity = 0; - m_notes[channel][note] = velocity; - } - } else if ((cmd & 0xF0) == 0xB0 && buffer[1] == 0x7B) { - /* All notes off */ - int8_t channel = cmd & 0x0F; - memset(m_notes[channel], 0, sizeof m_notes[channel]); - } - } + void HandleEvent(jack_midi_event_t &event); }; #endif /* NOTECACHE_H */ diff --git a/src/wscript b/src/wscript index fc7d9fe..0d0eced 100644 --- a/src/wscript +++ b/src/wscript @@ -8,6 +8,6 @@ def configure(conf): def build(bld): bld.new_task_gen( features = 'cxx cprogram', - source = 'jack.cpp loop.cpp mloop.cpp ui.cpp', + source = 'jack.cpp loop.cpp mloop.cpp notecache.cpp ui.cpp', target = 'mloop', uselib = 'JACK NCURSES')