summaryrefslogtreecommitdiff
path: root/attic/muse_qt4_evolution/muse/synth.h
blob: cae9c417f2ab17ec18250305618ba3739e7c963b (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
219
220
221
222
223
224
225
226
227
//=============================================================================
//  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 __SYNTH_H__
#define __SYNTH_H__

#include "globals.h"
#include "instruments/minstrument.h"
#include "audiotrack.h"
#include "midiout.h"
#include "midififo.h"

class Mess;
struct MESS;

class SynthI;
class SynthIF;

//---------------------------------------------------------
//   Synth
//    software synthesizer
//---------------------------------------------------------

class Synth {
   protected:
      QFileInfo info;
      QString _name;
      int _instances;

   public:
      Synth(const QFileInfo* fi, QString label);
      virtual ~Synth() {}
      virtual const char* description() const { return ""; }
      virtual const char* version() const { return ""; }

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

      QString name() const        { return _name; }
      QString path() const        { return info.absolutePath(); }
      virtual SynthIF* createSIF(SynthI*) = 0;
      };

//---------------------------------------------------------
//   MessSynth
//---------------------------------------------------------

class MessSynth : public Synth {
      const MESS* descr;

   public:
      MessSynth(const QFileInfo* fi) : Synth(fi, fi->baseName()) { descr = 0; }
      virtual ~MessSynth() {}
      virtual const char* description() const;
      virtual const char* version() const;
      virtual void* instantiate(const QString&);
      virtual SynthIF* createSIF(SynthI*);
      };

class Mess;

//---------------------------------------------------------
//   SynthIF
//    synth instance interface
//---------------------------------------------------------

class SynthIF {

   protected:
      SynthI* synti;

   public:
      SynthIF(SynthI* s) { synti = s; }
      virtual ~SynthIF() {}

      virtual bool guiVisible() const = 0;
      virtual void showGui(bool v) = 0;
      virtual bool hasGui() const = 0;
      virtual void getGeometry(int*, int*, int*, int*) const = 0;
      virtual void setGeometry(int, int, int, int) = 0;
      virtual void getData(MidiEventList*, unsigned pos, int ports, unsigned n, float** buffer) = 0;
      virtual bool putEvent(const MidiEvent& ev) = 0;
      virtual MidiEvent receiveEvent() = 0;
      virtual int eventsPending() const = 0;
      virtual int channels() const = 0;
      virtual void deactivate3() = 0;
      virtual QString getPatchName(int, int) = 0;
      virtual void populatePatchPopup(QMenu*, int) = 0;
      virtual void write(Xml& xml) const = 0;
      virtual void setParameter(int idx, float value) = 0;
      virtual int getControllerInfo(int id, const char** name, int* ctrl, int* min, int* max) = 0;
      virtual bool hasAuxSend() const  { return true; }
      };

//---------------------------------------------------------
//   SynthI
//    software synthesizer instance
//    Track
//    MidiInstrument
//---------------------------------------------------------

class SynthI : public AudioTrack, public MidiOut, public MidiInstrument
      {
      Q_OBJECT

      SynthIF* _sif;

   protected:
      Synth* synthesizer;
      std::vector<float> initParams;
      MidiFifo putFifo;

      bool putMidiEvent(const MidiEvent& ev) {
            return _sif->putEvent(ev);
            }

      virtual QString open() { return QString("OK");}
      virtual void close()   {}
      virtual void collectInputData();

   public:
      friend class SynthIF;
      friend class MessSynthIF;
      friend class DssiSynthIF;

      SynthI();
      virtual ~SynthI();
      virtual TrackType type() const { return AUDIO_SOFTSYNTH; }

      virtual void setName(const QString& s);

      SynthIF* sif() const { return _sif; }
      bool initInstance(Synth* s);

      void read(QDomNode);
      virtual void write(Xml&) const;

      Synth* synth() const          { return synthesizer; }
      virtual bool isSynti() const  { return true; }

      virtual QString getPatchName(int ch, int prog) {
            return _sif ? _sif->getPatchName(ch, prog) : "";
            }
      virtual void populatePatchPopup(QMenu* m, int i) {
            _sif->populatePatchPopup(m, i);
            }

      void setParameter(const char* name, const char* value) const;

      bool guiVisible() const { return _sif->guiVisible(); }
      void showGui(bool v)    { _sif->showGui(v); }
      bool hasGui() const     { return _sif->hasGui(); }
      void getGeometry(int* x, int* y, int* w, int* h) const {
            _sif->getGeometry(x, y, w, h);
            }
      void setGeometry(int x, int y, int w, int h) {
            _sif->setGeometry(x, y, w, h);
            }
      MidiEvent receiveEvent() 	   { return _sif->receiveEvent(); }
      int eventsPending() const    	   { return _sif->eventsPending(); }
      void deactivate2();
      void deactivate3();
      bool isActivated() const         { return synthesizer && _sif; }
      virtual bool hasAuxSend() const  { return _sif->hasAuxSend(); }
      virtual void processMidi(SeqTime*);

      virtual MidiOut* midiOut() { return this; }
      virtual MidiInstrument* instrument() { return this; }
      };

//---------------------------------------------------------
//   MessSynthIF
//    mess synthesizer instance
//---------------------------------------------------------

class MessSynthIF : public SynthIF {
      Mess* _mess;

   public:
      MessSynthIF(SynthI* s) : SynthIF(s) { _mess = 0; }
      virtual ~MessSynthIF();

      virtual bool guiVisible() const;
      virtual void showGui(bool v);
      virtual bool hasGui() const;
      virtual void getGeometry(int*, int*, int*, int*) const;
      virtual void setGeometry(int, int, int, int);
      virtual void getData(MidiEventList*, unsigned pos, int ports, unsigned n, float** buffer);
      virtual bool putEvent(const MidiEvent& ev);
      virtual MidiEvent receiveEvent();
      virtual int eventsPending() const;
      virtual int channels() const;
      virtual void deactivate3();
      virtual QString getPatchName(int, int);
      virtual void populatePatchPopup(QMenu*, int);
      virtual void write(Xml& xml) const;
      virtual void setParameter(int, float) {}
      virtual int getControllerInfo(int id, const char** name, int* ctrl, int* min, int* max);
      bool init(Synth* s, SynthI* si);
      };

typedef QList<SynthI*> SynthIList;
typedef SynthIList::iterator iSynthI;
typedef SynthIList::const_iterator ciSynthI;

extern std::vector<Synth*> synthis;  // array of available synthis
extern Synth* findSynth(const QString& sclass);

#endif