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 |
* * |
8 |
* This program is free software; you can redistribute it and/or modify * |
9 |
* it under the terms of the GNU General Public License as published by * |
10 |
* the Free Software Foundation; either version 2 of the License, or * |
11 |
* (at your option) any later version. * |
12 |
* * |
13 |
* This program is distributed in the hope that it will be useful, * |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
16 |
* GNU General Public License for more details. * |
17 |
* * |
18 |
* You should have received a copy of the GNU General Public License * |
19 |
* along with this program; if not, write to the Free Software * |
20 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
21 |
* MA 02111-1307 USA * |
22 |
***************************************************************************/ |
23 |
|
24 |
#ifndef __LS_GIG_ENGINECHANNEL_H__ |
25 |
#define __LS_GIG_ENGINECHANNEL_H__ |
26 |
|
27 |
#include "../common/Event.h" |
28 |
#include "../EngineChannel.h" |
29 |
#include "../../common/RingBuffer.h" |
30 |
#include "../../common/ArrayList.h" |
31 |
#include "../../drivers/audio/AudioChannel.h" |
32 |
#include "EngineGlobals.h" |
33 |
#include "Engine.h" |
34 |
#include "Voice.h" |
35 |
#include "InstrumentResourceManager.h" |
36 |
|
37 |
namespace LinuxSampler { namespace gig { |
38 |
|
39 |
// just symbol prototyping |
40 |
class midi_key_info_t; |
41 |
class Voice; |
42 |
|
43 |
/** @brief Engine Channel of a gig::Engine |
44 |
* |
45 |
* Encapsulates a engine channel for the Gigasampler format capable |
46 |
* sampler engine. |
47 |
*/ |
48 |
class EngineChannel : public LinuxSampler::EngineChannel, public InstrumentConsumer { |
49 |
public: |
50 |
EngineChannel(); |
51 |
virtual ~EngineChannel(); |
52 |
|
53 |
// implementation of abstract methods derived from interface class 'LinuxSampler::EngineChannel' |
54 |
virtual void PrepareLoadInstrument(const char* FileName, uint Instrument); |
55 |
virtual void LoadInstrument(); |
56 |
virtual void Reset(); |
57 |
virtual void SendNoteOn(uint8_t Key, uint8_t Velocity); |
58 |
virtual void SendNoteOn(uint8_t Key, uint8_t Velocity, int32_t FragmentPos); |
59 |
virtual void SendNoteOff(uint8_t Key, uint8_t Velocity); |
60 |
virtual void SendNoteOff(uint8_t Key, uint8_t Velocity, int32_t FragmentPos); |
61 |
virtual void SendPitchbend(int Pitch); |
62 |
virtual void SendPitchbend(int Pitch, int32_t FragmentPos); |
63 |
virtual void SendControlChange(uint8_t Controller, uint8_t Value); |
64 |
virtual void SendControlChange(uint8_t Controller, uint8_t Value, int32_t FragmentPos); |
65 |
virtual bool StatusChanged(bool bNewStatus = false); |
66 |
virtual float Volume(); |
67 |
virtual void Volume(float f); |
68 |
virtual float Pan(); |
69 |
virtual void Pan(float f); |
70 |
virtual uint Channels(); |
71 |
virtual void Connect(AudioOutputDevice* pAudioOut); |
72 |
virtual void DisconnectAudioOutputDevice(); |
73 |
virtual AudioOutputDevice* GetAudioOutputDevice(); |
74 |
virtual void SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel); |
75 |
virtual int OutputChannel(uint EngineAudioChannel); |
76 |
virtual void Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel); |
77 |
virtual void DisconnectMidiInputPort(); |
78 |
virtual MidiInputPort* GetMidiInputPort(); |
79 |
virtual midi_chan_t MidiChannel(); |
80 |
virtual String InstrumentFileName(); |
81 |
virtual String InstrumentName(); |
82 |
virtual int InstrumentIndex(); |
83 |
virtual int InstrumentStatus(); |
84 |
virtual LinuxSampler::Engine* GetEngine(); |
85 |
virtual String EngineName(); |
86 |
virtual FxSend* AddFxSend(uint8_t MidiCtrl, String Name = "") throw (Exception); |
87 |
virtual FxSend* GetFxSend(uint FxSendIndex); |
88 |
virtual uint GetFxSendCount(); |
89 |
virtual void RemoveFxSend(FxSend* pFxSend); |
90 |
virtual void Connect(VirtualMidiDevice* pDevice); |
91 |
virtual void Disconnect(VirtualMidiDevice* pDevice); |
92 |
|
93 |
// implementation of abstract methods derived from interface class 'InstrumentConsumer' |
94 |
virtual void ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg); |
95 |
virtual void ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg); |
96 |
virtual void OnResourceProgress(float fProgress); |
97 |
|
98 |
//protected: |
99 |
Engine* pEngine; |
100 |
AudioChannel* pChannelLeft; ///< encapsulates the audio rendering buffer (left) |
101 |
AudioChannel* pChannelRight; ///< encapsulates the audio rendering buffer (right) |
102 |
int AudioDeviceChannelLeft; ///< audio device channel number to which the left channel is connected to |
103 |
int AudioDeviceChannelRight; ///< audio device channel number to which the right channel is connected to |
104 |
MidiInputPort* pMidiInputPort; ///< Points to the connected MIDI input port or NULL if none assigned. |
105 |
midi_chan_t midiChannel; ///< MIDI channel(s) on which this engine channel listens to. |
106 |
RingBuffer<Event,false>* pEventQueue; ///< Input event queue. |
107 |
RTList<Event>* pEvents; ///< All engine channel specific events for the current audio fragment. |
108 |
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). |
109 |
midi_key_info_t* pMIDIKeyInfo; ///< Contains all active voices sorted by MIDI key number and other informations to the respective MIDI key |
110 |
Pool<uint>* pActiveKeys; ///< Holds all keys in it's allocation list with active voices. |
111 |
std::map<uint,uint*> ActiveKeyGroups; ///< Contains active keys (in case they belong to a key group) ordered by key group ID. |
112 |
::gig::Instrument* pInstrument; |
113 |
bool SustainPedal; ///< true if sustain pedal is down |
114 |
bool SostenutoPedal; ///< true if sostenuto pedal is down |
115 |
bool SoloMode; ///< in Solo Mode we only play one voice (group) at a time |
116 |
int SoloKey; ///< Currently 'active' solo key, that is the key to which the currently sounding voice belongs to (only if SoloMode is enabled) |
117 |
bool PortamentoMode; ///< in Portamento Mode we slide the pitch from the last note to the current note. |
118 |
float PortamentoTime; ///< How long it will take to glide from the previous note to the current (in seconds) |
119 |
float PortamentoPos; ///< Current position on the keyboard, that is integer and fractional part (only used if PortamentoMode is on) |
120 |
double GlobalVolume; ///< Master volume factor set through the C++ API / LSCP (a value < 1.0 means attenuation, a value > 1.0 means amplification) |
121 |
double MidiVolume; ///< Volume factor altered by MIDI CC#7 (a value < 1.0 means attenuation, a value > 1.0 means amplification) |
122 |
float GlobalPanLeft; |
123 |
float GlobalPanRight; |
124 |
int Pitch; ///< Current (absolute) MIDI pitch value. |
125 |
float CurrentKeyDimension; ///< Current value (0-1.0) for the keyboard dimension, altered by pressing a keyswitching key. |
126 |
String InstrumentFile; |
127 |
int InstrumentIdx; |
128 |
String InstrumentIdxName; |
129 |
int InstrumentStat; |
130 |
int iEngineIndexSelf; ///< Reflects the index of this EngineChannel in the Engine's ArrayList. |
131 |
bool bStatusChanged; ///< true in case an engine parameter has changed (e.g. new instrument, another volumet) |
132 |
std::vector<FxSend*> fxSends; |
133 |
int GlobalTranspose; ///< amount of semi tones all notes should be transposed |
134 |
int iLastPanRequest; ///< just for the return value of Pan(), so we don't have to make an injective function |
135 |
|
136 |
/// Command used by the instrument loader thread to |
137 |
/// request an instrument change on a channel. |
138 |
struct instrument_change_command_t { |
139 |
bool bChangeInstrument; ///< Set to true by the loader when the channel should change instrument. |
140 |
::gig::Instrument* pInstrument; ///< The new instrument. Also used by the loader to read the previously loaded instrument. |
141 |
RTList< ::gig::DimensionRegion*>* pDimRegionsInUse; ///< List of dimension regions in use by the currently loaded instrument. Continuously updated by the audio thread. |
142 |
}; |
143 |
SynchronizedConfig<instrument_change_command_t> InstrumentChangeCommand; |
144 |
SynchronizedConfig<instrument_change_command_t>::Reader InstrumentChangeCommandReader; |
145 |
|
146 |
RTList< ::gig::DimensionRegion*>* pDimRegionsInUse; ///< temporary pointer into the instrument change command, used by the audio thread |
147 |
|
148 |
SynchronizedConfig< ArrayList<VirtualMidiDevice*> > virtualMidiDevices; |
149 |
SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_AudioThread; |
150 |
SynchronizedConfig< ArrayList<VirtualMidiDevice*> >::Reader virtualMidiDevicesReader_MidiThread; |
151 |
|
152 |
void ResetControllers(); |
153 |
void ClearEventLists(); |
154 |
void ImportEvents(uint Samples); |
155 |
|
156 |
friend class Engine; |
157 |
friend class Voice; |
158 |
friend class InstrumentResourceManager; |
159 |
|
160 |
private: |
161 |
void ResetInternal(); |
162 |
void RemoveAllFxSends(); |
163 |
instrument_change_command_t& ChangeInstrument(::gig::Instrument* pInstrument); |
164 |
}; |
165 |
|
166 |
}} // namespace LinuxSampler::gig |
167 |
|
168 |
#endif // __LS_GIG_ENGINECHANNEL_H__ |