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
|
//
// C++ Implementation: fxpluginhandler
//
// Description:
//
//
// Author: Robert Vogl <voglrobe@lapislazuli>, (C) 2004
//
// Copyright: See COPYING file that comes with this distribution
//
//
// QT includes
#include <tqdir.h>
// KDE includes
#include <kdebug.h>
#include <tdeapplication.h>
#include <ktrader.h>
#include <klibloader.h>
#include <kservice.h>
// App specific includes
#include "fxpluginhandler.h"
#include "ksayit_fxplugin.h"
#include "ksayit_ttsplugin.h"
FXPluginHandler::FXPluginHandler(TQObject *parent, const char *name, TDEConfig *config)
: TQObject(parent, name), m_config(config)
{
m_mapPluginList.clear();
m_lstActivePlugins.clear();
}
FXPluginHandler::~FXPluginHandler()
{
TQMap<TQString, fx_struct>::Iterator mit;
for (mit=m_mapPluginList.begin(); mit!=m_mapPluginList.end(); ++mit){
if ( (*mit).p != 0 ){
delete (*mit).p;
}
}
}
void FXPluginHandler::searchPlugins()
{
kdDebug(100200) << "FXPluginHandler::searchPlugins()" << endl;
TQStringList sRegistered;
fx_struct plugin;
sRegistered.clear();
m_mapPluginList.clear();
TDETrader::OfferList offers = TDETrader::self()->query("KSayIt/FXPlugin");
KLibFactory *factory = NULL;
TQString library = TQString();
TQString name = TQString();
TDETrader::OfferList::Iterator it=offers.begin();
for ( ;it!=offers.end(); ++it ){
KService::Ptr ptr = (*it);
library = ptr->library();
name = ptr->name();
factory = KLibLoader::self()->factory( library.latin1() );
if ( factory ){
kdDebug(100200) << "FXPluginHandler::searchPlugins(): Plugin factory found." << endl;
// register found plugin
if ( !sRegistered.contains( TQString(name) )){
sRegistered.append( TQString(name) );
plugin.name = name;
plugin.library = library;
plugin.description = TQString();
plugin.EffectID = 0;
plugin.p = NULL;
m_mapPluginList[plugin.name] = plugin; // update Plugin Map
kdDebug(100200) << "FXPluginHandler::searchPlugins(): " << plugin.name << " registered." << endl;
}
}
}
}
void FXPluginHandler::readConfiguration()
{
kdDebug(100200) << "+++ entering FXPluginHandler::readConfiguration()" << endl;
fx_struct plugin;
TQMap<TQString, fx_struct>::Iterator mit;
TQStringList::Iterator lit;
// unload all plugins and destroy the effect objects
lit = m_lstActivePlugins.begin();
while ( lit != m_lstActivePlugins.end() ){
mit = m_mapPluginList.find( *lit );
if ( mit!=m_mapPluginList.end() ){
plugin = *mit;
if ( (plugin.p != NULL) && (plugin.EffectID == 0) ){
delete plugin.p;
plugin.p = NULL;
m_mapPluginList[plugin.name] = plugin; // update Plugin Map
lit = m_lstActivePlugins.remove( lit );
} else {
lit++;
}
}
}
// load active plugins as given in config file
m_config->setGroup("Effect Stack Configuration");
TQStringList conf_active = m_config->readListEntry("Activated");
KLibFactory *factory = NULL;
for (lit=conf_active.begin(); lit!=conf_active.end(); ++lit){ // for all in config
mit = m_mapPluginList.find(*lit);
if( mit!=m_mapPluginList.end() ){
// plugin found in list of registered plugins
plugin = *mit;
// load plugin
factory = KLibLoader::self()->factory( (plugin.library).latin1() );
if ( factory ){
plugin.p = static_cast<FXPlugin*>( factory->create( (TQObject*)this, (plugin.name).latin1() ) );
if ( plugin.p ){ // Plugin found
plugin.p->setApplication( TDEApplication::kApplication() );
plugin.description = plugin.p->getDescription_KS();
// append to list of active plugins
m_lstActivePlugins.append( plugin.name );
m_mapPluginList[plugin.name] = plugin; // update Plugin Map
kdDebug(100200) << "FXPluginHandler: FX-Plugin " << plugin.name << " active." << endl;
}
}
}
}
}
void FXPluginHandler::showEffectGUI(const TQString &pname)
{
kdDebug(100200) << "FXPluginHandler::showEffectGUI(): " << pname << endl;
TQMap<TQString, fx_struct>::Iterator mit;
fx_struct plugin;
// find plugin with name==pname in list and show its GUI
mit = m_mapPluginList.find(pname);
if ( mit != m_mapPluginList.end() ){
plugin = *mit;
if ( plugin.p != NULL ){ // plugin loaded
plugin.p->showGUI_KS();
return;
} else {
kdDebug(100200) << "Effect not active yet. Loading..." << endl;
KLibFactory *factory = KLibLoader::self()->factory( (plugin.library).latin1() );
if ( factory ){
plugin.p = static_cast<FXPlugin*>( factory->create( (TQObject*)this, (plugin.name).latin1() ) );
if ( plugin.p ){ // Plugin found
plugin.p->setApplication( TDEApplication::kApplication() );
plugin.description = plugin.p->getDescription_KS();
// append to list of active plugins
m_lstActivePlugins.append( plugin.name );
m_mapPluginList[plugin.name] = plugin; // update Plugin Map
kdDebug(100200) << "FXPluginHandler: FX-Plugin " << plugin.name << " active." << endl;
plugin.p->showGUI_KS();
return;
}
}
}
}
}
void FXPluginHandler::getPlugins(TQStringList &pluginlist)
{
// kdDebug(100200) << "FXPluginHandler::getPlugins" << endl;
pluginlist.clear();
TQString sPname;
TQMap<TQString, fx_struct>::Iterator mit;
for (mit=m_mapPluginList.begin(); mit!=m_mapPluginList.end(); ++mit){
sPname = (*mit).name; //testing
pluginlist.append( sPname );
}
}
void FXPluginHandler::activateEffect(const TQString &pname,
KArtsServer *server,
StereoEffectStack *fx_stack)
{
kdDebug(100200) << "FXPluginHandler::activateEffect: " << pname << endl;
TQMap<TQString, fx_struct>::Iterator mit;
fx_struct plugin;
// find plugin with name==pname
mit = m_mapPluginList.find(pname);
if ( mit!=m_mapPluginList.end() ){
plugin = *mit;
if ( plugin.p != NULL ){
plugin.EffectID = plugin.p->activate_KS(server, fx_stack);
m_mapPluginList[plugin.name] = plugin; // update Plugin Map
} else {
kdDebug(100200) << "Effect " << pname << " not found or inactive." << endl;
}
}
}
void FXPluginHandler::deactivateEffects(StereoEffectStack *fx_stack)
{
kdDebug(100200) << "FXPluginHandler::deactivateEffects." << endl;
TQMap<TQString, fx_struct>::Iterator mit;
fx_struct plugin;
for (mit=m_mapPluginList.begin(); mit!=m_mapPluginList.end(); ++mit){
if ( mit != m_mapPluginList.end() ){
plugin = *mit;
if ( (plugin.EffectID != 0) && (plugin.p != NULL) ){
// effect active and on stack
plugin.p->deactivate_KS(fx_stack, plugin.EffectID);
kdDebug(100200) << plugin.name << " with Effect ID " << plugin.EffectID << " removed." << endl;
plugin.EffectID = 0;
m_mapPluginList[plugin.name] = plugin; // update Plugin Map
}
}
}
}
#include "fxpluginhandler.moc"
|