~ubuntu-branches/ubuntu/breezy/kdemultimedia/breezy

« back to all changes in this revision

Viewing changes to arts/modules/common/env_effectrackitem_impl.cc

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2005-03-24 04:48:58 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20050324044858-8ff88o9jxej6ii3d
Tags: 4:3.4.0-0ubuntu3
Add kubuntu_02_hide_arts_menu_entries.diff to hide artsbuilder and artscontrol k-menu entries

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the KDE project
 
2
    Copyright (C) 2002-2003 Matthias Kretz <kretz@kde.org>
 
3
                  2002 Arnold Krille <arnold@arnoldarts.de>
 
4
 
 
5
    This library is free software; you can redistribute it and/or
 
6
    modify it under the terms of the GNU Library General Public
 
7
    License version 2 as published by the Free Software Foundation.
 
8
 
 
9
    This library is distributed in the hope that it will be useful,
 
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
    Library General Public License for more details.
 
13
 
 
14
    You should have received a copy of the GNU Library General Public License
 
15
    along with this library; see the file COPYING.LIB.  If not, write to
 
16
    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
    Boston, MA 02111-1307, USA.
 
18
 
 
19
*/
 
20
// $Id: env_effectrackitem_impl.cc,v 1.4 2003/08/22 15:37:22 mkretz Exp $
 
21
 
 
22
#include "artsmodulescommon.h"
 
23
#include <debug.h>
 
24
#include "env_item_impl.h"
 
25
#include <connect.h>
 
26
#include <stdio.h>
 
27
#include <vector>
 
28
#include <map>
 
29
 
 
30
 
 
31
// Wether you are able to edit the name of the effectrack with an ugly LineInput or not.
 
32
//#define EFFECTRACK_NAME
 
33
// We should implement something like a ConfigWidget or at least a KLineInputBox or something...
 
34
 
 
35
namespace Arts {
 
36
namespace Environment {
 
37
 
 
38
class EffectRackItem_impl : virtual public EffectRackItem_skel,
 
39
                            virtual public Item_impl
 
40
{
 
41
protected:
 
42
        std::string _name;
 
43
        AudioManagerClient _amClient;
 
44
 
 
45
        struct RackWiring {
 
46
                RackWiring( const std::string & type, AudioManagerClient _amClient )
 
47
                        : routedtomaster( false )
 
48
                        , amClient( _amClient )
 
49
                {
 
50
                        effect = SubClass( type );
 
51
 
 
52
                        connect( input, effect );
 
53
                        connect( effect, output );
 
54
                }
 
55
 
 
56
                inline void setName( const std::string & efname )
 
57
                {
 
58
                        name = efname;
 
59
                        input.busname( efname );
 
60
                        if( ! routedtomaster )
 
61
                        {
 
62
                                output.title( efname );
 
63
                                output.autoRestoreID( efname );
 
64
                        }
 
65
                }
 
66
 
 
67
                inline void start()
 
68
                {
 
69
                        input.start();
 
70
                        effect.start();
 
71
                        output.start();
 
72
                }
 
73
 
 
74
                inline void stop()
 
75
                {
 
76
                        input.stop();
 
77
                        effect.stop();
 
78
                        output.stop();
 
79
                }
 
80
 
 
81
                inline void master( bool tomaster )
 
82
                {
 
83
                        routedtomaster = tomaster;
 
84
 
 
85
                        output.stop();
 
86
                        output = tomaster ? Synth_AMAN_PLAY( amClient ) : Synth_AMAN_PLAY();
 
87
                        connect( effect, output );
 
88
                        if( ! tomaster )
 
89
                        {
 
90
                                output.title( name );
 
91
                                output.autoRestoreID( name );
 
92
                        }
 
93
                        output.start();
 
94
                }
 
95
 
 
96
                bool routedtomaster;
 
97
                std::string name;
 
98
                std::string effectName;
 
99
                Synth_BUS_DOWNLINK input;
 
100
                Arts::StereoEffect effect;
 
101
                Synth_AMAN_PLAY output;
 
102
                AudioManagerClient amClient;
 
103
        };
 
104
        std::vector<RackWiring> _wirings;
 
105
 
 
106
public:
 
107
        EffectRackItem_impl()
 
108
                : _name( "effect rack" )
 
109
                , _amClient( amPlay, _name + " Master", "effectrack_" + _name )
 
110
        {
 
111
                // TODO: check if there's another effect rack with the same name already - if so prefix with 2./3./4.
 
112
        }
 
113
 
 
114
        // readonly attribute sequence<Arts::StereoEffect> effects;
 
115
        std::vector<Arts::StereoEffect> *effects()
 
116
        {
 
117
                std::vector<Arts::StereoEffect> * effects = new std::vector<Arts::StereoEffect>;
 
118
                for( std::vector<RackWiring>::iterator it = _wirings.begin(); it != _wirings.end(); ++it )
 
119
                        effects->push_back( it->effect );
 
120
                return effects;
 
121
        }
 
122
 
 
123
        // attribute long effectCount;
 
124
        long effectCount() { return _wirings.size(); }
 
125
 
 
126
        // attribute string name;
 
127
        void name(const std::string& newName) {
 
128
                if(newName != _name)
 
129
                {
 
130
                        _name = newName;
 
131
                        _amClient.title( _name + " Master" );
 
132
                        _amClient.autoRestoreID( "effectrack_" + _name );
 
133
                        for( unsigned int i = 0; i < _wirings.size(); i++ )
 
134
                                _wirings[i].setName( effectName( i, _wirings[ i ].effectName ) );
 
135
                        name_changed( newName );
 
136
                }
 
137
        }
 
138
        std::string name() { return _name; }
 
139
 
 
140
        void loadFromList(const std::vector<std::string>& /*list*/)
 
141
        {
 
142
        }
 
143
 
 
144
        std::vector<std::string> *saveToList()
 
145
        {
 
146
                std::vector<std::string> *result = new std::vector<std::string>;
 
147
                return result;
 
148
        }
 
149
 
 
150
        std::string effectName( int n, const std::string & en )
 
151
        {
 
152
                char * efname = new char[ _name.length() + en.length() + 128 ];
 
153
                sprintf( efname, "%s%02d (%s)", _name.c_str(), n, en.c_str() );
 
154
                return efname;
 
155
        }
 
156
 
 
157
        Arts::StereoEffect createEffect( const std::string & type, const std::string & name )
 
158
        {
 
159
                RackWiring wiring( type, _amClient );
 
160
                wiring.setName( effectName( _wirings.size() + 1, name ) );
 
161
                wiring.start();
 
162
                _wirings.push_back( wiring );
 
163
                return wiring.effect;
 
164
        }
 
165
 
 
166
        void delEffect( long pos )
 
167
        {
 
168
                _wirings[ pos ].stop();
 
169
                _wirings.erase( _wirings.begin() + pos );
 
170
                for( unsigned int i = pos; i < _wirings.size(); ++i )
 
171
                        _wirings[ i ].setName( effectName( i, _wirings[ i ].effectName ) );
 
172
        }
 
173
 
 
174
        void routeToMaster( long pos, bool tomaster )
 
175
        {
 
176
                _wirings[ pos ].master( tomaster );
 
177
        }
 
178
};
 
179
REGISTER_IMPLEMENTATION(EffectRackItem_impl);
 
180
}
 
181
 
 
182
using namespace Environment;
 
183
 
 
184
typedef WeakReference<VBox> VBox_wref;
 
185
 
 
186
class EffectRackItemGui_impl : virtual public EffectRackItemGui_skel {
 
187
private:
 
188
        bool _active;
 
189
        long _effectCount;
 
190
        std::string _type;
 
191
        EffectRackItem _effectRack;
 
192
 
 
193
        /* widgets */
 
194
        VBox_wref _widget;
 
195
        HBox hbox;
 
196
        VBox effect_vbox;
 
197
#ifdef EFFECTRACK_NAME
 
198
        LineEdit name;
 
199
#endif
 
200
        ComboBox typebox;
 
201
        Button addbutton;
 
202
        GenericGuiFactory guiFactory;
 
203
        std::vector<EffectRackSlot> _slots;
 
204
        std::map<std::string, std::string> typeforname;
 
205
        std::map<std::string, std::string> namefortype;
 
206
 
 
207
public:
 
208
        EffectRackItemGui self() { return EffectRackItemGui::_from_base(_copy()); }
 
209
 
 
210
        void redoGui()
 
211
        {
 
212
                VBox vbox = _widget;
 
213
                if(vbox.isNull())
 
214
                        arts_warning("update with vbox null");
 
215
                if(_effectRack.isNull())
 
216
                        arts_warning("update with _effectRack null");
 
217
                if(!_effectRack.isNull() && !vbox.isNull())
 
218
                {
 
219
                        vbox.spacing( 0 );
 
220
                        vbox.margin( 10 );
 
221
                        hbox = HBox( vbox );
 
222
                        hbox.spacing( 5 );
 
223
                        hbox.margin( 0 );
 
224
 
 
225
#ifdef EFFECTRACK_NAME
 
226
                        name = LineEdit();
 
227
                        name.caption("name");
 
228
                        name.text(_effectRack.name());
 
229
                        name.parent(hbox);
 
230
                        connect(name,"text_changed", _effectRack, "name");
 
231
#endif
 
232
 
 
233
                        std::vector<std::string> choices;
 
234
                        TraderQuery query;
 
235
                        query.supports( "Interface", "Arts::StereoEffect" );
 
236
                        query.supports( "Features", "RackGUI" );
 
237
                        std::vector<TraderOffer> *queryResults = query.query();
 
238
                        for(std::vector<TraderOffer>::iterator it = queryResults->begin(); it != queryResults->end(); ++it)
 
239
                        {
 
240
                                std::vector<std::string> * names = it->getProperty( "Name" );
 
241
                                std::string name = names->empty() ? it->interfaceName() : names->front();
 
242
                                delete names;
 
243
                                choices.push_back( name );
 
244
                                typeforname[ name ] = it->interfaceName();
 
245
                                namefortype[ it->interfaceName() ] = name;
 
246
                        }
 
247
                        delete queryResults;
 
248
                        typebox = ComboBox();
 
249
                        typebox.choices(choices);
 
250
                        typebox.value(_type);
 
251
                        typebox.parent(hbox);
 
252
                        connect(typebox,"value_changed", self(), "type");
 
253
 
 
254
                        addbutton = Button( "add", hbox );
 
255
                        connect( addbutton, "clicked_changed", self(), "addeffect" );
 
256
 
 
257
                        effect_vbox = VBox( vbox );
 
258
                        effect_vbox.margin( 0 );
 
259
                        effect_vbox.spacing( 5 );
 
260
                        effect_vbox.show();
 
261
 
 
262
                        Frame spacer;
 
263
                        spacer.parent( effect_vbox );
 
264
                        spacer.vSizePolicy( spExpanding );
 
265
                        spacer.show();
 
266
                        effect_vbox._addChild( spacer, "spacer" );
 
267
 
 
268
                        _slots.clear();
 
269
 
 
270
                        // add Arts::StereoEffect widgets
 
271
                        std::vector<Arts::StereoEffect> * effects = _effectRack.effects();
 
272
                        for( std::vector<Arts::StereoEffect>::iterator it = effects->begin(); it != effects->end(); ++it )
 
273
                                createEffectGui( *it );
 
274
                        delete effects;
 
275
                }
 
276
                else
 
277
                {
 
278
                        /* FIXME: maybe insert a "dead" label here */
 
279
                        if(!vbox.isNull())
 
280
                                vbox.show();
 
281
                        effect_vbox = VBox::null();
 
282
                        hbox = HBox::null();
 
283
                        // name = LineEdit::null();
 
284
                        typebox = ComboBox::null();
 
285
                        _slots.clear();
 
286
                }
 
287
        }
 
288
 
 
289
        void createEffectGui( Arts::StereoEffect effect )
 
290
        {
 
291
                Widget w = guiFactory.createGui( effect );
 
292
                if( ! w.isNull() )
 
293
                {
 
294
                        // insert effect GUI into the "Rack"
 
295
                        EffectRackSlot slot( effect_vbox, w, self() );
 
296
                        _slots.push_back( slot );
 
297
                }
 
298
        }
 
299
 
 
300
        void removeSlot( EffectRackSlot slot )
 
301
        {
 
302
                unsigned int i;
 
303
                for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i );
 
304
                if( i < _slots.size() )
 
305
                {
 
306
                        _slots.erase( _slots.begin() + i );
 
307
                        _effectRack.delEffect( i );
 
308
                }
 
309
                else
 
310
                        arts_warning( "WARNING: Trying to remove an unknown slot" );
 
311
        }
 
312
 
 
313
        void routeToMaster( EffectRackSlot slot, bool tomaster )
 
314
        {
 
315
                unsigned int i;
 
316
                for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i );
 
317
                if( i < _slots.size() )
 
318
                        _effectRack.routeToMaster( i, tomaster );
 
319
                else
 
320
                        arts_warning( "WARNING: Trying to route an unknown slot" );
 
321
        }
 
322
 
 
323
        bool active() { return _active; }
 
324
        void active(bool newActive)
 
325
        {
 
326
                if(newActive != _active)
 
327
                {
 
328
                        _active = newActive;
 
329
                        if(!newActive)
 
330
                                _effectRack = EffectRackItem::null();
 
331
                        redoGui();
 
332
                }
 
333
        }
 
334
 
 
335
        std::string type()
 
336
        {
 
337
                return _type;
 
338
        }
 
339
        void type(const std::string& t)
 
340
        {
 
341
                _type = typeforname[ t ];
 
342
        }
 
343
 
 
344
        bool addeffect() { return false; } //unused
 
345
        void addeffect( bool clicked )
 
346
        {
 
347
                if( ! addbutton.clicked() || ! clicked )
 
348
                        return;
 
349
 
 
350
                Arts::StereoEffect effect = _effectRack.createEffect( _type, namefortype[ _type ] );
 
351
                createEffectGui( effect );
 
352
        }
 
353
 
 
354
        Widget initialize(EffectRackItem item)
 
355
        {
 
356
                VBox vbox;
 
357
                vbox._addChild(self(),"the_gui_updating_widget");
 
358
 
 
359
                _widget = vbox;
 
360
                _effectRack = item;
 
361
                _active = item.active();
 
362
                _type = "Arts::Synth_VOICE_REMOVAL";
 
363
                _effectCount = item.effectCount();
 
364
 
 
365
                if(!_effectRack.isNull())
 
366
                {
 
367
                        connect(_effectRack, "active_changed", self(), "active");
 
368
                }
 
369
                redoGui();
 
370
 
 
371
                return vbox;
 
372
        }
 
373
};
 
374
 
 
375
REGISTER_IMPLEMENTATION(EffectRackItemGui_impl);
 
376
 
 
377
class EffectRackGuiFactory_impl : virtual public EffectRackGuiFactory_skel
 
378
{
 
379
public:
 
380
        Widget createGui(Object object) 
 
381
        {
 
382
                arts_return_val_if_fail(!object.isNull(), Arts::Widget::null());
 
383
 
 
384
                std::string iface = object._interfaceName();
 
385
                arts_return_val_if_fail(iface == "Arts::Environment::EffectRackItem",
 
386
                                Arts::Widget::null());
 
387
                if(iface == "Arts::Environment::EffectRackItem")
 
388
                {
 
389
                        EffectRackItem effectRack = DynamicCast(object);
 
390
                        arts_return_val_if_fail(!effectRack.isNull(), Arts::Widget::null());
 
391
 
 
392
                        EffectRackItemGui gui;
 
393
                        return gui.initialize(effectRack);
 
394
                }
 
395
                return Arts::Widget::null();
 
396
        }
 
397
};
 
398
REGISTER_IMPLEMENTATION(EffectRackGuiFactory_impl);
 
399
}
 
400
// vim:ts=4:sw=4