1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2007 Christian Schoenebeck * |
* Copyright (C) 2007, 2008 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" |
24 |
|
#include "../common/atomic.h" |
25 |
|
|
26 |
#include <algorithm> |
#include <algorithm> |
27 |
#include <functional> |
#include <functional> |
28 |
|
|
29 |
|
#define MIDI_KEYS 128 |
30 |
|
|
31 |
namespace LinuxSampler { |
namespace LinuxSampler { |
32 |
|
|
33 |
InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) { |
InstrumentEditor::InstrumentEditor() : Thread(false, false, -1, 0) { |
34 |
pInstrument = NULL; |
pInstrument = NULL; |
35 |
|
pNotesChanged = new atomic_t; |
36 |
|
pNoteChanged = new atomic_t[MIDI_KEYS]; |
37 |
|
pNoteIsActive = new atomic_t[MIDI_KEYS]; |
38 |
|
atomic_t zero = ATOMIC_INIT(0); |
39 |
|
for (int i = 0; i < MIDI_KEYS; i++) { |
40 |
|
((atomic_t*)pNoteChanged)[i] = zero; |
41 |
|
((atomic_t*)pNoteIsActive)[i] = zero; |
42 |
|
} |
43 |
|
*((atomic_t*)pNotesChanged) = zero; |
44 |
|
} |
45 |
|
|
46 |
|
InstrumentEditor::~InstrumentEditor() { |
47 |
|
if (pNoteIsActive) delete[] (atomic_t*)pNoteIsActive; |
48 |
|
if (pNoteChanged) delete[] (atomic_t*)pNoteChanged; |
49 |
|
if (pNotesChanged) delete (atomic_t*)pNotesChanged; |
50 |
} |
} |
51 |
|
|
52 |
void InstrumentEditor::Launch(void* pInstrument, String sTypeName, String sTypeVersion) { |
void InstrumentEditor::Launch(void* pInstrument, String sTypeName, String sTypeVersion) { |
77 |
return iResult; |
return iResult; |
78 |
} |
} |
79 |
|
|
80 |
|
void InstrumentEditor::SendNoteOnToEditor(uint8_t Key, uint8_t /*Velocity*/) { |
81 |
|
if (Key >= MIDI_KEYS) return; |
82 |
|
atomic_inc( &((atomic_t*)pNoteIsActive)[Key] ); |
83 |
|
atomic_inc( &((atomic_t*)pNoteChanged)[Key] ); |
84 |
|
atomic_inc( (atomic_t*)pNotesChanged ); |
85 |
|
} |
86 |
|
|
87 |
|
void InstrumentEditor::SendNoteOffToEditor(uint8_t Key, uint8_t /*Velocity*/) { |
88 |
|
if (Key >= MIDI_KEYS) return; |
89 |
|
atomic_dec( &((atomic_t*)pNoteIsActive)[Key] ); |
90 |
|
atomic_inc( &((atomic_t*)pNoteChanged)[Key] ); |
91 |
|
atomic_inc( (atomic_t*)pNotesChanged ); |
92 |
|
} |
93 |
|
|
94 |
|
bool InstrumentEditor::NotesChanged() { |
95 |
|
int c = atomic_read( (atomic_t*)pNotesChanged ); |
96 |
|
atomic_sub(c, (atomic_t*)pNotesChanged ); |
97 |
|
return c; |
98 |
|
} |
99 |
|
|
100 |
|
bool InstrumentEditor::NoteChanged(uint8_t Key) { |
101 |
|
int c = atomic_read( &((atomic_t*)pNoteChanged)[Key] ); |
102 |
|
atomic_sub(c, &((atomic_t*)pNoteChanged)[Key] ); |
103 |
|
return c; |
104 |
|
} |
105 |
|
|
106 |
|
bool InstrumentEditor::NoteIsActive(uint8_t Key) { |
107 |
|
return atomic_read( &((atomic_t*)pNoteIsActive)[Key] ); |
108 |
|
} |
109 |
|
|
110 |
void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) { |
void InstrumentEditor::AddListener(InstrumentEditorListener* pListener) { |
111 |
listeners.insert(pListener); |
listeners.insert(pListener); |
112 |
} |
} |