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

« back to all changes in this revision

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