/[svn]/linuxsampler/trunk/src/engines/AbstractEngineChannel.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/AbstractEngineChannel.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2326 by persson, Thu Mar 8 19:40:14 2012 UTC revision 2598 by schoenebeck, Fri Jun 6 12:38:54 2014 UTC
# Line 5  Line 5 
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     *
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  *
# Line 31  Line 32 
32  #include "../common/Pool.h"  #include "../common/Pool.h"
33  #include "../common/RingBuffer.h"  #include "../common/RingBuffer.h"
34    
35    #define CTRL_TABLE_IDX_AFTERTOUCH   128
36    #define CTRL_TABLE_IDX_PITCHBEND    129
37    
38  namespace LinuxSampler {  namespace LinuxSampler {
39    
40      class AbstractEngineChannel: public EngineChannel {      class AbstractEngineChannel: public EngineChannel, public AbstractEngine::ScriptConsumer {
41          public:          public:
42              // implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel'              // implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel'
43              virtual void    PrepareLoadInstrument(const char* FileName, uint Instrument);              virtual void    PrepareLoadInstrument(const char* FileName, uint Instrument) OVERRIDE;
44              virtual void    Reset();              virtual void    Reset() OVERRIDE;
45              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel);              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) OVERRIDE;
46              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos);              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
47              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel);              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) OVERRIDE;
48              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos);              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
49              virtual void    SendPitchbend(int Pitch, uint8_t MidiChannel);              virtual void    SendPitchbend(int Pitch, uint8_t MidiChannel) OVERRIDE;
50              virtual void    SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos);              virtual void    SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
51              virtual void    SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel);              virtual void    SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel) OVERRIDE;
52              virtual void    SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos);              virtual void    SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;            
53              virtual bool    StatusChanged(bool bNewStatus = false);              virtual void    SendChannelPressure(uint8_t Value, uint8_t MidiChannel) OVERRIDE;
54              virtual float   Volume();              virtual void    SendChannelPressure(uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
55              virtual void    Volume(float f);              virtual void    SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel) OVERRIDE;
56              virtual float   Pan();              virtual void    SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
57              virtual void    Pan(float f);              virtual bool    StatusChanged(bool bNewStatus = false) OVERRIDE;
58              virtual uint    Channels();              virtual float   Volume() OVERRIDE;
59              virtual AudioOutputDevice* GetAudioOutputDevice();              virtual void    Volume(float f) OVERRIDE;
60              virtual void    SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);              virtual float   Pan() OVERRIDE;
61              virtual int     OutputChannel(uint EngineAudioChannel);              virtual void    Pan(float f) OVERRIDE;
62              virtual void    Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel);              virtual uint    Channels() OVERRIDE;
63              virtual void    DisconnectMidiInputPort();              virtual AudioOutputDevice* GetAudioOutputDevice() OVERRIDE;
64              virtual MidiInputPort* GetMidiInputPort();              virtual void    SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) OVERRIDE;
65              virtual midi_chan_t MidiChannel();              virtual int     OutputChannel(uint EngineAudioChannel) OVERRIDE;
66              virtual String  InstrumentFileName();              virtual void    Connect(MidiInputPort* pMidiPort) OVERRIDE;
67              virtual String  InstrumentName();              virtual void    Disconnect(MidiInputPort* pMidiPort) OVERRIDE;
68              virtual int     InstrumentIndex();              virtual void    DisconnectAllMidiInputPorts() OVERRIDE;
69              virtual int     InstrumentStatus();              virtual uint    GetMidiInputPortCount() OVERRIDE;
70              virtual Engine* GetEngine();              virtual MidiInputPort* GetMidiInputPort(uint index) OVERRIDE;
71              virtual String  EngineName();              virtual midi_chan_t MidiChannel() OVERRIDE;
72              virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception);              virtual void    SetMidiChannel(midi_chan_t MidiChannel) OVERRIDE;
73              virtual FxSend* GetFxSend(uint FxSendIndex);              virtual void    Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) OVERRIDE; // deprecated, may be removed
74              virtual uint    GetFxSendCount();              virtual void    DisconnectMidiInputPort() OVERRIDE; // deprecated, may be removed
75              virtual void    RemoveFxSend(FxSend* pFxSend);              virtual MidiInputPort* GetMidiInputPort() OVERRIDE; // deprecated, may be removed
76              virtual void    Connect(VirtualMidiDevice* pDevice);              virtual String  InstrumentFileName() OVERRIDE;
77              virtual void    Disconnect(VirtualMidiDevice* pDevice);              virtual String  InstrumentName() OVERRIDE;
78                virtual int     InstrumentIndex() OVERRIDE;
79                virtual int     InstrumentStatus() OVERRIDE;
80                virtual Engine* GetEngine() OVERRIDE;
81                virtual String  EngineName() OVERRIDE;
82                virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception) OVERRIDE;
83                virtual FxSend* GetFxSend(uint FxSendIndex) OVERRIDE;
84                virtual uint    GetFxSendCount() OVERRIDE;
85                virtual void    RemoveFxSend(FxSend* pFxSend) OVERRIDE;
86                virtual void    Connect(VirtualMidiDevice* pDevice) OVERRIDE;
87                virtual void    Disconnect(VirtualMidiDevice* pDevice) OVERRIDE;
88    
89                // implementation of abstract methods derived from AbstractEngine::ScriptConsumer
90                virtual void ResourceToBeUpdated(VMParserContext* pResource, void*& pUpdateArg) OVERRIDE {}
91                virtual void ResourceUpdated(VMParserContext* pOldResource, VMParserContext* pNewResource, void* pUpdateArg) OVERRIDE {}
92                virtual void OnResourceProgress(float fProgress) OVERRIDE {}
93    
94              virtual AbstractEngine::Format GetEngineFormat() = 0;              virtual AbstractEngine::Format GetEngineFormat() = 0;
95    
96              AudioOutputDevice* GetAudioOutputDeviceSafe();              AudioOutputDevice* GetAudioOutputDeviceSafe();
97                void loadInstrumentScript(const String& text);
98                void unloadCurrentInstrumentScript();
99    
100              friend class AbstractVoice;              friend class AbstractVoice;
101              friend class AbstractEngine;              friend class AbstractEngine;
102              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;
103              template<class EC, class R, class S, class D> friend class VoiceBase;              template<class EC, class R, class S, class D> friend class VoiceBase;
104    
105          protected:          //protected:
106              AbstractEngineChannel();              AbstractEngineChannel();
107              virtual ~AbstractEngineChannel();              virtual ~AbstractEngineChannel();
108    
109              AbstractEngine*           pEngine;              AbstractEngine*           pEngine;
110              Mutex                     EngineMutex; ///< protects the Engine from access by the instrument loader thread when lscp is disconnecting              Mutex                     EngineMutex; ///< protects the Engine from access by the instrument loader thread when lscp is disconnecting
111                Mutex                     MidiInputMutex; ///< Introduced when support for multiple MIDI inputs per engine channel was added: protects the MIDI event input ringbuffer on this engine channel to be accessed concurrently by multiple midi input threads. As alternative one might also move the ringbuffer from this engine channel to the individual MIDI ports/devices and let the sampler engine read the events from there instead of receiving them here.
112    
113          public: // TODO: should be protected          //protected:
114              AudioChannel*             pChannelLeft;             ///< encapsulates the audio rendering buffer (left)              AudioChannel*             pChannelLeft;             ///< encapsulates the audio rendering buffer (left)
115              AudioChannel*             pChannelRight;            ///< encapsulates the audio rendering buffer (right)              AudioChannel*             pChannelRight;            ///< encapsulates the audio rendering buffer (right)
         protected:  
116              int                       AudioDeviceChannelLeft;   ///< audio device channel number to which the left channel is connected to              int                       AudioDeviceChannelLeft;   ///< audio device channel number to which the left channel is connected to
117              int                       AudioDeviceChannelRight;  ///< audio device channel number to which the right channel is connected to              int                       AudioDeviceChannelRight;  ///< audio device channel number to which the right channel is connected to
118              MidiInputPort*            pMidiInputPort;           ///< Points to the connected MIDI input port or NULL if none assigned.              DoubleBuffer< ArrayList<MidiInputPort*> > midiInputs; ///< MIDI input ports on which this sampler engine channel shall listen to.
119              midi_chan_t               midiChannel;              ///< MIDI channel(s) on which this engine channel listens to.              midi_chan_t               midiChannel;              ///< MIDI channel(s) on which this engine channel listens to (on all MIDI input ports).
120              RingBuffer<Event,false>*  pEventQueue;              ///< Input event queue.              RingBuffer<Event,false>*  pEventQueue;              ///< Input event queue.
121              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.
122              uint8_t                   ControllerTable[129];     ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel. Number 128 is for channel pressure (mono aftertouch).              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.
123              String                    InstrumentFile;              String                    InstrumentFile;
124              int                       InstrumentIdx;              int                       InstrumentIdx;
125              String                    InstrumentIdxName;              String                    InstrumentIdxName;
126              int                       InstrumentStat;              int                       InstrumentStat;
127              double                    GlobalVolume;             ///< Master volume factor set through the C++ API / LSCP (a value < 1.0 means attenuation, a value > 1.0 means amplification)              double                    GlobalVolume;             ///< Master volume factor set through the C++ API / LSCP (a value < 1.0 means attenuation, a value > 1.0 means amplification)
128              double                    MidiVolume;               ///< Volume factor altered by MIDI CC#7 (a value < 1.0 means attenuation, a value > 1.0 means amplification)              double                    MidiVolume;               ///< Volume factor altered by MIDI CC#7 (a value < 1.0 means attenuation, a value > 1.0 means amplification)
             float                     GlobalPanLeft;  
             float                     GlobalPanRight;  
