summaryrefslogtreecommitdiff
path: root/muse_qt4_evolution/muse/plugin.h
blob: c01a1f189f67322ce00c7fa9fd98457da7699720 (plain)
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
//=============================================================================
//  MusE
//  Linux Music Editor
//  $Id:$
//
//  Copyright (C) 2002-2006 by Werner Schweer and others
//
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License version 2.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
//=============================================================================

#ifndef __PLUGIN_H__
#define __PLUGIN_H__

#include "ladspa.h"
#include "globals.h"

namespace AL {
      class Xml;
      };
using AL::Xml;

class PluginIF;
class PluginGui;
class PluginI;
class LadspaPluginIF;
class AudioTrack;
class Ctrl;

#define AUDIO_IN (LADSPA_PORT_AUDIO  | LADSPA_PORT_INPUT)
#define AUDIO_OUT (LADSPA_PORT_AUDIO | LADSPA_PORT_OUTPUT)

//---------------------------------------------------------
//   Plugin
//---------------------------------------------------------

class Plugin {

   protected:
      int _instances;
      QFileInfo fi;

   public:
      Plugin(const QFileInfo* f);
      virtual ~Plugin() {}

      int instances() const              { return _instances; }
      virtual void incInstances(int val) { _instances += val; }

      QString lib() const               { return fi.baseName();    }
      QString path() const              { return fi.absolutePath();     }

      virtual QString label() const     { return QString(); }
      virtual QString name() const      { return QString(); }
      virtual unsigned long id() const  { return 0;         }
      virtual QString maker() const     { return QString(); }
      virtual QString copyright() const { return QString(); }

      virtual PluginIF* createPIF(PluginI*) = 0;

      virtual void range(int, double* min, double* max) const {
            *min = 0.0f;
            *max = 1.0f;
            }

      virtual int parameter() const       { return 0;     }
      virtual int inports() const         { return 0;     }
      virtual int outports() const        { return 0;     }

      virtual bool inPlaceCapable() const { return false; }

      virtual bool isLog(int) const       { return false; }
      virtual bool isBool(int) const      { return false; }
      virtual bool isInt(int) const       { return false; }
      virtual double defaultValue(int) const { return 0.0f;  }
      };

//---------------------------------------------------------
//   PluginList
//---------------------------------------------------------

typedef std::list<Plugin*>::iterator iPlugin;

class PluginList : public std::list<Plugin*> {
   public:
      Plugin* find(const QString&, const QString&);
      PluginList() {}
      };

//---------------------------------------------------------
//   PluginIF
//    plugin instance interface
//---------------------------------------------------------

class PluginIF {
   protected:
      PluginI* pluginI;

   public:
      PluginIF(PluginI* pi) { pluginI = pi; }
      virtual ~PluginIF() {}

      PluginI* pluginInstance() { return pluginI; }
      const PluginI* pluginInstance() const { return pluginI; }

      virtual void apply(unsigned nframes, float** src, float** dst) = 0;
      virtual void activate() = 0;
      virtual void deactivate() = 0;
      virtual void cleanup() = 0;
      virtual void setParam(int i, double val) = 0;
      virtual float param(int i) const = 0;
      virtual const char* getParameterName(int) const           { return ""; }
      virtual const char* getParameterLabel(int) const          { return 0; }
      virtual const char* getParameterDisplay(int, float) const { return 0; }
      virtual bool hasGui() const { return false; }
      virtual bool guiVisible() const { return false; }
      virtual void showGui(bool) {}
      };

//---------------------------------------------------------
//   PluginI
//    plugin instance
//---------------------------------------------------------

class PluginI {
      Plugin* _plugin;
      AudioTrack* _track;

      int instances;
      PluginIF** pif;

      int _channel;

      PluginGui* _gui;
      bool _on;

      QString _name;
      QString _label;

      std::vector<Ctrl*> controllerList;

      void makeGui();

   protected:
      bool initControlValues;
      friend class LadspaPluginIF;

   public:
      PluginI(AudioTrack*);
      ~PluginI();

      Plugin* plugin() const { return _plugin; }
      bool on() const        { return _on; }
      void setOn(bool val)   { _on = val; }
      PluginGui* gui() const { return _gui; }

      bool initPluginInstance(Plugin*, int channels);
      void setChannels(int);
      int channel() const    { return _channel; }
      void apply(unsigned nframes, int ports, float** b1, float** b2);

      void activate();
      void deactivate();
      QString label() const          { return _label; }
      QString name() const           { return _name; }
      QString lib() const            { return _plugin->lib(); }

      AudioTrack* track() const      { return _track; }

      void writeConfiguration(Xml&, bool);
      void writeConfiguration1(Xml&, bool); // without end tag!
      bool readConfiguration(QDomNode, bool*);

      void showGui();
      void showGui(bool);
      bool guiVisible() const;

      bool hasNativeGui() const                  { return pif[0]->hasGui(); }
      void showNativeGui(bool f)                 { return pif[0]->showGui(f); }
      bool nativeGuiVisible() const              { return pif[0]->guiVisible(); }

      void setControllerList(Ctrl* cl)           { controllerList.push_back(cl); }
      Ctrl* controller(int idx) const            { return controllerList[idx]; }
      bool setParameter(const QString& s, double val);
      void setParam(int i, double val);
      double param(int i) const                   { return pif[0]->param(i); }

      const char* getParameterName(int i) const  { return pif[0]->getParameterName(i); }
      const char* getParameterLabel(int i) const { return pif[0]->getParameterLabel(i); }
      const char* getParameterDisplay(int i, float v) const { return pif[0]->getParameterDisplay(i, v); }

      void range(int i, double* min, double* max) const {
            _plugin->range(i, min, max);
            }
      double defaultValue(int i) const { return _plugin->defaultValue(i);   }
      bool inPlaceCapable() const      { return _plugin->inPlaceCapable(); }

      bool isLog(int k) const          { return _plugin->isLog(k);  }
      bool isBool(int k) const         { return _plugin->isBool(k); }
      bool isInt(int k) const          { return _plugin->isInt(k);  }

      PluginIF* pluginIF(int idx)      { return pif[idx]; }
      };

extern void initPlugins();
extern PluginList plugins;

#endif