1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2007, 2008 Christian Schoenebeck * |
* Copyright (C) 2007 - 2009 Christian Schoenebeck * |
4 |
* * |
* * |
5 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
6 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
21 |
#include "InstrumentEditor.h" |
#include "InstrumentEditor.h" |
22 |
|
|
23 |
#include "../common/global_private.h" |
#include "../common/global_private.h" |
|
#include "../common/atomic.h" |
|
24 |
|
|
25 |
#include <algorithm> |
#include <algorithm> |
26 |
#include <functional> |
#include <functional> |
27 |
|
|
|
#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) |
|
|
}; |
|
|
|
|
28 |
namespace LinuxSampler { |
namespace LinuxSampler { |
29 |
|
|
30 |
InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) { |
InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) { |
31 |
pInstrument = NULL; |
pInstrument = NULL; |
32 |
_private_data_t* p = new _private_data_t; |
pUserData = NULL; |
|
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, void* pUserData) { |
39 |
dmsg(1,("InstrumentEditor::Launch(instr=%x,type=%s,version=%s)\n", pInstrument, sTypeName.c_str(), sTypeVersion.c_str())); |
dmsg(1,("InstrumentEditor::Launch(instr=%x,type=%s,version=%s)\n", pInstrument, sTypeName.c_str(), sTypeVersion.c_str())); |
40 |
// prepare the editor's mandatory parameters |
// prepare the editor's mandatory parameters |
41 |
this->pInstrument = pInstrument; |
this->pInstrument = pInstrument; |
42 |
this->sTypeName = sTypeName; |
this->sTypeName = sTypeName; |
43 |
this->sTypeVersion = sTypeVersion; |
this->sTypeVersion = sTypeVersion; |
44 |
|
this->pUserData = pUserData; |
45 |
// start the editor in its own thread |
// start the editor in its own thread |
46 |
StartThread(); |
StartThread(); |
47 |
} |
} |
49 |
int InstrumentEditor::Main() { |
int InstrumentEditor::Main() { |
50 |
dmsg(1,("InstrumentEditor::Main()\n")); |
dmsg(1,("InstrumentEditor::Main()\n")); |
51 |
// run the editor's main loop |
// run the editor's main loop |
52 |
int iResult = Main(pInstrument, sTypeName, sTypeVersion); |
int iResult = Main(pInstrument, sTypeName, sTypeVersion, pUserData); |
53 |
// reset editor parameters |
// reset editor parameters |
54 |
this->pInstrument = NULL; |
this->pInstrument = NULL; |
55 |
this->sTypeName = ""; |
this->sTypeName = ""; |
56 |
this->sTypeVersion = ""; |
this->sTypeVersion = ""; |
57 |
|
this->pUserData = NULL; |
58 |
dmsg(1,("Instrument editor '%s' returned with exit status %d\n", Name().c_str(), iResult)); |
dmsg(1,("Instrument editor '%s' returned with exit status %d\n", Name().c_str(), iResult)); |
59 |
// notify all registered listeners |
// notify all registered listeners |
60 |
std::for_each( |
std::for_each( |
65 |
return iResult; |
return iResult; |
66 |
} |
} |
67 |
|
|
|
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] ); |
|
|
} |
|
|
|
|
68 |
void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) { |
void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) { |
69 |
listeners.insert(pListener); |
listeners.insert(pListener); |
70 |
} |
} |