@marmooo/midi-player 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ export class MIDIPlayer {
2
+ constructor(midy: any);
3
+ soundFontDir: string;
4
+ midy: any;
5
+ timer: any;
6
+ currentTime: number;
7
+ currTimeInterval: number;
8
+ currTimeNode: any;
9
+ totalTimeNode: any;
10
+ seekBarNode: any;
11
+ playNode: any;
12
+ pauseNode: any;
13
+ resumeNode: any;
14
+ stopNode: any;
15
+ root: any;
16
+ defaultLayout(): void;
17
+ row(): any;
18
+ formatTime(seconds: any): string;
19
+ button(title: any, className: any, spriteId: any, display: any): any;
20
+ formRange(title: any, className: any, value: any, display: any): any;
21
+ text(text: any, className: any): any;
22
+ startTimer(): void;
23
+ loadMIDI(file: any): Promise<void>;
24
+ setSoundFontDir(dir: any): void;
25
+ start(): Promise<void>;
26
+ stop(): any;
27
+ playPauseResume(): any;
28
+ volumeText(): any;
29
+ volume(): any;
30
+ seekBar(): any;
31
+ currTime(): any;
32
+ totalTime(): any;
33
+ currTimeTotalTime(): any;
34
+ }
35
+ //# sourceMappingURL=midi-player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"midi-player.d.ts","sourceRoot":"","sources":["../src/midi-player.js"],"names":[],"mappings":"AAAA;IAcE,uBAGC;IAhBD,qBAAoE;IACpE,UAAK;IACL,WAAM;IACN,oBAAgB;IAChB,yBAAuB;IACvB,kBAAa;IACb,mBAAc;IACd,iBAAY;IACZ,cAAS;IACT,eAAU;IACV,gBAAW;IACX,cAAS;IAIP,UAAiD;IAGnD,sBAMC;IAED,WAOC;IAED,iCASC;IAED,qEASC;IAED,qEAOC;IAED,qCAKC;IAED,mBAYC;IAED,mCAKC;IAED,gCAEC;IAED,uBAoBC;IAED,YAYC;IAED,uBA2CC;IAED,kBAEC;IAED,cA8BC;IAED,eAgBC;IAED,gBAIC;IAED,iBAIC;IAED,yBAWC;CACF"}
@@ -0,0 +1,301 @@
1
+ export class MIDIPlayer {
2
+ constructor(midy) {
3
+ Object.defineProperty(this, "soundFontDir", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: "https://soundfonts.pages.dev/GeneralUser_GS_v1.471"
8
+ });
9
+ Object.defineProperty(this, "midy", {
10
+ enumerable: true,
11
+ configurable: true,
12
+ writable: true,
13
+ value: void 0
14
+ });
15
+ Object.defineProperty(this, "timer", {
16
+ enumerable: true,
17
+ configurable: true,
18
+ writable: true,
19
+ value: void 0
20
+ });
21
+ Object.defineProperty(this, "currentTime", {
22
+ enumerable: true,
23
+ configurable: true,
24
+ writable: true,
25
+ value: 0
26
+ });
27
+ Object.defineProperty(this, "currTimeInterval", {
28
+ enumerable: true,
29
+ configurable: true,
30
+ writable: true,
31
+ value: 100
32
+ });
33
+ Object.defineProperty(this, "currTimeNode", {
34
+ enumerable: true,
35
+ configurable: true,
36
+ writable: true,
37
+ value: void 0
38
+ });
39
+ Object.defineProperty(this, "totalTimeNode", {
40
+ enumerable: true,
41
+ configurable: true,
42
+ writable: true,
43
+ value: void 0
44
+ });
45
+ Object.defineProperty(this, "seekBarNode", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: void 0
50
+ });
51
+ Object.defineProperty(this, "playNode", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: void 0
56
+ });
57
+ Object.defineProperty(this, "pauseNode", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: void 0
62
+ });
63
+ Object.defineProperty(this, "resumeNode", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ Object.defineProperty(this, "stopNode", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: void 0
74
+ });
75
+ this.midy = midy;
76
+ this.root = document.createElement("midi-player");
77
+ }
78
+ defaultLayout() {
79
+ const div = this.row();
80
+ div.appendChild(this.playPauseResume());
81
+ div.appendChild(this.volume());
82
+ div.appendChild(this.currTimeTotalTime());
83
+ div.appendChild(this.seekBar());
84
+ }
85
+ row() {
86
+ const div = document.createElement("div");
87
+ div.className = "midi-player-row";
88
+ div.style.display = "flex";
89
+ div.style.alignItems = "center";
90
+ this.root.appendChild(div);
91
+ return div;
92
+ }
93
+ formatTime(seconds) {
94
+ seconds = Math.floor(seconds);
95
+ const s = seconds % 60;
96
+ const m = (seconds - s) / 60;
97
+ const h = (seconds - s - 60 * m) / 3600;
98
+ const ss = String(s).padStart(2, "0");
99
+ const mm = (m > 9 || !h) ? `${m}:` : `0${m}:`;
100
+ const hh = h ? `${h}:` : "";
101
+ return `${hh}${mm}${ss}`;
102
+ }
103
+ button(title, className, spriteId, display) {
104
+ const div = document.createElement("div");
105
+ div.style.display = display;
106
+ div.innerHTML = `
107
+ <button title="${title}" class="midi-player-btn ${className}" type="button">
108
+ ${spriteId}
109
+ </button>
110
+ `;
111
+ return div;
112
+ }
113
+ formRange(title, className, value, display) {
114
+ const div = document.createElement("div");
115
+ div.innerHTML = `
116
+ <input title="${title}" class="midi-player-range ${className}" style="display:${display};"
117
+ type="range" min="0" max="1" step="0.001" value="${value}">
118
+ `;
119
+ return div.firstElementChild;
120
+ }
121
+ text(text, className) {
122
+ const div = document.createElement("div");
123
+ div.className = `midi-player-text ${className}`;
124
+ div.textContent = text;
125
+ return div;
126
+ }
127
+ startTimer() {
128
+ const endTime = this.midy.totalTime;
129
+ this.timer = setInterval(() => {
130
+ const now = this.midy.currentTime();
131
+ const seconds = Math.ceil(now);
132
+ if (this.currTimeNode) {
133
+ this.currTimeNode.textContent = this.formatTime(seconds);
134
+ }
135
+ if (this.seekBarNode) {
136
+ this.seekBarNode.value = now / endTime;
137
+ }
138
+ }, this.currTimeInterval);
139
+ }
140
+ async loadMIDI(file) {
141
+ await this.midy.loadMIDI(file);
142
+ if (this.totalTimeNode) {
143
+ this.totalTimeNode.textContent = this.formatTime(this.midy.totalTime);
144
+ }
145
+ }
146
+ setSoundFontDir(dir) {
147
+ this.soundFontDir = dir;
148
+ }
149
+ async start() {
150
+ if (this.midy.soundFonts.length === 0) {
151
+ for (const instrument of this.midy.instruments) {
152
+ const [bankNumber, programNumber] = instrument.split(":").map(Number);
153
+ if (this.midy.soundFontTable[programNumber].has(bankNumber))
154
+ continue;
155
+ const program = programNumber.toString().padStart(3, "0");
156
+ if (bankNumber === 128) {
157
+ await this.midy.loadSoundFont(`${this.soundFontDir}/128.sf3`);
158
+ }
159
+ else {
160
+ await this.midy.loadSoundFont(`${this.soundFontDir}/${program}.sf3`);
161
+ }
162
+ }
163
+ }
164
+ this.startTimer();
165
+ await this.midy.start();
166
+ clearInterval(this.timer);
167
+ if (!this.midy.isPaused && this.currTimeNode) {
168
+ this.currTimeNode.textContent = "0:00";
169
+ this.seekBarNode.value = 0;
170
+ }
171
+ }
172
+ stop() {
173
+ const stop = this.button("start", "start", "stop", "initial");
174
+ stop.onclick = () => {
175
+ if (!this.midy.isPlaying)
176
+ return;
177
+ clearInterval(this.timer);
178
+ this.playNode.style.display = "initial";
179
+ this.pauseNode.style.display = "none";
180
+ this.resumeNode.style.display = "none";
181
+ this.midy.stop();
182
+ };
183
+ this.stopNode = stop;
184
+ return stop;
185
+ }
186
+ playPauseResume() {
187
+ const play = this.button("start", "start", "play_arrow", "initial");
188
+ const pause = this.button("pause", "pause", "pause", "none");
189
+ const resume = this.button("resume", "resume", "play_arrow", "none");
190
+ play.onclick = async () => {
191
+ if (this.midy.isPlaying || this.midy.isPaused)
192
+ return;
193
+ play.style.display = "none";
194
+ pause.style.display = "initial";
195
+ await this.start();
196
+ if (!this.midy.isPaused) {
197
+ pause.style.display = "none";
198
+ play.style.display = "initial";
199
+ }
200
+ };
201
+ pause.onclick = () => {
202
+ if (!this.midy.isPlaying || this.midy.isPaused)
203
+ return;
204
+ pause.style.display = "none";
205
+ resume.style.display = "initial";
206
+ clearInterval(this.timer);
207
+ this.midy.pause();
208
+ };
209
+ resume.onclick = async () => {
210
+ if (!this.midy.isPaused)
211
+ return;
212
+ pause.style.display = "initial";
213
+ resume.style.display = "none";
214
+ this.startTimer();
215
+ await this.midy.resume();
216
+ clearInterval(this.timer);
217
+ if (!this.midy.isPaused) {
218
+ pause.style.display = "none";
219
+ play.style.display = "initial";
220
+ }
221
+ };
222
+ const div = document.createElement("div");
223
+ div.style.display = "flex";
224
+ div.style.alignItems = "center";
225
+ div.appendChild(play);
226
+ div.appendChild(pause);
227
+ div.appendChild(resume);
228
+ this.playNode = play;
229
+ this.pauseNode = pause;
230
+ this.resumeNode = resume;
231
+ return div;
232
+ }
233
+ volumeText() {
234
+ return this.text("volume", "volumeText");
235
+ }
236
+ volume() {
237
+ const muteOn = this.button("mute ON", "muteOn", "volume_down", "initial");
238
+ const muteOff = this.button("mute OFF", "muteOff", "volume_off", "none");
239
+ const volumeBar = this.formRange("volume", "volume", 1, "none");
240
+ muteOn.onclick = () => {
241
+ muteOn.style.display = "none";
242
+ muteOff.style.display = "initial";
243
+ this.midy.handleMasterVolume(0);
244
+ };
245
+ muteOff.onclick = () => {
246
+ muteOn.style.display = "initial";
247
+ muteOff.style.display = "none";
248
+ this.midy.handleMasterVolume(1);
249
+ };
250
+ volumeBar.oninput = (event) => {
251
+ this.midy.handleMasterVolume(event.target.value);
252
+ };
253
+ const div = document.createElement("div");
254
+ div.style.display = "flex";
255
+ div.style.alignItems = "center";
256
+ div.appendChild(muteOn);
257
+ div.appendChild(muteOff);
258
+ div.appendChild(volumeBar);
259
+ div.onmouseover = () => {
260
+ volumeBar.style.display = "initial";
261
+ };
262
+ div.onmouseout = () => {
263
+ volumeBar.style.display = "none";
264
+ };
265
+ return div;
266
+ }
267
+ seekBar() {
268
+ const seekBar = this.formRange("playback position", "seekBar", 0, "initial");
269
+ seekBar.oninput = (event) => {
270
+ const time = event.target.value * this.midy.totalTime;
271
+ this.midy.seekTo(time);
272
+ if (this.currTimeNode) {
273
+ this.currTimeNode.textContent = this.formatTime(time);
274
+ }
275
+ };
276
+ this.seekBarNode = seekBar;
277
+ return seekBar;
278
+ }
279
+ currTime() {
280
+ const currTime = this.text("0:00", "currTime");
281
+ this.currTimeNode = currTime;
282
+ return currTime;
283
+ }
284
+ totalTime() {
285
+ const totalTime = this.text("0:00", "totalTime");
286
+ this.totalTimeNode = totalTime;
287
+ return totalTime;
288
+ }
289
+ currTimeTotalTime() {
290
+ const currTime = this.currTime();
291
+ const separator = this.text("/", "timeSeparator");
292
+ const totalTime = this.totalTime();
293
+ const div = document.createElement("div");
294
+ div.style.display = "flex";
295
+ div.style.alignItems = "center";
296
+ div.appendChild(currTime);
297
+ div.appendChild(separator);
298
+ div.appendChild(totalTime);
299
+ return div;
300
+ }
301
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@marmooo/midi-player",
3
+ "version": "0.0.1",
4
+ "description": "<midi-player> HTML elements powered by Midy.",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/marmooo/midi-player.git"
8
+ },
9
+ "license": "Apache-2.0",
10
+ "bugs": {
11
+ "url": "https://github.com/marmooo/midi-player/issues"
12
+ },
13
+ "main": "./script/midi-player.js",
14
+ "module": "./esm/midi-player.js",
15
+ "exports": {
16
+ ".": {
17
+ "import": "./esm/midi-player.js",
18
+ "require": "./script/midi-player.js"
19
+ }
20
+ },
21
+ "scripts": {
22
+ "test": "node test_runner.js"
23
+ },
24
+ "devDependencies": {
25
+ "@types/node": "^20.9.0",
26
+ "picocolors": "^1.0.0"
27
+ },
28
+ "_generatedBy": "dnt@dev"
29
+ }
@@ -0,0 +1,35 @@
1
+ export class MIDIPlayer {
2
+ constructor(midy: any);
3
+ soundFontDir: string;
4
+ midy: any;
5
+ timer: any;
6
+ currentTime: number;
7
+ currTimeInterval: number;
8
+ currTimeNode: any;
9
+ totalTimeNode: any;
10
+ seekBarNode: any;
11
+ playNode: any;
12
+ pauseNode: any;
13
+ resumeNode: any;
14
+ stopNode: any;
15
+ root: any;
16
+ defaultLayout(): void;
17
+ row(): any;
18
+ formatTime(seconds: any): string;
19
+ button(title: any, className: any, spriteId: any, display: any): any;
20
+ formRange(title: any, className: any, value: any, display: any): any;
21
+ text(text: any, className: any): any;
22
+ startTimer(): void;
23
+ loadMIDI(file: any): Promise<void>;
24
+ setSoundFontDir(dir: any): void;
25
+ start(): Promise<void>;
26
+ stop(): any;
27
+ playPauseResume(): any;
28
+ volumeText(): any;
29
+ volume(): any;
30
+ seekBar(): any;
31
+ currTime(): any;
32
+ totalTime(): any;
33
+ currTimeTotalTime(): any;
34
+ }
35
+ //# sourceMappingURL=midi-player.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"midi-player.d.ts","sourceRoot":"","sources":["../src/midi-player.js"],"names":[],"mappings":"AAAA;IAcE,uBAGC;IAhBD,qBAAoE;IACpE,UAAK;IACL,WAAM;IACN,oBAAgB;IAChB,yBAAuB;IACvB,kBAAa;IACb,mBAAc;IACd,iBAAY;IACZ,cAAS;IACT,eAAU;IACV,gBAAW;IACX,cAAS;IAIP,UAAiD;IAGnD,sBAMC;IAED,WAOC;IAED,iCASC;IAED,qEASC;IAED,qEAOC;IAED,qCAKC;IAED,mBAYC;IAED,mCAKC;IAED,gCAEC;IAED,uBAoBC;IAED,YAYC;IAED,uBA2CC;IAED,kBAEC;IAED,cA8BC;IAED,eAgBC;IAED,gBAIC;IAED,iBAIC;IAED,yBAWC;CACF"}
@@ -0,0 +1,305 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MIDIPlayer = void 0;
4
+ class MIDIPlayer {
5
+ constructor(midy) {
6
+ Object.defineProperty(this, "soundFontDir", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: "https://soundfonts.pages.dev/GeneralUser_GS_v1.471"
11
+ });
12
+ Object.defineProperty(this, "midy", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "timer", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "currentTime", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: 0
29
+ });
30
+ Object.defineProperty(this, "currTimeInterval", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: 100
35
+ });
36
+ Object.defineProperty(this, "currTimeNode", {
37
+ enumerable: true,
38
+ configurable: true,
39
+ writable: true,
40
+ value: void 0
41
+ });
42
+ Object.defineProperty(this, "totalTimeNode", {
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true,
46
+ value: void 0
47
+ });
48
+ Object.defineProperty(this, "seekBarNode", {
49
+ enumerable: true,
50
+ configurable: true,
51
+ writable: true,
52
+ value: void 0
53
+ });
54
+ Object.defineProperty(this, "playNode", {
55
+ enumerable: true,
56
+ configurable: true,
57
+ writable: true,
58
+ value: void 0
59
+ });
60
+ Object.defineProperty(this, "pauseNode", {
61
+ enumerable: true,
62
+ configurable: true,
63
+ writable: true,
64
+ value: void 0
65
+ });
66
+ Object.defineProperty(this, "resumeNode", {
67
+ enumerable: true,
68
+ configurable: true,
69
+ writable: true,
70
+ value: void 0
71
+ });
72
+ Object.defineProperty(this, "stopNode", {
73
+ enumerable: true,
74
+ configurable: true,
75
+ writable: true,
76
+ value: void 0
77
+ });
78
+ this.midy = midy;
79
+ this.root = document.createElement("midi-player");
80
+ }
81
+ defaultLayout() {
82
+ const div = this.row();
83
+ div.appendChild(this.playPauseResume());
84
+ div.appendChild(this.volume());
85
+ div.appendChild(this.currTimeTotalTime());
86
+ div.appendChild(this.seekBar());
87
+ }
88
+ row() {
89
+ const div = document.createElement("div");
90
+ div.className = "midi-player-row";
91
+ div.style.display = "flex";
92
+ div.style.alignItems = "center";
93
+ this.root.appendChild(div);
94
+ return div;
95
+ }
96
+ formatTime(seconds) {
97
+ seconds = Math.floor(seconds);
98
+ const s = seconds % 60;
99
+ const m = (seconds - s) / 60;
100
+ const h = (seconds - s - 60 * m) / 3600;
101
+ const ss = String(s).padStart(2, "0");
102
+ const mm = (m > 9 || !h) ? `${m}:` : `0${m}:`;
103
+ const hh = h ? `${h}:` : "";
104
+ return `${hh}${mm}${ss}`;
105
+ }
106
+ button(title, className, spriteId, display) {
107
+ const div = document.createElement("div");
108
+ div.style.display = display;
109
+ div.innerHTML = `
110
+ <button title="${title}" class="midi-player-btn ${className}" type="button">
111
+ ${spriteId}
112
+ </button>
113
+ `;
114
+ return div;
115
+ }
116
+ formRange(title, className, value, display) {
117
+ const div = document.createElement("div");
118
+ div.innerHTML = `
119
+ <input title="${title}" class="midi-player-range ${className}" style="display:${display};"
120
+ type="range" min="0" max="1" step="0.001" value="${value}">
121
+ `;
122
+ return div.firstElementChild;
123
+ }
124
+ text(text, className) {
125
+ const div = document.createElement("div");
126
+ div.className = `midi-player-text ${className}`;
127
+ div.textContent = text;
128
+ return div;
129
+ }
130
+ startTimer() {
131
+ const endTime = this.midy.totalTime;
132
+ this.timer = setInterval(() => {
133
+ const now = this.midy.currentTime();
134
+ const seconds = Math.ceil(now);
135
+ if (this.currTimeNode) {
136
+ this.currTimeNode.textContent = this.formatTime(seconds);
137
+ }
138
+ if (this.seekBarNode) {
139
+ this.seekBarNode.value = now / endTime;
140
+ }
141
+ }, this.currTimeInterval);
142
+ }
143
+ async loadMIDI(file) {
144
+ await this.midy.loadMIDI(file);
145
+ if (this.totalTimeNode) {
146
+ this.totalTimeNode.textContent = this.formatTime(this.midy.totalTime);
147
+ }
148
+ }
149
+ setSoundFontDir(dir) {
150
+ this.soundFontDir = dir;
151
+ }
152
+ async start() {
153
+ if (this.midy.soundFonts.length === 0) {
154
+ for (const instrument of this.midy.instruments) {
155
+ const [bankNumber, programNumber] = instrument.split(":").map(Number);
156
+ if (this.midy.soundFontTable[programNumber].has(bankNumber))
157
+ continue;
158
+ const program = programNumber.toString().padStart(3, "0");
159
+ if (bankNumber === 128) {
160
+ await this.midy.loadSoundFont(`${this.soundFontDir}/128.sf3`);
161
+ }
162
+ else {
163
+ await this.midy.loadSoundFont(`${this.soundFontDir}/${program}.sf3`);
164
+ }
165
+ }
166
+ }
167
+ this.startTimer();
168
+ await this.midy.start();
169
+ clearInterval(this.timer);
170
+ if (!this.midy.isPaused && this.currTimeNode) {
171
+ this.currTimeNode.textContent = "0:00";
172
+ this.seekBarNode.value = 0;
173
+ }
174
+ }
175
+ stop() {
176
+ const stop = this.button("start", "start", "stop", "initial");
177
+ stop.onclick = () => {
178
+ if (!this.midy.isPlaying)
179
+ return;
180
+ clearInterval(this.timer);
181
+ this.playNode.style.display = "initial";
182
+ this.pauseNode.style.display = "none";
183
+ this.resumeNode.style.display = "none";
184
+ this.midy.stop();
185
+ };
186
+ this.stopNode = stop;
187
+ return stop;
188
+ }
189
+ playPauseResume() {
190
+ const play = this.button("start", "start", "play_arrow", "initial");
191
+ const pause = this.button("pause", "pause", "pause", "none");
192
+ const resume = this.button("resume", "resume", "play_arrow", "none");
193
+ play.onclick = async () => {
194
+ if (this.midy.isPlaying || this.midy.isPaused)
195
+ return;
196
+ play.style.display = "none";
197
+ pause.style.display = "initial";
198
+ await this.start();
199
+ if (!this.midy.isPaused) {
200
+ pause.style.display = "none";
201
+ play.style.display = "initial";
202
+ }
203
+ };
204
+ pause.onclick = () => {
205
+ if (!this.midy.isPlaying || this.midy.isPaused)
206
+ return;
207
+ pause.style.display = "none";
208
+ resume.style.display = "initial";
209
+ clearInterval(this.timer);
210
+ this.midy.pause();
211
+ };
212
+ resume.onclick = async () => {
213
+ if (!this.midy.isPaused)
214
+ return;
215
+ pause.style.display = "initial";
216
+ resume.style.display = "none";
217
+ this.startTimer();
218
+ await this.midy.resume();
219
+ clearInterval(this.timer);
220
+ if (!this.midy.isPaused) {
221
+ pause.style.display = "none";
222
+ play.style.display = "initial";
223
+ }
224
+ };
225
+ const div = document.createElement("div");
226
+ div.style.display = "flex";
227
+ div.style.alignItems = "center";
228
+ div.appendChild(play);
229
+ div.appendChild(pause);
230
+ div.appendChild(resume);
231
+ this.playNode = play;
232
+ this.pauseNode = pause;
233
+ this.resumeNode = resume;
234
+ return div;
235
+ }
236
+ volumeText() {
237
+ return this.text("volume", "volumeText");
238
+ }
239
+ volume() {
240
+ const muteOn = this.button("mute ON", "muteOn", "volume_down", "initial");
241
+ const muteOff = this.button("mute OFF", "muteOff", "volume_off", "none");
242
+ const volumeBar = this.formRange("volume", "volume", 1, "none");
243
+ muteOn.onclick = () => {
244
+ muteOn.style.display = "none";
245
+ muteOff.style.display = "initial";
246
+ this.midy.handleMasterVolume(0);
247
+ };
248
+ muteOff.onclick = () => {
249
+ muteOn.style.display = "initial";
250
+ muteOff.style.display = "none";
251
+ this.midy.handleMasterVolume(1);
252
+ };
253
+ volumeBar.oninput = (event) => {
254
+ this.midy.handleMasterVolume(event.target.value);
255
+ };
256
+ const div = document.createElement("div");
257
+ div.style.display = "flex";
258
+ div.style.alignItems = "center";
259
+ div.appendChild(muteOn);
260
+ div.appendChild(muteOff);
261
+ div.appendChild(volumeBar);
262
+ div.onmouseover = () => {
263
+ volumeBar.style.display = "initial";
264
+ };
265
+ div.onmouseout = () => {
266
+ volumeBar.style.display = "none";
267
+ };
268
+ return div;
269
+ }
270
+ seekBar() {
271
+ const seekBar = this.formRange("playback position", "seekBar", 0, "initial");
272
+ seekBar.oninput = (event) => {
273
+ const time = event.target.value * this.midy.totalTime;
274
+ this.midy.seekTo(time);
275
+ if (this.currTimeNode) {
276
+ this.currTimeNode.textContent = this.formatTime(time);
277
+ }
278
+ };
279
+ this.seekBarNode = seekBar;
280
+ return seekBar;
281
+ }
282
+ currTime() {
283
+ const currTime = this.text("0:00", "currTime");
284
+ this.currTimeNode = currTime;
285
+ return currTime;
286
+ }
287
+ totalTime() {
288
+ const totalTime = this.text("0:00", "totalTime");
289
+ this.totalTimeNode = totalTime;
290
+ return totalTime;
291
+ }
292
+ currTimeTotalTime() {
293
+ const currTime = this.currTime();
294
+ const separator = this.text("/", "timeSeparator");
295
+ const totalTime = this.totalTime();
296
+ const div = document.createElement("div");
297
+ div.style.display = "flex";
298
+ div.style.alignItems = "center";
299
+ div.appendChild(currTime);
300
+ div.appendChild(separator);
301
+ div.appendChild(totalTime);
302
+ return div;
303
+ }
304
+ }
305
+ exports.MIDIPlayer = MIDIPlayer;
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }