4 |
* * |
* * |
5 |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
* Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009-2011 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
8 |
|
* Copyright (C) 2012-2017 Christian Schoenebeck and Andreas Persson * |
9 |
* * |
* * |
10 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
11 |
* 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 * |
40 |
bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. |
bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. |
41 |
I* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. |
I* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. |
42 |
RTList<R*>* pRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. |
RTList<R*>* pRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. |
43 |
|
InstrumentScript* pScript; ///< Instrument script to be executed for this instrument. This is never NULL, it is always a valid InstrumentScript pointer. Use InstrumentScript::bHasValidScript whether it reflects a valid instrument script to be executed. |
44 |
}; |
}; |
45 |
|
|
46 |
template<class R> |
template<class R> |
50 |
}; |
}; |
51 |
|
|
52 |
template<class V> |
template<class V> |
53 |
class VoicePool { |
class NotePool { |
54 |
public: |
public: |
55 |
|
/** |
56 |
|
* Pool from where Voice objects are allocated from (and freed back to). |
57 |
|
*/ |
58 |
virtual Pool<V>* GetVoicePool() = 0; |
virtual Pool<V>* GetVoicePool() = 0; |
59 |
|
|
60 |
|
/** |
61 |
|
* Pool from where new Note objects are allocated from (and freed back to). |
62 |
|
*/ |
63 |
|
virtual Pool< Note<V> >* GetNotePool() = 0; |
64 |
|
|
65 |
|
/** |
66 |
|
* Pool for saving already existing Note object IDs somewhere. |
67 |
|
* |
68 |
|
* @b IMPORTANT: This pool is @b NOT used for generating any IDs for |
69 |
|
* Note objects! The respective Note objective IDs are emitted by |
70 |
|
* the Note object pool (see GetNotePool() above). |
71 |
|
*/ |
72 |
|
virtual Pool<note_id_t>* GetNoteIDPool() = 0; |
73 |
}; |
}; |
74 |
|
|
75 |
template <class V /* Voice */, class R /* Region */, class I /* Instrument */> |
template <class V /* Voice */, class R /* Region */, class I /* Instrument */> |
76 |
class EngineChannelBase: public AbstractEngineChannel, public MidiKeyboardManager<V>, public ResourceConsumer<I> { |
class EngineChannelBase: public AbstractEngineChannel, public MidiKeyboardManager<V>, public ResourceConsumer<I> { |
77 |
public: |
public: |
78 |
|
typedef typename RTList< Note<V> >::Iterator NoteIterator; |
79 |
typedef typename RTList<R*>::Iterator RTListRegionIterator; |
typedef typename RTList<R*>::Iterator RTListRegionIterator; |
80 |
typedef typename MidiKeyboardManager<V>::MidiKey MidiKey; |
typedef typename MidiKeyboardManager<V>::MidiKey MidiKey; |
81 |
|
|
82 |
|
virtual MidiKeyboardManagerBase* GetMidiKeyboardManager() OVERRIDE { |
83 |
|
return this; |
84 |
|
} |
85 |
|
|
86 |
virtual void HandBack(I* Instrument) { |
virtual void HandBack(I* Instrument) { |
87 |
ResourceManager<InstrumentManager::instrument_id_t, I>* mgr = |
ResourceManager<InstrumentManager::instrument_id_t, I>* mgr = |
88 |
dynamic_cast<ResourceManager<InstrumentManager::instrument_id_t, I>*>(pEngine->GetInstrumentManager()); |
dynamic_cast<ResourceManager<InstrumentManager::instrument_id_t, I>*>(pEngine->GetInstrumentManager()); |
108 |
} |
} |
109 |
|
|
110 |
virtual void DeleteRegionsInUse() { |
virtual void DeleteRegionsInUse() { |
111 |
|
RTList<R*>* previous = NULL; // prevent double free |
112 |
{ |
{ |
113 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
114 |
if (cmd.pRegionsInUse) { |
if (cmd.pRegionsInUse) { |
115 |
|
previous = cmd.pRegionsInUse; |
116 |
delete cmd.pRegionsInUse; |
delete cmd.pRegionsInUse; |
117 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
118 |
} |
} |
121 |
{ |
{ |
122 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
123 |
if (cmd.pRegionsInUse) { |
if (cmd.pRegionsInUse) { |
124 |
delete cmd.pRegionsInUse; |
if (cmd.pRegionsInUse != previous) |
125 |
|
delete cmd.pRegionsInUse; |
126 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
127 |
} |
} |
128 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
142 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
virtual void Connect(AudioOutputDevice* pAudioOut) { |
virtual void Connect(AudioOutputDevice* pAudioOut) OVERRIDE { |
146 |
if (pEngine) { |
if (pEngine) { |
147 |
if (pEngine->pAudioOutputDevice == pAudioOut) return; |
if (pEngine->pAudioOutputDevice == pAudioOut) return; |
148 |
DisconnectAudioOutputDevice(); |
DisconnectAudioOutputDevice(); |
149 |
} |
} |
150 |
pEngine = AbstractEngine::AcquireEngine(this, pAudioOut); |
AbstractEngine* newEngine = AbstractEngine::AcquireEngine(this, pAudioOut); |
151 |
ResetInternal(); |
{ |
152 |
|
LockGuard lock(EngineMutex); |
153 |
|
pEngine = newEngine; |
154 |
|
} |
155 |
|
ResetInternal(false/*don't reset engine*/); // 'false' is error prone here, but the danger of recursion with 'true' would be worse, there could be a better solution though |
156 |
pEvents = new RTList<Event>(pEngine->pEventPool); |
pEvents = new RTList<Event>(pEngine->pEventPool); |
157 |
|
delayedEvents.pList = new RTList<Event>(pEngine->pEventPool); |
158 |
|
|
159 |
RegionPools<R>* pRegionPool = dynamic_cast<RegionPools<R>*>(pEngine); |
RegionPools<R>* pRegionPool = dynamic_cast<RegionPools<R>*>(pEngine); |
160 |
// reset the instrument change command struct (need to be done |
// reset the instrument change command struct (need to be done |
181 |
bStatusChanged = true; |
bStatusChanged = true; |
182 |
} |
} |
183 |
|
|
184 |
VoicePool<V>* pVoicePool = dynamic_cast<VoicePool<V>*>(pEngine); |
NotePool<V>* pNotePool = dynamic_cast<NotePool<V>*>(pEngine); |
185 |
MidiKeyboardManager<V>::AllocateActiveVoices(pVoicePool->GetVoicePool()); |
MidiKeyboardManager<V>::AllocateActiveNotesLists( |
186 |
MidiKeyboardManager<V>::AllocateEvents(pEngine->pEventPool); |
pNotePool->GetNotePool(), |
187 |
|
pNotePool->GetVoicePool() |
188 |
|
); |
189 |
|
MidiKeyboardManager<V>::AllocateEventsLists(pEngine->pEventPool); |
190 |
|
|
191 |
AudioDeviceChannelLeft = 0; |
AudioDeviceChannelLeft = 0; |
192 |
AudioDeviceChannelRight = 1; |
AudioDeviceChannelRight = 1; |
204 |
MidiInputPort::AddSysexListener(pEngine); |
MidiInputPort::AddSysexListener(pEngine); |
205 |
} |
} |
206 |
|
|
207 |
virtual void DisconnectAudioOutputDevice() { |
virtual void DisconnectAudioOutputDevice() OVERRIDE { |
208 |
if (pEngine) { // if clause to prevent disconnect loops |
if (pEngine) { // if clause to prevent disconnect loops |
209 |
|
|
210 |
ResetInternal(); |
ResetInternal(false/*don't reset engine*/); // 'false' is error prone here, but the danger of recursion with 'true' would be worse, there could be a better solution though |
211 |
|
|
212 |
DeleteRegionsInUse(); |
DeleteRegionsInUse(); |
213 |
|
UnloadScriptInUse(); |
214 |
|
|
215 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
216 |
if (cmd.pInstrument) { |
if (cmd.pInstrument) { |
222 |
delete pEvents; |
delete pEvents; |
223 |
pEvents = NULL; |
pEvents = NULL; |
224 |
} |
} |
225 |
|
if (delayedEvents.pList) { |
226 |
|
delete delayedEvents.pList; |
227 |
|
delayedEvents.pList = NULL; |
228 |
|
} |
229 |
|
|
230 |
MidiKeyboardManager<V>::DeleteActiveVoices(); |
MidiKeyboardManager<V>::DeleteActiveNotesLists(); |
231 |
MidiKeyboardManager<V>::DeleteEvents(); |
MidiKeyboardManager<V>::DeleteEventsLists(); |
232 |
DeleteGroupEventLists(); |
DeleteGroupEventLists(); |
233 |
|
|
234 |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
235 |
pEngine = NULL; |
{ |
236 |
|
LockGuard lock(EngineMutex); |
237 |
|
pEngine = NULL; |
238 |
|
} |
239 |
AbstractEngine::FreeEngine(this, oldAudioDevice); |
AbstractEngine::FreeEngine(this, oldAudioDevice); |
240 |
AudioDeviceChannelLeft = -1; |
AudioDeviceChannelLeft = -1; |
241 |
AudioDeviceChannelRight = -1; |
AudioDeviceChannelRight = -1; |
253 |
virtual bool Process(MidiKey* pMidiKey) { pMidiKey->pEvents->clear(); return false; } |
virtual bool Process(MidiKey* pMidiKey) { pMidiKey->pEvents->clear(); return false; } |
254 |
}; |
}; |
255 |
|
|
256 |
void ClearEventLists() { |
/** |
257 |
|
* Free all events of the current audio fragment cycle. Calling |
258 |
|
* this method will @b NOT free events scheduled past the current |
259 |
|
* fragment's boundary! (@see AbstractEngineChannel::delayedEvents). |
260 |
|
*/ |
261 |
|
void ClearEventListsOfCurrentFragment() { |
262 |
pEvents->clear(); |
pEvents->clear(); |
263 |
// empty MIDI key specific event lists |
// empty MIDI key specific event lists |
264 |
ClearEventListsHandler handler; |
ClearEventListsHandler handler; |
265 |
ProcessActiveVoices(&handler); |
this->ProcessActiveVoices(&handler); |
266 |
|
|
267 |
// empty exclusive group specific event lists |
// empty exclusive group specific event lists |
268 |
ClearGroupEventLists(); |
// (pInstrument == 0 could mean that LoadInstrument is |
269 |
|
// building new group event lists, so we must check |
270 |
|
// for that) |
271 |
|
if (pInstrument) ClearGroupEventLists(); |
272 |
} |
} |
273 |
|
|
274 |
// implementation of abstract methods derived from interface class 'InstrumentConsumer' |
// implementation of abstract methods derived from interface class 'InstrumentConsumer' |
278 |
* we are currently using on this EngineChannel is going to be updated, |
* we are currently using on this EngineChannel is going to be updated, |
279 |
* so we can stop playback before that happens. |
* so we can stop playback before that happens. |
280 |
*/ |
*/ |
281 |
virtual void ResourceToBeUpdated(I* pResource, void*& pUpdateArg) { |
virtual void ResourceToBeUpdated(I* pResource, void*& pUpdateArg) OVERRIDE { |
282 |
dmsg(3,("EngineChannelBase: Received instrument update message.\n")); |
dmsg(3,("EngineChannelBase: Received instrument update message.\n")); |
283 |
if (pEngine) pEngine->DisableAndLock(); |
if (pEngine) pEngine->DisableAndLock(); |
284 |
ResetInternal(); |
ResetInternal(false/*don't reset engine*/); |
285 |
this->pInstrument = NULL; |
this->pInstrument = NULL; |
286 |
} |
} |
287 |
|
|
289 |
* Will be called by the InstrumentResourceManager when the instrument |
* Will be called by the InstrumentResourceManager when the instrument |
290 |
* update process was completed, so we can continue with playback. |
* update process was completed, so we can continue with playback. |
291 |
*/ |
*/ |
292 |
virtual void ResourceUpdated(I* pOldResource, I* pNewResource, void* pUpdateArg) { |
virtual void ResourceUpdated(I* pOldResource, I* pNewResource, void* pUpdateArg) OVERRIDE { |
293 |
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()) |
294 |
if (pEngine) pEngine->Enable(); |
if (pEngine) pEngine->Enable(); |
295 |
bStatusChanged = true; // status of engine has changed, so set notify flag |
bStatusChanged = true; // status of engine has changed, so set notify flag |
301 |
* |
* |
302 |
* @param fProgress - current progress as value between 0.0 and 1.0 |
* @param fProgress - current progress as value between 0.0 and 1.0 |
303 |
*/ |
*/ |
304 |
virtual void OnResourceProgress(float fProgress) { |
virtual void OnResourceProgress(float fProgress) OVERRIDE { |
305 |
this->InstrumentStat = int(fProgress * 100.0f); |
this->InstrumentStat = int(fProgress * 100.0f); |
306 |
dmsg(7,("EngineChannelBase: progress %d%", InstrumentStat)); |
dmsg(7,("EngineChannelBase: progress %d%%", InstrumentStat)); |
307 |
bStatusChanged = true; // status of engine has changed, so set notify flag |
bStatusChanged = true; // status of engine has changed, so set notify flag |
308 |
} |
} |
309 |
|
|
310 |
|
/** |
311 |
|
* Called on sustain pedal up events to check and if required, |
312 |
|
* launch release trigger voices on the respective active key. |
313 |
|
* |
314 |
|
* @param pEngineChannel - engine channel on which this event occurred on |
315 |
|
* @param itEvent - release trigger event (contains note number) |
316 |
|
*/ |
317 |
|
virtual void ProcessReleaseTrigger(RTList<Event>::Iterator& itEvent) OVERRIDE { |
318 |
|
if (!pEngine) return; |
319 |
|
pEngine->ProcessReleaseTrigger(this, itEvent); |
320 |
|
} |
321 |
|
|
322 |
void RenderActiveVoices(uint Samples) { |
void RenderActiveVoices(uint Samples) { |
323 |
RenderVoicesHandler handler(this, Samples); |
RenderVoicesHandler handler(this, Samples); |
324 |
ProcessActiveVoices(&handler); |
this->ProcessActiveVoices(&handler); |
325 |
|
|
326 |
SetVoiceCount(handler.VoiceCount); |
SetVoiceCount(handler.VoiceCount); |
327 |
SetDiskStreamCount(handler.StreamCount); |
SetDiskStreamCount(handler.StreamCount); |
328 |
} |
} |
329 |
|
|
330 |
|
/** |
331 |
|
* Called by real-time instrument script functions to schedule a |
332 |
|
* new note (new note-on event and a new @c Note object linked to it) |
333 |
|
* @a delay microseconds in future. |
334 |
|
* |
335 |
|
* @b IMPORTANT: for the supplied @a delay to be scheduled |
336 |
|
* correctly, the passed @a pEvent must be assigned a valid |
337 |
|
* fragment time within the current audio fragment boundaries. That |
338 |
|
* fragment time will be used by this method as basis for |
339 |
|
* interpreting what "now" acutally is, and thus it will be used as |
340 |
|
* basis for calculating the precise scheduling time for @a delay. |
341 |
|
* The easiest way to achieve this is by copying a recent event |
342 |
|
* which happened within the current audio fragment cycle: i.e. the |
343 |
|
* original event which caused calling this method here, or by using |
344 |
|
* Event::copyTimefrom() method to only copy the time, without any |
345 |
|
* other event data. |
346 |
|
* |
347 |
|
* @param pEvent - note-on event to be scheduled in future (event |
348 |
|
* data will be copied) |
349 |
|
* @param delay - amount of microseconds in future (from now) when |
350 |
|
* event shall be processed |
351 |
|
* @returns unique note ID of scheduled new note, or NULL on error |
352 |
|
*/ |
353 |
|
note_id_t ScheduleNoteMicroSec(const Event* pEvent, int delay) OVERRIDE { |
354 |
|
// add (copied) note-on event into scheduler queue |
355 |
|
const event_id_t noteOnEventID = ScheduleEventMicroSec(pEvent, delay); |
356 |
|
if (!noteOnEventID) return 0; // error |
357 |
|
// get access to (copied) event on the scheduler queue |
358 |
|
RTList<Event>::Iterator itEvent = pEvents->fromID(noteOnEventID); |
359 |
|
// stick a new note to the (copied) event on the queue |
360 |
|
const note_id_t noteID = pEngine->LaunchNewNote(this, &*itEvent); |
361 |
|
return noteID; |
362 |
|
} |
363 |
|
|
364 |
|
/** |
365 |
|
* Called by real-time instrument script functions to ignore the note |
366 |
|
* reflected by given note ID. The note's event will be freed immediately |
367 |
|
* to its event pool and this will prevent voices to be launched for the |
368 |
|
* note. |
369 |
|
* |
370 |
|
* NOTE: preventing a note by calling this method works only if the note |
371 |
|
* was launched within the current audio fragment cycle. |
372 |
|
* |
373 |
|
* @param id - unique ID of note to be dropped |
374 |
|
*/ |
375 |
|
void IgnoreNote(note_id_t id) OVERRIDE { |
376 |
|
Pool< Note<V> >* pNotePool = |
377 |
|
dynamic_cast<NotePool<V>*>(pEngine)->GetNotePool(); |
378 |
|
|
379 |
|
NoteIterator itNote = pNotePool->fromID(id); |
380 |
|
if (!itNote) return; // note probably already released |
381 |
|
|
382 |
|
// if the note already got active voices, then it is too late to drop it |
383 |
|
if (!itNote->pActiveVoices->isEmpty()) return; |
384 |
|
|
385 |
|
// if the original (note-on) event is not available anymore, then it is too late to drop it |
386 |
|
RTList<Event>::Iterator itEvent = pEvents->fromID(itNote->eventID); |
387 |
|
if (!itEvent) return; |
388 |
|
|
389 |
|
// drop the note |
390 |
|
pNotePool->free(itNote); |
391 |
|
|
392 |
|
// drop the original event |
393 |
|
pEvents->free(itEvent); |
394 |
|
} |
395 |
|
|
396 |
|
/** |
397 |
|
* Copies the note IDs of all currently active notes on this engine |
398 |
|
* channel to the note ID buffer @a dstBuf, and returns the amount |
399 |
|
* of note IDs that have been copied to the destination buffer. |
400 |
|
* |
401 |
|
* @param dstBuf - destination buffer for note IDs |
402 |
|
* @param bufSize - size of destination buffer (as amount of max. |
403 |
|
* note IDs, not as amount of bytes) |
404 |
|
* @returns amount of note IDs that have been copied to buffer |
405 |
|
*/ |
406 |
|
uint AllNoteIDs(note_id_t* dstBuf, uint bufSize) OVERRIDE { |
407 |
|
uint n = 0; |
408 |
|
|
409 |
|
Pool< Note<V> >* pNotePool = |
410 |
|
dynamic_cast<NotePool<V>*>(pEngine)->GetNotePool(); |
411 |
|
|
412 |
|
RTList<uint>::Iterator iuiKey = this->pActiveKeys->first(); |
413 |
|
RTList<uint>::Iterator end = this->pActiveKeys->end(); |
414 |
|
for(; iuiKey != end; ++iuiKey) { |
415 |
|
MidiKey* pKey = &this->pMIDIKeyInfo[*iuiKey]; |
416 |
|
NoteIterator itNote = pKey->pActiveNotes->first(); |
417 |
|
for (; itNote; ++itNote) { |
418 |
|
if (n >= bufSize) goto done; |
419 |
|
dstBuf[n++] = pNotePool->getID(itNote); |
420 |
|
} |
421 |
|
} |
422 |
|
done: |
423 |
|
return n; |
424 |
|
} |
425 |
|
|
426 |
RTList<R*>* pRegionsInUse; ///< temporary pointer into the instrument change command, used by the audio thread |
RTList<R*>* pRegionsInUse; ///< temporary pointer into the instrument change command, used by the audio thread |
427 |
I* pInstrument; |
I* pInstrument; |
428 |
|
|
429 |
template<class TV, class TRR, class TR, class TD, class TIM, class TI> friend class EngineBase; |
template<class TV, class TRR, class TR, class TD, class TIM, class TI> friend class EngineBase; |
430 |
|
|
431 |
protected: |
protected: |
432 |
EngineChannelBase() : InstrumentChangeCommandReader(InstrumentChangeCommand) { |
EngineChannelBase() : |
433 |
|
MidiKeyboardManager<V>(this), |
434 |
|
InstrumentChangeCommandReader(InstrumentChangeCommand) |
435 |
|
{ |
436 |
pInstrument = NULL; |
pInstrument = NULL; |
437 |
|
|
438 |
// reset the instrument change command struct (need to be done |
// reset the instrument change command struct (need to be done |
441 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
442 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
443 |
cmd.pInstrument = NULL; |
cmd.pInstrument = NULL; |
444 |
|
cmd.pScript = new InstrumentScript(this); |
445 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
446 |
} |
} |
447 |
{ |
{ |
448 |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
449 |
cmd.pRegionsInUse = NULL; |
cmd.pRegionsInUse = NULL; |
450 |
cmd.pInstrument = NULL; |
cmd.pInstrument = NULL; |
451 |
|
cmd.pScript = new InstrumentScript(this); |
452 |
cmd.bChangeInstrument = false; |
cmd.bChangeInstrument = false; |
453 |
} |
} |
454 |
} |
} |
455 |
|
|
456 |
virtual ~EngineChannelBase() { } |
virtual ~EngineChannelBase() { |
457 |
|
InstrumentScript* previous = NULL; // prevent double free |
458 |
|
{ |
459 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
460 |
|
if (cmd.pScript) { |
461 |
|
previous = cmd.pScript; |
462 |
|
delete cmd.pScript; |
463 |
|
cmd.pScript = NULL; |
464 |
|
} |
465 |
|
} |
466 |
|
{ |
467 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
468 |
|
if (cmd.pScript) { |
469 |
|
if (previous != cmd.pScript) |
470 |
|
delete cmd.pScript; |
471 |
|
cmd.pScript = NULL; |
472 |
|
} |
473 |
|
} |
474 |
|
} |
475 |
|
|
476 |
typedef typename RTList<V>::Iterator RTListVoiceIterator; |
typedef typename RTList<V>::Iterator RTListVoiceIterator; |
477 |
|
|
483 |
EngineChannelBase<V, R, I>* pChannel; |
EngineChannelBase<V, R, I>* pChannel; |
484 |
|
|
485 |
RenderVoicesHandler(EngineChannelBase<V, R, I>* channel, uint samples) : |
RenderVoicesHandler(EngineChannelBase<V, R, I>* channel, uint samples) : |
486 |
pChannel(channel), Samples(samples), VoiceCount(0), StreamCount(0) { } |
Samples(samples), VoiceCount(0), StreamCount(0), pChannel(channel) { } |
487 |
|
|
488 |
virtual void Process(RTListVoiceIterator& itVoice) { |
virtual void Process(RTListVoiceIterator& itVoice) { |
489 |
// now render current voice |
// now render current voice |
510 |
SyncConfInstrChangeCmdReader InstrumentChangeCommandReader; |
SyncConfInstrChangeCmdReader InstrumentChangeCommandReader; |
511 |
|
|
512 |
/** This method is not thread safe! */ |
/** This method is not thread safe! */ |
513 |
virtual void ResetInternal() { |
virtual void ResetInternal(bool bResetEngine) OVERRIDE { |
514 |
AbstractEngineChannel::ResetInternal(); |
AbstractEngineChannel::ResetInternal(bResetEngine); |
515 |
|
|
516 |
MidiKeyboardManager<V>::Reset(); |
MidiKeyboardManager<V>::Reset(); |
517 |
} |
} |
518 |
|
|
519 |
virtual void ResetControllers() { |
virtual void ResetControllers() OVERRIDE { |
520 |
AbstractEngineChannel::ResetControllers(); |
AbstractEngineChannel::ResetControllers(); |
521 |
|
|
522 |
MidiKeyboardManager<V>::SustainPedal = false; |
MidiKeyboardManager<V>::SustainPedal = false; |
524 |
} |
} |
525 |
|
|
526 |
/** |
/** |
527 |
|
* Unload the currently used and loaded real-time instrument script. |
528 |
|
* The source code of the script is retained, so that it can still |
529 |
|
* be reloaded. |
530 |
|
*/ |
531 |
|
void UnloadScriptInUse() { |
532 |
|
{ |
533 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
534 |
|
if (cmd.pScript) cmd.pScript->unload(); |
535 |
|
} |
536 |
|
{ |
537 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.SwitchConfig(); |
538 |
|
if (cmd.pScript) cmd.pScript->unload(); |
539 |
|
} |
540 |
|
InstrumentChangeCommand.SwitchConfig(); // switch back to original one |
541 |
|
} |
542 |
|
|
543 |
|
/** |
544 |
|
* Load real-time instrument script and all its resources required |
545 |
|
* for the upcoming instrument change. |
546 |
|
* |
547 |
|
* @param text - source code of script |
548 |
|
*/ |
549 |
|
void LoadInstrumentScript(const String& text) { |
550 |
|
InstrumentChangeCmd<R, I>& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
551 |
|
// load the new script |
552 |
|
cmd.pScript->load(text); |
553 |
|
} |
554 |
|
|
555 |
|
/** |
556 |
* Changes the instrument for an engine channel. |
* Changes the instrument for an engine channel. |
557 |
* |
* |
558 |
* @param pInstrument - new instrument |
* @param pInstrument - new instrument |