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, 2006 Christian Schoenebeck * |
* Copyright (C) 2005 - 2010 Christian Schoenebeck * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
9 |
* 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 |
#include "FxSend.h" |
#include "FxSend.h" |
25 |
|
|
26 |
|
#include "../common/global_private.h" |
27 |
#include "../drivers/audio/AudioOutputDevice.h" |
#include "../drivers/audio/AudioOutputDevice.h" |
28 |
|
#include "../common/RTMath.h" |
29 |
|
|
30 |
#include <map> |
#include <map> |
31 |
|
|
32 |
namespace LinuxSampler { |
#define DEFAULT_FX_SEND_LEVEL 0.0f |
33 |
|
|
34 |
/* |
namespace LinuxSampler { |
|
FIXME: we create fx send indeces globally for now, although we might |
|
|
want them to be an individual sequence per sampler channel, beside that |
|
|
we don't handle the cases yet where __indexer overflows back to 0 |
|
|
*/ |
|
|
static uint __indexer = 0; |
|
35 |
|
|
36 |
FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) { |
FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) throw (Exception) |
37 |
|
: iDestinationEffectChain(-1), iDestinationEffectChainPos(-1), bInfoChanged(false) |
38 |
|
{ |
39 |
this->pEngineChannel = pEngineChannel; |
this->pEngineChannel = pEngineChannel; |
40 |
AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice(); |
AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice(); |
41 |
const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0; |
const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0; |
43 |
const int iDestination = iChanOffset + i; |
const int iDestination = iChanOffset + i; |
44 |
Routing.push_back(iDestination); |
Routing.push_back(iDestination); |
45 |
} |
} |
46 |
MidiFxSendController = MidiCtrl; |
SetMidiController(MidiCtrl); |
47 |
sName = Name; |
sName = Name; |
48 |
iId = __indexer; |
|
49 |
__indexer++; |
// create an EngineChannel unique ID for this FxSend instance |
50 |
fLevel = 0.3f; // default FX send level |
if (!pEngineChannel->GetFxSendCount()) iId = 0; |
51 |
|
else { |
52 |
|
// get the highest existing map ID |
53 |
|
uint highestIndex = 0; |
54 |
|
for (uint i = 0; i < pEngineChannel->GetFxSendCount(); i++) |
55 |
|
highestIndex = RTMath::Max(highestIndex, pEngineChannel->GetFxSend(i)->Id()); |
56 |
|
// check if we reached the index limit |
57 |
|
if (highestIndex + 1 < highestIndex) { |
58 |
|
// search for an unoccupied map ID starting from 0 |
59 |
|
for (uint i = 0; i < highestIndex; i++) { |
60 |
|
bool bOccupied = false; |
61 |
|
for (uint j = 0; j < pEngineChannel->GetFxSendCount(); j++) { |
62 |
|
if (pEngineChannel->GetFxSend(j)->Id() == i) { |
63 |
|
bOccupied = true; |
64 |
|
break; |
65 |
|
} |
66 |
|
} |
67 |
|
if (!bOccupied) { |
68 |
|
iId = i; |
69 |
|
goto __done; |
70 |
|
} |
71 |
|
} |
72 |
|
throw Exception("Internal error: could not find unoccupied FxSend ID."); |
73 |
|
} |
74 |
|
iId = highestIndex + 1; |
75 |
|
} |
76 |
|
__done: |
77 |
|
|
78 |
|
fLevel = DEFAULT_FX_SEND_LEVEL; |
79 |
|
} |
80 |
|
|
81 |
|
int FxSend::DestinationEffectChain() const { |
82 |
|
return iDestinationEffectChain; |
83 |
|
} |
84 |
|
|
85 |
|
int FxSend::DestinationEffectChainPosition() const { |
86 |
|
return iDestinationEffectChainPos; |
87 |
|
} |
88 |
|
|
89 |
|
void FxSend::SetDestinationEffect(int iChain, int iChainPos) throw (Exception) { |
90 |
|
AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice(); |
91 |
|
if (iChain < 0 || iChain >= pDevice->SendEffectChainCount()) |
92 |
|
throw Exception( |
93 |
|
"Could not assign FX Send to send effect chain " + |
94 |
|
ToString(iChain) + ": effect chain doesn't exist." |
95 |
|
); |
96 |
|
if (iChainPos < 0 || iChainPos >= pDevice->SendEffectChain(iChain)->EffectCount()) |
97 |
|
throw Exception( |
98 |
|
"Could not assign FX Send to send effect chain position " + |
99 |
|
ToString(iChainPos) + " of send effect chain " + ToString(iChain) + |
100 |
|
": effect chain position out of bounds." |
101 |
|
); |
102 |
|
iDestinationEffectChain = iChain; |
103 |
|
iDestinationEffectChainPos = iChainPos; |
104 |
|
} |
105 |
|
|
106 |
|
// TODO: to be removed |
107 |
|
int FxSend::DestinationMasterEffectChain() const { |
108 |
|
return DestinationEffectChain(); |
109 |
|
} |
110 |
|
|
111 |
|
// TODO: to be removed |
112 |
|
int FxSend::DestinationMasterEffect() const { |
113 |
|
return DestinationEffectChainPosition(); |
114 |
|
} |
115 |
|
|
116 |
|
// TODO: to be removed |
117 |
|
void FxSend::SetDestinationMasterEffect(int iChain, int iChainPos) throw (Exception) { |
118 |
|
SetDestinationEffect(iChain, iChainPos); |
119 |
} |
} |
120 |
|
|
121 |
int FxSend::DestinationChannel(int SrcChan) { |
int FxSend::DestinationChannel(int SrcChan) { |
161 |
} |
} |
162 |
|
|
163 |
void FxSend::SetLevel(float f) { |
void FxSend::SetLevel(float f) { |
164 |
|
if(fLevel == f) return; |
165 |
fLevel = f; |
fLevel = f; |
166 |
|
SetInfoChanged(true); |
167 |
} |
} |
168 |
|
|
169 |
void FxSend::SetLevel(uint8_t iMidiValue) { |
void FxSend::SetLevel(uint8_t iMidiValue) { |
170 |
fLevel = float(iMidiValue & 0x7f) / 127.0f; |
fLevel = float(iMidiValue & 0x7f) / 127.0f; |
171 |
|
SetInfoChanged(true); |
172 |
|
} |
173 |
|
|
174 |
|
void FxSend::Reset() { |
175 |
|
SetLevel(DEFAULT_FX_SEND_LEVEL); |
176 |
} |
} |
177 |
|
|
178 |
uint8_t FxSend::MidiController() { |
uint8_t FxSend::MidiController() { |
180 |
} |
} |
181 |
|
|
182 |
void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) { |
void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) { |
183 |
if (MidiCtrl & 0x7f) |
if (MidiCtrl >> 7) |
184 |
throw Exception("Invalid MIDI controller"); |
throw Exception("Invalid MIDI controller " + ToString((int)MidiCtrl)); |
185 |
MidiFxSendController = MidiCtrl; |
MidiFxSendController = MidiCtrl; |
186 |
} |
} |
187 |
|
|
189 |
return sName; |
return sName; |
190 |
} |
} |
191 |
|
|
192 |
|
void FxSend::SetName(String Name) { |
193 |
|
sName = Name; |
194 |
|
} |
195 |
|
|
196 |
uint FxSend::Id() { |
uint FxSend::Id() { |
197 |
return iId; |
return iId; |
198 |
} |
} |
199 |
|
|
200 |
|
void FxSend::SetInfoChanged(bool b) { |
201 |
|
bInfoChanged = b; |
202 |
|
} |
203 |
|
|
204 |
|
bool FxSend::IsInfoChanged() { |
205 |
|
return bInfoChanged; |
206 |
|
} |
207 |
|
|
208 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |