aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayer-lite/qmpcorewrapper.hpp
blob: 090edc78486924e48661c83e8f69b4387b574120 (plain) (blame)
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
#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();
	}
	~CQMPCoreWrapper(){delete mp;}
	Q_INVOKABLE void initFluidSynth(QUrl sfpath)
	{
		mp->fluid()->setOptStr("audio.driver","pulseaudio");
		mp->fluid()->deviceInit();
		mp->fluid()->loadSFont(sfpath.toLocalFile().toStdString().c_str());
		for(int i=0;i<16;++i)
		mp->setChannelOutput(i,0);
	}
	Q_INVOKABLE void deinitFluidSynth()
	{
		mp->fluid()->deviceDeinit();
	}
	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;
		mp->playerPanic();
	}
	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