diff options
author | Chris Xiong <chirs241097@gmail.com> | 2016-04-06 16:54:29 +0800 |
---|---|---|
committer | Chris Xiong <chirs241097@gmail.com> | 2016-04-06 16:54:29 +0800 |
commit | 70fd2d85c1bd6fb8732e680e8fda9d36c317c732 (patch) | |
tree | 4f048e7af294a2d40d3cabb9ea0ff266aa1fc36c /qmidiplayer-lite/qmpcorewrapper.hpp | |
parent | cf7eafca1fbc9aae495d7b7d7e1fb4bc92e6819f (diff) | |
download | QMidiPlayer-70fd2d85c1bd6fb8732e680e8fda9d36c317c732.tar.xz |
Too young too simple.
Diffstat (limited to 'qmidiplayer-lite/qmpcorewrapper.hpp')
-rw-r--r-- | qmidiplayer-lite/qmpcorewrapper.hpp | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/qmidiplayer-lite/qmpcorewrapper.hpp b/qmidiplayer-lite/qmpcorewrapper.hpp new file mode 100644 index 0000000..ed024df --- /dev/null +++ b/qmidiplayer-lite/qmpcorewrapper.hpp @@ -0,0 +1,58 @@ +#ifndef QMPCOREWRAPPER_H +#define QMPCOREWRAPPER_H +#include <QObject> +#include <QUrl> +#include <thread> +#include <fluidsynth.h> +#include "../core/qmpmidiplay.hpp" +class CQMPCoreWrapper:public QObject +{ + Q_OBJECT +private: + CMidiPlayer *mp; + std::thread *playerTh; + int curprog; +public: + explicit CQMPCoreWrapper(QObject* parent=0):QObject(parent) + { + mp=new CMidiPlayer(false); + } + ~CQMPCoreWrapper(){delete mp;} + Q_INVOKABLE void initFluidSynth() + { + fluid_settings_t *fsettings=mp->getFluidSettings(); + fluid_settings_setstr(fsettings,"audio.driver","pulseaudio"); + mp->fluidInitialize(); + mp->pushSoundFont("/media/Files/FluidR3_Ext.sf2"); + } + Q_INVOKABLE void deinitFluidSynth() + { + mp->fluidDeinitialize(); + } + Q_INVOKABLE void loadFile(QUrl file) + { + mp->playerLoadFile(file.toLocalFile().toStdString().c_str()); + mp->playerInit();curprog=0; + } + Q_INVOKABLE void playFile() + { + playerTh=new std::thread(&CMidiPlayer::playerThread,mp); + } + Q_INVOKABLE void stop() + { + mp->playerDeinit();playerTh->join();delete playerTh; + } + Q_INVOKABLE int getProgress() + { + while(!mp->isFinished()&&mp->getTCeptr()>mp->getStamp(curprog) + &&curprog<=100) + ++curprog; + return curprog; + } + Q_INVOKABLE void panic(){mp->playerPanic();} + Q_INVOKABLE void setTCeptr(int perct) + { + mp->setTCeptr(mp->getStamp(perct),perct);curprog=perct; + } +}; +#endif // QMPCOREWRAPPER_H |