import {Constants} from '../constants';
-import {NoteOnEvent} from './note-on-event';
+ import {NoteOnEvent} from './note-on-event';
import {NoteOffEvent} from './note-off-event';
import {Utils} from '../utils';
@@ -211,7 +210,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 cf788aa..cd081ec 100644
--- a/docs/note-events_note-off-event.js.html
+++ b/docs/note-events_note-off-event.js.html
@@ -24,7 +24,7 @@
@@ -61,7 +61,6 @@ note-events/note-off-event.js
this.duration = fields.duration;
this.velocity = fields.velocity;
- this.midiNumber = Utils.getPitch(this.pitch);
this.tick = fields.tick;
this.delta = Utils.getTickDuration(this.duration);
this.data = fields.data;
@@ -72,7 +71,7 @@ note-events/note-off-event.js
* @param {Track} track - parent track
* @return {NoteOffEvent}
*/
- buildData(track, precisionDelta) {
+ buildData(track, precisionDelta, options = {}) {
if (this.tick === null) {
this.tick = Utils.getRoundedIfClose(this.delta + track.tickPointer);
}
@@ -82,7 +81,7 @@ note-events/note-off-event.js
this.data = Utils.numberToVariableLength(this.deltaWithPrecisionCorrection)
.concat(
this.getStatusByte(),
- this.midiNumber,
+ Utils.getPitch(this.pitch, options.middleC),
Utils.convertVelocity(this.velocity)
);
@@ -111,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 ab5451f..087c6e9 100644
--- a/docs/note-events_note-on-event.js.html
+++ b/docs/note-events_note-on-event.js.html
@@ -24,7 +24,7 @@
@@ -63,7 +63,6 @@ note-events/note-on-event.js
this.velocity = fields.velocity;
this.startTick = fields.startTick;
- this.midiNumber = Utils.getPitch(this.pitch);
this.tick = null;
this.delta = null;
this.data = fields.data;
@@ -74,7 +73,7 @@ note-events/note-on-event.js
* @param {Track} track - parent track
* @return {NoteOnEvent}
*/
- buildData(track, precisionDelta) {
+ buildData(track, precisionDelta, options = {}) {
this.data = [];
// Explicitly defined startTick event
@@ -96,7 +95,7 @@ note-events/note-on-event.js
this.data = Utils.numberToVariableLength(this.deltaWithPrecisionCorrection)
.concat(
this.getStatusByte(),
- this.midiNumber,
+ Utils.getPitch(this.pitch, options.middleC),
Utils.convertVelocity(this.velocity)
);
@@ -125,7 +124,7 @@ note-events/note-on-event.js
diff --git a/docs/track.js.html b/docs/track.js.html
index 3e19d52..d3ced0e 100644
--- a/docs/track.js.html
+++ b/docs/track.js.html
@@ -24,7 +24,7 @@
@@ -130,9 +130,10 @@ track.js
/**
* Builds int array of all events.
+ * @param {object} options
* @return {Track}
*/
- buildData() {
+ 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());
@@ -147,10 +148,15 @@ track.js
this.events.forEach((event, eventIndex) => {
// Build event & add to total tick duration
if (event instanceof NoteOnEvent || event instanceof NoteOffEvent) {
- const built = event.buildData(this, precisionLoss);
+ const built = event.buildData(this, precisionLoss, options);
precisionLoss = Utils.getPrecisionLoss(event.deltaWithPrecisionCorrection || 0);
this.data = this.data.concat(built.data);
this.tickPointer = Utils.getRoundedIfClose(event.tick);
+
+ } else if (event instanceof TempoEvent) {
+ this.tickPointer = Utils.getRoundedIfClose(event.tick);
+ this.data = this.data.concat(event.data);
+
} else {
this.data = this.data.concat(event.data);
}
@@ -247,10 +253,11 @@ track.js
/**
* Sets tempo of the MIDI file.
* @param {number} bpm - Tempo in beats per minute.
+ * @param {number} tick - Start tick.
* @return {Track}
*/
- setTempo(bpm) {
- return this.addEvent(new TempoEvent(bpm));
+ setTempo(bpm, tick = 0) {
+ return this.addEvent(new TempoEvent({bpm, tick}));
}
/**
@@ -281,7 +288,7 @@ track.js
* @return {Track}
*/
addText(text) {
- return this.addEvent(new TextEvent(text));
+ return this.addEvent(new TextEvent({text}));
}
/**
@@ -290,7 +297,7 @@ track.js
* @return {Track}
*/
addCopyright(text) {
- return this.addEvent(new CopyrightEvent(text));
+ return this.addEvent(new CopyrightEvent({text}));
}
/**
@@ -299,7 +306,7 @@ track.js
* @return {Track}
*/
addTrackName(text) {
- return this.addEvent(new TrackNameEvent(text));
+ return this.addEvent(new TrackNameEvent({text}));
}
/**
@@ -308,7 +315,7 @@ track.js
* @return {Track}
*/
addInstrumentName(text) {
- return this.addEvent(new InstrumentNameEvent(text));
+ return this.addEvent(new InstrumentNameEvent({text}));
}
/**
@@ -317,7 +324,7 @@ track.js
* @return {Track}
*/
addMarker(text) {
- return this.addEvent(new MarkerEvent(text));
+ return this.addEvent(new MarkerEvent({text}));
}
/**
@@ -326,7 +333,7 @@ track.js
* @return {Track}
*/
addCuePoint(text) {
- return this.addEvent(new CuePointEvent(text));
+ return this.addEvent(new CuePointEvent({text}));
}
/**
@@ -335,7 +342,7 @@ track.js
* @return {Track}
*/
addLyric(text) {
- return this.addEvent(new LyricEvent(text));
+ return this.addEvent(new LyricEvent({text}));
}
/**
@@ -383,7 +390,7 @@ track.js
diff --git a/docs/utils.js.html b/docs/utils.js.html
index a3bd377..e1495d4 100644
--- a/docs/utils.js.html
+++ b/docs/utils.js.html
@@ -24,7 +24,7 @@
@@ -77,10 +77,11 @@ utils.js
* Returns the correct MIDI number for the specified pitch.
* Uses Tonal Midi - https://github.com/danigb/tonal/tree/master/packages/midi
* @param {(string|number)} pitch - 'C#4' or midi note code
+ * @param {string} middleC
* @return {number}
*/
- static getPitch(pitch) {
- return toMidi(pitch);
+ static getPitch(pitch, middleC = 'C4') {
+ return 60 - toMidi(middleC) + toMidi(pitch);
}
/**
@@ -303,7 +304,7 @@ utils.js
diff --git a/docs/vexflow.js.html b/docs/vexflow.js.html
index d934f8d..8d21995 100644
--- a/docs/vexflow.js.html
+++ b/docs/vexflow.js.html
@@ -24,7 +24,7 @@
@@ -148,7 +148,7 @@ vexflow.js
diff --git a/docs/writer.js.html b/docs/writer.js.html
index 508eb91..6e92f52 100644
--- a/docs/writer.js.html
+++ b/docs/writer.js.html
@@ -24,7 +24,7 @@
@@ -45,20 +45,30 @@ writer.js
/**
* Object that puts together tracks and provides methods for file output.
* @param {array|Track} tracks - A single {Track} object or an array of {Track} objects.
+ * @param {object} options - {middleC: 'C4'}
* @return {Writer}
*/
class Writer {
- constructor(tracks) {
- // Ensure track is an array
- tracks = Utils.toArray(tracks);
+ constructor(tracks, options = {}) {
+ // Ensure tracks is an array
+ this.tracks = Utils.toArray(tracks);
+ this.options = options;
+ }
- this.data = [];
- this.data.push(new HeaderChunk(tracks.length))
+ /**
+ * Builds array of data from chunkschunks.
+ * @return {array}
+ */
+ buildData() {
+ const data = [];
+ data.push(new HeaderChunk(this.tracks.length))
// For each track add final end of track event and build data
- tracks.forEach((track, i) => {
- this.data.push(track.buildData());
+ this.tracks.forEach((track, i) => {
+ data.push(track.buildData(this.options));
});
+
+ return data;
}
/**
@@ -69,7 +79,7 @@ writer.js
var build = [];
// Data consists of chunks which consists of data
- this.data.forEach((d) => build = build.concat(d.type, d.size, d.data));
+ this.buildData().forEach((d) => build = build.concat(d.type, d.size, d.data));
return new Uint8Array(build);
}
@@ -91,12 +101,24 @@ writer.js
return 'data:audio/midi;base64,' + this.base64();
}
+
+ /**
+ * Set option on instantiated Writer.
+ * @param {string} key
+ * @param {any} value
+ * @return {Writer}
+ */
+ setOption(key, value) {
+ this.options[key] = value;
+ return this;
+ }
+
/**
* Output to stdout
* @return {string}
*/
stdout() {
- return process.stdout.write(new Buffer(this.buildFile()));
+ return process.stdout.write(Buffer.from(this.buildFile()));
}
}
@@ -113,7 +135,7 @@ writer.js
Parameters:
Returns:
diff --git a/docs/CopyrightEvent.html b/docs/CopyrightEvent.html index 0a805f8..535a1bb 100644 --- a/docs/CopyrightEvent.html +++ b/docs/CopyrightEvent.html @@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new CopyrightEvent(text) → {CopyrightEvent}
+ new CopyrightEvent(fields) → {CopyrightEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Copyright text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/CuePointEvent.html b/docs/CuePointEvent.html
index 6287e79..a7ad534 100644
--- a/docs/CuePointEvent.html
+++ b/docs/CuePointEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new CuePointEvent(text) → {CuePointEvent}
+ new CuePointEvent(fields) → {CuePointEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Cue point text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/EndTrackEvent.html b/docs/EndTrackEvent.html
index df1d61a..9827ead 100644
--- a/docs/EndTrackEvent.html
+++ b/docs/EndTrackEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new EndTrackEvent() → {EndTrackEvent}
+ new EndTrackEvent(fields) → {EndTrackEvent}
@@ -99,7 +99,7 @@ new EndT
Source:
@@ -118,6 +118,58 @@ new EndT
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ fields
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {delta: integer}
+
+
+
+
+
+
+
+
+
@@ -186,7 +238,7 @@ Returns:
diff --git a/docs/HeaderChunk.html b/docs/HeaderChunk.html
index 7174956..344c838 100644
--- a/docs/HeaderChunk.html
+++ b/docs/HeaderChunk.html
@@ -24,7 +24,7 @@
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/InstrumentNameEvent.html b/docs/InstrumentNameEvent.html
index 5178c5c..03e6168 100644
--- a/docs/InstrumentNameEvent.html
+++ b/docs/InstrumentNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new InstrumentNameEvent(bpm) → {InstrumentNameEvent}
+ new InstrumentNameEvent(fields) → {InstrumentNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/KeySignatureEvent.html b/docs/KeySignatureEvent.html
index 3f6b19d..d2beab4 100644
--- a/docs/KeySignatureEvent.html
+++ b/docs/KeySignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/LyricEvent.html b/docs/LyricEvent.html
index 1920945..6b713e7 100644
--- a/docs/LyricEvent.html
+++ b/docs/LyricEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new LyricEvent(text) → {LyricEvent}
+ new LyricEvent(fields) → {LyricEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Lyric text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/MarkerEvent.html b/docs/MarkerEvent.html
index 8761367..fb4f36c 100644
--- a/docs/MarkerEvent.html
+++ b/docs/MarkerEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new MarkerEvent(text) → {MarkerEvent}
+ new MarkerEvent(fields) → {MarkerEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Marker text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/NoteEvent.html b/docs/NoteEvent.html
index 4433e6b..468590f 100644
--- a/docs/NoteEvent.html
+++ b/docs/NoteEvent.html
@@ -24,7 +24,7 @@
@@ -99,7 +99,7 @@ new NoteEven
Source:
@@ -273,7 +273,7 @@ buildDataSource:
@@ -346,7 +346,7 @@ Returns:
diff --git a/docs/NoteOffEvent.html b/docs/NoteOffEvent.html
index f4375a7..27247ac 100644
--- a/docs/NoteOffEvent.html
+++ b/docs/NoteOffEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
text
fields
string
+object
@@ -160,7 +160,7 @@ Parameters:
Constructor
- new CuePointEvent(text) → {CuePointEvent}
+ new CuePointEvent(fields) → {CuePointEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Cue point text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/EndTrackEvent.html b/docs/EndTrackEvent.html
index df1d61a..9827ead 100644
--- a/docs/EndTrackEvent.html
+++ b/docs/EndTrackEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new EndTrackEvent() → {EndTrackEvent}
+ new EndTrackEvent(fields) → {EndTrackEvent}
@@ -99,7 +99,7 @@ new EndT
Source:
@@ -118,6 +118,58 @@ new EndT
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ fields
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {delta: integer}
+
+
+
+
+
+
+
+
+
@@ -186,7 +238,7 @@ Returns:
diff --git a/docs/HeaderChunk.html b/docs/HeaderChunk.html
index 7174956..344c838 100644
--- a/docs/HeaderChunk.html
+++ b/docs/HeaderChunk.html
@@ -24,7 +24,7 @@
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/InstrumentNameEvent.html b/docs/InstrumentNameEvent.html
index 5178c5c..03e6168 100644
--- a/docs/InstrumentNameEvent.html
+++ b/docs/InstrumentNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new InstrumentNameEvent(bpm) → {InstrumentNameEvent}
+ new InstrumentNameEvent(fields) → {InstrumentNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/KeySignatureEvent.html b/docs/KeySignatureEvent.html
index 3f6b19d..d2beab4 100644
--- a/docs/KeySignatureEvent.html
+++ b/docs/KeySignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/LyricEvent.html b/docs/LyricEvent.html
index 1920945..6b713e7 100644
--- a/docs/LyricEvent.html
+++ b/docs/LyricEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new LyricEvent(text) → {LyricEvent}
+ new LyricEvent(fields) → {LyricEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Lyric text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/MarkerEvent.html b/docs/MarkerEvent.html
index 8761367..fb4f36c 100644
--- a/docs/MarkerEvent.html
+++ b/docs/MarkerEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new MarkerEvent(text) → {MarkerEvent}
+ new MarkerEvent(fields) → {MarkerEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Marker text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/NoteEvent.html b/docs/NoteEvent.html
index 4433e6b..468590f 100644
--- a/docs/NoteEvent.html
+++ b/docs/NoteEvent.html
@@ -24,7 +24,7 @@
@@ -99,7 +99,7 @@ new NoteEven
Source:
@@ -273,7 +273,7 @@ buildDataSource:
@@ -346,7 +346,7 @@ Returns:
diff --git a/docs/NoteOffEvent.html b/docs/NoteOffEvent.html
index f4375a7..27247ac 100644
--- a/docs/NoteOffEvent.html
+++ b/docs/NoteOffEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
text
fields
string
+object
@@ -160,7 +160,7 @@ Parameters:
Constructor
- new EndTrackEvent() → {EndTrackEvent}
+ new EndTrackEvent(fields) → {EndTrackEvent}
@@ -99,7 +99,7 @@ new EndT
Source:
@@ -118,6 +118,58 @@ new EndT
+ Parameters:
+
+
+
new EndT
+ Parameters:
+
+
+
Name | + + +Type | + + + + + +Description | +
---|---|---|
fields |
+
+
+
+
+
+object
+
+
+
+ |
+
+
+
+
+
+ + {delta: integer} + + | +
Returns:
diff --git a/docs/HeaderChunk.html b/docs/HeaderChunk.html index 7174956..344c838 100644 --- a/docs/HeaderChunk.html +++ b/docs/HeaderChunk.html @@ -24,7 +24,7 @@
@@ -238,7 +238,7 @@
diff --git a/docs/InstrumentNameEvent.html b/docs/InstrumentNameEvent.html index 5178c5c..03e6168 100644 --- a/docs/InstrumentNameEvent.html +++ b/docs/InstrumentNameEvent.html @@ -24,7 +24,7 @@
Returns:
diff --git a/docs/InstrumentNameEvent.html b/docs/InstrumentNameEvent.html index 5178c5c..03e6168 100644 --- a/docs/InstrumentNameEvent.html +++ b/docs/InstrumentNameEvent.html @@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new InstrumentNameEvent(bpm) → {InstrumentNameEvent}
+ new InstrumentNameEvent(fields) → {InstrumentNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/KeySignatureEvent.html b/docs/KeySignatureEvent.html
index 3f6b19d..d2beab4 100644
--- a/docs/KeySignatureEvent.html
+++ b/docs/KeySignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/LyricEvent.html b/docs/LyricEvent.html
index 1920945..6b713e7 100644
--- a/docs/LyricEvent.html
+++ b/docs/LyricEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new LyricEvent(text) → {LyricEvent}
+ new LyricEvent(fields) → {LyricEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Lyric text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/MarkerEvent.html b/docs/MarkerEvent.html
index 8761367..fb4f36c 100644
--- a/docs/MarkerEvent.html
+++ b/docs/MarkerEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new MarkerEvent(text) → {MarkerEvent}
+ new MarkerEvent(fields) → {MarkerEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Marker text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/NoteEvent.html b/docs/NoteEvent.html
index 4433e6b..468590f 100644
--- a/docs/NoteEvent.html
+++ b/docs/NoteEvent.html
@@ -24,7 +24,7 @@
@@ -99,7 +99,7 @@ new NoteEven
Source:
@@ -273,7 +273,7 @@ buildDataSource:
@@ -346,7 +346,7 @@ Returns:
diff --git a/docs/NoteOffEvent.html b/docs/NoteOffEvent.html
index f4375a7..27247ac 100644
--- a/docs/NoteOffEvent.html
+++ b/docs/NoteOffEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
bpm
fields
number
+object
@@ -160,7 +160,7 @@ Parameters:
Returns:
diff --git a/docs/LyricEvent.html b/docs/LyricEvent.html index 1920945..6b713e7 100644 --- a/docs/LyricEvent.html +++ b/docs/LyricEvent.html @@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new LyricEvent(text) → {LyricEvent}
+ new LyricEvent(fields) → {LyricEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Lyric text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/MarkerEvent.html b/docs/MarkerEvent.html
index 8761367..fb4f36c 100644
--- a/docs/MarkerEvent.html
+++ b/docs/MarkerEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new MarkerEvent(text) → {MarkerEvent}
+ new MarkerEvent(fields) → {MarkerEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Marker text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/NoteEvent.html b/docs/NoteEvent.html
index 4433e6b..468590f 100644
--- a/docs/NoteEvent.html
+++ b/docs/NoteEvent.html
@@ -24,7 +24,7 @@
@@ -99,7 +99,7 @@ new NoteEven
Source:
@@ -273,7 +273,7 @@ buildDataSource:
@@ -346,7 +346,7 @@ Returns:
diff --git a/docs/NoteOffEvent.html b/docs/NoteOffEvent.html
index f4375a7..27247ac 100644
--- a/docs/NoteOffEvent.html
+++ b/docs/NoteOffEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
text
fields
string
+object
@@ -160,7 +160,7 @@ Parameters:
Constructor
- new MarkerEvent(text) → {MarkerEvent}
+ new MarkerEvent(fields) → {MarkerEvent}
@@ -143,13 +143,13 @@ Parameters:
- text
+ fields
-string
+object
@@ -160,7 +160,7 @@ Parameters:
- Marker text
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/NoteEvent.html b/docs/NoteEvent.html
index 4433e6b..468590f 100644
--- a/docs/NoteEvent.html
+++ b/docs/NoteEvent.html
@@ -24,7 +24,7 @@
@@ -99,7 +99,7 @@ new NoteEven
Source:
@@ -273,7 +273,7 @@ buildDataSource:
@@ -346,7 +346,7 @@ Returns:
diff --git a/docs/NoteOffEvent.html b/docs/NoteOffEvent.html
index f4375a7..27247ac 100644
--- a/docs/NoteOffEvent.html
+++ b/docs/NoteOffEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
text
fields
string
+object
@@ -160,7 +160,7 @@ Parameters:
new NoteEven
Source:
@@ -273,7 +273,7 @@ buildDataSource:
@@ -346,7 +346,7 @@ Returns:
diff --git a/docs/NoteOffEvent.html b/docs/NoteOffEvent.html
index f4375a7..27247ac 100644
--- a/docs/NoteOffEvent.html
+++ b/docs/NoteOffEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
Returns:
diff --git a/docs/NoteOffEvent.html b/docs/NoteOffEvent.html index f4375a7..27247ac 100644 --- a/docs/NoteOffEvent.html +++ b/docs/NoteOffEvent.html @@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildData
buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/NoteOnEvent.html b/docs/NoteOnEvent.html
index 9e78288..d3d89e0 100644
--- a/docs/NoteOnEvent.html
+++ b/docs/NoteOnEvent.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
buildDataSource:
@@ -431,7 +431,7 @@ getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
getStatu
Source:
@@ -504,7 +504,7 @@ Returns:
diff --git a/docs/ProgramChangeEvent.html b/docs/ProgramChangeEvent.html
index dd6763c..1c41ffa 100644
--- a/docs/ProgramChangeEvent.html
+++ b/docs/ProgramChangeEvent.html
@@ -24,7 +24,7 @@
@@ -160,7 +160,7 @@ Parameters:
- {instrument: integer}
+ {instrument: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html
index a89f0e4..c17cffb 100644
--- a/docs/TempoEvent.html
+++ b/docs/TempoEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
Parameters:
Returns:
diff --git a/docs/TempoEvent.html b/docs/TempoEvent.html index a89f0e4..c17cffb 100644 --- a/docs/TempoEvent.html +++ b/docs/TempoEvent.html @@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TempoEvent(bpm) → {TempoEvent}
+ new TempoEvent(fields) → {TempoEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {bpm: integer, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TextEvent.html b/docs/TextEvent.html
index 7e352c6..66d840c 100644
--- a/docs/TextEvent.html
+++ b/docs/TextEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
bpm
fields
number
+object
@@ -160,7 +160,7 @@ Parameters:
Constructor
- new TextEvent(bpm) → {TextEvent}
+ new TextEvent(fields) → {TextEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/TimeSignatureEvent.html b/docs/TimeSignatureEvent.html
index 9bf2112..76d8a28 100644
--- a/docs/TimeSignatureEvent.html
+++ b/docs/TimeSignatureEvent.html
@@ -24,7 +24,7 @@
@@ -186,7 +186,7 @@ Returns:
diff --git a/docs/Track.html b/docs/Track.html
index 4467c13..db9ec6e 100644
--- a/docs/Track.html
+++ b/docs/Track.html
@@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
bpm
fields
number
+object
@@ -160,7 +160,7 @@ Parameters:
Returns:
diff --git a/docs/Track.html b/docs/Track.html index 4467c13..db9ec6e 100644 --- a/docs/Track.html +++ b/docs/Track.html @@ -24,7 +24,7 @@
@@ -273,7 +273,7 @@ addCopyri
addCopyri
Source:
@@ -429,7 +429,7 @@ addCuePoin
Source:
@@ -772,7 +772,7 @@ addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
addI
Source:
@@ -928,7 +928,7 @@ addLyricSource:
@@ -1084,7 +1084,7 @@ addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
addMarkerSource:
@@ -1240,7 +1240,7 @@ addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
addTextSource:
@@ -1396,7 +1396,7 @@ addTrackN
Source:
@@ -1509,7 +1509,7 @@ Returns:
- buildData() → {Track}
+ buildData(options) → {Track}
@@ -1552,7 +1552,7 @@ buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
Returns:
-buildData() → {Track}
+buildData(options) → {Track}
@@ -1552,7 +1552,7 @@buildDataSource:
@@ -1571,6 +1571,58 @@ buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
buildDataParameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1656,7 +1708,7 @@ contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
Name | + + +Type | + + + + + +Description | +
---|---|---|
options |
+
+
+
+
+
+object
+
+
+
+ |
+
+
+
+
+
+ + + + | +
contr
Source:
@@ -1838,7 +1890,7 @@ merge
Source:
@@ -1997,7 +2049,7 @@ mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
mergeTrack<
Source:
@@ -2153,7 +2205,7 @@ polyModeOn<
Source:
@@ -2257,7 +2309,7 @@ rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
rem
Source:
@@ -2413,7 +2465,7 @@ setKey
Source:
@@ -2595,7 +2647,7 @@ setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
setPitchB
Source:
@@ -2708,7 +2760,7 @@ Returns:
- setTempo(bpm) → {Track}
+ setTempo(bpm, tick) → {Track}
@@ -2751,7 +2803,7 @@ setTempoSource:
@@ -2785,6 +2837,8 @@ Parameters:
+ Default
+
Description
@@ -2810,6 +2864,10 @@ Parameters:
+
+
+
+
Tempo in beats per minute.
@@ -2818,6 +2876,38 @@ Parameters:
+
+
+
+ tick
+
+
+
+
+
+number
+
+
+
+
+
+
+
+
+
+
+ 0
+
+
+
+
+
+ Start tick.
+
+
+
+
+
@@ -2907,7 +2997,7 @@ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
Parameters:
+Parameters:
+Parameters:
+ +tick
number
+
+
+
+ setTi
Source:
@@ -3110,7 +3200,7 @@ Returns:
diff --git a/docs/TrackNameEvent.html b/docs/TrackNameEvent.html
index 206fac0..748b2c4 100644
--- a/docs/TrackNameEvent.html
+++ b/docs/TrackNameEvent.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
Constructor
- new TrackNameEvent(bpm) → {TrackNameEvent}
+ new TrackNameEvent(fields) → {TrackNameEvent}
@@ -143,13 +143,13 @@ Parameters:
- bpm
+ fields
-number
+object
@@ -160,7 +160,7 @@ Parameters:
- Beats per minute
+ {text: string, delta: integer}
@@ -238,7 +238,7 @@ Returns:
diff --git a/docs/Utils.html b/docs/Utils.html
index 0d2b9b4..75a39e9 100644
--- a/docs/Utils.html
+++ b/docs/Utils.html
@@ -24,7 +24,7 @@
@@ -200,7 +200,7 @@ (static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
+
+
+
+
+
+
+ setOption(key, value) → {Writer}
+
+
+
+
+
+
+ Set option on instantiated Writer.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Parameters:
+
+
+
+
+
+
+ Name
+
+
+ Type
+
+
+
+
+
+ Description
+
+
+
+
+
+
+
+
+ key
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ value
+
+
+
+
+
+any
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
Writer
+
+
+
+
+
+
+
+
+
+
+
@@ -588,7 +900,7 @@ stdoutSource:
@@ -661,7 +973,7 @@ Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html
index cbe55f4..1b83cf2 100644
--- a/docs/constants.js.html
+++ b/docs/constants.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ constants.js
*/
const Constants = {
- VERSION : require('../package.json').version,
+ VERSION : '2.1.0',
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
@@ -83,7 +83,7 @@ constants.js
diff --git a/docs/global.html b/docs/global.html
index 03dcaf8..94ada02 100644
--- a/docs/global.html
+++ b/docs/global.html
@@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@ Parameters:
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@ Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html
index 0319951..627f0cd 100644
--- a/docs/header-chunk.js.html
+++ b/docs/header-chunk.js.html
@@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@ header-chunk.js
diff --git a/docs/index.html b/docs/index.html
index b655d66..bf07d35 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@ Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-
bpm
fields
number
+object
@@ -160,7 +160,7 @@ Parameters:
(static) Source:
@@ -357,7 +357,7 @@ (stati
Source:
@@ -470,7 +470,7 @@ Returns:
- (static) getPitch(pitch) → {number}
+ (static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@ (static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
Returns:
-(static) getPitch(pitch) → {number}
+(static) getPitch(pitch, middleC) → {number}
@@ -514,7 +514,7 @@(static) get
Source:
@@ -548,6 +548,8 @@ Parameters:
+ Default
+
Description
@@ -576,6 +578,10 @@ Parameters:
+
+
+
+
'C#4' or midi note code
@@ -584,6 +590,38 @@ Parameters:
+
+
+
+ middleC
+
+
+
+
+
+string
+
+
+
+
+
+
+
+
+
+
+ C4
+
+
+
+
+
+
+
+
+
+
+
@@ -675,7 +713,7 @@ (static)
Source:
@@ -832,7 +870,7 @@ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
Parameters:
+ +middleC
string
+
+
+
+ (static) <
Source:
@@ -989,7 +1027,7 @@ (static) Source:
@@ -1304,7 +1342,7 @@ (static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
(static) Source:
@@ -1460,7 +1498,7 @@ (static) Source:
@@ -1649,7 +1687,7 @@ (stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
(stat
Source:
@@ -1809,7 +1847,7 @@ (static) Source:
@@ -2121,7 +2159,7 @@ (static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
(static) toAr
Source:
@@ -2350,7 +2388,7 @@ Returns:
diff --git a/docs/Writer.html b/docs/Writer.html
index 567eb5e..c3277de 100644
--- a/docs/Writer.html
+++ b/docs/Writer.html
@@ -24,7 +24,7 @@
@@ -60,7 +60,7 @@
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
+
+
+
+
+
+
+ buildData() → {array}
+
+
+
+
+
+
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ - Source:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Returns:
+
+
+
+
+ -
+ Type:
+
+ -
+
+
array
+
+
+
+
+
+
+
+
+
+
+
@@ -380,7 +510,7 @@ buildFileSource:
@@ -484,7 +614,7 @@ dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
Constructor
- new Writer(tracks) → {Writer}
+ new Writer(tracks, options) → {Writer}
@@ -99,7 +99,7 @@ new WriterSource:
@@ -169,6 +169,32 @@ Parameters:
+
+
+
+ options
+
+
+
+
+
+object
+
+
+
+
+
+
+
+
+
+
+ {middleC: 'C4'}
+
+
+
+
+
@@ -276,7 +302,7 @@ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
Parameters:
+ +options
object
+
+
+
+ base64Source:
@@ -330,6 +356,110 @@ Returns:
+
buildData() → {array}
+ + + + + +
+ Builds array of data from chunkschunks.
+
+
+
+
+
+
+-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
- + + + + + + + +
+
+
+
+
Returns:
+ + + +-
+
- + Type: + +
-
+
+
array
+ + +
+
dataUriSource:
@@ -538,6 +668,188 @@ Returns:
+
setOption(key, value) → {Writer}
+ + + + + +
+ Set option on instantiated Writer.
+
+
+
+
+
+
+-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
- Source: +
- + + + + + + + +
Parameters:
+ + +Name | + + +Type | + + + + + +Description | +
---|---|---|
key |
+
+
+
+
+
+string
+
+
+
+ |
+
+
+
+
+
+ + + + | +
value |
+
+
+
+
+
+any
+
+
+
+ |
+
+
+
+
+
+ + + + | +
+
+
+
+
Returns:
+ + + +-
+
- + Type: + +
-
+
+
Writer
+ + +
+
Returns:
diff --git a/docs/constants.js.html b/docs/constants.js.html index cbe55f4..1b83cf2 100644 --- a/docs/constants.js.html +++ b/docs/constants.js.html @@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@
diff --git a/docs/global.html b/docs/global.html index 03dcaf8..94ada02 100644 --- a/docs/global.html +++ b/docs/global.html @@ -24,7 +24,7 @@
constants.js
*/ const Constants = { - VERSION : require('../package.json').version, + VERSION : '2.1.0', 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 @@ -83,7 +83,7 @@constants.js
diff --git a/docs/global.html b/docs/global.html index 03dcaf8..94ada02 100644 --- a/docs/global.html +++ b/docs/global.html @@ -24,7 +24,7 @@
@@ -290,7 +290,7 @@
- { bend : float, channel : int }
+ { bend : float, channel : int, delta: int }
@@ -354,7 +354,7 @@
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html index 0319951..627f0cd 100644 --- a/docs/header-chunk.js.html +++ b/docs/header-chunk.js.html @@ -24,7 +24,7 @@
Parameters:
Returns:
diff --git a/docs/header-chunk.js.html b/docs/header-chunk.js.html index 0319951..627f0cd 100644 --- a/docs/header-chunk.js.html +++ b/docs/header-chunk.js.html @@ -24,7 +24,7 @@
@@ -75,7 +75,7 @@
diff --git a/docs/index.html b/docs/index.html index b655d66..bf07d35 100644 --- a/docs/index.html +++ b/docs/index.html @@ -24,7 +24,7 @@
header-chunk.js
diff --git a/docs/index.html b/docs/index.html index b655d66..bf07d35 100644 --- a/docs/index.html +++ b/docs/index.html @@ -24,7 +24,7 @@
@@ -59,20 +59,20 @@
Install
npm install midi-writer-js
Getting Started
-var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
// Start with a new track
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
// Define an instrument (optional):
track.addEvent(new MidiWriter.ProgramChangeEvent({instrument: 1}));
// Add some notes:
-var note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
+const note = new MidiWriter.NoteEvent({pitch: ['C4', 'D4', 'E4'], duration: '4'});
track.addEvent(note);
// Generate a data URI
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
Documentation
@@ -96,6 +96,7 @@ MidiWriter.NoteEvent({options})
Name
Type
+ Default
Description
@@ -103,11 +104,13 @@ MidiWriter.NoteEvent({options})
pitch
string or array
+
Each pitch can be a string or valid MIDI note code. Format for string is C#4
. Pro tip: You can use the output from tonal functions to build scales, chords, intervals, etc. in this parameter.
duration
string or array
+
How long the note should sound.
@@ -135,36 +138,43 @@ MidiWriter.NoteEvent({options})
wait
string or array
+ 0
How long to wait before sounding note (rest). Takes same values as duration.
sequential
boolean
- If true then array of pitches will be played sequentially as opposed to simulatanously. Default: false
+ false
+ If true then array of pitches will be played sequentially as opposed to simulatanously.
velocity
number
- How loud the note should sound, values 1-100. Default: 50
+ 50
+ How loud the note should sound, values 1-100.
repeat
number
- How many times this event should be repeated. Default: 1
+ 1
+ How many times this event should be repeated.
channel
number
- MIDI channel to use. Default: 1
+ 1
+ MIDI channel to use.
grace
string or array
+
Grace note to be applied to note event. Takes same value format as pitch
startTick
number
+
Specific tick where this event should be played. If this parameter is supplied then wait
is disregarded if also supplied.
@@ -180,9 +190,9 @@ 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'.
-
var MidiWriter = require('midi-writer-js');
+const MidiWriter = require('midi-writer-js');
-var track = new MidiWriter.Track();
+const track = new MidiWriter.Track();
track.addEvent([
new MidiWriter.NoteEvent({pitch: ['E4','D4'], duration: '4'}),
@@ -197,18 +207,18 @@ Hot Cross Buns
}
);
-var write = new MidiWriter.Writer(track);
+const write = new MidiWriter.Writer(track);
console.log(write.dataUri());
VexFlow Integration
MidiWriterJS can export MIDI from VexFlow voices, though this feature is still experimental. Current usage is to use MidiWriter.VexFlow.trackFromVoice(voice)
to create a MidiWriterJS Track
object:
// ...VexFlow code defining notes
-var voice = create_4_4_voice().addTickables(notes);
+const voice = create_4_4_voice().addTickables(notes);
-var vexWriter = new MidiWriter.VexFlow();
-var track = vexWriter.trackFromVoice(voice);
-var writer = new MidiWriter.Writer([track]);
+const vexWriter = new MidiWriter.VexFlow();
+const track = vexWriter.trackFromVoice(voice);
+const writer = new MidiWriter.Writer([track]);
console.log(writer.dataUri());
@@ -223,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 1729e5a..3ffface 100644
--- a/docs/meta-events_controller-change-event.js.html
+++ b/docs/meta-events_controller-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/controller-change-event.js
/**
* Holds all data for a "controller change" MIDI event
- * @param {object} fields {controllerNumber: integer, controllerValue: integer}
+ * @param {object} fields {controllerNumber: integer, controllerValue: integer, delta: integer}
* @return {ControllerChangeEvent}
*/
class ControllerChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'controller';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.CONTROLLER_CHANGE_STATUS, fields.controllerNumber, fields.controllerValue);
}
}
@@ -68,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 9020f36..cae0435 100644
--- a/docs/meta-events_copyright-event.js.html
+++ b/docs/meta-events_copyright-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/copyright-event.js
/**
* Object representation of a tempo meta event.
- * @param {string} text - Copyright text
+ * @param {object} fields {text: string, delta: integer}
* @return {CopyrightEvent}
*/
class CopyrightEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'copyright';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_COPYRIGHT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 2b2e855..c1f6624 100644
--- a/docs/meta-events_cue-point-event.js.html
+++ b/docs/meta-events_cue-point-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/cue-point-event.js
/**
* Object representation of a cue point meta event.
- * @param {string} text - Cue point text
+ * @param {object} fields {text: string, delta: integer}
* @return {CuePointEvent}
*/
class CuePointEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'cue-point';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_CUE_POINT,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47fd38..46a2c61 100644
--- a/docs/meta-events_end-track-event.js.html
+++ b/docs/meta-events_end-track-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,20 @@ meta-events/end-track-event.js
/**
* Object representation of a end track meta event.
+ * @param {object} fields {delta: integer}
* @return {EndTrackEvent}
*/
class EndTrackEvent {
- constructor() {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'end-track';
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_END_OF_TRACK_ID
);
@@ -71,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 ab03e50..13a5191 100644
--- a/docs/meta-events_instrument-name-event.js.html
+++ b/docs/meta-events_instrument-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/instrument-name-event.js
/**
* Object representation of an instrument name meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {InstrumentNameEvent}
*/
class InstrumentNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'instrument-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_INSTRUMENT_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 0c4b766..f7b2586 100644
--- a/docs/meta-events_key-signature-event.js.html
+++ b/docs/meta-events_key-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 3c4cbfc..24e8070 100644
--- a/docs/meta-events_lyric-event.js.html
+++ b/docs/meta-events_lyric-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/lyric-event.js
/**
* Object representation of a lyric meta event.
- * @param {string} text - Lyric text
+ * @param {object} fields {text: string, delta: integer}
* @return {LyricEvent}
*/
class LyricEvent {
- constructor(text) {
- this.type = 'marker';
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
- const textBytes = Utils.stringToBytes(text);
+ this.type = 'lyric';
+
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_LYRIC_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d47a2ef..89e48a8 100644
--- a/docs/meta-events_marker-event.js.html
+++ b/docs/meta-events_marker-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/marker-event.js
/**
* Object representation of a marker meta event.
- * @param {string} text - Marker text
+ * @param {object} fields {text: string, delta: integer}
* @return {MarkerEvent}
*/
class MarkerEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'marker';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_MARKER_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 d0d006f..0c76684 100644
--- a/docs/meta-events_pitch-bend-event.js.html
+++ b/docs/meta-events_pitch-bend-event.js.html
@@ -24,7 +24,7 @@
@@ -45,7 +45,7 @@ meta-events/pitch-bend-event.js
/**
* Holds all data for a "Pitch Bend" MIDI event
* [ -1.0, 0, 1.0 ] -> [ 0, 8192, 16383]
- * @param {object} fields { bend : float, channel : int }
+ * @param {object} fields { bend : float, channel : int, delta: int }
* @return {PitchBendEvent}
*/
const scale14bits = (zeroOne) => {
@@ -58,6 +58,11 @@ meta-events/pitch-bend-event.js
class PitchBendEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'pitch-bend';
let bend14 = scale14bits(fields.bend);
@@ -65,7 +70,7 @@ meta-events/pitch-bend-event.js
let lsbValue = bend14 & 0x7f;
let msbValue = ( bend14 >> 7 ) & 0x7f;
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PITCH_BEND_STATUS | channel, lsbValue, msbValue);
}
}
@@ -82,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 1c15e89..8c40587 100644
--- a/docs/meta-events_program-change-event.js.html
+++ b/docs/meta-events_program-change-event.js.html
@@ -24,7 +24,7 @@
@@ -44,14 +44,19 @@ meta-events/program-change-event.js
/**
* Holds all data for a "program change" MIDI event
- * @param {object} fields {instrument: integer}
+ * @param {object} fields {instrument: integer, delta: integer}
* @return {ProgramChangeEvent}
*/
class ProgramChangeEvent {
constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'program';
// delta time defaults to 0.
- this.data = Utils.numberToVariableLength(0x00).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
+ this.data = Utils.numberToVariableLength(fields.delta).concat(Constants.PROGRAM_CHANGE_STATUS, fields.instrument);
}
}
@@ -68,7 +73,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 15db55b..4929234 100644
--- a/docs/meta-events_tempo-event.js.html
+++ b/docs/meta-events_tempo-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,24 @@ meta-events/tempo-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {bpm: integer, delta: integer}
* @return {TempoEvent}
*/
class TempoEvent {
- constructor(bpm) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'tempo';
- const tempo = Math.round(60000000 / bpm);
+ this.tick = fields.tick;
+
+ const tempo = Math.round(60000000 / fields.bpm);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEMPO_ID,
[0x03], // Size
@@ -76,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 966bf42..d990200 100644
--- a/docs/meta-events_text-event.js.html
+++ b/docs/meta-events_text-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/text-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TextEvent}
*/
class TextEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'text';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TEXT_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 b29087f..e1eabc1 100644
--- a/docs/meta-events_time-signature-event.js.html
+++ b/docs/meta-events_time-signature-event.js.html
@@ -24,7 +24,7 @@
@@ -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 14723f5..e0d8039 100644
--- a/docs/meta-events_track-name-event.js.html
+++ b/docs/meta-events_track-name-event.js.html
@@ -24,7 +24,7 @@
@@ -44,17 +44,22 @@ meta-events/track-name-event.js
/**
* Object representation of a tempo meta event.
- * @param {number} bpm - Beats per minute
+ * @param {object} fields {text: string, delta: integer}
* @return {TrackNameEvent}
*/
class TrackNameEvent {
- constructor(text) {
+ constructor(fields) {
+ // Set default fields
+ fields = Object.assign({
+ delta: 0x00,
+ }, fields);
+
this.type = 'track-name';
- const textBytes = Utils.stringToBytes(text);
+ const textBytes = Utils.stringToBytes(fields.text);
// Start with zero time delta
- this.data = Utils.numberToVariableLength(0x00).concat(
+ this.data = Utils.numberToVariableLength(fields.delta).concat(
Constants.META_EVENT_ID,
Constants.META_TRACK_NAME_ID,
Utils.numberToVariableLength(textBytes.length), // Size
@@ -76,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 facd89c..34ca3a5 100644
--- a/docs/note-events_note-event.js.html
+++ b/docs/note-events_note-event.js.html
@@ -24,7 +24,7 @@
@@ -39,8 +39,7 @@ note-events/note-event.js
-