aboutsummaryrefslogtreecommitdiff
path: root/qmidiplayerlite.src.d/main.qml
blob: 0ec0975d9094245986b003193a4839a3b44b00d7 (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import QtQuick 2.3
import QtQuick.Window 2.2
import QtQuick.Controls 1.0
import QtQuick.Dialogs 1.0
import org.chrisoft.qmpcore 1.0

Window {
	id: window1
	width: 420
	height: 240
	title: "QMidiPlayer Lite"
	visible: true
	property bool playing
	playing: false

	MouseArea {
		id: mouseArea1
		anchors.rightMargin: 0
		anchors.bottomMargin: 0
		anchors.leftMargin: 0
		anchors.topMargin: 0
		anchors.fill: parent
		onClicked: {
			//Qt.quit();
		}

		Button {
			id: button2
			x: 170
			text: qsTr("Play")
			anchors.top: parent.top
			anchors.topMargin: 172
			anchors.horizontalCenter: parent.horizontalCenter
			onClicked: {
				if(!playing)
				{
					qmpcore.loadFile(fileName.text);
					qmpcore.initFluidSynth();
					qmpcore.playFile();
					playing=true;
					uiTimer.start();
					text="Stop";
				}
				else
				{
					qmpcore.stop();
					playing=false;
					text="Play";
					hsTimer.value=0;uiTimer.stop();
				}
			}
		}

		Slider {
			id: hsTimer
			y: 210
			height: 22
			anchors.right: parent.right
			anchors.rightMargin: 8
			anchors.left: parent.left
			anchors.leftMargin: 8
			anchors.bottom: parent.bottom
			anchors.bottomMargin: 8
			tickmarksEnabled: false
			stepSize: 1
			maximumValue: 100
			property bool autovalchange: false
			onValueChanged: {
				if(autovalchange||pressed)return;
				if(playing){qmpcore.setTCeptr(value);qmpcore.panic();}
			}
			onPressedChanged: {
				if(!pressed)
				{
					/*if(playing)
					{
						if(ui->hsTimer->value()==100){on_pbNext_clicked();return;}
						player->setTCeptr(player->getStamp(ui->hsTimer->value()),ui->hsTimer->value());
						player->playerPanic();
						offset=ui->hsTimer->value()/100.*player->getFtime();
						st=std::chrono::steady_clock::now();
					}
					else
					{
						player->setTCeptr(player->getStamp(ui->hsTimer->value()),ui->hsTimer->value());
						offset=ui->hsTimer->value()/100.*player->getFtime();
						char ts[100];
						sprintf(ts,"%02d:%02d",(int)(offset)/60,(int)(offset)%60);
						ui->lbCurTime->setText(ts);
					}*/
					if(playing){qmpcore.setTCeptr(value);qmpcore.panic();}
				}
			}
		}
	}

	CQMPCoreWrapper {
		id: qmpcore
	}
	Timer {
		id: uiTimer
		interval: 100
		running: false
		repeat: true
		onTriggered: {
			if(!hsTimer.pressed)
			{
				hsTimer.autovalchange=true;
				hsTimer.value=qmpcore.getProgress();
				hsTimer.autovalchange=false;
			}
		}
	}

	Text {
		id: fileName
		text: qsTr("...")
		anchors.centerIn: parent
	}

	Button {
		id: button1
		x: 170
		width: 80
		height: 27
		text: qsTr("Open")
		anchors.top: parent.top
		anchors.topMargin: 142
		anchors.horizontalCenter: parent.horizontalCenter
		onClicked: {
			fileDialog.open();
		}
	}

	FileDialog {
		id: fileDialog
		title: qsTr("Select midi file")
		nameFilters: ["MIDI Files (*.mid *.midi)"]
		onAccepted: {
			fileName.text=fileUrl;
		}
	}
}