~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to noatun/noatun/library/noatunarts/StereoEffectStack_impl.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "noatunarts.h"
 
2
 
 
3
#include <artsflow.h>
 
4
#include <flowsystem.h>
 
5
#include <stdsynthmodule.h>
 
6
#include <debug.h>
 
7
 
 
8
using namespace std;
 
9
using namespace Arts;
 
10
 
 
11
namespace Noatun
 
12
{
 
13
class StereoEffectStack_impl : public StereoEffectStack_skel, public StdSynthModule
 
14
{
 
15
        public:
 
16
                long nextID;
 
17
 
 
18
                struct EffectEntry
 
19
                {
 
20
                        StereoEffect effect;
 
21
                        string name;
 
22
                        long id;
 
23
                };
 
24
                list<EffectEntry *> fx;
 
25
 
 
26
                void xconnect(bool connect, Object from, string fromP, Object to, string toP)
 
27
                {
 
28
                        if(connect)
 
29
                                from._node()->connect(fromP,to._node(),toP);
 
30
                        else
 
31
                                from._node()->disconnect(fromP,to._node(),toP);
 
32
                }
 
33
                
 
34
                void xvirtualize(bool connect, string myPort, Object impl, string implPort)
 
35
                {
 
36
                        if(connect)
 
37
                                _node()->virtualize(myPort,impl._node(),implPort);
 
38
                        else
 
39
                                _node()->devirtualize(myPort,impl._node(),implPort);
 
40
                }
 
41
                
 
42
                void internalconnect(bool c)
 
43
                {
 
44
                        if(fx.empty())
 
45
                        {
 
46
                                /* no effects - forward input through to output */
 
47
                                xvirtualize(c,"outleft",Object::_from_base(this->_copy()),"inleft");
 
48
                                xvirtualize(c,"outright",Object::_from_base(this->_copy()),"inright");
 
49
                        }
 
50
                        else
 
51
                        {
 
52
                                list<EffectEntry *>::iterator ei;
 
53
                                EffectEntry *laste = 0;
 
54
 
 
55
                                long count = 0;
 
56
                                for(ei = fx.begin(); ei != fx.end(); ei++, count++)
 
57
                                {
 
58
                                        EffectEntry *e = *ei;
 
59
                                        if(count == 0)          /* top of chain? virtualize to effect */
 
60
                                        {
 
61
                                                xvirtualize(c,"inleft",e->effect,"inleft");
 
62
                                                xvirtualize(c,"inright",e->effect,"inright");
 
63
                                        }
 
64
                                        else                            /* not top? connect last effect to current effect */
 
65
                                        {
 
66
                                                xconnect(c,laste->effect,"outleft",e->effect,"inleft");
 
67
                                                xconnect(c,laste->effect,"outright",e->effect,"inright");
 
68
                                        }
 
69
                                        laste = e;
 
70
                                }
 
71
                                /* end: virtualize effect output to our output */
 
72
                                xvirtualize(c,"outleft",laste->effect,"outleft");
 
73
                                xvirtualize(c,"outright",laste->effect,"outright");
 
74
                        }
 
75
                }
 
76
                void disconnect() { internalconnect(false); }
 
77
                void reconnect()  { internalconnect(true); }
 
78
 
 
79
 
 
80
                long insertAfter(long after, StereoEffect effect, const string &name)
 
81
                {
 
82
                        arts_return_val_if_fail(!effect.isNull(),0);
 
83
                        disconnect();
 
84
 
 
85
                        list<EffectEntry*>::iterator i = fx.begin();
 
86
 
 
87
                        bool found=false;
 
88
                        // seek through until we find 'after'
 
89
                        while(i != fx.end())
 
90
                                if((*i)->id == after)
 
91
                                {
 
92
                                        found = true;
 
93
                                        break;
 
94
                                }
 
95
                                else
 
96
                                        i++;
 
97
 
 
98
                        long newId=0;
 
99
                        if (found)
 
100
                        {
 
101
                                i++;
 
102
                                EffectEntry *e = new EffectEntry;
 
103
                                e->effect=effect;
 
104
                                e->name=name;
 
105
                                e->id=nextID++;
 
106
                                fx.insert(i, e);
 
107
                                newId=e->id;
 
108
                        }
 
109
                        else
 
110
                                arts_warning("StereoEffectStack::insertAfter failed. "
 
111
                                                "id %d not found?", after);
 
112
 
 
113
                        reconnect();
 
114
                        return newId;
 
115
 
 
116
                }
 
117
 
 
118
                void move(long after, long item)
 
119
                {
 
120
                        arts_return_if_fail(item != 0);
 
121
                        disconnect();
 
122
 
 
123
                        list<EffectEntry*>::iterator iAfter=fx.begin();
 
124
                        bool found=false;
 
125
                        if (after)
 
126
                                while(iAfter != fx.end())
 
127
                                        if((*iAfter)->id == after)
 
128
                                        {
 
129
                                                found = true;
 
130
                                                iAfter++;
 
131
                                                break;
 
132
                                        }
 
133
                                        else
 
134
                                                iAfter++;
 
135
                        else
 
136
                                found=true;
 
137
 
 
138
                        list<EffectEntry*>::iterator iItem=fx.begin();
 
139
                        while (iItem != fx.end())
 
140
                                if((*iItem)->id == item)
 
141
                                {
 
142
                                        found &= true;
 
143
                                        break;
 
144
                                }
 
145
                                else
 
146
                                        iItem++;
 
147
                        if (!found)
 
148
                                arts_warning("StereoEffectStack::move couldn't find items");
 
149
                        else
 
150
                        {
 
151
                                fx.insert(iAfter, *iItem);
 
152
                                fx.erase(iItem);
 
153
                        }
 
154
 
 
155
                        reconnect();
 
156
 
 
157
                }
 
158
 
 
159
                vector<long> *effectList()
 
160
                {
 
161
                        vector<long> *items=new vector<long>;
 
162
                        for (list<EffectEntry*>::iterator i=fx.begin(); i!=fx.end();i++)
 
163
                                items->push_back((*i)->id);
 
164
                        return items;
 
165
                }
 
166
 
 
167
                // as stolen from stereoeffectstack_impl.cc
 
168
                StereoEffectStack_impl() : nextID(1)
 
169
                {
 
170
                        reconnect();
 
171
                }
 
172
                
 
173
                ~StereoEffectStack_impl()
 
174
                {
 
175
                        // disconnect remaining effects
 
176
                        EffectEntry *laste = 0;
 
177
                        list<EffectEntry *>::iterator ei;
 
178
 
 
179
                        for(ei = fx.begin(); ei != fx.end(); ei++)
 
180
                        {
 
181
                                EffectEntry *e = *ei;
 
182
                                if(laste)
 
183
                                {
 
184
                                        xconnect(false,laste->effect,"outleft",e->effect,"inleft");
 
185
                                        xconnect(false,laste->effect,"outright",e->effect,"inright");
 
186
                                }
 
187
                                laste = e;
 
188
                        }
 
189
                        // delete remaining effect entries
 
190
                        for(ei = fx.begin(); ei != fx.end(); ei++)
 
191
                                delete *ei;
 
192
                        fx.clear();
 
193
                }
 
194
                long insertTop(StereoEffect effect, const string& name)
 
195
                {
 
196
                        arts_return_val_if_fail(!effect.isNull(),0);
 
197
 
 
198
                        disconnect();
 
199
                        EffectEntry *e = new EffectEntry();
 
200
                        e->effect = effect;
 
201
                        e->name = name;
 
202
                        e->id = nextID++;
 
203
                        fx.push_front(e);
 
204
                        reconnect();
 
205
                        return e->id;
 
206
                }
 
207
                long insertBottom(StereoEffect effect, const string& name)
 
208
                {
 
209
                        arts_return_val_if_fail(!effect.isNull(),0);
 
210
 
 
211
                        disconnect();
 
212
                        EffectEntry *e = new EffectEntry();
 
213
                        e->effect = effect;
 
214
                        e->name = name;
 
215
                        e->id = nextID++;
 
216
                        fx.push_back(e);
 
217
                        reconnect();
 
218
                        return e->id;
 
219
                }
 
220
 
 
221
                void remove(long ID)
 
222
                {
 
223
                        arts_return_if_fail(ID != 0);
 
224
 
 
225
                        bool found = false;
 
226
                        disconnect();
 
227
                        list<EffectEntry *>::iterator ei = fx.begin();
 
228
 
 
229
                        while(ei != fx.end())
 
230
                        {
 
231
                                if((*ei)->id == ID) {
 
232
                                        found = true;
 
233
                                        delete (*ei);
 
234
                                        fx.erase(ei);
 
235
                                        ei = fx.begin();
 
236
                                }
 
237
                                else ei++;
 
238
                        }
 
239
                        if(!found) {
 
240
                                arts_warning("StereoEffectStack::remove failed. id %d not found?",
 
241
                                                ID);
 
242
                        }
 
243
                        reconnect();
 
244
                }
 
245
 
 
246
                AutoSuspendState autoSuspend() { return asSuspend; }
 
247
 
 
248
};
 
249
 
 
250
REGISTER_IMPLEMENTATION(StereoEffectStack_impl);
 
251
 
 
252
}
 
253