/[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 2015 by iliev, Sun Oct 25 22:22:52 2009 UTC revision 2559 by schoenebeck, Sun May 18 17:38:25 2014 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
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-2009 Christian Schoenebeck                         *   *   Copyright (C) 2005-2008 Christian Schoenebeck                         *
7   *   Copyright (C) 2009 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 23  Line 24 
24   ***************************************************************************/   ***************************************************************************/
25    
26  #ifndef __LS_ABSTRACTENGINECHANNEL_H__  #ifndef __LS_ABSTRACTENGINECHANNEL_H__
27  #define __LS_ABSTRACTENGINECHANNEL_H__  #define __LS_ABSTRACTENGINECHANNEL_H__
28    
29  #include "EngineChannel.h"  #include "EngineChannel.h"
30  #include "AbstractEngine.h"  #include "AbstractEngine.h"
# Line 36  namespace LinuxSampler { Line 37  namespace LinuxSampler {
37      class AbstractEngineChannel: public EngineChannel {      class AbstractEngineChannel: public EngineChannel {
38          public:          public:
39              // implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel'              // implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel'
40              virtual void    PrepareLoadInstrument(const char* FileName, uint Instrument);              virtual void    PrepareLoadInstrument(const char* FileName, uint Instrument) OVERRIDE;
41              virtual void    Reset();              virtual void    Reset() OVERRIDE;
42              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity);              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) OVERRIDE;
43              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity, int32_t FragmentPos);              virtual void    SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
44              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity);              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) OVERRIDE;
45              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity, int32_t FragmentPos);              virtual void    SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
46              virtual void    SendPitchbend(int Pitch);              virtual void    SendPitchbend(int Pitch, uint8_t MidiChannel) OVERRIDE;
47              virtual void    SendPitchbend(int Pitch, int32_t FragmentPos);              virtual void    SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
48              virtual void    SendControlChange(uint8_t Controller, uint8_t Value);              virtual void    SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel) OVERRIDE;
49              virtual void    SendControlChange(uint8_t Controller, uint8_t Value, int32_t FragmentPos);              virtual void    SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;            
50              virtual bool    StatusChanged(bool bNewStatus = false);              virtual void    SendChannelPressure(uint8_t Value, uint8_t MidiChannel) OVERRIDE;
51              virtual float   Volume();              virtual void    SendChannelPressure(uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
52              virtual void    Volume(float f);              virtual void    SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel) OVERRIDE;
53              virtual float   Pan();              virtual void    SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
54              virtual void    Pan(float f);              virtual bool    StatusChanged(bool bNewStatus = false) OVERRIDE;
55              virtual uint    Channels();              virtual float   Volume() OVERRIDE;
56              virtual AudioOutputDevice* GetAudioOutputDevice();              virtual void    Volume(float f) OVERRIDE;
57              virtual void    SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel);              virtual float   Pan() OVERRIDE;
58              virtual int     OutputChannel(uint EngineAudioChannel);              virtual void    Pan(float f) OVERRIDE;
59              virtual void    Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel);              virtual uint    Channels() OVERRIDE;
60              virtual void    DisconnectMidiInputPort();              virtual AudioOutputDevice* GetAudioOutputDevice() OVERRIDE;
61              virtual MidiInputPort* GetMidiInputPort();              virtual void    SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) OVERRIDE;
62              virtual midi_chan_t MidiChannel();              virtual int     OutputChannel(uint EngineAudioChannel) OVERRIDE;
63              virtual String  InstrumentFileName();              virtual void    Connect(MidiInputPort* pMidiPort) OVERRIDE;
64              virtual String  InstrumentName();              virtual void    Disconnect(MidiInputPort* pMidiPort) OVERRIDE;
65              virtual int     InstrumentIndex();              virtual void    DisconnectAllMidiInputPorts() OVERRIDE;
66              virtual int     InstrumentStatus();              virtual uint    GetMidiInputPortCount() OVERRIDE;
67              virtual LinuxSampler::Engine* GetEngine();              virtual MidiInputPort* GetMidiInputPort(uint index) OVERRIDE;
68              virtual String  EngineName();              virtual midi_chan_t MidiChannel() OVERRIDE;
69              virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception);              virtual void    SetMidiChannel(midi_chan_t MidiChannel) OVERRIDE;
70              virtual FxSend* GetFxSend(uint FxSendIndex);              virtual void    Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) OVERRIDE; // deprecated, may be removed
71              virtual uint    GetFxSendCount();              virtual void    DisconnectMidiInputPort() OVERRIDE; // deprecated, may be removed
72              virtual void    RemoveFxSend(FxSend* pFxSend);              virtual MidiInputPort* GetMidiInputPort() OVERRIDE; // deprecated, may be removed
73              virtual void    Connect(VirtualMidiDevice* pDevice);              virtual String  InstrumentFileName() OVERRIDE;
74              virtual void    Disconnect(VirtualMidiDevice* pDevice);              virtual String  InstrumentName() OVERRIDE;
75                virtual int     InstrumentIndex() OVERRIDE;
76                virtual int     InstrumentStatus() OVERRIDE;
77                virtual Engine* GetEngine() OVERRIDE;
78                virtual String  EngineName() OVERRIDE;
79                virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception) OVERRIDE;
80                virtual FxSend* GetFxSend(uint FxSendIndex) OVERRIDE;
81                virtual uint    GetFxSendCount() OVERRIDE;
82                virtual void    RemoveFxSend(FxSend* pFxSend) OVERRIDE;
83                virtual void    Connect(VirtualMidiDevice* pDevice) OVERRIDE;
84                virtual void    Disconnect(VirtualMidiDevice* pDevice) OVERRIDE;
85    
86    
87              virtual AbstractEngine::Format GetEngineFormat() = 0;              virtual AbstractEngine::Format GetEngineFormat() = 0;
88    
89                AudioOutputDevice* GetAudioOutputDeviceSafe();
90    
91              friend class AbstractVoice;              friend class AbstractVoice;
92              friend class AbstractEngine;              friend class AbstractEngine;
93              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;
# Line 85  namespace LinuxSampler { Line 98  namespace LinuxSampler {
98              virtual ~AbstractEngineChannel();              virtual ~AbstractEngineChannel();
99    
100              AbstractEngine*           pEngine;              AbstractEngine*           pEngine;
101          public: // TODO: should be protected              Mutex                     EngineMutex; ///< protects the Engine from access by the instrument loader thread when lscp is disconnecting
102                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.
103    
104            protected:
105              AudioChannel*             pChannelLeft;             ///< encapsulates the audio rendering buffer (left)              AudioChannel*             pChannelLeft;             ///< encapsulates the audio rendering buffer (left)
106              AudioChannel*             pChannelRight;            ///< encapsulates the audio rendering buffer (right)              AudioChannel*             pChannelRight;            ///< encapsulates the audio rendering buffer (right)
         protected:  
