diff --git a/.github/workflows/release-package.yml b/.github/workflows/release-package.yml deleted file mode 100644 index 7faaccd..0000000 --- a/.github/workflows/release-package.yml +++ /dev/null @@ -1,33 +0,0 @@ -name: midi-writer-js - -on: - release: - types: [created] - -jobs: - build: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - - run: npm ci - - run: npm test - - publish-gpr: - needs: build - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - steps: - - uses: actions/checkout@v3 - - uses: actions/setup-node@v3 - with: - node-version: 16 - registry-url: https://npm.pkg.github.com/ - - run: npm ci - - run: npm publish - env: - NODE_AUTH_TOKEN: ${{secrets.GITHUB_TOKEN}} \ No newline at end of file diff --git a/browser/midiwriter.js b/browser/midiwriter.js index 2d1226d..e08dedb 100644 --- a/browser/midiwriter.js +++ b/browser/midiwriter.js @@ -6,7 +6,7 @@ var MidiWriter = (function () { * @return {Constants} */ var Constants = { - VERSION: '2.1.3', + VERSION: '2.1.4', HEADER_CHUNK_TYPE: [0x4d, 0x54, 0x68, 0x64], // Mthd HEADER_CHUNK_LENGTH: [0x00, 0x00, 0x00, 0x06], @@ -1283,6 +1283,12 @@ var MidiWriter = (function () { return _this.events.push(e); }); } + } else if (event instanceof EndTrackEvent) { + // Only one EndTrackEvent is allowed, so remove + // any existing ones before adding. + _this.removeEventsByType('end-track'); + + _this.events.push(event); } else { _this.events.push(event); } @@ -1301,9 +1307,12 @@ var MidiWriter = (function () { var _this2 = this; var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; - // Remove existing end track event and add one. - // This makes sure it's at the very end of the event list. - this.removeEventsByType('end-track').addEvent(new EndTrackEvent()); // Reset + + // If the last event isn't EndTrackEvent, then tack it onto the data. + if (!this.events.length || !(this.events[this.events.length - 1] instanceof EndTrackEvent)) { + this.addEvent(new EndTrackEvent()); + } // Reset + this.data = []; this.size = []; @@ -1384,8 +1393,14 @@ var MidiWriter = (function () { }, { key: "mergeSingleEvent", value: function mergeSingleEvent(event) { - // Find index of existing event we need to follow with - var lastEventIndex = 0; + // There are no events yet, so just add it in. + if (!this.events.length) { + this.addEvent(event); + return; + } // Find index of existing event we need to follow with + + + var lastEventIndex; for (var i = 0; i < this.events.length; i++) { if (this.events[i].tick > event.tick) break; diff --git a/docs/ControllerChangeEvent.html b/docs/ControllerChangeEvent.html index 6f4a378..86dbfb0 100644 --- a/docs/ControllerChangeEvent.html +++ b/docs/ControllerChangeEvent.html @@ -238,7 +238,7 @@
npm install midi-writer-js
const MidiWriter = require('midi-writer-js');
+import MidiWriter from 'midi-writer-js';
// Start with a new track
const track = new MidiWriter.Track();
@@ -190,7 +190,7 @@ MidiWriter.Writer(tracks)
Hot Cross Buns
Here's an example of how everyone's favorite song "Hot Cross Buns" could be written. Note use of the mapping function passed as the second argument of addEvent()
. This can be used to apply specific properties to all events. With some
street smarts you could also use it for programmatic crescendos and other property 'animation'.
-const MidiWriter = require('midi-writer-js');
+import MidiWriter from 'midi-writer-js';
const track = new MidiWriter.Track();
@@ -233,7 +233,7 @@ VexFlow Integration
diff --git a/docs/meta-events_controller-change-event.js.html b/docs/meta-events_controller-change-event.js.html
index 77b7470..9a9f480 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -73,7 +73,7 @@ meta-events/controller-change-event.js
diff --git a/docs/meta-events_copyright-event.js.html b/docs/meta-events_copyright-event.js.html
index 1f9c239..02c5f05 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -81,7 +81,7 @@ meta-events/copyright-event.js
diff --git a/docs/meta-events_cue-point-event.js.html b/docs/meta-events_cue-point-event.js.html
index a9a3012..bb493bd 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -81,7 +81,7 @@ meta-events/cue-point-event.js
diff --git a/docs/meta-events_end-track-event.js.html b/docs/meta-events_end-track-event.js.html
index 3a8df6a..447b89d 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -77,7 +77,7 @@ meta-events/end-track-event.js
diff --git a/docs/meta-events_instrument-name-event.js.html b/docs/meta-events_instrument-name-event.js.html
index aa6f3a1..67b82b9 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -81,7 +81,7 @@ meta-events/instrument-name-event.js
diff --git a/docs/meta-events_key-signature-event.js.html b/docs/meta-events_key-signature-event.js.html
index a251f3b..69af62a 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -117,7 +117,7 @@ meta-events/key-signature-event.js
diff --git a/docs/meta-events_lyric-event.js.html b/docs/meta-events_lyric-event.js.html
index 69bf897..a52c51b 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -81,7 +81,7 @@ meta-events/lyric-event.js
diff --git a/docs/meta-events_marker-event.js.html b/docs/meta-events_marker-event.js.html
index a054d7b..e37fbda 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -81,7 +81,7 @@ meta-events/marker-event.js
diff --git a/docs/meta-events_pitch-bend-event.js.html b/docs/meta-events_pitch-bend-event.js.html
index 96fdecf..deb7520 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -87,7 +87,7 @@ meta-events/pitch-bend-event.js
diff --git a/docs/meta-events_program-change-event.js.html b/docs/meta-events_program-change-event.js.html
index 46c3ca8..a5d2dd6 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -82,7 +82,7 @@ meta-events/program-change-event.js
diff --git a/docs/meta-events_tempo-event.js.html b/docs/meta-events_tempo-event.js.html
index d200803..45062e8 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -83,7 +83,7 @@ meta-events/tempo-event.js
diff --git a/docs/meta-events_text-event.js.html b/docs/meta-events_text-event.js.html
index 994a852..a1966dc 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -81,7 +81,7 @@ meta-events/text-event.js
diff --git a/docs/meta-events_time-signature-event.js.html b/docs/meta-events_time-signature-event.js.html
index c1bc65e..7dd49da 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -76,7 +76,7 @@ meta-events/time-signature-event.js
diff --git a/docs/meta-events_track-name-event.js.html b/docs/meta-events_track-name-event.js.html
index f48ddf1..bfab2f0 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -81,7 +81,7 @@ meta-events/track-name-event.js
diff --git a/docs/note-events_note-event.js.html b/docs/note-events_note-event.js.html
index de5ecec..9a0cf50 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -204,7 +204,7 @@ note-events/note-event.js
diff --git a/docs/note-events_note-off-event.js.html b/docs/note-events_note-off-event.js.html
index 01c94e4..928a406 100644
--- a/docs/note-events_note-off-event.js.html
+++ b/docs/note-events_note-off-event.js.html
@@ -110,7 +110,7 @@ note-events/note-off-event.js
diff --git a/docs/note-events_note-on-event.js.html b/docs/note-events_note-on-event.js.html
index 122eeba..114d8e8 100644
--- a/docs/note-events_note-on-event.js.html
+++ b/docs/note-events_note-on-event.js.html
@@ -124,7 +124,7 @@ note-events/note-on-event.js
diff --git a/docs/track.js.html b/docs/track.js.html
index c7494f5..582a743 100644
--- a/docs/track.js.html
+++ b/docs/track.js.html
@@ -120,6 +120,12 @@ track.js
event.buildData().events.forEach((e) => this.events.push(e));
}
+ } else if (event instanceof EndTrackEvent) {
+ // Only one EndTrackEvent is allowed, so remove
+ // any existing ones before adding.
+ this.removeEventsByType('end-track');
+ this.events.push(event);
+
} else {
this.events.push(event);
}
@@ -134,9 +140,10 @@ track.js
* @return {Track}
*/
buildData(options = {}) {
- // Remove existing end track event and add one.
- // This makes sure it's at the very end of the event list.
- this.removeEventsByType('end-track').addEvent(new EndTrackEvent());
+ // If the last event isn't EndTrackEvent, then tack it onto the data.
+ if (!this.events.length || !(this.events[this.events.length - 1] instanceof EndTrackEvent)) {
+ this.addEvent(new EndTrackEvent());
+ }
// Reset
this.data = [];
@@ -211,8 +218,14 @@ track.js
* @return {Track}
*/
mergeSingleEvent(event) {
+ // There are no events yet, so just add it in.
+ if (!this.events.length) {
+ this.addEvent(event);
+ return;
+ }
+
// Find index of existing event we need to follow with
- var lastEventIndex = 0;
+ let lastEventIndex;
for (let i = 0; i < this.events.length; i++) {
if (this.events[i].tick > event.tick) break;
@@ -390,7 +403,7 @@ track.js
diff --git a/docs/utils.js.html b/docs/utils.js.html
index 40284b6..c850220 100644
--- a/docs/utils.js.html
+++ b/docs/utils.js.html
@@ -311,7 +311,7 @@ utils.js
diff --git a/docs/vexflow.js.html b/docs/vexflow.js.html
index d3f0a8e..dbe3da6 100644
--- a/docs/vexflow.js.html
+++ b/docs/vexflow.js.html
@@ -147,7 +147,7 @@ vexflow.js
diff --git a/docs/writer.js.html b/docs/writer.js.html
index 867272a..444ac45 100644
--- a/docs/writer.js.html
+++ b/docs/writer.js.html
@@ -135,7 +135,7 @@ writer.js
diff --git a/package.json b/package.json
index 667a81b..783d570 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "midi-writer-js",
- "version": "2.1.3",
+ "version": "2.1.4",
"description": "A library providing an API for generating MIDI files.",
"main": "build/index.js",
"types": "types.d.ts",
diff --git a/src/constants.js b/src/constants.js
index 80ce49c..46d8e42 100644
--- a/src/constants.js
+++ b/src/constants.js
@@ -4,7 +4,7 @@
*/
const Constants = {
- VERSION : '2.1.3',
+ VERSION : '2.1.4',
HEADER_CHUNK_TYPE : [0x4d, 0x54, 0x68, 0x64], // Mthd
HEADER_CHUNK_LENGTH : [0x00, 0x00, 0x00, 0x06], // Header size for SMF
HEADER_CHUNK_FORMAT0 : [0x00, 0x00], // Midi Type 0 id