drumstick  1.0.1
synthengine.h
1 /*
2  Drumstick RT (realtime MIDI In/Out)
3  Copyright (C) 2009-2015 Pedro Lopez-Cabanillas <plcl@users.sf.net>
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License along
16  with this program; If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #ifndef SynthEngine_H
20 #define SynthEngine_H
21 
22 #include <QObject>
23 #include <QString>
24 #include <QList>
25 #include <QDir>
26 #include <QSettings>
27 #include <fluidsynth.h>
28 
29 #define cvtstr(s) #s
30 #define stringify(s) cvtstr(s)
31 
32 const QString QSTR_FLUIDSYNTH(QLatin1String("FluidSynth"));
33 
34 class SynthEngine : public QObject
35 {
36  Q_OBJECT
37  Q_PROPERTY(QString soundFont READ soundFont WRITE setSoundFont)
38 
39 public:
40  SynthEngine(QObject *parent = 0);
41  virtual ~SynthEngine();
42 
43  QString soundFont() const { return m_soundFont; }
44  void setSoundFont(const QString &value);
45 
46  Q_INVOKABLE void initialize(QSettings *settings);
47  Q_INVOKABLE void readSettings(QSettings *settings);
48  Q_INVOKABLE void scanSoundFonts();
49  Q_INVOKABLE void panic();
50  Q_INVOKABLE void setInstrument(const int channel, int i);
51  Q_INVOKABLE void noteOn(const int channel, const int midiNote, const int velocity);
52  Q_INVOKABLE void noteOff(const int channel, const int midiNote, const int velocity);
53  Q_INVOKABLE void controlChange(const int channel, const int ctl, const int value);
54  Q_INVOKABLE void bender(const int channel, const int value);
55  Q_INVOKABLE QString version() const { return stringify(VERSION); }
56 
57  QString currentConnection() const { return m_currentConnection; }
58  void close();
59  void open();
60  void uninitialize();
61 
62 private:
63  void scanSoundFonts(const QDir &dir);
64  void initializeSynth(QSettings *settings = 0);
65  void loadSoundFont();
66 
67  int m_sfid;
68  QString m_currentConnection;
69  QString m_soundFont;
70  QString m_defSoundFont;
71  fluid_settings_t* m_settings;
72  fluid_synth_t* m_synth;
73  fluid_audio_driver_t* m_driver;
74  QStringList m_soundFontsList;
75 };
76 
77 #endif // SynthEngine_H
78 
The QObject class is the base class of all Qt objects.