-Split off notecache code into its own file instead of in the header.
git-svn-id: http://svn.fuzzle.org/mloop/trunk@14 ba049829-c6ef-42ef-81ac-908dd8d2e907master
parent
40dc1d0de9
commit
070414d450
|
@ -1,5 +1,6 @@
|
|||
/* $Id$ */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <jack/jack.h>
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
/* $Id$ */
|
||||
|
||||
#include <string.h>
|
||||
#include <jack/midiport.h>
|
||||
#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]);
|
||||
}
|
||||
}
|
||||
|
|
@ -3,54 +3,24 @@
|
|||
#ifndef NOTECACHE_H
|
||||
#define NOTECACHE_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <jack/midiport.h>
|
||||
|
||||
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 */
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Reference in New Issue