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-2012 Christian Schoenebeck and Grigor Iliev * |
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
8 |
* Copyright (C) 2013-2014 Christian Schoenebeck and Andreas Persson * |
* Copyright (C) 2012-2016 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 * |
31 |
|
|
32 |
#include "../common/Pool.h" |
#include "../common/Pool.h" |
33 |
#include "../common/RingBuffer.h" |
#include "../common/RingBuffer.h" |
34 |
|
#include "../common/ResourceManager.h" |
35 |
|
#include "common/AbstractInstrumentManager.h" |
36 |
|
#include "common/InstrumentScriptVM.h" |
37 |
|
|
38 |
#define CTRL_TABLE_IDX_AFTERTOUCH 128 |
#define CTRL_TABLE_IDX_AFTERTOUCH 128 |
39 |
#define CTRL_TABLE_IDX_PITCHBEND 129 |
#define CTRL_TABLE_IDX_PITCHBEND 129 |
40 |
|
|
41 |
namespace LinuxSampler { |
namespace LinuxSampler { |
42 |
|
|
43 |
class AbstractEngineChannel: public EngineChannel, public AbstractEngine::ScriptConsumer { |
class MidiKeyboardManagerBase; |
44 |
|
|
45 |
|
class AbstractEngineChannel: public EngineChannel, public InstrumentScriptConsumer { |
46 |
public: |
public: |
47 |
// implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel' |
// implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel' |
48 |
virtual void PrepareLoadInstrument(const char* FileName, uint Instrument) OVERRIDE; |
virtual void PrepareLoadInstrument(const char* FileName, uint Instrument) OVERRIDE; |
97 |
virtual void OnResourceProgress(float fProgress) OVERRIDE {} |
virtual void OnResourceProgress(float fProgress) OVERRIDE {} |
98 |
|
|
99 |
virtual AbstractEngine::Format GetEngineFormat() = 0; |
virtual AbstractEngine::Format GetEngineFormat() = 0; |
100 |
|
virtual MidiKeyboardManagerBase* GetMidiKeyboardManager() = 0; |
101 |
|
|
102 |
AudioOutputDevice* GetAudioOutputDeviceSafe(); |
AudioOutputDevice* GetAudioOutputDeviceSafe(); |
|
void loadInstrumentScript(const String& text); |
|
|
void unloadCurrentInstrumentScript(); |
|
103 |
|
|
104 |
friend class AbstractVoice; |
friend class AbstractVoice; |
105 |
friend class AbstractEngine; |
friend class AbstractEngine; |
123 |
midi_chan_t midiChannel; ///< MIDI channel(s) on which this engine channel listens to (on all MIDI input ports). |
midi_chan_t midiChannel; ///< MIDI channel(s) on which this engine channel listens to (on all MIDI input ports). |
124 |
RingBuffer<Event,false>* pEventQueue; ///< Input event queue. |
RingBuffer<Event,false>* pEventQueue; ///< Input event queue. |
125 |
RTList<Event>* pEvents; ///< All engine channel specific events for the current audio fragment. |
RTList<Event>* pEvents; ///< All engine channel specific events for the current audio fragment. |
126 |
|
struct _DelayedEvents { |
127 |
|
RTList<Event>* pList; ///< Unsorted list where all delayed events are moved to and remain here until they're finally processed. |
128 |
|
Pool<ScheduledEvent> schedulerNodes; ///< Nodes used to sort the delayed events (stored on pList) with time sorted queue. |
129 |
|
RTAVLTree<ScheduledEvent> queue; ///< Used to access the delayed events (from pList) in time sorted manner. |
130 |
|
|
131 |
|
_DelayedEvents() : pList(NULL), schedulerNodes(CONFIG_MAX_EVENTS_PER_FRAGMENT) {} |
132 |
|
|
133 |
|
inline void clear() { |
134 |
|
if (pList) pList->clear(); |
135 |
|
schedulerNodes.clear(); |
136 |
|
queue.clear(); |
137 |
|
} |
138 |
|
} delayedEvents; |
139 |
uint8_t ControllerTable[130]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel. Number 128 is for channel pressure (mono aftertouch), 129 for pitch bend. |
uint8_t ControllerTable[130]; ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel. Number 128 is for channel pressure (mono aftertouch), 129 for pitch bend. |
140 |
String InstrumentFile; |
String InstrumentFile; |
141 |
int InstrumentIdx; |
int InstrumentIdx; |
154 |
int iEngineIndexSelf; ///< Reflects the index of this EngineChannel in the Engine's ArrayList. |
int iEngineIndexSelf; ///< Reflects the index of this EngineChannel in the Engine's ArrayList. |
155 |
bool bStatusChanged; ///< true in case an engine parameter has changed (e.g. new instrument, another volumet) |
bool bStatusChanged; ///< true in case an engine parameter has changed (e.g. new instrument, another volumet) |
156 |
uint32_t RoundRobinIndex; ///< counter for round robin sample selection, incremented for each note on |
uint32_t RoundRobinIndex; ///< counter for round robin sample selection, incremented for each note on |
157 |
Pool<ScriptEvent>* pScriptEvents; ///< Pool of all available script execution instances. ScriptEvents available to be allocated from the Pool are currently unused / not executiong, whereas the ScriptEvents allocated on the list are currently suspended / have not finished execution yet. |
InstrumentScript* pScript; ///< Points to the real-time instrument script(s) to be executed, NULL if current instrument does not have an instrument script. Even though the underlying VM representation of the script is shared among multiple sampler channels, the InstrumentScript object here is not shared though, it exists for each sampler channel separately. |
|
struct _Script { |
|
|
VMParserContext* parserContext; ///< VM represenation of the currently loaded script or NULL if not script was loaded. Note that it is also not NULL if parser errors occurred! |
|
|
bool bHasValidScript; ///< True in case there is a valid script currently loaded, false if script processing shall be skipped. |
|
|
VMEventHandler* handlerInit; ///< VM representation of script's initilization callback or NULL if current script did not define such an init handler. |
|
|
VMEventHandler* handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler. |
|
|
VMEventHandler* handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler. |
|
|
VMEventHandler* handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler. |
|
|
_Script() { |
|
|
parserContext = NULL; |
|
|
bHasValidScript = false; |
|
|
handlerInit = NULL; |
|
|
handlerNote = NULL; |
|
|
handlerRelease = NULL; |
|
|
handlerController = NULL; |
|
|
} |
|
|
} script; |
|
158 |
|
|
159 |
SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices; |
SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices; |
160 |
SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread; |
SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread; |
179 |
ActiveKeyGroupMap ActiveKeyGroups; ///< Contains event queues for key groups, ordered by key group ID. |
ActiveKeyGroupMap ActiveKeyGroups; ///< Contains event queues for key groups, ordered by key group ID. |
180 |
|
|
181 |
virtual void ResetControllers(); |
virtual void ResetControllers(); |
182 |
virtual void ResetInternal(); |
virtual void ResetInternal(bool bResetEngine); |
183 |
virtual void RemoveAllFxSends(); |
virtual void RemoveAllFxSends(); |
184 |
|
|
185 |
void ImportEvents(uint Samples); |
void ImportEvents(uint Samples); |
186 |
void ScheduleEvent(const Event* pEvent, int delay); //TODO: delay not implemented yet |
virtual note_id_t ScheduleNoteMicroSec(const Event* pEvent, int delay) = 0; |
187 |
|
event_id_t ScheduleEventMicroSec(const Event* pEvent, int delay); |
188 |
|
void IgnoreEvent(event_id_t id); |
189 |
|
void IgnoreNote(note_id_t id); |
190 |
|
void IgnoreEventByScriptID(const ScriptID& id); |
191 |
|
|
192 |
void AddGroup(uint group); |
void AddGroup(uint group); |
193 |
void HandleKeyGroupConflicts(uint KeyGroup, Pool<Event>::Iterator& itNoteOnEvent); |
void HandleKeyGroupConflicts(uint KeyGroup, Pool<Event>::Iterator& itNoteOnEvent); |
207 |
//FIXME: leaves tiny time frames open (shortly after 1->2 devices connected or 2->1 disconnected) which could lead to concurrency issue for the purpose described above, however in practice it "should" be acceptable |
//FIXME: leaves tiny time frames open (shortly after 1->2 devices connected or 2->1 disconnected) which could lead to concurrency issue for the purpose described above, however in practice it "should" be acceptable |
208 |
return midiInputs.unsafeBack().size() > 1; |
return midiInputs.unsafeBack().size() > 1; |
209 |
} |
} |
210 |
|
|
211 |
|
inline bool applyTranspose(Event* event); |
212 |
}; |
}; |
213 |
|
|
214 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |