Skip to content

Commit 42c1678

Browse files
committedNov 29, 2018
feat: add getMIDI
1 parent 975ed87 commit 42c1678

File tree

7 files changed

+74
-3
lines changed

7 files changed

+74
-3
lines changed
 

‎README.md

+20
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ When instantiating `Flat.Embed`, you can pass options in the second parameter. I
8888
* [`getMusicXML`](#getmusicxmloptions-object-promisestringuint8array-error): Get the score in MusicXML (compressed or not)
8989
* [`getJSON`](#getjson-object): Get the score data in Flat JSON format
9090
* [`getPNG`](#getpngoptions-object-promisestringuint8array-error): Get the score as a PNG file
91+
* [`getMIDI`](#getmidi-promiseuint8array-error): Get the score as a MIDI file
9192
* [`getScoreMeta`](#getscoremeta-object): Get the metadata from the current score (for hosted scores)
9293
* [`fullscreen`](#fullscreenstate-bool-promisevoid-error): Toggle fullscreen mode
9394
* [`play`](#play-promisevoid-error): Start playback
@@ -295,6 +296,25 @@ embed.getPNG({result: 'dataURL'}).then(function (png) {
295296
});
296297
```
297298

299+
### `getMIDI(): Promise<Uint8Array, Error>`
300+
301+
Get the current displayed score as a MIDI file
302+
303+
```js
304+
embed.getMIDI().then(function (midi) {
305+
// MIDI file as a Uint8Array
306+
console.log(midi);
307+
});
308+
```
309+
310+
```js
311+
// PNG
312+
embed.getPNG({result: 'dataURL'}).then(function (png) {
313+
// PNG file as a DataURL
314+
console.log(png);
315+
});
316+
```
317+
298318
### `getScoreMeta(): object`
299319

300320
Get the score metadata of the hosted score. The object will have the same format that the one returned [by our API `GET /v2/scores/{score}`](https://flat.io/developers/api/reference/#operation/getScore).

‎dist/embed.js

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/embed.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/embed.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎dist/embed.min.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/embed.js

+11
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,17 @@ class Embed {
204204
});
205205
}
206206

207+
/**
208+
* Convert the displayed score in MIDI
209+
*
210+
* @return {Promise}
211+
* @fullfill {Uint8Array} MIDI File
212+
* @reject {Error} Conversion error
213+
*/
214+
getMIDI() {
215+
return this.call('getMIDI').then(data => new Uint8Array(data));
216+
}
217+
207218
/**
208219
* Get the metadata of the score (for scores hosted on Flat)
209220
*

‎test/integration/embed-integration.js

+24
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,30 @@ describe('Integration - Embed', () => {
434434
});
435435
});
436436

437+
describe('MIDI export', () => {
438+
it('should export in MIDI', (done) => {
439+
var container = document.createElement('div');
440+
document.body.appendChild(container);
441+
442+
var embed = new Flat.Embed(container, {
443+
score: PUBLIC_SCORE,
444+
baseUrl: BASE_URL,
445+
embedParams: {
446+
appId: APP_ID,
447+
layout: 'page'
448+
}
449+
});
450+
451+
embed.getMIDI()
452+
.then((midi) => {
453+
assert.ok(midi instanceof Uint8Array);
454+
assert.ok(midi.length > 0);
455+
container.parentNode.removeChild(container);
456+
done();
457+
});
458+
});
459+
});
460+
437461
describe('Cursor position', () => {
438462
it('should get the cursor position (default: 0)', (done) => {
439463
var container = document.createElement('div');

0 commit comments

Comments
 (0)
Please sign in to comment.