-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incomplete fix for reentrant TimingObject update event
- Loading branch information
1 parent
97fd294
commit 78559ec
Showing
7 changed files
with
62 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/*! | ||
* musicxml-player v0.17.0 | ||
* musicxml-player v0.17.1 | ||
* (c) Karim Ratib <[email protected]> (https://github.com/infojunkie) | ||
* Released under the GPL-3.0-only License. | ||
*/ | ||
|
@@ -12547,7 +12547,7 @@ const timingObjectConstructor = createTimingObjectConstructor(createCalculateTim | |
// @todo Expose an isSupported flag which checks for performance.now() support. | ||
|
||
var name = "musicxml-player"; | ||
var version = "0.17.0"; | ||
var version = "0.17.1"; | ||
var description = "A simple JavaScript component that loads and plays MusicXML files in the browser using Web Audio and Web MIDI."; | ||
var main = "dist/musicxml-player.esm.js"; | ||
var type = "module"; | ||
|
@@ -12695,8 +12695,9 @@ class Player { | |
} | ||
}); | ||
} | ||
//private _timingObjectUpdating: boolean; | ||
constructor(_options, _sheet, _parseResult, _musicXml) { | ||
var _a, _b, _c, _d, _e; | ||
var _a, _b, _c, _d, _e, _f; | ||
this._options = _options; | ||
this._sheet = _sheet; | ||
this._parseResult = _parseResult; | ||
|
@@ -12763,10 +12764,10 @@ class Player { | |
}); | ||
this._observer.observe(this._sheet); | ||
// Create the TimingObject. | ||
this._timingObject = new timingObjectConstructor({ velocity: 1, position: 0 }, 0, this._options.converter.timemap.last().timestamp + | ||
this._timingObject = new timingObjectConstructor({ velocity: (_f = this._options.velocity) !== null && _f !== void 0 ? _f : 1, position: 0 }, 0, this._options.converter.timemap.last().timestamp + | ||
this._options.converter.timemap.last().duration); | ||
this._timingObjectListener = (event) => this._handleTimingObjectChange(event); | ||
this._timingObjectUpdating = false; | ||
//this._timingObjectUpdating = false; | ||
this._timingObject.addEventListener('change', this._timingObjectListener); | ||
} | ||
/** | ||
|
@@ -12937,9 +12938,7 @@ class Player { | |
} | ||
_play() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
var _a, _b; | ||
const synchronizeMidi = () => { | ||
var _a; | ||
if (this._midiPlayer.state !== PlayerState.Playing) | ||
return; | ||
// Lookup the current measure number by binary-searching the timemap. | ||
|
@@ -12957,21 +12956,19 @@ class Player { | |
// Update the cursors and listeners. | ||
const entry = this._options.converter.timemap[index >= 0 ? index : Math.max(0, -index - 2)]; | ||
this._options.renderer.moveTo(entry.measure, entry.timestamp, Math.max(0, timestamp - entry.timestamp), entry.duration); | ||
this._timingObjectUpdate({ | ||
position: timestamp, | ||
velocity: (_a = this._options.velocity) !== null && _a !== void 0 ? _a : 1, | ||
}); | ||
this._timingObjectUpdate({ position: timestamp }); | ||
// Schedule next cursor movement. | ||
requestAnimationFrame(synchronizeMidi); | ||
}; | ||
// Schedule first cursor movement. | ||
requestAnimationFrame(synchronizeMidi); | ||
// Activate the MIDI player. | ||
const { velocity } = this.timingObject.query(); | ||
if (this._midiPlayer.state === PlayerState.Paused) { | ||
yield this._midiPlayer.resume((_a = this._options.velocity) !== null && _a !== void 0 ? _a : 1); | ||
yield this._midiPlayer.resume(velocity); | ||
} | ||
else { | ||
yield this._midiPlayer.play((_b = this._options.velocity) !== null && _b !== void 0 ? _b : 1); | ||
yield this._midiPlayer.play(velocity); | ||
} | ||
// Repeat if needed. | ||
if (this._midiPlayer.state === PlayerState.Stopped) { | ||
|
@@ -12983,32 +12980,30 @@ class Player { | |
} | ||
_timingObjectUpdate(newVector) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
this._timingObjectUpdating = true; | ||
//this._timingObjectUpdating = true; | ||
this._timingObject.update(newVector); | ||
}); | ||
} | ||
_handleTimingObjectChange(_event) { | ||
// Don't handle our internally-generated events. | ||
if (this._timingObjectUpdating) { | ||
this._timingObjectUpdating = false; | ||
return; | ||
} | ||
// Handle externally-generated events. | ||
const { velocity, position } = this.timingObject.query(); | ||
if (velocity === 0) { | ||
if (position === 0) { | ||
this.rewind(); | ||
} | ||
else { | ||
this.pause(); | ||
} | ||
} | ||
else { | ||
if (this._midiPlayer.state !== PlayerState.Stopped) { | ||
this._midiPlayer.velocity = velocity; | ||
this._midiPlayer.position = position; | ||
} | ||
} | ||
// // Don't handle our internally-generated events. | ||
// if (this._timingObjectUpdating) { | ||
// this._timingObjectUpdating = false; | ||
// return; | ||
// } | ||
// // Handle externally-generated events. | ||
// const { velocity, position } = this.timingObject.query(); | ||
// if (velocity === 0) { | ||
// if (position === 0) { | ||
// this.rewind(); | ||
// } else { | ||
// this.pause(); | ||
// } | ||
// } else { | ||
// if (this._midiPlayer.state !== PlayerState.Stopped) { | ||
// this._midiPlayer.velocity = velocity; | ||
// this._midiPlayer.position = position; | ||
// } | ||
// } | ||
} | ||
static _unroll(musicXml) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters