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

Annotation of /linuxsampler/trunk/src/engines/common/ModulatorGraph.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2298 - (hide annotations) (download)
Fri Dec 9 17:04:24 2011 UTC (12 years, 5 months ago) by iliev
File size: 6253 byte(s)
* use different EQ effect instance for every voice

1 iliev 2296 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5     * Copyright (C) 2011 Grigor Iliev *
6     * *
7     * This program is free software; you can redistribute it and/or modify *
8     * it under the terms of the GNU General Public License as published by *
9     * the Free Software Foundation; either version 2 of the License, or *
10     * (at your option) any later version. *
11     * *
12     * This program is distributed in the hope that it will be useful, *
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15     * GNU General Public License for more details. *
16     * *
17     * You should have received a copy of the GNU General Public License *
18     * along with this program; if not, write to the Free Software *
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
20     * MA 02111-1307 USA *
21     ***************************************************************************/
22    
23     #include "SignalUnitRack.h"
24     #include "../../effects/EffectFactory.h"
25    
26     namespace LinuxSampler {
27    
28     /**
29     * Searches for know EQ effects and create one if the search succeed.
30     */
31     EqSupport::EqSupport() {
32     pEffect = pEffect2 = NULL;
33     BandCount = 0;
34     GainIdxs = FreqIdxs = BandwidthIdxs = NULL;
35    
36     Install();
37     }
38    
39     void EqSupport::Install() {
40     Uninstall();
41     for (int i = 0; i < EffectFactory::AvailableEffectsCount(); i++) {
42     EffectInfo* pEffectInfo = EffectFactory::GetEffectInfo(i);
43     /*if (!pEffectInfo->Name().compare("tap_equalizer_bw")) {
44     try { pEffect = EffectFactory::Create(pEffectInfo); }
45     catch(Exception e) { std::cerr << e.Message(); continue; }
46    
47     BandCount = 8;
48     GainIdxs = new int[BandCount];
49     FreqIdxs = new int[BandCount];
50     BandwidthIdxs = new int[BandCount];
51     for(int i = 0; i < BandCount; i++) {
52     GainIdxs[i] = i;
53     FreqIdxs[i] = i + 8;
54     BandwidthIdxs[i] = i + 16;
55     }
56     dmsg(1,("EQ support: %s\n", pEffectInfo->Description().c_str()));
57     break;
58     }*/
59    
60     if (!pEffectInfo->Name().compare("triplePara")) {
61     try {
62     pEffect = EffectFactory::Create(pEffectInfo);
63     pEffect2 = EffectFactory::Create(pEffectInfo);
64     } catch(Exception e) { std::cerr << e.Message(); continue; }
65    
66     BandCount = 3;
67     GainIdxs = new int[BandCount];
68     FreqIdxs = new int[BandCount];
69     BandwidthIdxs = new int[BandCount];
70     for(int i = 0; i < BandCount; i++) {
71     GainIdxs[i] = i*3 + 3;
72     FreqIdxs[i] = i*3 + 4;
73     BandwidthIdxs[i] = i*3 + 5;
74     }
75    
76     pEffect->InputControl(0)->SetValue(0); // Low-shelving gain (0dB)
77     pEffect->InputControl(12)->SetValue(0); // High-shelving gain (0dB)
78    
79     pEffect2->InputControl(0)->SetValue(0); // Low-shelving gain (0dB)
80     pEffect2->InputControl(12)->SetValue(0); // High-shelving gain (0dB)
81    
82     break;
83     }
84     }
85    
86 iliev 2298 if (pEffect == NULL) return;
87 iliev 2296
88     Reset();
89     }
90    
91 iliev 2298 void EqSupport::PrintInfo() {
92     if (!HasSupport()) {
93     dmsg(1,("EQ support: no\n"));
94     } else {
95     dmsg(1,("EQ support: %s\n", pEffect->GetEffectInfo()->Description().c_str()));
96     }
97     }
98    
99 iliev 2296 void EqSupport::SetGain(int band, float gain) {
100     if (!HasSupport()) return;
101     if (band < 0 || band >= BandCount) throw Exception("EQ support: invalid band");
102    
103     EffectControl* ctrl = pEffect->InputControl(GainIdxs[band]);
104     gain = check(ctrl->MinValue(), ctrl->MaxValue(), gain);
105     ctrl->SetValue(gain);
106     if (pEffect2 != NULL) pEffect2->InputControl(GainIdxs[band])->SetValue(gain);
107     }
108    
109     void EqSupport::SetFreq(int band, float freq) {
110     if (!HasSupport()) return;
111     if (band < 0 || band >= BandCount) throw Exception("EQ support: invalid band");
112    
113     EffectControl* ctrl = pEffect->InputControl(FreqIdxs[band]);
114     freq = check(ctrl->MinValue(), ctrl->MaxValue(), freq);
115     ctrl->SetValue(freq);
116     if (pEffect2 != NULL) pEffect2->InputControl(FreqIdxs[band])->SetValue(freq);
117     }
118    
119     void EqSupport::SetBandwidth(int band, float octaves) {
120     if (!HasSupport()) return;
121     if (band < 0 || band >= BandCount) throw Exception("EQ support: invalid band");
122    
123     EffectControl* ctrl = pEffect->InputControl(BandwidthIdxs[band]);
124     octaves = check(ctrl->MinValue(), ctrl->MaxValue(), octaves);
125     ctrl->SetValue(octaves);
126     if (pEffect2 != NULL) pEffect2->InputControl(BandwidthIdxs[band])->SetValue(octaves);
127     }
128    
129     void EqSupport::Uninstall() {
130     if (pEffect != NULL) EffectFactory::Destroy(pEffect);
131     if (pEffect2 != NULL) EffectFactory::Destroy(pEffect2);
132     if (GainIdxs != NULL) delete[] GainIdxs;
133     if (FreqIdxs != NULL) delete[] FreqIdxs;
134     if (BandwidthIdxs != NULL) delete[] BandwidthIdxs;
135    
136     pEffect = pEffect2 = NULL;
137     BandCount = 0;
138     GainIdxs = FreqIdxs = BandwidthIdxs = NULL;
139     }
140    
141     EqSupport::~EqSupport() {
142     Uninstall();
143     }
144     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC