aboutsummaryrefslogtreecommitdiff
path: root/visualization/qmpvisualization.hpp
blob: 76cfee2853a11b9bf5011bf5acbb02eff392ef41 (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
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
#ifndef QMPVISUALIZATION_H
#define QMPVISUALIZATION_H

#include <vector>
#include <stack>
#include <thread>
#include <smelt.hpp>
#include <smmath.hpp>
#include <smttfont.hpp>
#include "qmpvirtualpiano3d.hpp"
#include "../include/qmpcorepublic.hpp"

class qmpVisualization;
class CReaderCallBack:public IMidiCallBack
{
	private:
		qmpVisualization *par;
	public:
		CReaderCallBack(qmpVisualization *_par){par=_par;}
		void callBack(void *callerdata,void *userdata);
};
class CHandlerCallBack:public IMidiCallBack
{
	private:
		qmpVisualization *par;
	public:
		CHandlerCallBack(qmpVisualization *_par){par=_par;}
		void callBack(void*,void*);
};
struct MidiVisualEvent
{
	uint32_t tcs,tce;
	uint32_t key,vel;
	uint32_t ch;
};
class qmpVisualization:public qmpPluginIntf
{
	friend class CHandlerCallBack;
	friend class CloseHandler;
	private:
		qmpPluginAPI* api;
		CReaderCallBack* cb;
		CHandlerCallBack* hcb;
		qmpVisualizationIntf* vi;
		std::thread* rendererTh;
		std::vector<MidiVisualEvent*>pool;
		smHandler *h,*closeh;
		std::stack<uint32_t> pendingt[16][128],pendingv[16][128];
		SMELT *sm;
		SMTRG tdscn,tdparticles;
		SMTEX chequer,bgtex,particletex,pianotex;
		smTTFont font,font2,fonthdpi;
		qmpVirtualPiano3D* p3d[16];
		smEntity3DBuffer* nebuf;
		smParticleSystem* pss[16][128];
		smPSEmissionPositionGenerator* psepg;
		float pos[3],rot[3],lastx,lasty;
		uint32_t ctc,ctk,fintk,elb;
		double etps;
		bool shouldclose,playing;
		int hvif,herif,hehif;
		int traveld[16][128];bool notestatus[16][128];
		void drawCube(smvec3d a,smvec3d b,DWORD col,SMTEX tex);
		void showThread();
	public:
		qmpVisualization(qmpPluginAPI* _api);
		~qmpVisualization();
		void pushNoteOn(uint32_t tc,uint32_t ch,uint32_t key,uint32_t vel);
		void pushNoteOff(uint32_t tc,uint32_t ch,uint32_t key);
		bool update();
		void start();
		void stop();
		void pause();
		void show();
		void close();
		void reset();

		void init();
		void deinit();
		const char* pluginGetName();
		const char* pluginGetVersion();
};

class CMidiVisualHandler:public smHandler
{
	private:
		qmpVisualization *p;
	public:
		CMidiVisualHandler(qmpVisualization* par){p=par;}
		bool handlerFunc(){return p->update();}
};

class CloseHandler:public smHandler
{
	private:
		qmpVisualization *p;
	public:
		CloseHandler(qmpVisualization* par){p=par;}
	public:
		bool handlerFunc(){return true;}
};

class CDemoVisualization:public qmpVisualizationIntf
{
	private:
		qmpVisualization* par;
	public:
		CDemoVisualization(qmpVisualization *p){par=p;}
		void show(){par->show();}
		void close(){par->close();}
		void start(){par->start();}
		void stop(){par->stop();}
		void pause(){par->pause();}
		void reset(){par->reset();}
};

extern "C"{
	EXPORTSYM qmpPluginIntf* qmpPluginGetInterface(qmpPluginAPI* api)
	{return new qmpVisualization(api);}
}

#endif // QMPVISUALIZATION_H