129              int                       Pitch;                    ///< Current (absolute) MIDI pitch value.              int                       Pitch;                    ///< Current (absolute) MIDI pitch value.
130              float                     CurrentKeyDimension;      ///< Current value (0-1.0) for the keyboard dimension, altered by pressing a keyswitching key.              float                     CurrentKeyDimension;      ///< Current value (0-1.0) for the keyboard dimension, altered by pressing a keyswitching key.
131              bool                      PortamentoMode;           ///< in Portamento Mode we slide the pitch from the last note to the current note.              bool                      PortamentoMode;           ///< in Portamento Mode we slide the pitch from the last note to the current note.
# Line 119  namespace LinuxSampler { Line 137  namespace LinuxSampler {
137              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.
138              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)
139              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
140                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.
141                struct _Script {
142                    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!
143                    bool                  bHasValidScript; ///< True in case there is a valid script currently loaded, false if script processing shall be skipped.
144                    VMEventHandler*       handlerInit; ///< VM representation of script's initilization callback or NULL if current script did not define such an init handler.
145                    VMEventHandler*       handlerNote; ///< VM representation of script's MIDI note on callback or NULL if current script did not define such an event handler.
146                    VMEventHandler*       handlerRelease; ///< VM representation of script's MIDI note off callback or NULL if current script did not define such an event handler.
147                    VMEventHandler*       handlerController; ///< VM representation of script's MIDI controller callback or NULL if current script did not define such an event handler.
148                    _Script() {
149                        parserContext = NULL;
150                        bHasValidScript = false;
151                        handlerInit = NULL;
152                        handlerNote = NULL;
153                        handlerRelease = NULL;
154                        handlerController = NULL;
155                    }
156                } script;
157    
158              SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices;              SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices;
159              SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread;              SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread;
# Line 147  namespace LinuxSampler { Line 182  namespace LinuxSampler {
182              virtual void RemoveAllFxSends();              virtual void RemoveAllFxSends();
183    
184              void ImportEvents(uint Samples);              void ImportEvents(uint Samples);
185                int  ScheduleEvent(const Event* pEvent, int delay); //TODO: delay not implemented yet
186                void IgnoreEvent(int id);
187    
188              void AddGroup(uint group);              void AddGroup(uint group);
189              void HandleKeyGroupConflicts(uint KeyGroup, Pool<Event>::Iterator& itNoteOnEvent);              void HandleKeyGroupConflicts(uint KeyGroup, Pool<Event>::Iterator& itNoteOnEvent);
190              void ClearGroupEventLists();              void ClearGroupEventLists();
191              void DeleteGroupEventLists();              void DeleteGroupEventLists();
192    
193            private:
194                /**
195                 * Returns @c true if there are 2 ore more MidiInputPorts connected
196                 * to this engine channel.
197                 *
198                 * This method is currently only used to prevent unnecessary
199                 * MidiInputMutex.Lock() if there is not more than 1 MIDI input on
200                 * this engine channel.
201                 */
202                inline bool hasMultipleMIDIInputs() const {
203                    //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
204                    return midiInputs.unsafeBack().size() > 1;
205                }
206      };      };
207    
208  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2326  
changed lines
  Added in v.2598

  ViewVC Help
Powered by ViewVC