107              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
108              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
109              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.
110              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).
111              RingBuffer<Event,false>*  pEventQueue;              ///< Input event queue.              RingBuffer<Event,false>*  pEventQueue;              ///< Input event queue.
112              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.
113              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[129];     ///< Reflects the current values (0-127) of all MIDI controllers for this engine / sampler channel. Number 128 is for channel pressure (mono aftertouch).
# Line 102  namespace LinuxSampler { Line 117  namespace LinuxSampler {
117              int                       InstrumentStat;              int                       InstrumentStat;
118              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)
119              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;  
120              int                       Pitch;                    ///< Current (absolute) MIDI pitch value.              int                       Pitch;                    ///< Current (absolute) MIDI pitch value.
121              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.
122              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 114  namespace LinuxSampler { Line 127  namespace LinuxSampler {
127              int                       iLastPanRequest;          ///< just for the return value of Pan(), so we don't have to make an injective function              int                       iLastPanRequest;          ///< just for the return value of Pan(), so we don't have to make an injective function
128              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.
129              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)
130                uint32_t                  RoundRobinIndex;          ///< counter for round robin sample selection, incremented for each note on
131    
132              SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices;              SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices;
133              SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread;              SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread;
134              SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_MidiThread;              SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_MidiThread;
135    
136                // specialization of RTList that doesn't require the pool
137                // to be provided at construction time
138                template<typename T>
139                class LazyList : public RTList<T> {
140                public:
141                    using RTList<T>::allocAppend;
142                    using RTList<T>::pPool;
143    
144                    LazyList() : RTList<T>(0) { }
145                    typename RTList<T>::Iterator allocAppend(Pool<T>* pool) {
146                        pPool = pool;
147                        return allocAppend();
148                    }
149                };
150                
151                typedef std::map<uint, LazyList<Event>*> ActiveKeyGroupMap;
152                ActiveKeyGroupMap ActiveKeyGroups;      ///< Contains event queues for key groups, ordered by key group ID.
153    
154              virtual void ResetControllers();              virtual void ResetControllers();
155              virtual void ResetInternal();              virtual void ResetInternal();
156              virtual void RemoveAllFxSends();              virtual void RemoveAllFxSends();
157    
158              void ImportEvents(uint Samples);              void ImportEvents(uint Samples);
159    
160                void AddGroup(uint group);
161                void HandleKeyGroupConflicts(uint KeyGroup, Pool<Event>::Iterator& itNoteOnEvent);
162                void ClearGroupEventLists();
163                void DeleteGroupEventLists();
164    
165            private:
166                /**
167                 * Returns @c true if there are 2 ore more MidiInputPorts connected
168                 * to this engine channel.
169                 *
170                 * This method is currently only used to prevent unnecessary
171                 * MidiInputMutex.Lock() if there is not more than 1 MIDI input on
172                 * this engine channel.
173                 */
174                inline bool hasMultipleMIDIInputs() const {
175                    //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
176                    return midiInputs.unsafeBack().size() > 1;
177                }
178      };      };
179    
180  } // namespace LinuxSampler  } // namespace LinuxSampler
181    
182  #endif  /* __LS_ABSTRACTENGINECHANNEL_H__ */  #endif  /* __LS_ABSTRACTENGINECHANNEL_H__ */
183    

Legend:
Removed from v.2015  
changed lines
  Added in v.2559

  ViewVC Help
Powered by ViewVC