/[svn]/linuxsampler/trunk/src/effects/EffectChain.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/effects/EffectChain.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2198 - (show annotations) (download)
Sun Jul 3 18:06:51 2011 UTC (12 years, 8 months ago) by iliev
File size: 5292 byte(s)
* bugfix: LSCP command "REMOVE FX_SEND EFFECT" was broken
* fixed a bug in FxSend::SetDestinationEffect
* bugfix: parent was not set when effect instance is appended
* bugfix: was able to remove effect chain while FX send is connected to it
* bugfix: was able to remove effect instance from effect chain while
  FX send is connected to that instance

1 /***************************************************************************
2 * *
3 * Copyright (C) 2008 - 2010 Christian Schoenebeck *
4 * *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the Free Software *
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18 * MA 02111-1307 USA *
19 ***************************************************************************/
20
21 #include "EffectChain.h"
22
23 #include "../common/global_private.h"
24
25 namespace LinuxSampler {
26
27 EffectChain::EffectChain(AudioOutputDevice* pDevice, int iEffectChainId) {
28 this->pDevice = pDevice;
29 iID = iEffectChainId;
30 }
31
32 void EffectChain::AppendEffect(Effect* pEffect) {
33 pEffect->InitEffect(pDevice);
34 _ChainEntry entry = { pEffect, true };
35 vEntries.push_back(entry);
36 pEffect->SetParent(this);
37 }
38
39 void EffectChain::InsertEffect(Effect* pEffect, int iChainPos) throw (Exception) {
40 if (iChainPos < 0 || iChainPos >= vEntries.size())
41 throw Exception(
42 "Cannot insert effect at chain position " +
43 ToString(iChainPos) + ", index out of bounds."
44 );
45 pEffect->InitEffect(pDevice); // might throw Exception !
46 std::vector<_ChainEntry>::iterator iter = vEntries.begin();
47 for (int i = 0; i < iChainPos; ++i) ++iter;
48 _ChainEntry entry = { pEffect, true };
49 vEntries.insert(iter, entry);
50 pEffect->SetParent(this);
51 }
52
53 void EffectChain::RemoveEffect(int iChainPos) throw (Exception) {
54 if (iChainPos < 0 || iChainPos >= vEntries.size())
55 throw Exception(
56 "Cannot remove effect at chain position " +
57 ToString(iChainPos) + ", index out of bounds."
58 );
59 std::vector<_ChainEntry>::iterator iter = vEntries.begin();
60 for (int i = 0; i < iChainPos; ++i) ++iter;
61 Effect* pEffect = (*iter).pEffect;
62 vEntries.erase(iter);
63 pEffect->SetParent(NULL); // mark effect as not in use anymore
64 }
65
66 void EffectChain::RenderAudio(uint Samples) {
67 for (int i = 0; i < vEntries.size(); ++i) {
68 Effect* pCurrentEffect = vEntries[i].pEffect;
69 if (i) { // import signal from previous effect
70 Effect* pPrevEffect = vEntries[i - 1].pEffect;
71 for (int iChan = 0; iChan < pPrevEffect->OutputChannelCount() && iChan < pCurrentEffect->InputChannelCount(); ++iChan) {
72 pPrevEffect->OutputChannel(iChan)->MixTo(
73 pCurrentEffect->InputChannel(iChan),
74 Samples
75 );
76 }
77 }
78 if (IsEffectActive(i)) pCurrentEffect->RenderAudio(Samples);
79 else { //TODO: lazy, suboptimal implementation of inactive, bypassed effects
80 for (int iChan = 0; iChan < pCurrentEffect->OutputChannelCount() && iChan < pCurrentEffect->InputChannelCount(); ++iChan) {
81 pCurrentEffect->InputChannel(iChan)->MixTo(
82 pCurrentEffect->OutputChannel(iChan),
83 Samples
84 );
85 }
86 }
87 }
88 }
89
90 Effect* EffectChain::GetEffect(int iChainPos) const {
91 if (iChainPos < 0 || iChainPos >= vEntries.size()) return NULL;
92 return vEntries[iChainPos].pEffect;
93 }
94
95 int EffectChain::EffectCount() const {
96 return vEntries.size();
97 }
98
99 void EffectChain::SetEffectActive(int iChainPos, bool bOn) throw (Exception) {
100 if (iChainPos < 0 || iChainPos >= vEntries.size())
101 throw Exception(
102 "Cannot change active state of effect at chain position " +
103 ToString(iChainPos) + ", index out of bounds."
104 );
105 vEntries[iChainPos].bActive = bOn;
106 }
107
108 bool EffectChain::IsEffectActive(int iChainPos) const {
109 if (iChainPos < 0 || iChainPos >= vEntries.size()) return false;
110 return vEntries[iChainPos].bActive;
111 }
112
113 void EffectChain::ClearAllChannels() {
114 for (int iEffect = 0; iEffect < vEntries.size(); ++iEffect) {
115 Effect* pEffect = vEntries[iEffect].pEffect;
116 for (int i = 0; i < pEffect->InputChannelCount(); ++i)
117 pEffect->InputChannel(i)->Clear(); // zero out buffers
118 for (int i = 0; i < pEffect->OutputChannelCount(); ++i)
119 pEffect->OutputChannel(i)->Clear(); // zero out buffers
120 }
121 }
122
123 int EffectChain::ID() const {
124 return iID;
125 }
126
127 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC