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>
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.
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.
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.
20
// $Id: env_effectrackitem_impl.cc,v 1.4 2003/08/22 15:37:22 mkretz Exp $
22
#include "artsmodulescommon.h"
24
#include "env_item_impl.h"
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...
36
namespace Environment {
38
class EffectRackItem_impl : virtual public EffectRackItem_skel,
39
virtual public Item_impl
43
AudioManagerClient _amClient;
46
RackWiring( const std::string & type, AudioManagerClient _amClient )
47
: routedtomaster( false )
48
, amClient( _amClient )
50
effect = SubClass( type );
52
connect( input, effect );
53
connect( effect, output );
56
inline void setName( const std::string & efname )
59
input.busname( efname );
60
if( ! routedtomaster )
62
output.title( efname );
63
output.autoRestoreID( efname );
81
inline void master( bool tomaster )
83
routedtomaster = tomaster;
86
output = tomaster ? Synth_AMAN_PLAY( amClient ) : Synth_AMAN_PLAY();
87
connect( effect, output );
91
output.autoRestoreID( name );
98
std::string effectName;
99
Synth_BUS_DOWNLINK input;
100
Arts::StereoEffect effect;
101
Synth_AMAN_PLAY output;
102
AudioManagerClient amClient;
104
std::vector<RackWiring> _wirings;
107
EffectRackItem_impl()
108
: _name( "effect rack" )
109
, _amClient( amPlay, _name + " Master", "effectrack_" + _name )
111
// TODO: check if there's another effect rack with the same name already - if so prefix with 2./3./4.
114
// readonly attribute sequence<Arts::StereoEffect> effects;
115
std::vector<Arts::StereoEffect> *effects()
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 );
123
// attribute long effectCount;
124
long effectCount() { return _wirings.size(); }
126
// attribute string name;
127
void name(const std::string& 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 );
138
std::string name() { return _name; }
140
void loadFromList(const std::vector<std::string>& /*list*/)
144
std::vector<std::string> *saveToList()
146
std::vector<std::string> *result = new std::vector<std::string>;
150
std::string effectName( int n, const std::string & en )
152
char * efname = new char[ _name.length() + en.length() + 128 ];
153
sprintf( efname, "%s%02d (%s)", _name.c_str(), n, en.c_str() );
157
Arts::StereoEffect createEffect( const std::string & type, const std::string & name )
159
RackWiring wiring( type, _amClient );
160
wiring.setName( effectName( _wirings.size() + 1, name ) );
162
_wirings.push_back( wiring );
163
return wiring.effect;
166
void delEffect( long pos )
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 ) );
174
void routeToMaster( long pos, bool tomaster )
176
_wirings[ pos ].master( tomaster );
179
REGISTER_IMPLEMENTATION(EffectRackItem_impl);
182
using namespace Environment;
184
typedef WeakReference<VBox> VBox_wref;
186
class EffectRackItemGui_impl : virtual public EffectRackItemGui_skel {
191
EffectRackItem _effectRack;
197
#ifdef EFFECTRACK_NAME
202
GenericGuiFactory guiFactory;
203
std::vector<EffectRackSlot> _slots;
204
std::map<std::string, std::string> typeforname;
205
std::map<std::string, std::string> namefortype;
208
EffectRackItemGui self() { return EffectRackItemGui::_from_base(_copy()); }
214
arts_warning("update with vbox null");
215
if(_effectRack.isNull())
216
arts_warning("update with _effectRack null");
217
if(!_effectRack.isNull() && !vbox.isNull())
225
#ifdef EFFECTRACK_NAME
227
name.caption("name");
228
name.text(_effectRack.name());
230
connect(name,"text_changed", _effectRack, "name");
233
std::vector<std::string> choices;
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)
240
std::vector<std::string> * names = it->getProperty( "Name" );
241
std::string name = names->empty() ? it->interfaceName() : names->front();
243
choices.push_back( name );
244
typeforname[ name ] = it->interfaceName();
245
namefortype[ it->interfaceName() ] = name;
248
typebox = ComboBox();
249
typebox.choices(choices);
250
typebox.value(_type);
251
typebox.parent(hbox);
252
connect(typebox,"value_changed", self(), "type");
254
addbutton = Button( "add", hbox );
255
connect( addbutton, "clicked_changed", self(), "addeffect" );
257
effect_vbox = VBox( vbox );
258
effect_vbox.margin( 0 );
259
effect_vbox.spacing( 5 );
263
spacer.parent( effect_vbox );
264
spacer.vSizePolicy( spExpanding );
266
effect_vbox._addChild( spacer, "spacer" );
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 );
278
/* FIXME: maybe insert a "dead" label here */
281
effect_vbox = VBox::null();
283
// name = LineEdit::null();
284
typebox = ComboBox::null();
289
void createEffectGui( Arts::StereoEffect effect )
291
Widget w = guiFactory.createGui( effect );
294
// insert effect GUI into the "Rack"
295
EffectRackSlot slot( effect_vbox, w, self() );
296
_slots.push_back( slot );
300
void removeSlot( EffectRackSlot slot )
303
for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i );
304
if( i < _slots.size() )
306
_slots.erase( _slots.begin() + i );
307
_effectRack.delEffect( i );
310
arts_warning( "WARNING: Trying to remove an unknown slot" );
313
void routeToMaster( EffectRackSlot slot, bool tomaster )
316
for( i = 0; i < _slots.size() && ! _slots[ i ]._isEqual( slot ) ; ++i );
317
if( i < _slots.size() )
318
_effectRack.routeToMaster( i, tomaster );
320
arts_warning( "WARNING: Trying to route an unknown slot" );
323
bool active() { return _active; }
324
void active(bool newActive)
326
if(newActive != _active)
330
_effectRack = EffectRackItem::null();
339
void type(const std::string& t)
341
_type = typeforname[ t ];
344
bool addeffect() { return false; } //unused
345
void addeffect( bool clicked )
347
if( ! addbutton.clicked() || ! clicked )
350
Arts::StereoEffect effect = _effectRack.createEffect( _type, namefortype[ _type ] );
351
createEffectGui( effect );
354
Widget initialize(EffectRackItem item)
357
vbox._addChild(self(),"the_gui_updating_widget");
361
_active = item.active();
362
_type = "Arts::Synth_VOICE_REMOVAL";
363
_effectCount = item.effectCount();
365
if(!_effectRack.isNull())
367
connect(_effectRack, "active_changed", self(), "active");
375
REGISTER_IMPLEMENTATION(EffectRackItemGui_impl);
377
class EffectRackGuiFactory_impl : virtual public EffectRackGuiFactory_skel
380
Widget createGui(Object object)
382
arts_return_val_if_fail(!object.isNull(), Arts::Widget::null());
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")
389
EffectRackItem effectRack = DynamicCast(object);
390
arts_return_val_if_fail(!effectRack.isNull(), Arts::Widget::null());
392
EffectRackItemGui gui;
393
return gui.initialize(effectRack);
395
return Arts::Widget::null();
398
REGISTER_IMPLEMENTATION(EffectRackGuiFactory_impl);