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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2500 - (show annotations) (download) (as text)
Fri Jan 10 12:20:05 2014 UTC (10 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 12183 byte(s)
* Added support for multiple MIDI input ports per sampler channel (added
  various new C++ API methods for this new feature/design, old C++ API
  methods are now marked as deprecated but should still provide full
  behavior backward compatibility).
* LSCP Network interface: Added the following new LSCP commands for the new
  feature mentioned above: "ADD CHANNEL MIDI_INPUT",
  "REMOVE CHANNEL MIDI_INPUT" and "LIST CHANNEL MIDI_INPUTS". As with the
  C++ API changes, the old LSCP commands for MIDI input management are now
  marked as deprecated, but are still there and should provide full behavior
  backward compatibility.
* New LSCP specification document (LSCP v1.6).
* AbstractEngine::GSCheckSum(): don't allocate memory on the stack (was
  unsafe and caused compilation error with old clang 2.x).
* Bumped version (1.0.0.svn25).

1 /***************************************************************************
2 * *
3 * LinuxSampler - modular, streaming capable sampler *
4 * *
5 * Copyright (C) 2003,2004 by Benno Senoner and Christian Schoenebeck *
6 * Copyright (C) 2005-2008 Christian Schoenebeck *
7 * 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 *
11 * it under the terms of the GNU General Public License as published by *
12 * the Free Software Foundation; either version 2 of the License, or *
13 * (at your option) any later version. *
14 * *
15 * This program is distributed in the hope that it will be useful, *
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
18 * GNU General Public License for more details. *
19 * *
20 * You should have received a copy of the GNU General Public License *
21 * along with this program; if not, write to the Free Software *
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
23 * MA 02111-1307 USA *
24 ***************************************************************************/
25
26 #ifndef __LS_ABSTRACTENGINECHANNEL_H__
27 #define __LS_ABSTRACTENGINECHANNEL_H__
28
29 #include "EngineChannel.h"
30 #include "AbstractEngine.h"
31
32 #include "../common/Pool.h"
33 #include "../common/RingBuffer.h"
34
35 namespace LinuxSampler {
36
37 class AbstractEngineChannel: public EngineChannel {
38 public:
39 // implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel'
40 virtual void PrepareLoadInstrument(const char* FileName, uint Instrument) OVERRIDE;
41 virtual void Reset() OVERRIDE;
42 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) OVERRIDE;
43 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, uint8_t MidiChannel) OVERRIDE;
45 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
46 virtual void SendPitchbend(int Pitch, uint8_t MidiChannel) OVERRIDE;
47 virtual void SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
48 virtual void SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel) OVERRIDE;
49 virtual void SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
50 virtual bool StatusChanged(bool bNewStatus = false) OVERRIDE;
51 virtual float Volume() OVERRIDE;
52 virtual void Volume(float f) OVERRIDE;
53 virtual float Pan() OVERRIDE;
54 virtual void Pan(float f) OVERRIDE;
55 virtual uint Channels() OVERRIDE;
56 virtual AudioOutputDevice* GetAudioOutputDevice() OVERRIDE;
57 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) OVERRIDE;
58 virtual int OutputChannel(uint EngineAudioChannel) OVERRIDE;
59 virtual void Connect(MidiInputPort* pMidiPort) OVERRIDE;
60 virtual void Disconnect(MidiInputPort* pMidiPort) OVERRIDE;
61 virtual void DisconnectAllMidiInputPorts() OVERRIDE;
62 virtual uint GetMidiInputPortCount() OVERRIDE;
63 virtual MidiInputPort* GetMidiInputPort(uint index) OVERRIDE;
64 virtual midi_chan_t MidiChannel() OVERRIDE;
65 virtual void SetMidiChannel(midi_chan_t MidiChannel) OVERRIDE;
66 virtual void Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) OVERRIDE; // deprecated, may be removed
67 virtual void DisconnectMidiInputPort() OVERRIDE; // deprecated, may be removed
68 virtual MidiInputPort* GetMidiInputPort() OVERRIDE; // deprecated, may be removed
69 virtual String InstrumentFileName() OVERRIDE;
70 virtual String InstrumentName() OVERRIDE;
71 virtual int InstrumentIndex() OVERRIDE;
72 virtual int InstrumentStatus() OVERRIDE;
73 virtual Engine* GetEngine() OVERRIDE;
74 virtual String EngineName() OVERRIDE;
75 virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception) OVERRIDE;
76 virtual FxSend* GetFxSend(uint FxSendIndex) OVERRIDE;
77 virtual uint GetFxSendCount() OVERRIDE;
78 virtual void RemoveFxSend(FxSend* pFxSend) OVERRIDE;
79 virtual void Connect(VirtualMidiDevice* pDevice) OVERRIDE;
80 virtual void Disconnect(VirtualMidiDevice* pDevice) OVERRIDE;
81
82
83 virtual AbstractEngine::Format GetEngineFormat() = 0;
84
85 AudioOutputDevice* GetAudioOutputDeviceSafe();
86
87 friend class AbstractVoice;
88 friend class AbstractEngine;
89 template<class TV, class TRR, class TR, class TD, class TIM, class TI> friend class EngineBase;
90 template<class EC, class R, class S, class D> friend class VoiceBase;
91
92 protected:
93 AbstractEngineChannel();
94 virtual ~AbstractEngineChannel();
95
96 AbstractEngine* pEngine;
97 Mutex EngineMutex; ///< protects the Engine from access by the instrument loader thread when lscp is disconnecting
98 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.
99
100 protected:
101 AudioChannel* pChannelLeft; ///< encapsulates the audio rendering buffer (left)
102 AudioChannel* pChannelRight; ///< encapsulates the audio rendering buffer (right)
103 int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to
104 int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
105 DoubleBuffer< ArrayList<MidiInputPort*> > midiInputs; ///< MIDI input ports on which this sampler engine channel shall listen to.
106 midi_chan_t midiChannel; ///< MIDI channel(s) on which this engine channel listens to (on all MIDI input ports).
107 RingBuffer<Event,false>* pEventQueue; ///< Input event queue.
108 RTList<Event>* pEvents; ///< All engine channel specific events for the current audio fragment.
109 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).
110 String InstrumentFile;
111 int InstrumentIdx;
112 String InstrumentIdxName;
113 int InstrumentStat;
114 double GlobalVolume; ///< Master volume factor set through the C++ API / LSCP (a value < 1.0 means attenuation, a value > 1.0 means amplification)
115 double MidiVolume; ///< Volume factor altered by MIDI CC#7 (a value < 1.0 means attenuation, a value > 1.0 means amplification)
116 int Pitch; ///< Current (absolute) MIDI pitch value.
117 float CurrentKeyDimension; ///< Current value (0-1.0) for the keyboard dimension, altered by pressing a keyswitching key.
118 bool PortamentoMode; ///< in Portamento Mode we slide the pitch from the last note to the current note.
119 float PortamentoTime; ///< How long it will take to glide from the previous note to the current (in seconds)
120 float PortamentoPos; ///< Current position on the keyboard, that is integer and fractional part (only used if PortamentoMode is on)
121 std::vector<FxSend*> fxSends;
122 int GlobalTranspose; ///< amount of semi tones all notes should be transposed
123 int iLastPanRequest; ///< just for the return value of Pan(), so we don't have to make an injective function
124 int iEngineIndexSelf; ///< Reflects the index of this EngineChannel in the Engine's ArrayList.
125 bool bStatusChanged; ///< true in case an engine parameter has changed (e.g. new instrument, another volumet)
126 uint32_t RoundRobinIndex; ///< counter for round robin sample selection, incremented for each note on
127
128 SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices;
129 SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread;
130 SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_MidiThread;
131
132 // specialization of RTList that doesn't require the pool
133 // to be provided at construction time
134 template<typename T>
135 class LazyList : public RTList<T> {
136 public:
137 using RTList<T>::allocAppend;
138 using RTList<T>::pPool;
139
140 LazyList() : RTList<T>(0) { }
141 typename RTList<T>::Iterator allocAppend(Pool<T>* pool) {
142 pPool = pool;
143 return allocAppend();
144 }
145 };
146
147 typedef std::map<uint, LazyList<Event>*> ActiveKeyGroupMap;
148 ActiveKeyGroupMap ActiveKeyGroups; ///< Contains event queues for key groups, ordered by key group ID.
149
150 virtual void ResetControllers();
151 virtual void ResetInternal();
152 virtual void RemoveAllFxSends();
153
154 void ImportEvents(uint Samples);
155
156 void AddGroup(uint group);
157 void HandleKeyGroupConflicts(uint KeyGroup, Pool<Event>::Iterator& itNoteOnEvent);
158 void ClearGroupEventLists();
159 void DeleteGroupEventLists();
160
161 private:
162 /**
163 * Returns @c true if there are 2 ore more MidiInputPorts connected
164 * to this engine channel.
165 *
166 * This method is currently only used to prevent unnecessary
167 * MidiInputMutex.Lock() if there is not more than 1 MIDI input on
168 * this engine channel.
169 */
170 inline bool hasMultipleMIDIInputs() const {
171 //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
172 return midiInputs.unsafeBack().size() > 1;
173 }
174 };
175
176 } // namespace LinuxSampler
177
178 #endif /* __LS_ABSTRACTENGINECHANNEL_H__ */
179

  ViewVC Help
Powered by ViewVC