/[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 2611 - (show annotations) (download) (as text)
Mon Jun 9 19:20:37 2014 UTC (9 years, 10 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 13646 byte(s)
* Fixed crash when loading an instrument script.
* Fixed "init" script handler only to be executed once:
  when the script was loaded.
* Fixed aftertouch script event which always had value zero
  and controller number was set to aftertouch value instead.
* gig Engine: Fixed handling of "smartmidi" dimension, which
  was recognized as "unknown" dimension.
* Fixed script function gig_set_dim_zone(): was accessing
  wrong event.
* ls_instr_script command line tool: is now not limited to
  core language scripts, but can now also parse sampler format
  dependent instrument scripts, with the respective specific
  built-in script variables and functions.
* ScriptVM: Fixed runtime behavior of "and" and "or" binary
  script expressions, which also evaluated the right hand side
  of the expression even if the left hand side already failed
  the overall expression semantic to become true.
* Bumped version (1.0.0.svn46).

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 #include "../common/ResourceManager.h"
35 #include "common/AbstractInstrumentManager.h"
36 #include "common/InstrumentScriptVM.h"
37
38 #define CTRL_TABLE_IDX_AFTERTOUCH 128
39 #define CTRL_TABLE_IDX_PITCHBEND 129
40
41 namespace LinuxSampler {
42
43 class AbstractEngineChannel: public EngineChannel, public InstrumentScriptConsumer {
44 public:
45 // implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel'
46 virtual void PrepareLoadInstrument(const char* FileName, uint Instrument) OVERRIDE;
47 virtual void Reset() OVERRIDE;
48 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) OVERRIDE;
49 virtual void SendNoteOn(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
50 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel) OVERRIDE;
51 virtual void SendNoteOff(uint8_t Key, uint8_t Velocity, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
52 virtual void SendPitchbend(int Pitch, uint8_t MidiChannel) OVERRIDE;
53 virtual void SendPitchbend(int Pitch, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
54 virtual void SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel) OVERRIDE;
55 virtual void SendControlChange(uint8_t Controller, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
56 virtual void SendChannelPressure(uint8_t Value, uint8_t MidiChannel) OVERRIDE;
57 virtual void SendChannelPressure(uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
58 virtual void SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel) OVERRIDE;
59 virtual void SendPolyphonicKeyPressure(uint8_t Key, uint8_t Value, uint8_t MidiChannel, int32_t FragmentPos) OVERRIDE;
60 virtual bool StatusChanged(bool bNewStatus = false) OVERRIDE;
61 virtual float Volume() OVERRIDE;
62 virtual void Volume(float f) OVERRIDE;
63 virtual float Pan() OVERRIDE;
64 virtual void Pan(float f) OVERRIDE;
65 virtual uint Channels() OVERRIDE;
66 virtual AudioOutputDevice* GetAudioOutputDevice() OVERRIDE;
67 virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) OVERRIDE;
68 virtual int OutputChannel(uint EngineAudioChannel) OVERRIDE;
69 virtual void Connect(MidiInputPort* pMidiPort) OVERRIDE;
70 virtual void Disconnect(MidiInputPort* pMidiPort) OVERRIDE;
71 virtual void DisconnectAllMidiInputPorts() OVERRIDE;
72 virtual uint GetMidiInputPortCount() OVERRIDE;
73 virtual MidiInputPort* GetMidiInputPort(uint index) OVERRIDE;
74 virtual midi_chan_t MidiChannel() OVERRIDE;
75 virtual void SetMidiChannel(midi_chan_t MidiChannel) OVERRIDE;
76 virtual void Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) OVERRIDE; // deprecated, may be removed
77 virtual void DisconnectMidiInputPort() OVERRIDE; // deprecated, may be removed
78 virtual MidiInputPort* GetMidiInputPort() OVERRIDE; // deprecated, may be removed
79 virtual String InstrumentFileName() OVERRIDE;
80 virtual String InstrumentName() OVERRIDE;
81 virtual int InstrumentIndex() OVERRIDE;
82 virtual int InstrumentStatus() OVERRIDE;
83 virtual Engine* GetEngine() OVERRIDE;
84 virtual String EngineName() OVERRIDE;
85 virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception) OVERRIDE;
86 virtual FxSend* GetFxSend(uint FxSendIndex) OVERRIDE;
87 virtual uint GetFxSendCount() OVERRIDE;
88 virtual void RemoveFxSend(FxSend* pFxSend) OVERRIDE;
89 virtual void Connect(VirtualMidiDevice* pDevice) OVERRIDE;
90 virtual void Disconnect(VirtualMidiDevice* pDevice) OVERRIDE;
91
92 // implementation of abstract methods derived from AbstractEngine::ScriptConsumer
93 virtual void ResourceToBeUpdated(VMParserContext* pResource, void*& pUpdateArg) OVERRIDE {}
94 virtual void ResourceUpdated(VMParserContext* pOldResource, VMParserContext* pNewResource, void* pUpdateArg) OVERRIDE {}
95 virtual void OnResourceProgress(float fProgress) OVERRIDE {}
96
97 virtual AbstractEngine::Format GetEngineFormat() = 0;
98
99 AudioOutputDevice* GetAudioOutputDeviceSafe();
100
101 friend class AbstractVoice;
102 friend class AbstractEngine;
103 template<class TV, class TRR, class TR, class TD, class TIM, class TI> friend class EngineBase;
104 template<class EC, class R, class S, class D> friend class VoiceBase;
105
106 //protected:
107 AbstractEngineChannel();
108 virtual ~AbstractEngineChannel();
109
110 AbstractEngine* pEngine;
111 Mutex EngineMutex; ///< protects the Engine from access by the instrument loader thread when lscp is disconnecting
112 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.
113
114 //protected:
115 AudioChannel* pChannelLeft; ///< encapsulates the audio rendering buffer (left)
116 AudioChannel* pChannelRight; ///< encapsulates the audio rendering buffer (right)
117 int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to
118 int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to
119 DoubleBuffer< ArrayList<MidiInputPort*> > midiInputs; ///< MIDI input ports on which this sampler engine channel shall listen to.
120 midi_chan_t midiChannel; ///< MIDI channel(s) on which this engine channel listens to (on all MIDI input ports).
121 RingBuffer<Event,false>* pEventQueue; ///< Input event queue.
122 RTList<Event>* pEvents; ///< All engine channel specific events for the current audio fragment.
123 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.
124 String InstrumentFile;
125 int InstrumentIdx;
126 String InstrumentIdxName;
127 int InstrumentStat;
128 double GlobalVolume; ///< Master volume factor set through the C++ API / LSCP (a value < 1.0 means attenuation, a value > 1.0 means amplification)
129 double MidiVolume; ///< Volume factor altered by MIDI CC#7 (a value < 1.0 means attenuation, a value > 1.0 means amplification)
130 int Pitch; ///< Current (absolute) MIDI pitch value.
131 float CurrentKeyDimension; ///< Current value (0-1.0) for the keyboard dimension, altered by pressing a keyswitching key.
132 bool PortamentoMode; ///< in Portamento Mode we slide the pitch from the last note to the current note.
133 float PortamentoTime; ///< How long it will take to glide from the previous note to the current (in seconds)
134 float PortamentoPos; ///< Current position on the keyboard, that is integer and fractional part (only used if PortamentoMode is on)
135 std::vector<FxSend*> fxSends;
136 int GlobalTranspose; ///< amount of semi tones all notes should be transposed
137 int iLastPanRequest; ///< just for the return value of Pan(), so we don't have to make an injective function
138 int iEngineIndexSelf; ///< Reflects the index of this EngineChannel in the Engine's ArrayList.
139 bool bStatusChanged; ///< true in case an engine parameter has changed (e.g. new instrument, another volumet)
140 uint32_t RoundRobinIndex; ///< counter for round robin sample selection, incremented for each note on
141 InstrumentScript* pScript; ///< Points to the real-time instrument script(s) to be executed, NULL if current instrument does not have an instrument script.
142
143 SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices;
144 SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread;
145 SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_MidiThread;
146
147 // specialization of RTList that doesn't require the pool
148 // to be provided at construction time
149 template<typename T>
150 class LazyList : public RTList<T> {
151 public:
152 using RTList<T>::allocAppend;
153 using RTList<T>::pPool;
154
155 LazyList() : RTList<T>(0) { }
156 typename RTList<T>::Iterator allocAppend(Pool<T>* pool) {
157 pPool = pool;
158 return allocAppend();
159 }
160 };
161
162 typedef std::map<uint, LazyList<Event>*> ActiveKeyGroupMap;
163 ActiveKeyGroupMap ActiveKeyGroups; ///< Contains event queues for key groups, ordered by key group ID.
164
165 virtual void ResetControllers();
166 virtual void ResetInternal();
167 virtual void RemoveAllFxSends();
168
169 void ImportEvents(uint Samples);
170 int ScheduleEvent(const Event* pEvent, int delay); //TODO: delay not implemented yet
171 void IgnoreEvent(int id);
172
173 void AddGroup(uint group);
174 void HandleKeyGroupConflicts(uint KeyGroup, Pool<Event>::Iterator& itNoteOnEvent);
175 void ClearGroupEventLists();
176 void DeleteGroupEventLists();
177
178 private:
179 /**
180 * Returns @c true if there are 2 ore more MidiInputPorts connected
181 * to this engine channel.
182 *
183 * This method is currently only used to prevent unnecessary
184 * MidiInputMutex.Lock() if there is not more than 1 MIDI input on
185 * this engine channel.
186 */
187 inline bool hasMultipleMIDIInputs() const {
188 //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
189 return midiInputs.unsafeBack().size() > 1;
190 }
191 };
192
193 } // namespace LinuxSampler
194
195 #endif /* __LS_ABSTRACTENGINECHANNEL_H__ */
196

  ViewVC Help
Powered by ViewVC