drumstick  1.0.2
synthengine.h
00001 /*
00002     Drumstick RT (realtime MIDI In/Out)
00003     Copyright (C) 2009-2015 Pedro Lopez-Cabanillas <plcl@users.sf.net>
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License along
00016     with this program; If not, see <http://www.gnu.org/licenses/>.
00017 */
00018 
00019 #ifndef SynthEngine_H
00020 #define SynthEngine_H
00021 
00022 #include <QObject>
00023 #include <QString>
00024 #include <QList>
00025 #include <QDir>
00026 #include <QSettings>
00027 #include <fluidsynth.h>
00028 
00029 #define cvtstr(s) #s
00030 #define stringify(s) cvtstr(s)
00031 
00032 const QString QSTR_FLUIDSYNTH(QLatin1String("FluidSynth"));
00033 
00034 class SynthEngine : public QObject
00035 {
00036     Q_OBJECT
00037     Q_PROPERTY(QString soundFont READ soundFont WRITE setSoundFont)
00038 
00039 public:
00040     SynthEngine(QObject *parent = 0);
00041     virtual ~SynthEngine();
00042 
00043     QString soundFont() const { return m_soundFont; }
00044     void setSoundFont(const QString &value);
00045 
00046     Q_INVOKABLE void initialize(QSettings *settings);
00047     Q_INVOKABLE void readSettings(QSettings *settings);
00048     Q_INVOKABLE void scanSoundFonts();
00049     Q_INVOKABLE void panic();
00050     Q_INVOKABLE void setInstrument(const int channel, int i);
00051     Q_INVOKABLE void noteOn(const int channel, const int midiNote, const int velocity);
00052     Q_INVOKABLE void noteOff(const int channel, const int midiNote, const int velocity);
00053     Q_INVOKABLE void controlChange(const int channel, const int ctl, const int value);
00054     Q_INVOKABLE void bender(const int channel, const int value);
00055     Q_INVOKABLE QString version() const { return stringify(VERSION); }
00056 
00057     QString currentConnection() const { return m_currentConnection; }
00058     void close();
00059     void open();
00060     void uninitialize();
00061 
00062 private:
00063     void scanSoundFonts(const QDir &dir);
00064     void initializeSynth(QSettings *settings = 0);
00065     void loadSoundFont();
00066 
00067     int m_sfid;
00068     QString m_currentConnection;
00069     QString m_soundFont;
00070     QString m_defSoundFont;
00071     fluid_settings_t* m_settings;
00072     fluid_synth_t* m_synth;
00073     fluid_audio_driver_t* m_driver;
00074     QStringList m_soundFontsList;
00075 };
00076 
00077 #endif // SynthEngine_H
00078