30 |
pEngine = NULL; |
pEngine = NULL; |
31 |
pInstrument = NULL; |
pInstrument = NULL; |
32 |
pEvents = NULL; // we allocate when we retrieve the right Engine object |
pEvents = NULL; // we allocate when we retrieve the right Engine object |
33 |
pCCEvents = NULL; // we allocate when we retrieve the right Engine object |
pEventQueue = new RingBuffer<Event>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
|
pEventQueue = new RingBuffer<Event>(MAX_EVENTS_PER_FRAGMENT, 0); |
|
34 |
pActiveKeys = new Pool<uint>(128); |
pActiveKeys = new Pool<uint>(128); |
35 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
36 |
pMIDIKeyInfo[i].pActiveVoices = NULL; // we allocate when we retrieve the right Engine object |
pMIDIKeyInfo[i].pActiveVoices = NULL; // we allocate when we retrieve the right Engine object |
41 |
pMIDIKeyInfo[i].VoiceTheftsQueued = 0; |
pMIDIKeyInfo[i].VoiceTheftsQueued = 0; |
42 |
pMIDIKeyInfo[i].RoundRobinIndex = 0; |
pMIDIKeyInfo[i].RoundRobinIndex = 0; |
43 |
} |
} |
|
for (uint i = 0; i < Event::destination_count; i++) { |
|
|
pSynthesisEvents[i] = NULL; // we allocate when we retrieve the right Engine object |
|
|
} |
|
44 |
InstrumentIdx = -1; |
InstrumentIdx = -1; |
45 |
InstrumentStat = -1; |
InstrumentStat = -1; |
46 |
AudioDeviceChannelLeft = -1; |
AudioDeviceChannelLeft = -1; |
47 |
AudioDeviceChannelRight = -1; |
AudioDeviceChannelRight = -1; |
48 |
|
pMidiInputPort = NULL; |
49 |
|
midiChannel = midi_chan_all; |
50 |
|
ResetControllers(); |
51 |
} |
} |
52 |
|
|
53 |
EngineChannel::~EngineChannel() { |
EngineChannel::~EngineChannel() { |
59 |
} |
} |
60 |
|
|
61 |
/** |
/** |
62 |
|
* Implementation of virtual method from abstract EngineChannel interface. |
63 |
|
* This method will periodically be polled (e.g. by the LSCP server) to |
64 |
|
* check if some engine channel parameter has changed since the last |
65 |
|
* StatusChanged() call. |
66 |
|
* |
67 |
|
* This method can also be used to mark the engine channel as changed |
68 |
|
* from outside, e.g. by a MIDI input device. The optional argument |
69 |
|
* \a nNewStatus can be used for this. |
70 |
|
* |
71 |
|
* TODO: This "poll method" is just a lazy solution and might be |
72 |
|
* replaced in future. |
73 |
|
* @param bNewStatus - (optional, default: false) sets the new status flag |
74 |
|
* @returns true if engine channel status has changed since last |
75 |
|
* StatusChanged() call |
76 |
|
*/ |
77 |
|
bool EngineChannel::StatusChanged(bool bNewStatus) { |
78 |
|
bool b = bStatusChanged; |
79 |
|
bStatusChanged = bNewStatus; |
80 |
|
return b; |
81 |
|
} |
82 |
|
|
83 |
|
void EngineChannel::Reset() { |
84 |
|
if (pEngine) pEngine->DisableAndLock(); |
85 |
|
ResetInternal(); |
86 |
|
ResetControllers(); |
87 |
|
if (pEngine) { |
88 |
|
pEngine->Enable(); |
89 |
|
pEngine->Reset(); |
90 |
|
} |
91 |
|
} |
92 |
|
|
93 |
|
/** |
94 |
* This method is not thread safe! |
* This method is not thread safe! |
95 |
*/ |
*/ |
96 |
void EngineChannel::ResetInternal() { |
void EngineChannel::ResetInternal() { |
|
Pitch = 0; |
|
|
SustainPedal = false; |
|
|
GlobalVolume = 1.0; |
|
|
GlobalPanLeft = 1.0f; |
|
|
GlobalPanRight = 1.0f; |
|
97 |
CurrentKeyDimension = 0; |
CurrentKeyDimension = 0; |
98 |
|
|
|
ResetControllers(); |
|
|
|
|
99 |
// reset key info |
// reset key info |
100 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
101 |
if (pMIDIKeyInfo[i].pActiveVoices) |
if (pMIDIKeyInfo[i].pActiveVoices) |
120 |
pEventQueue->init(); |
pEventQueue->init(); |
121 |
|
|
122 |
if (pEngine) pEngine->ResetInternal(); |
if (pEngine) pEngine->ResetInternal(); |
123 |
|
|
124 |
|
// status of engine channel has changed, so set notify flag |
125 |
|
bStatusChanged = true; |
126 |
} |
} |
127 |
|
|
128 |
LinuxSampler::Engine* EngineChannel::GetEngine() { |
LinuxSampler::Engine* EngineChannel::GetEngine() { |
235 |
void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) { |
void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) { |
236 |
this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument()) |
this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument()) |
237 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
238 |
|
bStatusChanged = true; // status of engine has changed, so set notify flag |
239 |
} |
} |
240 |
|
|
241 |
/** |
/** |
247 |
void EngineChannel::OnResourceProgress(float fProgress) { |
void EngineChannel::OnResourceProgress(float fProgress) { |
248 |
this->InstrumentStat = int(fProgress * 100.0f); |
this->InstrumentStat = int(fProgress * 100.0f); |
249 |
dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat)); |
dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat)); |
250 |
|
bStatusChanged = true; // status of engine has changed, so set notify flag |
251 |
} |
} |
252 |
|
|
253 |
void EngineChannel::Connect(AudioOutputDevice* pAudioOut) { |
void EngineChannel::Connect(AudioOutputDevice* pAudioOut) { |
257 |
} |
} |
258 |
pEngine = Engine::AcquireEngine(this, pAudioOut); |
pEngine = Engine::AcquireEngine(this, pAudioOut); |
259 |
ResetInternal(); |
ResetInternal(); |
260 |
pEvents = new RTList<Event>(pEngine->pEventPool); |
pEvents = new RTList<Event>(pEngine->pEventPool); |
|
pCCEvents = new RTList<Event>(pEngine->pEventPool); |
|
|
for (uint i = 0; i < Event::destination_count; i++) { |
|
|
pSynthesisEvents[i] = new RTList<Event>(pEngine->pEventPool); |
|
|
} |
|
261 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
262 |
pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool); |
pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool); |
263 |
pMIDIKeyInfo[i].pEvents = new RTList<Event>(pEngine->pEventPool); |
pMIDIKeyInfo[i].pEvents = new RTList<Event>(pEngine->pEventPool); |
275 |
delete pEvents; |
delete pEvents; |
276 |
pEvents = NULL; |
pEvents = NULL; |
277 |
} |
} |
|
if (pCCEvents) { |
|
|
delete pCCEvents; |
|
|
pCCEvents = NULL; |
|
|
} |
|
278 |
for (uint i = 0; i < 128; i++) { |
for (uint i = 0; i < 128; i++) { |
279 |
if (pMIDIKeyInfo[i].pActiveVoices) { |
if (pMIDIKeyInfo[i].pActiveVoices) { |
280 |
delete pMIDIKeyInfo[i].pActiveVoices; |
delete pMIDIKeyInfo[i].pActiveVoices; |
285 |
pMIDIKeyInfo[i].pEvents = NULL; |
pMIDIKeyInfo[i].pEvents = NULL; |
286 |
} |
} |
287 |
} |
} |
|
for (uint i = 0; i < Event::destination_count; i++) { |
|
|
if (pSynthesisEvents[i]) { |
|
|
delete pSynthesisEvents[i]; |
|
|
pSynthesisEvents[i] = NULL; |
|
|
} |
|
|
} |
|
288 |
Engine* oldEngine = pEngine; |
Engine* oldEngine = pEngine; |
289 |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
290 |
pEngine = NULL; |
pEngine = NULL; |
324 |
} |
} |
325 |
} |
} |
326 |
|
|
327 |
|
void EngineChannel::Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) { |
328 |
|
if (!pMidiPort || pMidiPort == this->pMidiInputPort) return; |
329 |
|
DisconnectMidiInputPort(); |
330 |
|
this->pMidiInputPort = pMidiPort; |
331 |
|
this->midiChannel = MidiChannel; |
332 |
|
pMidiPort->Connect(this, MidiChannel); |
333 |
|
} |
334 |
|
|
335 |
|
void EngineChannel::DisconnectMidiInputPort() { |
336 |
|
MidiInputPort* pOldPort = this->pMidiInputPort; |
337 |
|
this->pMidiInputPort = NULL; |
338 |
|
if (pOldPort) pOldPort->Disconnect(this); |
339 |
|
} |
340 |
|
|
341 |
|
MidiInputPort* EngineChannel::GetMidiInputPort() { |
342 |
|
return pMidiInputPort; |
343 |
|
} |
344 |
|
|
345 |
|
midi_chan_t EngineChannel::MidiChannel() { |
346 |
|
return midiChannel; |
347 |
|
} |
348 |
|
|
349 |
/** |
/** |
350 |
* Will be called by the MIDIIn Thread to let the audio thread trigger a new |
* Will be called by the MIDIIn Thread to let the audio thread trigger a new |
351 |
* voice for the given key. |
* voice for the given key. |
422 |
|
|
423 |
void EngineChannel::ClearEventLists() { |
void EngineChannel::ClearEventLists() { |
424 |
pEvents->clear(); |
pEvents->clear(); |
|
pCCEvents->clear(); |
|
|
for (uint i = 0; i < Event::destination_count; i++) { |
|
|
pSynthesisEvents[i]->clear(); |
|
|
} |
|
425 |
// empty MIDI key specific event lists |
// empty MIDI key specific event lists |
426 |
{ |
{ |
427 |
RTList<uint>::Iterator iuiKey = pActiveKeys->first(); |
RTList<uint>::Iterator iuiKey = pActiveKeys->first(); |
433 |
} |
} |
434 |
|
|
435 |
void EngineChannel::ResetControllers() { |
void EngineChannel::ResetControllers() { |
436 |
|
Pitch = 0; |
437 |
|
SustainPedal = false; |
438 |
|
SostenutoPedal = false; |
439 |
|
GlobalVolume = 1.0; |
440 |
|
GlobalPanLeft = 1.0f; |
441 |
|
GlobalPanRight = 1.0f; |
442 |
// set all MIDI controller values to zero |
// set all MIDI controller values to zero |
443 |
memset(ControllerTable, 0x00, 128); |
memset(ControllerTable, 0x00, 128); |
444 |
} |
} |
485 |
|
|
486 |
void EngineChannel::Volume(float f) { |
void EngineChannel::Volume(float f) { |
487 |
GlobalVolume = f; |
GlobalVolume = f; |
488 |
|
bStatusChanged = true; // status of engine channel has changed, so set notify flag |
489 |
} |
} |
490 |
|
|
491 |
uint EngineChannel::Channels() { |
uint EngineChannel::Channels() { |
511 |
String EngineChannel::EngineName() { |
String EngineChannel::EngineName() { |
512 |
return LS_GIG_ENGINE_NAME; |
return LS_GIG_ENGINE_NAME; |
513 |
} |
} |
514 |
|
|
515 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |