26 |
#include <algorithm> |
#include <algorithm> |
27 |
#include <functional> |
#include <functional> |
28 |
|
|
|
#define MIDI_KEYS 128 |
|
|
|
|
|
struct _private_data_t { |
|
|
atomic_t notesChanged; // whether some key changed at all |
|
|
atomic_t pNoteChanged[MIDI_KEYS]; // which key(s) changed |
|
|
atomic_t pNoteIsActive[MIDI_KEYS]; // status of each key (either active or inactive) |
|
|
}; |
|
|
|
|
29 |
namespace LinuxSampler { |
namespace LinuxSampler { |
30 |
|
|
31 |
InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) { |
InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) { |
32 |
pInstrument = NULL; |
pInstrument = NULL; |
|
_private_data_t* p = new _private_data_t; |
|
|
pPrivateData = p; |
|
|
atomic_t zero = ATOMIC_INIT(0); |
|
|
p->notesChanged = zero; |
|
|
for (int i = 0; i < MIDI_KEYS; i++) { |
|
|
p->pNoteChanged[i] = zero; |
|
|
p->pNoteIsActive[i] = zero; |
|
|
} |
|
33 |
} |
} |
34 |
|
|
35 |
InstrumentEditor::~InstrumentEditor() { |
InstrumentEditor::~InstrumentEditor() { |
|
if (pPrivateData) delete (_private_data_t*)pPrivateData; |
|
36 |
} |
} |
37 |
|
|
38 |
void InstrumentEditor::Launch(void* pInstrument, String sTypeName, String sTypeVersion) { |
void InstrumentEditor::Launch(void* pInstrument, String sTypeName, String sTypeVersion) { |
63 |
return iResult; |
return iResult; |
64 |
} |
} |
65 |
|
|
|
void InstrumentEditor::SendNoteOnToEditor(uint8_t Key, uint8_t /*Velocity*/) { |
|
|
if (Key >= MIDI_KEYS) return; |
|
|
_private_data_t* p = (_private_data_t*)pPrivateData; |
|
|
atomic_inc( &(p->pNoteIsActive)[Key] ); |
|
|
atomic_inc( &(p->pNoteChanged)[Key] ); |
|
|
atomic_inc( &p->notesChanged ); |
|
|
} |
|
|
|
|
|
void InstrumentEditor::SendNoteOffToEditor(uint8_t Key, uint8_t /*Velocity*/) { |
|
|
if (Key >= MIDI_KEYS) return; |
|
|
_private_data_t* p = (_private_data_t*)pPrivateData; |
|
|
atomic_dec( &(p->pNoteIsActive)[Key] ); |
|
|
atomic_inc( &(p->pNoteChanged)[Key] ); |
|
|
atomic_inc( &p->notesChanged ); |
|
|
} |
|
|
|
|
|
bool InstrumentEditor::NotesChanged() { |
|
|
_private_data_t* p = (_private_data_t*)pPrivateData; |
|
|
int c = atomic_read( &p->notesChanged ); |
|
|
atomic_sub(c, &p->notesChanged ); |
|
|
return c; |
|
|
} |
|
|
|
|
|
bool InstrumentEditor::NoteChanged(uint8_t Key) { |
|
|
_private_data_t* p = (_private_data_t*)pPrivateData; |
|
|
int c = atomic_read( &(p->pNoteChanged)[Key] ); |
|
|
atomic_sub(c, &(p->pNoteChanged)[Key] ); |
|
|
return c; |
|
|
} |
|
|
|
|
|
bool InstrumentEditor::NoteIsActive(uint8_t Key) { |
|
|
_private_data_t* p = (_private_data_t*)pPrivateData; |
|
|
return atomic_read( &(p->pNoteIsActive)[Key] ); |
|
|
} |
|
|
|
|
66 |
void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) { |
void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) { |
67 |
listeners.insert(pListener); |
listeners.insert(pListener); |
68 |
} |
} |