/[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 2135 - (show annotations) (download)
Thu Sep 30 20:00:43 2010 UTC (13 years, 6 months ago) by schoenebeck
File size: 5262 byte(s)
* added and implemented a set of 19 new LSCP commands for controlling
  internal effects:
  - added LSCP command "GET AVAILABLE_EFFECTS"
  - added LSCP command "LIST AVAILABLE_EFFECTS"
  - added LSCP command "GET EFFECT INFO <effect-index>"
  - added LSCP command "CREATE EFFECT_INSTANCE <effect-index>"
  - added LSCP command
    "CREATE EFFECT_INSTANCE <effect-system> <module> <effect-name>"
  - added LSCP command "DESTROY EFFECT_INSTANCE <effect-instance>"
  - added LSCP command "GET EFFECT_INSTANCES"
  - added LSCP command "LIST EFFECT_INSTANCES"
  - added LSCP command "GET EFFECT_INSTANCE INFO <effect-instance>"
  - added LSCP command "GET EFFECT_INSTANCE_INPUT_CONTROL INFO
    <effect-instance> <input-control>"
  - added LSCP command "SET EFFECT_INSTANCE_INPUT_CONTROL <effect-instance>
    <input-control> <value>"
  - added LSCP command "GET MASTER_EFFECT_CHAINS <audio-device>"
  - added LSCP command "LIST MASTER_EFFECT_CHAINS <audio-device>"
  - added LSCP command "ADD MASTER_EFFECT_CHAIN <audio-device>"
  - added LSCP command
    "REMOVE MASTER_EFFECT_CHAIN <audio-device> <effect-chain>"
  - added LSCP command
    "GET MASTER_EFFECT_CHAIN INFO <audio-device> <effect-chain>"
  - added LSCP command "APPEND MASTER_EFFECT_CHAIN EFFECT <audio-device>
    <effect-chain> <effect-instance>"
  - added LSCP command "INSERT MASTER_EFFECT_CHAIN EFFECT <audio-device>
    <effect-chain> <effect-instance> <effect-chain-pos>"
  - added LSCP command "REMOVE MASTER_EFFECT_CHAIN EFFECT <audio-device>
    <effect-chain> <effect-instance>"
* bumped version to 1.0.0.cvs7

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 }
37
38 void EffectChain::InsertEffect(Effect* pEffect, int iChainPos) throw (Exception) {
39 if (iChainPos < 0 || iChainPos >= vEntries.size())
40 throw Exception(
41 "Cannot insert effect at chain position " +
42 ToString(iChainPos) + ", index out of bounds."
43 );
44 pEffect->InitEffect(pDevice); // might throw Exception !
45 std::vector<_ChainEntry>::iterator iter = vEntries.begin();
46 for (int i = 0; i < iChainPos; ++i) ++iter;
47 _ChainEntry entry = { pEffect, true };
48 vEntries.insert(iter, entry);
49 pEffect->SetParent(this);
50 }
51
52 void EffectChain::RemoveEffect(int iChainPos) throw (Exception) {
53 if (iChainPos < 0 || iChainPos >= vEntries.size())
54 throw Exception(
55 "Cannot remove effect at chain position " +
56 ToString(iChainPos) + ", index out of bounds."
57 );
58 std::vector<_ChainEntry>::iterator iter = vEntries.begin();
59 for (int i = 0; i < iChainPos; ++i) ++iter;
60 Effect* pEffect = (*iter).pEffect;
61 vEntries.erase(iter);
62 pEffect->SetParent(NULL); // mark effect as not in use anymore
63 }
64
65 void EffectChain::RenderAudio(uint Samples) {
66 for (int i = 0; i < vEntries.size(); ++i) {
67 Effect* pCurrentEffect = vEntries[i].pEffect;
68 if (i) { // import signal from previous effect
69 Effect* pPrevEffect = vEntries[i - 1].pEffect;
70 for (int iChan = 0; iChan < pPrevEffect->OutputChannelCount() && iChan < pCurrentEffect->InputChannelCount(); ++iChan) {
71 pPrevEffect->OutputChannel(iChan)->MixTo(
72 pCurrentEffect->InputChannel(iChan),
73 Samples
74 );
75 }
76 }
77 if (IsEffectActive(i)) pCurrentEffect->RenderAudio(Samples);
78 else { //TODO: lazy, suboptimal implementation of inactive, bypassed effects
79 for (int iChan = 0; iChan < pCurrentEffect->OutputChannelCount() && iChan < pCurrentEffect->InputChannelCount(); ++iChan) {
80 pCurrentEffect->InputChannel(iChan)->MixTo(
81 pCurrentEffect->OutputChannel(iChan),
82 Samples
83 );
84 }
85 }
86 }
87 }
88
89 Effect* EffectChain::GetEffect(int iChainPos) const {
90 if (iChainPos < 0 || iChainPos >= vEntries.size()) return NULL;
91 return vEntries[iChainPos].pEffect;
92 }
93
94 int EffectChain::EffectCount() const {
95 return vEntries.size();
96 }
97
98 void EffectChain::SetEffectActive(int iChainPos, bool bOn) throw (Exception) {
99 if (iChainPos < 0 || iChainPos >= vEntries.size())
100 throw Exception(
101 "Cannot change active state of effect at chain position " +
102 ToString(iChainPos) + ", index out of bounds."
103 );
104 vEntries[iChainPos].bActive = bOn;
105 }
106
107 bool EffectChain::IsEffectActive(int iChainPos) const {
108 if (iChainPos < 0 || iChainPos >= vEntries.size()) return false;
109 return vEntries[iChainPos].bActive;
110 }
111
112 void EffectChain::ClearAllChannels() {
113 for (int iEffect = 0; iEffect < vEntries.size(); ++iEffect) {
114 Effect* pEffect = vEntries[iEffect].pEffect;
115 for (int i = 0; i < pEffect->InputChannelCount(); ++i)
116 pEffect->InputChannel(i)->Clear(); // zero out buffers
117 for (int i = 0; i < pEffect->OutputChannelCount(); ++i)
118 pEffect->OutputChannel(i)->Clear(); // zero out buffers
119 }
120 }
121
122 int EffectChain::ID() const {
123 return iID;
124 }
125
126 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC