1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
|
#include "effects.h"
#include "engine.h"
#include <common.h>
#include <dynamicrequest.h>
#include <artsflow.h>
#include <app.h>
#include <player.h>
#include <soundserver.h>
#include <noatunarts.h>
#include <tqlayout.h>
#include <config.h>
#define HAS_ARTSVERSION_H
#ifdef HAS_ARTSVERSION_H
#include <artsgui.h>
#include <kartswidget.h>
#endif
#define engine napp->player()->engine()
#define server (*(engine->server()))
#define stack (*engine->effectStack())
using namespace std;
using namespace Arts;
class EffectConfigWidget : public TQWidget
{
public:
EffectConfigWidget(Effect *e, TQWidget *tqparent=0)
: TQWidget(tqparent), mEf(e)
{}
virtual ~EffectConfigWidget()
{
mEf->mConfig=0;
}
private:
Effect *mEf;
};
Effect::Effect(const char *name)
: mId(0), mName(name), mConfig(0)
{
mEffect=new StereoEffect;
*mEffect=DynamicCast(server.createObject(std::string(name)));
napp->effects()->mItems.append(this);
}
long Effect::id() const
{
return mId;
}
StereoEffect *Effect::effect() const
{
return mEffect;
}
Effect *Effect::after() const
{
TQPtrList<Effect> effects=napp->effects()->effects();
TQPtrListIterator<Effect> i(effects);
for(; i.current(); ++i)
if ((*i)->id()==mId)
{
++i;
if (*i)
return *i;
}
return 0;
}
Effect *Effect::before() const
{
TQPtrList<Effect> effects=napp->effects()->effects();
TQPtrListIterator<Effect> i(effects);
for(; i.current(); ++i)
if ((*i)->id()==mId)
{
--i;
if (*i)
return *i;
}
return 0;
}
TQCString Effect::name() const
{
return mName;
}
TQString Effect::title() const
{
return clean(mName);
}
TQString Effect::clean(const TQCString &name)
{
int pos=name.findRev("::");
if (pos>0)
return name.right(name.length()-pos-2);
return name;
}
bool Effect::isNull() const
{
return effect()->isNull();
}
TQWidget *Effect::configure(bool /*friendly*/)
{
#ifdef HAS_ARTSVERSION_H
if (mConfig) return mConfig;
if (!configurable()) return 0;
GenericGuiFactory factory;
Widget gui = factory.createGui(*mEffect);
if(!gui.isNull())
{
mConfig=new EffectConfigWidget(this);
mConfig->setCaption(title());
TQBoxLayout *l=new TQHBoxLayout(mConfig);
l->add(new KArtsWidget(gui, mConfig));
l->freeze();
}
return mConfig;
#else
return 0;
#endif
}
bool Effect::configurable() const
{
#ifdef HAS_ARTSVERSION_H
TraderQuery query;
query.supports("Interface","Arts::GuiFactory");
query.supports("CanCreate", mEffect->_interfaceName());
vector<TraderOffer> *queryResults = query.query();
bool yes= queryResults->size();
delete queryResults;
return yes;
#else
return 0;
#endif
}
Effect::~Effect()
{
delete mConfig;
napp->effects()->remove(this, false);
emit napp->effects()->deleting(this);
delete mEffect;
napp->effects()->mItems.removeRef(this);
}
Effects::Effects()
{
mItems.setAutoDelete(false);
}
bool Effects::insert(const Effect *after, Effect *item)
{
if (!item) return false;
if (item->id()) return false;
if (item->isNull()) return false;
long i;
item->effect()->start();
if (!after)
i=stack.insertTop(*item->effect(), (const char*)item->name());
else
i=stack.insertAfter(after->id(), *item->effect(), (const char*)item->name());
if (!i)
{
item->effect()->stop();
return false;
}
item->mId=i;
emit added(item);
return true;
}
bool Effects::append(Effect *item)
{
if (!item) return false;
if (item->id()) return false;
if (item->isNull()) return false;
item->effect()->start();
item->mId=stack.insertBottom(*item->effect(), (const char*)item->name());
if (!item->mId)
{
item->effect()->stop();
return false;
}
emit added(item);
return true;
}
void Effects::move(const Effect *after, Effect *item)
{
if (!item) return;
if (!item->id()) return;
long id=after ? after->id() : 0;
stack.move(id, item->id());
emit moved(item);
}
void Effects::remove(Effect *item, bool del)
{
if (!item) return;
if (!item->id()) return;
stack.remove(item->id());
item->effect()->stop();
item->mId=0;
removed(item);
if (del)
delete item;
}
void Effects::removeAll(bool del)
{
for (TQPtrListIterator<Effect> i(mItems); i.current(); ++i)
if ((*i)->id())
remove(*i, del);
}
TQStrList Effects::available() const
{
TQStrList val;
Arts::TraderQuery query;
query.supports("Interface", "Arts::StereoEffect");
query.supports("Interface", "Arts::SynthModule");
query.supports("Use", "directly");
vector<Arts::TraderOffer> *offers = query.query();
for (vector<Arts::TraderOffer>::iterator i=offers->begin(); i!=offers->end(); i++)
{
Arts::TraderOffer &offer=*i;
TQCString name = offer.interfaceName().c_str();
val.append(name);
}
delete offers;
return val;
}
Effect *Effects::findId(long id) const
{
for (TQPtrListIterator<Effect> i(mItems); i.current(); ++i)
if ((*i)->id()==id)
return *i;
return 0;
}
TQPtrList<Effect> Effects::effects() const
{
vector<long> *items=stack.effectList();
TQPtrList<Effect> effects;
for (vector<long>::iterator i=items->begin();i!=items->end();i++)
if (Effect *e=findId(*i))
effects.append(e);
delete items;
return effects;
}
#undef server
#undef stack
#undef engine
#include "effects.moc"
|