2 |
* * |
* * |
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 - 2008 Christian Schoenebeck * |
* Copyright (C) 2005-2008 Christian Schoenebeck * |
7 |
|
* Copyright (C) 2009-2012 Christian Schoenebeck and Grigor Iliev * |
8 |
* * |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
* This program is free software; you can redistribute it and/or modify * |
10 |
* 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 * |
23 |
***************************************************************************/ |
***************************************************************************/ |
24 |
|
|
25 |
#include "EngineChannel.h" |
#include "EngineChannel.h" |
26 |
|
#include "Engine.h" |
|
#include "../../common/global_private.h" |
|
|
#include "../../Sampler.h" |
|
27 |
|
|
28 |
namespace LinuxSampler { namespace gig { |
namespace LinuxSampler { namespace gig { |
29 |
|
EngineChannel::EngineChannel() { |
30 |
EngineChannel::EngineChannel() : |
|
|
InstrumentChangeCommandReader(InstrumentChangeCommand), |
|
|
virtualMidiDevicesReader_AudioThread(virtualMidiDevices), |
|
|
virtualMidiDevicesReader_MidiThread(virtualMidiDevices) |
|
|
{ |
|
|
pMIDIKeyInfo = new midi_key_info_t[128]; |
|
|
pEngine = NULL; |
|
|
pInstrument = NULL; |
|
|
pEvents = NULL; // we allocate when we retrieve the right Engine object |
|
|
pEventQueue = new RingBuffer<Event,false>(CONFIG_MAX_EVENTS_PER_FRAGMENT, 0); |
|
|
pActiveKeys = new Pool<uint>(128); |
|
|
for (uint i = 0; i < 128; i++) { |
|
|
pMIDIKeyInfo[i].pActiveVoices = NULL; // we allocate when we retrieve the right Engine object |
|
|
pMIDIKeyInfo[i].KeyPressed = false; |
|
|
pMIDIKeyInfo[i].Active = false; |
|
|
pMIDIKeyInfo[i].ReleaseTrigger = false; |
|
|
pMIDIKeyInfo[i].pEvents = NULL; // we allocate when we retrieve the right Engine object |
|
|
pMIDIKeyInfo[i].VoiceTheftsQueued = 0; |
|
|
pMIDIKeyInfo[i].RoundRobinIndex = 0; |
|
|
} |
|
|
InstrumentIdx = -1; |
|
|
InstrumentStat = -1; |
|
|
pChannelLeft = NULL; |
|
|
pChannelRight = NULL; |
|
|
AudioDeviceChannelLeft = -1; |
|
|
AudioDeviceChannelRight = -1; |
|
|
pMidiInputPort = NULL; |
|
|
midiChannel = midi_chan_all; |
|
|
ResetControllers(); |
|
|
SoloMode = false; |
|
|
PortamentoMode = false; |
|
|
PortamentoTime = CONFIG_PORTAMENTO_TIME_DEFAULT; |
|
|
|
|
|
// reset the instrument change command struct (need to be done |
|
|
// twice, as it is double buffered) |
|
|
{ |
|
|
instrument_change_command_t& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
|
|
cmd.pDimRegionsInUse = NULL; |
|
|
cmd.pInstrument = NULL; |
|
|
cmd.bChangeInstrument = false; |
|
|
} |
|
|
{ |
|
|
instrument_change_command_t& cmd = InstrumentChangeCommand.SwitchConfig(); |
|
|
cmd.pDimRegionsInUse = NULL; |
|
|
cmd.pInstrument = NULL; |
|
|
cmd.bChangeInstrument = false; |
|
|
} |
|
31 |
} |
} |
32 |
|
|
33 |
EngineChannel::~EngineChannel() { |
EngineChannel::~EngineChannel() { |
34 |
DisconnectAudioOutputDevice(); |
DisconnectAudioOutputDevice(); |
|
|
|
35 |
// In case the channel was removed before the instrument was |
// In case the channel was removed before the instrument was |
36 |
// fully loaded, try to give back instrument again (see bug #113) |
// fully loaded, try to give back instrument again (see bug #113) |
37 |
instrument_change_command_t& cmd = ChangeInstrument(NULL); |
InstrumentChangeCmd< ::gig::DimensionRegion, ::gig::Instrument>& cmd = ChangeInstrument(NULL); |
38 |
if (cmd.pInstrument) { |
if (cmd.pInstrument) { |
39 |
Engine::instruments.HandBack(cmd.pInstrument, this); |
Engine::instruments.HandBack(cmd.pInstrument, this); |
40 |
} |
} |
41 |
/////// |
/////// |
|
|
|
|
if (pEventQueue) delete pEventQueue; |
|
|
if (pActiveKeys) delete pActiveKeys; |
|
|
if (pMIDIKeyInfo) delete[] pMIDIKeyInfo; |
|
|
RemoveAllFxSends(); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Implementation of virtual method from abstract EngineChannel interface. |
|
|
* This method will periodically be polled (e.g. by the LSCP server) to |
|
|
* check if some engine channel parameter has changed since the last |
|
|
* StatusChanged() call. |
|
|
* |
|
|
* This method can also be used to mark the engine channel as changed |
|
|
* from outside, e.g. by a MIDI input device. The optional argument |
|
|
* \a nNewStatus can be used for this. |
|
|
* |
|
|
* TODO: This "poll method" is just a lazy solution and might be |
|
|
* replaced in future. |
|
|
* @param bNewStatus - (optional, default: false) sets the new status flag |
|
|
* @returns true if engine channel status has changed since last |
|
|
* StatusChanged() call |
|
|
*/ |
|
|
bool EngineChannel::StatusChanged(bool bNewStatus) { |
|
|
bool b = bStatusChanged; |
|
|
bStatusChanged = bNewStatus; |
|
|
return b; |
|
42 |
} |
} |
43 |
|
|
44 |
void EngineChannel::Reset() { |
AbstractEngine::Format EngineChannel::GetEngineFormat() { return AbstractEngine::GIG; } |
|
if (pEngine) pEngine->DisableAndLock(); |
|
|
ResetInternal(); |
|
|
ResetControllers(); |
|
|
if (pEngine) { |
|
|
pEngine->Enable(); |
|
|
pEngine->Reset(); |
|
|
} |
|
|
} |
|
45 |
|
|
46 |
/** |
/** This method is not thread safe! */ |
|
* This method is not thread safe! |
|
|
*/ |
|
47 |
void EngineChannel::ResetInternal() { |
void EngineChannel::ResetInternal() { |
48 |
CurrentKeyDimension = 0; |
CurrentKeyDimension = 0; |
49 |
|
EngineChannelBase<Voice, ::gig::DimensionRegion, ::gig::Instrument>::ResetInternal(); |
|
// reset key info |
|
|
for (uint i = 0; i < 128; i++) { |
|
|
if (pMIDIKeyInfo[i].pActiveVoices) |
|
|
pMIDIKeyInfo[i].pActiveVoices->clear(); |
|
|
if (pMIDIKeyInfo[i].pEvents) |
|
|
pMIDIKeyInfo[i].pEvents->clear(); |
|
|
pMIDIKeyInfo[i].KeyPressed = false; |
|
|
pMIDIKeyInfo[i].Active = false; |
|
|
pMIDIKeyInfo[i].ReleaseTrigger = false; |
|
|
pMIDIKeyInfo[i].itSelf = Pool<uint>::Iterator(); |
|
|
pMIDIKeyInfo[i].VoiceTheftsQueued = 0; |
|
|
} |
|
|
SoloKey = -1; // no solo key active yet |
|
|
PortamentoPos = -1.0f; // no portamento active yet |
|
|
|
|
|
// reset all key groups |
|
|
std::map<uint,uint*>::iterator iter = ActiveKeyGroups.begin(); |
|
|
for (; iter != ActiveKeyGroups.end(); iter++) iter->second = NULL; |
|
|
|
|
|
// free all active keys |
|
|
pActiveKeys->clear(); |
|
|
|
|
|
// delete all input events |
|
|
pEventQueue->init(); |
|
|
|
|
|
if (pEngine) pEngine->ResetInternal(); |
|
|
|
|
|
// status of engine channel has changed, so set notify flag |
|
|
bStatusChanged = true; |
|
|
} |
|
|
|
|
|
LinuxSampler::Engine* EngineChannel::GetEngine() { |
|
|
return pEngine; |
|
50 |
} |
} |
51 |
|
|
52 |
/** |
/** |
53 |
* More or less a workaround to set the instrument name, index and load |
* Will be called by the MIDIIn Thread to signal that a program |
54 |
* status variable to zero percent immediately, that is without blocking |
* change should be performed. As a program change isn't |
55 |
* the calling thread. It might be used in future for other preparations |
* real-time safe, the actual change is performed by the disk |
56 |
* as well though. |
* thread. |
57 |
* |
* |
58 |
* @param FileName - file name of the Gigasampler instrument file |
* @param Program - MIDI program change number |
|
* @param Instrument - index of the instrument in the .gig file |
|
|
* @see LoadInstrument() |
|
59 |
*/ |
*/ |
60 |
void EngineChannel::PrepareLoadInstrument(const char* FileName, uint Instrument) { |
void EngineChannel::SendProgramChange(uint8_t Program) { |
61 |
InstrumentFile = FileName; |
SetMidiProgram(Program); |
62 |
InstrumentIdx = Instrument; |
Engine* engine = dynamic_cast<Engine*>(pEngine); |
63 |
InstrumentStat = 0; |
if(engine == NULL) return; |
64 |
|
|
65 |
|
if(engine->GetDiskThread()) { |
66 |
|
uint32_t merged = (GetMidiBankMsb() << 16) | (GetMidiBankLsb() << 8) | Program; |
67 |
|
engine->GetDiskThread()->OrderProgramChange(merged, this); |
68 |
|
} else { |
69 |
|
// TODO: |
70 |
|
} |
71 |
} |
} |
72 |
|
|
73 |
/** |
/** |
79 |
* @see PrepareLoadInstrument() |
* @see PrepareLoadInstrument() |
80 |
*/ |
*/ |
81 |
void EngineChannel::LoadInstrument() { |
void EngineChannel::LoadInstrument() { |
82 |
|
InstrumentResourceManager* pInstrumentManager = dynamic_cast<InstrumentResourceManager*>(pEngine->GetInstrumentManager()); |
83 |
|
|
84 |
// make sure we don't trigger any new notes with an old |
// make sure we don't trigger any new notes with an old |
85 |
// instrument |
// instrument |
86 |
instrument_change_command_t& cmd = ChangeInstrument(0); |
InstrumentChangeCmd< ::gig::DimensionRegion, ::gig::Instrument>& cmd = ChangeInstrument(0); |
87 |
if (cmd.pInstrument) { |
if (cmd.pInstrument) { |
88 |
// give old instrument back to instrument manager, but |
// give old instrument back to instrument manager, but |
89 |
// keep the dimension regions and samples that are in use |
// keep the dimension regions and samples that are in use |
90 |
Engine::instruments.HandBackInstrument(cmd.pInstrument, this, cmd.pDimRegionsInUse); |
pInstrumentManager->HandBackInstrument(cmd.pInstrument, this, cmd.pRegionsInUse); |
91 |
} |
} |
92 |
cmd.pDimRegionsInUse->clear(); |
cmd.pRegionsInUse->clear(); |
93 |
|
|
94 |
// delete all key groups |
// delete all key groups |
95 |
ActiveKeyGroups.clear(); |
DeleteGroupEventLists(); |
96 |
|
|
97 |
// request gig instrument from instrument manager |
// request gig instrument from instrument manager |
98 |
::gig::Instrument* newInstrument; |
::gig::Instrument* newInstrument; |
100 |
InstrumentManager::instrument_id_t instrid; |
InstrumentManager::instrument_id_t instrid; |
101 |
instrid.FileName = InstrumentFile; |
instrid.FileName = InstrumentFile; |
102 |
instrid.Index = InstrumentIdx; |
instrid.Index = InstrumentIdx; |
103 |
newInstrument = Engine::instruments.Borrow(instrid, this); |
|
104 |
|
newInstrument = pInstrumentManager->Borrow(instrid, this); |
105 |
if (!newInstrument) { |
if (!newInstrument) { |
106 |
throw InstrumentManagerException("resource was not created"); |
throw InstrumentManagerException("resource was not created"); |
107 |
} |
} |
108 |
|
|
109 |
|
::gig::Script* script = newInstrument->GetScriptOfSlot(0); |
110 |
|
if (script) { |
111 |
|
String sourceCode = script->GetScriptAsText(); |
112 |
|
loadInstrumentScript(sourceCode); |
113 |
|
} |
114 |
} |
} |
115 |
catch (RIFF::Exception e) { |
catch (RIFF::Exception e) { |
116 |
InstrumentStat = -2; |
InstrumentStat = -2; |
130 |
throw Exception("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file."); |
throw Exception("gig::Engine error: Failed to load instrument, cause: Unknown exception while trying to parse gig file."); |
131 |
} |
} |
132 |
|
|
133 |
// rebuild ActiveKeyGroups map with key groups of current instrument |
RoundRobinIndex = 0; |
134 |
for (::gig::Region* pRegion = newInstrument->GetFirstRegion(); pRegion; pRegion = newInstrument->GetNextRegion()) |
for (int i = 0 ; i < 128 ; i++) pMIDIKeyInfo[i].pRoundRobinIndex = NULL; |
135 |
if (pRegion->KeyGroup) ActiveKeyGroups[pRegion->KeyGroup] = NULL; |
|
136 |
|
// rebuild ActiveKeyGroups map with key groups of current |
137 |
|
// instrument and set the round robin pointers to use one |
138 |
|
// counter for each region |
139 |
|
int region = 0; |
140 |
|
for (::gig::Region* pRegion = newInstrument->GetFirstRegion(); pRegion; pRegion = newInstrument->GetNextRegion()) { |
141 |
|
AddGroup(pRegion->KeyGroup); |
142 |
|
|
143 |
|
RoundRobinIndexes[region] = 0; |
144 |
|
for (int iKey = pRegion->KeyRange.low; iKey <= pRegion->KeyRange.high; iKey++) { |
145 |
|
pMIDIKeyInfo[iKey].pRoundRobinIndex = &RoundRobinIndexes[region]; |
146 |
|
} |
147 |
|
region++; |
148 |
|
} |
149 |
|
|
150 |
InstrumentIdxName = newInstrument->pInfo->Name; |
InstrumentIdxName = newInstrument->pInfo->Name; |
151 |
InstrumentStat = 100; |
InstrumentStat = 100; |
155 |
StatusChanged(true); |
StatusChanged(true); |
156 |
} |
} |
157 |
|
|
158 |
|
void EngineChannel::ProcessKeySwitchChange(int key) { |
159 |
/** |
// Change key dimension value if key is in keyswitching area |
|
* Changes the instrument for an engine channel. |
|
|
* |
|
|
* @param pInstrument - new instrument |
|
|
* @returns the resulting instrument change command after the |
|
|
* command switch, containing the old instrument and |
|
|
* the dimregions it is using |
|
|
*/ |
|
|
EngineChannel::instrument_change_command_t& EngineChannel::ChangeInstrument(::gig::Instrument* pInstrument) { |
|
|
instrument_change_command_t& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
|
|
cmd.pInstrument = pInstrument; |
|
|
cmd.bChangeInstrument = true; |
|
|
|
|
|
return InstrumentChangeCommand.SwitchConfig(); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the InstrumentResourceManager when the instrument |
|
|
* we are currently using on this EngineChannel is going to be updated, |
|
|
* so we can stop playback before that happens. |
|
|
*/ |
|
|
void EngineChannel::ResourceToBeUpdated(::gig::Instrument* pResource, void*& pUpdateArg) { |
|
|
dmsg(3,("gig::Engine: Received instrument update message.\n")); |
|
|
if (pEngine) pEngine->DisableAndLock(); |
|
|
ResetInternal(); |
|
|
this->pInstrument = NULL; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the InstrumentResourceManager when the instrument |
|
|
* update process was completed, so we can continue with playback. |
|
|
*/ |
|
|
void EngineChannel::ResourceUpdated(::gig::Instrument* pOldResource, ::gig::Instrument* pNewResource, void* pUpdateArg) { |
|
|
this->pInstrument = pNewResource; //TODO: there are couple of engine parameters we should update here as well if the instrument was updated (see LoadInstrument()) |
|
|
if (pEngine) pEngine->Enable(); |
|
|
bStatusChanged = true; // status of engine has changed, so set notify flag |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the InstrumentResourceManager on progress changes |
|
|
* while loading or realoading an instrument for this EngineChannel. |
|
|
* |
|
|
* @param fProgress - current progress as value between 0.0 and 1.0 |
|
|
*/ |
|
|
void EngineChannel::OnResourceProgress(float fProgress) { |
|
|
this->InstrumentStat = int(fProgress * 100.0f); |
|
|
dmsg(7,("gig::EngineChannel: progress %d%", InstrumentStat)); |
|
|
bStatusChanged = true; // status of engine has changed, so set notify flag |
|
|
} |
|
|
|
|
|
void EngineChannel::Connect(AudioOutputDevice* pAudioOut) { |
|
|
if (pEngine) { |
|
|
if (pEngine->pAudioOutputDevice == pAudioOut) return; |
|
|
DisconnectAudioOutputDevice(); |
|
|
} |
|
|
pEngine = Engine::AcquireEngine(this, pAudioOut); |
|
|
ResetInternal(); |
|
|
pEvents = new RTList<Event>(pEngine->pEventPool); |
|
|
|
|
|
// reset the instrument change command struct (need to be done |
|
|
// twice, as it is double buffered) |
|
|
{ |
|
|
instrument_change_command_t& cmd = InstrumentChangeCommand.GetConfigForUpdate(); |
|
|
cmd.pDimRegionsInUse = new RTList< ::gig::DimensionRegion*>(pEngine->pDimRegionPool[0]); |
|
|
cmd.pInstrument = 0; |
|
|
cmd.bChangeInstrument = false; |
|
|
} |
|
160 |
{ |
{ |
161 |
instrument_change_command_t& cmd = InstrumentChangeCommand.SwitchConfig(); |
if (key >= pInstrument->DimensionKeyRange.low && key <= pInstrument->DimensionKeyRange.high) |
162 |
cmd.pDimRegionsInUse = new RTList< ::gig::DimensionRegion*>(pEngine->pDimRegionPool[1]); |
CurrentKeyDimension = float(key - pInstrument->DimensionKeyRange.low) / |
163 |
cmd.pInstrument = 0; |
(pInstrument->DimensionKeyRange.high - pInstrument->DimensionKeyRange.low + 1); |
|
cmd.bChangeInstrument = false; |
|
|
} |
|
|
|
|
|
for (uint i = 0; i < 128; i++) { |
|
|
pMIDIKeyInfo[i].pActiveVoices = new RTList<Voice>(pEngine->pVoicePool); |
|
|
pMIDIKeyInfo[i].pEvents = new RTList<Event>(pEngine->pEventPool); |
|
|
} |
|
|
AudioDeviceChannelLeft = 0; |
|
|
AudioDeviceChannelRight = 1; |
|
|
if (fxSends.empty()) { // render directly into the AudioDevice's output buffers |
|
|
pChannelLeft = pAudioOut->Channel(AudioDeviceChannelLeft); |
|
|
pChannelRight = pAudioOut->Channel(AudioDeviceChannelRight); |
|
|
} else { // use local buffers for rendering and copy later |
|
|
// ensure the local buffers have the correct size |
|
|
if (pChannelLeft) delete pChannelLeft; |
|
|
if (pChannelRight) delete pChannelRight; |
|
|
pChannelLeft = new AudioChannel(0, pAudioOut->MaxSamplesPerCycle()); |
|
|
pChannelRight = new AudioChannel(1, pAudioOut->MaxSamplesPerCycle()); |
|
|
} |
|
|
if (pEngine->EngineDisabled.GetUnsafe()) pEngine->Enable(); |
|
|
MidiInputPort::AddSysexListener(pEngine); |
|
|
} |
|
|
|
|
|
void EngineChannel::DisconnectAudioOutputDevice() { |
|
|
if (pEngine) { // if clause to prevent disconnect loops |
|
|
|
|
|
// delete the structures used for instrument change |
|
|
RTList< ::gig::DimensionRegion*>* d = InstrumentChangeCommand.GetConfigForUpdate().pDimRegionsInUse; |
|
|
if (d) delete d; |
|
|
EngineChannel::instrument_change_command_t& cmd = InstrumentChangeCommand.SwitchConfig(); |
|
|
d = cmd.pDimRegionsInUse; |
|
|
|
|
|
if (cmd.pInstrument) { |
|
|
// release the currently loaded instrument |
|
|
Engine::instruments.HandBackInstrument(cmd.pInstrument, this, d); |
|
|
} |
|
|
|
|
|
if (d) delete d; |
|
|
|
|
|
// release all active dimension regions to resource |
|
|
// manager |
|
|
RTList<uint>::Iterator iuiKey = pActiveKeys->first(); |
|
|
RTList<uint>::Iterator end = pActiveKeys->end(); |
|
|
while (iuiKey != end) { // iterate through all active keys |
|
|
midi_key_info_t* pKey = &pMIDIKeyInfo[*iuiKey]; |
|
|
++iuiKey; |
|
|
|
|
|
RTList<Voice>::Iterator itVoice = pKey->pActiveVoices->first(); |
|
|
RTList<Voice>::Iterator itVoicesEnd = pKey->pActiveVoices->end(); |
|
|
for (; itVoice != itVoicesEnd; ++itVoice) { // iterate through all voices on this key |
|
|
Engine::instruments.HandBackDimReg(itVoice->pDimRgn); |
|
|
} |
|
|
} |
|
|
|
|
|
ResetInternal(); |
|
|
if (pEvents) { |
|
|
delete pEvents; |
|
|
pEvents = NULL; |
|
|
} |
|
|
for (uint i = 0; i < 128; i++) { |
|
|
if (pMIDIKeyInfo[i].pActiveVoices) { |
|
|
delete pMIDIKeyInfo[i].pActiveVoices; |
|
|
pMIDIKeyInfo[i].pActiveVoices = NULL; |
|
|
} |
|
|
if (pMIDIKeyInfo[i].pEvents) { |
|
|
delete pMIDIKeyInfo[i].pEvents; |
|
|
pMIDIKeyInfo[i].pEvents = NULL; |
|
|
} |
|
|
} |
|
|
Engine* oldEngine = pEngine; |
|
|
AudioOutputDevice* oldAudioDevice = pEngine->pAudioOutputDevice; |
|
|
pEngine = NULL; |
|
|
Engine::FreeEngine(this, oldAudioDevice); |
|
|
AudioDeviceChannelLeft = -1; |
|
|
AudioDeviceChannelRight = -1; |
|
|
if (!fxSends.empty()) { // free the local rendering buffers |
|
|
if (pChannelLeft) delete pChannelLeft; |
|
|
if (pChannelRight) delete pChannelRight; |
|
|
} |
|
|
pChannelLeft = NULL; |
|
|
pChannelRight = NULL; |
|
164 |
} |
} |
165 |
} |
} |
166 |
|
|
|
AudioOutputDevice* EngineChannel::GetAudioOutputDevice() { |
|
|
return (pEngine) ? pEngine->pAudioOutputDevice : NULL; |
|
|
} |
|
|
|
|
|
void EngineChannel::SetOutputChannel(uint EngineAudioChannel, uint AudioDeviceChannel) { |
|
|
if (!pEngine || !pEngine->pAudioOutputDevice) throw AudioOutputException("No audio output device connected yet."); |
|
|
|
|
|
AudioChannel* pChannel = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannel); |
|
|
if (!pChannel) throw AudioOutputException("Invalid audio output device channel " + ToString(AudioDeviceChannel)); |
|
|
switch (EngineAudioChannel) { |
|
|
case 0: // left output channel |
|
|
if (fxSends.empty()) pChannelLeft = pChannel; |
|
|
AudioDeviceChannelLeft = AudioDeviceChannel; |
|
|
break; |
|
|
case 1: // right output channel |
|
|
if (fxSends.empty()) pChannelRight = pChannel; |
|
|
AudioDeviceChannelRight = AudioDeviceChannel; |
|
|
break; |
|
|
default: |
|
|
throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel)); |
|
|
} |
|
|
|
|
|
bStatusChanged = true; |
|
|
} |
|
|
|
|
|
int EngineChannel::OutputChannel(uint EngineAudioChannel) { |
|
|
switch (EngineAudioChannel) { |
|
|
case 0: // left channel |
|
|
return AudioDeviceChannelLeft; |
|
|
case 1: // right channel |
|
|
return AudioDeviceChannelRight; |
|
|
default: |
|
|
throw AudioOutputException("Invalid engine audio channel " + ToString(EngineAudioChannel)); |
|
|
} |
|
|
} |
|
|
|
|
|
void EngineChannel::Connect(MidiInputPort* pMidiPort, midi_chan_t MidiChannel) { |
|
|
if (!pMidiPort || pMidiPort == this->pMidiInputPort) return; |
|
|
DisconnectMidiInputPort(); |
|
|
this->pMidiInputPort = pMidiPort; |
|
|
this->midiChannel = MidiChannel; |
|
|
pMidiPort->Connect(this, MidiChannel); |
|
|
} |
|
|
|
|
|
void EngineChannel::DisconnectMidiInputPort() { |
|
|
MidiInputPort* pOldPort = this->pMidiInputPort; |
|
|
this->pMidiInputPort = NULL; |
|
|
if (pOldPort) pOldPort->Disconnect(this); |
|
|
} |
|
|
|
|
|
MidiInputPort* EngineChannel::GetMidiInputPort() { |
|
|
return pMidiInputPort; |
|
|
} |
|
|
|
|
|
midi_chan_t EngineChannel::MidiChannel() { |
|
|
return midiChannel; |
|
|
} |
|
|
|
|
|
FxSend* EngineChannel::AddFxSend(uint8_t MidiCtrl, String Name) throw (Exception) { |
|
|
if (pEngine) pEngine->DisableAndLock(); |
|
|
FxSend* pFxSend = new FxSend(this, MidiCtrl, Name); |
|
|
if (fxSends.empty()) { |
|
|
if (pEngine && pEngine->pAudioOutputDevice) { |
|
|
AudioOutputDevice* pDevice = pEngine->pAudioOutputDevice; |
|
|
// create local render buffers |
|
|
pChannelLeft = new AudioChannel(0, pDevice->MaxSamplesPerCycle()); |
|
|
pChannelRight = new AudioChannel(1, pDevice->MaxSamplesPerCycle()); |
|
|
} else { |
|
|
// postpone local render buffer creation until audio device is assigned |
|
|
pChannelLeft = NULL; |
|
|
pChannelRight = NULL; |
|
|
} |
|
|
} |
|
|
fxSends.push_back(pFxSend); |
|
|
if (pEngine) pEngine->Enable(); |
|
|
fireFxSendCountChanged(GetSamplerChannel()->Index(), GetFxSendCount()); |
|
|
|
|
|
return pFxSend; |
|
|
} |
|
|
|
|
|
FxSend* EngineChannel::GetFxSend(uint FxSendIndex) { |
|
|
return (FxSendIndex < fxSends.size()) ? fxSends[FxSendIndex] : NULL; |
|
|
} |
|
|
|
|
|
uint EngineChannel::GetFxSendCount() { |
|
|
return fxSends.size(); |
|
|
} |
|
|
|
|
|
void EngineChannel::RemoveFxSend(FxSend* pFxSend) { |
|
|
if (pEngine) pEngine->DisableAndLock(); |
|
|
for ( |
|
|
std::vector<FxSend*>::iterator iter = fxSends.begin(); |
|
|
iter != fxSends.end(); iter++ |
|
|
) { |
|
|
if (*iter == pFxSend) { |
|
|
delete pFxSend; |
|
|
fxSends.erase(iter); |
|
|
if (fxSends.empty()) { |
|
|
// destroy local render buffers |
|
|
if (pChannelLeft) delete pChannelLeft; |
|
|
if (pChannelRight) delete pChannelRight; |
|
|
// fallback to render directly into AudioOutputDevice's buffers |
|
|
if (pEngine && pEngine->pAudioOutputDevice) { |
|
|
pChannelLeft = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelLeft); |
|
|
pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight); |
|
|
} else { // we update the pointers later |
|
|
pChannelLeft = NULL; |
|
|
pChannelRight = NULL; |
|
|
} |
|
|
} |
|
|
break; |
|
|
} |
|
|
} |
|
|
if (pEngine) pEngine->Enable(); |
|
|
fireFxSendCountChanged(GetSamplerChannel()->Index(), GetFxSendCount()); |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to let the audio thread trigger a new |
|
|
* voice for the given key. This method is meant for real time rendering, |
|
|
* that is an event will immediately be created with the current system |
|
|
* time as time stamp. |
|
|
* |
|
|
* @param Key - MIDI key number of the triggered key |
|
|
* @param Velocity - MIDI velocity value of the triggered key |
|
|
*/ |
|
|
void EngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity) { |
|
|
if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(); |
|
|
event.Type = Event::type_note_on; |
|
|
event.Param.Note.Key = Key; |
|
|
event.Param.Note.Velocity = Velocity; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
// inform connected virtual MIDI devices if any ... |
|
|
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
|
|
ArrayList<VirtualMidiDevice*>& devices = |
|
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
|
|
virtualMidiDevicesReader_MidiThread.Lock() |
|
|
); |
|
|
for (int i = 0; i < devices.size(); i++) { |
|
|
devices[i]->SendNoteOnToDevice(Key, Velocity); |
|
|
} |
|
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to let the audio thread trigger a new |
|
|
* voice for the given key. This method is meant for offline rendering |
|
|
* and / or for cases where the exact position of the event in the current |
|
|
* audio fragment is already known. |
|
|
* |
|
|
* @param Key - MIDI key number of the triggered key |
|
|
* @param Velocity - MIDI velocity value of the triggered key |
|
|
* @param FragmentPos - sample point position in the current audio |
|
|
* fragment to which this event belongs to |
|
|
*/ |
|
|
void EngineChannel::SendNoteOn(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) { |
|
|
if (FragmentPos < 0) { |
|
|
dmsg(1,("EngineChannel::SendNoteOn(): negative FragmentPos! Seems MIDI driver is buggy!")); |
|
|
} |
|
|
else if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
|
|
event.Type = Event::type_note_on; |
|
|
event.Param.Note.Key = Key; |
|
|
event.Param.Note.Velocity = Velocity; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
// inform connected virtual MIDI devices if any ... |
|
|
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
|
|
ArrayList<VirtualMidiDevice*>& devices = |
|
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
|
|
virtualMidiDevicesReader_MidiThread.Lock() |
|
|
); |
|
|
for (int i = 0; i < devices.size(); i++) { |
|
|
devices[i]->SendNoteOnToDevice(Key, Velocity); |
|
|
} |
|
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to signal the audio thread to release |
|
|
* voice(s) on the given key. This method is meant for real time rendering, |
|
|
* that is an event will immediately be created with the current system |
|
|
* time as time stamp. |
|
|
* |
|
|
* @param Key - MIDI key number of the released key |
|
|
* @param Velocity - MIDI release velocity value of the released key |
|
|
*/ |
|
|
void EngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity) { |
|
|
if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(); |
|
|
event.Type = Event::type_note_off; |
|
|
event.Param.Note.Key = Key; |
|
|
event.Param.Note.Velocity = Velocity; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
// inform connected virtual MIDI devices if any ... |
|
|
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
|
|
ArrayList<VirtualMidiDevice*>& devices = |
|
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
|
|
virtualMidiDevicesReader_MidiThread.Lock() |
|
|
); |
|
|
for (int i = 0; i < devices.size(); i++) { |
|
|
devices[i]->SendNoteOffToDevice(Key, Velocity); |
|
|
} |
|
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to signal the audio thread to release |
|
|
* voice(s) on the given key. This method is meant for offline rendering |
|
|
* and / or for cases where the exact position of the event in the current |
|
|
* audio fragment is already known. |
|
|
* |
|
|
* @param Key - MIDI key number of the released key |
|
|
* @param Velocity - MIDI release velocity value of the released key |
|
|
* @param FragmentPos - sample point position in the current audio |
|
|
* fragment to which this event belongs to |
|
|
*/ |
|
|
void EngineChannel::SendNoteOff(uint8_t Key, uint8_t Velocity, int32_t FragmentPos) { |
|
|
if (FragmentPos < 0) { |
|
|
dmsg(1,("EngineChannel::SendNoteOff(): negative FragmentPos! Seems MIDI driver is buggy!")); |
|
|
} |
|
|
else if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
|
|
event.Type = Event::type_note_off; |
|
|
event.Param.Note.Key = Key; |
|
|
event.Param.Note.Velocity = Velocity; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
// inform connected virtual MIDI devices if any ... |
|
|
// (e.g. virtual MIDI keyboard in instrument editor(s)) |
|
|
ArrayList<VirtualMidiDevice*>& devices = |
|
|
const_cast<ArrayList<VirtualMidiDevice*>&>( |
|
|
virtualMidiDevicesReader_MidiThread.Lock() |
|
|
); |
|
|
for (int i = 0; i < devices.size(); i++) { |
|
|
devices[i]->SendNoteOffToDevice(Key, Velocity); |
|
|
} |
|
|
virtualMidiDevicesReader_MidiThread.Unlock(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to signal the audio thread to change |
|
|
* the pitch value for all voices. This method is meant for real time |
|
|
* rendering, that is an event will immediately be created with the |
|
|
* current system time as time stamp. |
|
|
* |
|
|
* @param Pitch - MIDI pitch value (-8192 ... +8191) |
|
|
*/ |
|
|
void EngineChannel::SendPitchbend(int Pitch) { |
|
|
if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(); |
|
|
event.Type = Event::type_pitchbend; |
|
|
event.Param.Pitch.Pitch = Pitch; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to signal the audio thread to change |
|
|
* the pitch value for all voices. This method is meant for offline |
|
|
* rendering and / or for cases where the exact position of the event in |
|
|
* the current audio fragment is already known. |
|
|
* |
|
|
* @param Pitch - MIDI pitch value (-8192 ... +8191) |
|
|
* @param FragmentPos - sample point position in the current audio |
|
|
* fragment to which this event belongs to |
|
|
*/ |
|
|
void EngineChannel::SendPitchbend(int Pitch, int32_t FragmentPos) { |
|
|
if (FragmentPos < 0) { |
|
|
dmsg(1,("EngineChannel::SendPitchBend(): negative FragmentPos! Seems MIDI driver is buggy!")); |
|
|
} |
|
|
else if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
|
|
event.Type = Event::type_pitchbend; |
|
|
event.Param.Pitch.Pitch = Pitch; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to signal the audio thread that a |
|
|
* continuous controller value has changed. This method is meant for real |
|
|
* time rendering, that is an event will immediately be created with the |
|
|
* current system time as time stamp. |
|
|
* |
|
|
* @param Controller - MIDI controller number of the occured control change |
|
|
* @param Value - value of the control change |
|
|
*/ |
|
|
void EngineChannel::SendControlChange(uint8_t Controller, uint8_t Value) { |
|
|
if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(); |
|
|
event.Type = Event::type_control_change; |
|
|
event.Param.CC.Controller = Controller; |
|
|
event.Param.CC.Value = Value; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Will be called by the MIDIIn Thread to signal the audio thread that a |
|
|
* continuous controller value has changed. This method is meant for |
|
|
* offline rendering and / or for cases where the exact position of the |
|
|
* event in the current audio fragment is already known. |
|
|
* |
|
|
* @param Controller - MIDI controller number of the occured control change |
|
|
* @param Value - value of the control change |
|
|
* @param FragmentPos - sample point position in the current audio |
|
|
* fragment to which this event belongs to |
|
|
*/ |
|
|
void EngineChannel::SendControlChange(uint8_t Controller, uint8_t Value, int32_t FragmentPos) { |
|
|
if (FragmentPos < 0) { |
|
|
dmsg(1,("EngineChannel::SendControlChange(): negative FragmentPos! Seems MIDI driver is buggy!")); |
|
|
} |
|
|
else if (pEngine) { |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
|
|
event.Type = Event::type_control_change; |
|
|
event.Param.CC.Controller = Controller; |
|
|
event.Param.CC.Value = Value; |
|
|
event.pEngineChannel = this; |
|
|
if (this->pEventQueue->write_space() > 0) this->pEventQueue->push(&event); |
|
|
else dmsg(1,("EngineChannel: Input event queue full!")); |
|
|
} |
|
|
} |
|
|
|
|
|
void EngineChannel::ClearEventLists() { |
|
|
pEvents->clear(); |
|
|
// empty MIDI key specific event lists |
|
|
{ |
|
|
RTList<uint>::Iterator iuiKey = pActiveKeys->first(); |
|
|
RTList<uint>::Iterator end = pActiveKeys->end(); |
|
|
for(; iuiKey != end; ++iuiKey) { |
|
|
pMIDIKeyInfo[*iuiKey].pEvents->clear(); // free all events on the key |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
void EngineChannel::ResetControllers() { |
|
|
Pitch = 0; |
|
|
SustainPedal = false; |
|
|
SostenutoPedal = false; |
|
|
GlobalVolume = 1.0f; |
|
|
MidiVolume = 1.0; |
|
|
GlobalPanLeft = 1.0f; |
|
|
GlobalPanRight = 1.0f; |
|
|
iLastPanRequest = 64; |
|
|
GlobalTranspose = 0; |
|
|
// set all MIDI controller values to zero |
|
|
memset(ControllerTable, 0x00, 129); |
|
|
// reset all FX Send levels |
|
|
for ( |
|
|
std::vector<FxSend*>::iterator iter = fxSends.begin(); |
|
|
iter != fxSends.end(); iter++ |
|
|
) { |
|
|
(*iter)->Reset(); |
|
|
} |
|
|
} |
|
|
|
|
|
/** |
|
|
* Copy all events from the engine channel's input event queue buffer to |
|
|
* the internal event list. This will be done at the beginning of each |
|
|
* audio cycle (that is each RenderAudio() call) to distinguish all |
|
|
* events which have to be processed in the current audio cycle. Each |
|
|
* EngineChannel has it's own input event queue for the common channel |
|
|
* specific events (like NoteOn, NoteOff and ControlChange events). |
|
|
* Beside that, the engine also has a input event queue for global |
|
|
* events (usually SysEx messages). |
|
|
* |
|
|
* @param Samples - number of sample points to be processed in the |
|
|
* current audio cycle |
|
|
*/ |
|
|
void EngineChannel::ImportEvents(uint Samples) { |
|
|
// import events from pure software MIDI "devices" |
|
|
// (e.g. virtual keyboard in instrument editor) |
|
|
{ |
|
|
const int FragmentPos = 0; // randomly chosen, we don't care about jitter for virtual MIDI devices |
|
|
Event event = pEngine->pEventGenerator->CreateEvent(FragmentPos); |
|
|
VirtualMidiDevice::event_t devEvent; // the event format we get from the virtual MIDI device |
|
|
// as we're going to (carefully) write some status to the |
|
|
// synchronized struct, we cast away the const |
|
|
ArrayList<VirtualMidiDevice*>& devices = |
|
|
const_cast<ArrayList<VirtualMidiDevice*>&>(virtualMidiDevicesReader_AudioThread.Lock()); |
|
|
// iterate through all virtual MIDI devices |
|
|
for (int i = 0; i < devices.size(); i++) { |
|
|
VirtualMidiDevice* pDev = devices[i]; |
|
|
// I think we can simply flush the whole FIFO(s), the user shouldn't be so fast ;-) |
|
|
while (pDev->GetMidiEventFromDevice(devEvent)) { |
|
|
event.Type = |
|
|
(devEvent.Type == VirtualMidiDevice::EVENT_TYPE_NOTEON) ? |
|
|
Event::type_note_on : Event::type_note_off; |
|
|
event.Param.Note.Key = devEvent.Key; |
|
|
event.Param.Note.Velocity = devEvent.Velocity; |
|
|
event.pEngineChannel = this; |
|
|
// copy event to internal event list |
|
|
if (pEvents->poolIsEmpty()) { |
|
|
dmsg(1,("Event pool emtpy!\n")); |
|
|
goto exitVirtualDevicesLoop; |
|
|
} |
|
|
*pEvents->allocAppend() = event; |
|
|
} |
|
|
} |
|
|
} |
|
|
exitVirtualDevicesLoop: |
|
|
virtualMidiDevicesReader_AudioThread.Unlock(); |
|
|
|
|
|
// import events from the regular MIDI devices |
|
|
RingBuffer<Event,false>::NonVolatileReader eventQueueReader = pEventQueue->get_non_volatile_reader(); |
|
|
Event* pEvent; |
|
|
while (true) { |
|
|
// get next event from input event queue |
|
|
if (!(pEvent = eventQueueReader.pop())) break; |
|
|
// if younger event reached, ignore that and all subsequent ones for now |
|
|
if (pEvent->FragmentPos() >= Samples) { |
|
|
eventQueueReader--; |
|
|
dmsg(2,("Younger Event, pos=%d ,Samples=%d!\n",pEvent->FragmentPos(),Samples)); |
|
|
pEvent->ResetFragmentPos(); |
|
|
break; |
|
|
} |
|
|
// copy event to internal event list |
|
|
if (pEvents->poolIsEmpty()) { |
|
|
dmsg(1,("Event pool emtpy!\n")); |
|
|
break; |
|
|
} |
|
|
*pEvents->allocAppend() = *pEvent; |
|
|
} |
|
|
eventQueueReader.free(); // free all copied events from input queue |
|
|
} |
|
|
|
|
|
void EngineChannel::RemoveAllFxSends() { |
|
|
if (pEngine) pEngine->DisableAndLock(); |
|
|
if (!fxSends.empty()) { // free local render buffers |
|
|
if (pChannelLeft) { |
|
|
delete pChannelLeft; |
|
|
if (pEngine && pEngine->pAudioOutputDevice) { |
|
|
// fallback to render directly to the AudioOutputDevice's buffer |
|
|
pChannelLeft = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelLeft); |
|
|
} else pChannelLeft = NULL; |
|
|
} |
|
|
if (pChannelRight) { |
|
|
delete pChannelRight; |
|
|
if (pEngine && pEngine->pAudioOutputDevice) { |
|
|
// fallback to render directly to the AudioOutputDevice's buffer |
|
|
pChannelRight = pEngine->pAudioOutputDevice->Channel(AudioDeviceChannelRight); |
|
|
} else pChannelRight = NULL; |
|
|
} |
|
|
} |
|
|
for (int i = 0; i < fxSends.size(); i++) delete fxSends[i]; |
|
|
fxSends.clear(); |
|
|
if (pEngine) pEngine->Enable(); |
|
|
} |
|
|
|
|
|
void EngineChannel::Connect(VirtualMidiDevice* pDevice) { |
|
|
// double buffer ... double work ... |
|
|
{ |
|
|
ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.GetConfigForUpdate(); |
|
|
devices.add(pDevice); |
|
|
} |
|
|
{ |
|
|
ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.SwitchConfig(); |
|
|
devices.add(pDevice); |
|
|
} |
|
|
} |
|
|
|
|
|
void EngineChannel::Disconnect(VirtualMidiDevice* pDevice) { |
|
|
// double buffer ... double work ... |
|
|
{ |
|
|
ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.GetConfigForUpdate(); |
|
|
devices.remove(pDevice); |
|
|
} |
|
|
{ |
|
|
ArrayList<VirtualMidiDevice*>& devices = virtualMidiDevices.SwitchConfig(); |
|
|
devices.remove(pDevice); |
|
|
} |
|
|
} |
|
|
|
|
|
float EngineChannel::Volume() { |
|
|
return GlobalVolume; |
|
|
} |
|
|
|
|
|
void EngineChannel::Volume(float f) { |
|
|
GlobalVolume = f; |
|
|
bStatusChanged = true; // status of engine channel has changed, so set notify flag |
|
|
} |
|
|
|
|
|
float EngineChannel::Pan() { |
|
|
return float(iLastPanRequest - 64) / 64.0f; |
|
|
} |
|
|
|
|
|
void EngineChannel::Pan(float f) { |
|
|
int iMidiPan = int(f * 64.0f) + 64; |
|
|
if (iMidiPan > 127) iMidiPan = 127; |
|
|
else if (iMidiPan < 0) iMidiPan = 0; |
|
|
GlobalPanLeft = Engine::PanCurve[128 - iMidiPan]; |
|
|
GlobalPanRight = Engine::PanCurve[iMidiPan]; |
|
|
iLastPanRequest = iMidiPan; |
|
|
} |
|
|
|
|
|
uint EngineChannel::Channels() { |
|
|
return 2; |
|
|
} |
|
|
|
|
167 |
String EngineChannel::InstrumentFileName() { |
String EngineChannel::InstrumentFileName() { |
168 |
return InstrumentFile; |
return EngineChannelBase<Voice, ::gig::DimensionRegion, ::gig::Instrument>::InstrumentFileName(); |
169 |
} |
} |
170 |
|
|
171 |
String EngineChannel::InstrumentName() { |
String EngineChannel::InstrumentFileName(int index) { |
172 |
return InstrumentIdxName; |
if (index == 0) return InstrumentFileName(); |
173 |
} |
if (!pInstrument || !pInstrument->GetParent()) return ""; |
174 |
|
DLS::File* pMainFile = dynamic_cast<DLS::File*>(pInstrument->GetParent()); |
175 |
int EngineChannel::InstrumentIndex() { |
if (!pMainFile) return ""; |
176 |
return InstrumentIdx; |
RIFF::File* pExtensionFile = pMainFile->GetExtensionFile(index); |
177 |
} |
return (pExtensionFile) ? pExtensionFile->GetFileName() : ""; |
|
|
|
|
int EngineChannel::InstrumentStatus() { |
|
|
return InstrumentStat; |
|
|
} |
|
|
|
|
|
String EngineChannel::EngineName() { |
|
|
return LS_GIG_ENGINE_NAME; |
|
178 |
} |
} |
179 |
|
|
180 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |