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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2137 - (hide annotations) (download)
Mon Oct 4 12:20:23 2010 UTC (13 years, 6 months ago) by schoenebeck
File size: 8224 byte(s)
* revised previously added new LSCP commands regarding effect handling:
  renamed "master effects" to "send effects", since this is the actual
  correct common term for those effects
* also corrected the names regarding "send effects" in the respective
  methods of the "FxSsnd" class and "AudioOutputDevice" class of the
  sampler's C++ API, the old methods are still available but marked as
  deprecated and scheduled for removal
* added LSCP command "SET FX_SEND SEND_EFFECT <sampler_channel>
  <fx_send_id> <effect_chain> <chain_pos>"
* added LSCP command "REMOVE FX_SEND SEND_EFFECT <sampler_channel>
  <fx_send_id>"
* added a list of common known LADSPA paths (for Windows and POSIX) which
  will be automatically checked for being used as LADSPA plugin directory
  (if the user did not set the LADSPA_PATH environment variable explicitly)
* bumped version to 1.0.0.cvs8

1 schoenebeck 1001 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 persson 2114 * Copyright (C) 2005 - 2010 Christian Schoenebeck *
7 schoenebeck 1001 * *
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 schoenebeck 1424 #include "../common/global_private.h"
27 schoenebeck 1001 #include "../drivers/audio/AudioOutputDevice.h"
28 schoenebeck 1017 #include "../common/RTMath.h"
29 schoenebeck 1001
30     #include <map>
31    
32 schoenebeck 1040 #define DEFAULT_FX_SEND_LEVEL 0.0f
33    
34 schoenebeck 1001 namespace LinuxSampler {
35    
36 schoenebeck 1722 FxSend::FxSend(EngineChannel* pEngineChannel, uint8_t MidiCtrl, String Name) throw (Exception)
37 schoenebeck 2137 : iDestinationEffectChain(-1), iDestinationEffectChainPos(-1), bInfoChanged(false)
38 schoenebeck 1722 {
39 schoenebeck 1001 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 schoenebeck 1026 SetMidiController(MidiCtrl);
47 schoenebeck 1001 sName = Name;
48 schoenebeck 1017
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 schoenebeck 1040 fLevel = DEFAULT_FX_SEND_LEVEL;
79 schoenebeck 1001 }
80    
81 schoenebeck 2137 int FxSend::DestinationEffectChain() const {
82     return iDestinationEffectChain;
83 schoenebeck 1722 }
84    
85 schoenebeck 2137 int FxSend::DestinationEffectChainPosition() const {
86     return iDestinationEffectChainPos;
87 schoenebeck 1722 }
88    
89 schoenebeck 2137 void FxSend::SetDestinationEffect(int iChain, int iChainPos) throw (Exception) {
90 schoenebeck 1722 AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
91 schoenebeck 2137 if (iChain < 0 || iChain >= pDevice->SendEffectChainCount())
92 schoenebeck 1722 throw Exception(
93 schoenebeck 2137 "Could not assign FX Send to send effect chain " +
94 schoenebeck 1722 ToString(iChain) + ": effect chain doesn't exist."
95     );
96 schoenebeck 2137 if (iChainPos < 0 || iChainPos >= pDevice->SendEffectChain(iChain)->EffectCount())
97 schoenebeck 1722 throw Exception(
98 schoenebeck 2137 "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 schoenebeck 1722 );
102 schoenebeck 2137 iDestinationEffectChain = iChain;
103     iDestinationEffectChainPos = iChainPos;
104 schoenebeck 1722 }
105    
106 schoenebeck 2137 // 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 schoenebeck 1001 int FxSend::DestinationChannel(int SrcChan) {
122     if (SrcChan >= pEngineChannel->Channels()) return -1;
123     return Routing[SrcChan];
124     }
125    
126     void FxSend::SetDestinationChannel(int SrcChan, int DstChan) throw (Exception) {
127     if (SrcChan < 0 || SrcChan >= pEngineChannel->Channels())
128     throw Exception("Cannot alter FxSend routing, source channel out of bounds");
129     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
130     if (pDevice) {
131     if (DstChan < 0 || DstChan >= pDevice->ChannelCount())
132     throw Exception("Cannot alter FxSend routing, destination channel out of bounds");
133     } else { // no audio device assigned yet
134     if (DstChan < 0 || DstChan >= pEngineChannel->Channels())
135     throw Exception(
136     "there is no audio device yet, so you cannot set a "
137     "FxSend destination channel higher than the engine "
138     "channel's amount of channels"
139     );
140     }
141     Routing[SrcChan] = DstChan;
142     }
143    
144     void FxSend::UpdateChannels() {
145     if (Routing.size() > pEngineChannel->Channels()) {
146     // add routings with default destinations
147     AudioOutputDevice* pDevice = pEngineChannel->GetAudioOutputDevice();
148     const int iChanOffset = (pDevice) ? pDevice->ChannelCount() - pEngineChannel->Channels() : 0;
149     for (int i = Routing.size(); i < pEngineChannel->Channels(); i++) {
150     const int iDestination = iChanOffset + i;
151     Routing.push_back(iDestination);
152     }
153     } else if (Routing.size() < pEngineChannel->Channels()) {
154     // shrink routing vector
155     Routing.resize(pEngineChannel->Channels());
156     }
157     }
158    
159     float FxSend::Level() {
160     return fLevel;
161     }
162    
163     void FxSend::SetLevel(float f) {
164 iliev 1108 if(fLevel == f) return;
165 schoenebeck 1001 fLevel = f;
166 iliev 1108 SetInfoChanged(true);
167 schoenebeck 1001 }
168    
169     void FxSend::SetLevel(uint8_t iMidiValue) {
170     fLevel = float(iMidiValue & 0x7f) / 127.0f;
171 iliev 1108 SetInfoChanged(true);
172 schoenebeck 1001 }
173    
174 schoenebeck 1040 void FxSend::Reset() {
175 iliev 1108 SetLevel(DEFAULT_FX_SEND_LEVEL);
176 schoenebeck 1040 }
177    
178 schoenebeck 1001 uint8_t FxSend::MidiController() {
179     return MidiFxSendController;
180     }
181    
182     void FxSend::SetMidiController(uint8_t MidiCtrl) throw (Exception) {
183 schoenebeck 1026 if (MidiCtrl >> 7)
184     throw Exception("Invalid MIDI controller " + ToString((int)MidiCtrl));
185 schoenebeck 1001 MidiFxSendController = MidiCtrl;
186     }
187    
188     String FxSend::Name() {
189     return sName;
190     }
191    
192 iliev 1135 void FxSend::SetName(String Name) {
193     sName = Name;
194     }
195    
196 schoenebeck 1001 uint FxSend::Id() {
197     return iId;
198     }
199    
200 iliev 1108 void FxSend::SetInfoChanged(bool b) {
201     bInfoChanged = b;
202     }
203    
204     bool FxSend::IsInfoChanged() {
205     return bInfoChanged;
206     }
207    
208 schoenebeck 1001 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC