/[svn]/linuxsampler/trunk/src/engines/FxSend.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/FxSend.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1722 - (show annotations) (download)
Thu Apr 10 17:41:32 2008 UTC (16 years ago) by schoenebeck
File size: 7682 byte(s)
* minor preparations for internal effects support
* bumped version to 0.5.1.5cvs

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 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 *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library 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 library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 ***************************************************************************/
23
24 #include "FxSend.h"
25
26 #include "../common/global_private.h"
27 #include "../drivers/audio/AudioOutputDevice.h"
28 #include "../common/RTMath.h"
29
30 #include <map>
31
32 #define DEFAULT_FX_SEND_LEVEL 0.0f
33
34 namespace LinuxSampler {
35
36 FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) throw (Exception)
37 : iMasterEffectChain(-1), iMasterEffect(-1)
38 {
39 this->pEngineChannel = pEngineChannel;
40 AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
41 const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
42 for (int i = 0; i < pEngineChannel->Channels(); i++) {
43 const int iDestination = iChanOffset + i;
44 Routing.push_back(iDestination);
45 }
46 SetMidiController(MidiCtrl);
47 sName = Name;
48
49 // create an EngineChannel unique ID for this FxSend instance
50 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::DestinationMasterEffectChain() const {
82 return iMasterEffectChain;
83 }
84
85 int FxSend::DestinationMasterEffect() const {
86 return iMasterEffect;
87 }
88
89 void FxSend::SetDestinationMasterEffect(int iChain, int iEffect) throw (Exception) {
90 AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
91 if (iChain < 0 || iChain >= pDevice->MasterEffectChainCount())
92 throw Exception(
93 "Could not assign FX Send to master effect chain " +
94 ToString(iChain) + ": effect chain doesn't exist."
95 );
96 if (iEffect < 0 || iEffect >= pDevice->MasterEffectChain(iChain)->EffectCount())
97 throw Exception(
98 "Could not assign FX Send to master effect " +
99 ToString(iEffect) + " of effect chain " + ToString(iChain) +
100 ": effect doesn't exist."
101 );
102 iMasterEffectChain = iChain;
103 iMasterEffect = iEffect;
104 }
105
106 int FxSend::DestinationChannel(int SrcChan) {
107 if (SrcChan >= pEngineChannel->Channels()) return -1;
108 return Routing[SrcChan];
109 }
110
111 void FxSend::SetDestinationChannel(int SrcChan, int DstChan) throw (Exception) {
112 if (SrcChan < 0 || SrcChan >= pEngineChannel->Channels())
113 throw Exception("Cannot alter FxSend routing, source channel out of bounds");
114 AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
115 if (pDevice) {
116 if (DstChan < 0 || DstChan >= pDevice->ChannelCount())
117 throw Exception("Cannot alter FxSend routing, destination channel out of bounds");
118 } else { // no audio device assigned yet
119 if (DstChan < 0 || DstChan >= pEngineChannel->Channels())
120 throw Exception(
121 "there is no audio device yet, so you cannot set a "
122 "FxSend destination channel higher than the engine "
123 "channel's amount of channels"
124 );
125 }
126 Routing[SrcChan] = DstChan;
127 }
128
129 void FxSend::UpdateChannels() {
130 if (Routing.size() > pEngineChannel->Channels()) {
131 // add routings with default destinations
132 AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
133 const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
134 for (int i = Routing.size(); i < pEngineChannel->Channels(); i++) {
135 const int iDestination = iChanOffset + i;
136 Routing.push_back(iDestination);
137 }
138 } else if (Routing.size() < pEngineChannel->Channels()) {
139 // shrink routing vector
140 Routing.resize(pEngineChannel->Channels());
141 }
142 }
143
144 float FxSend::Level() {
145 return fLevel;
146 }
147
148 void FxSend::SetLevel(float f) {
149 if(fLevel == f) return;
150 fLevel = f;
151 SetInfoChanged(true);
152 }
153
154 void FxSend::SetLevel(uint8_t iMidiValue) {
155 fLevel = float(iMidiValue & 0x7f) / 127.0f;
156 SetInfoChanged(true);
157 }
158
159 void FxSend::Reset() {
160 SetLevel(DEFAULT_FX_SEND_LEVEL);
161 }
162
163 uint8_t FxSend::MidiController() {
164 return MidiFxSendController;
165 }
166
167 void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) {
168 if (MidiCtrl >> 7)
169 throw Exception("Invalid MIDI controller " + ToString((int)MidiCtrl));
170 MidiFxSendController = MidiCtrl;
171 }
172
173 String FxSend::Name() {
174 return sName;
175 }
176
177 void FxSend::SetName(String Name) {
178 sName = Name;
179 }
180
181 uint FxSend::Id() {
182 return iId;
183 }
184
185 void FxSend::SetInfoChanged(bool b) {
186 bInfoChanged = b;
187 }
188
189 bool FxSend::IsInfoChanged() {
190 return bInfoChanged;
191 }
192
193 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC