Skip to content

Commit 238ebee

Browse files
committedOct 23, 2018
feat: compat with new embed release
1 parent aeec1e9 commit 238ebee

File tree

6 files changed

+92
-271
lines changed

6 files changed

+92
-271
lines changed
 

‎README.md

-53
Original file line numberDiff line numberDiff line change
@@ -102,23 +102,19 @@ When instantiating `Flat.Embed`, you can pass options in the second parameter. I
102102
* [`getAutoZoom`](#getautozoom-promiseboolean-error): Get the state of the auto-zoom mode
103103
* [`setAutoZoom`](#setautozoomboolean-promiseboolean-error): Enable or disable the auto-zoom mode
104104
* [`focusScore`](#focusscore-promisevoid-error): Set the focus to the score
105-
* [`setNoteColor`](#setnotecolornotelocation-object-color-string-promiseobject-error): Set the color for the given note
106105
* [`getCursorPosition`](#getcursorposition-promiseobject-error): Get the current cursor position of the score
107106
* [`setCursorPosition`](#setcursorpositionposition-object-promiseobject-error): Set a new position for the cursor
108107
* [Editor Methods](#editor-methods)
109108
* [`setEditorConfig`](#seteditorconfigconfig-object-promiseobject-error): Set the config of the editor
110-
* [`edit`](#editoperations-object-promisevoid-error): Make a modification to the document
111109
* [Events API](#events-api)
112110
* [`scoreLoaded`](#event-scoreLoaded): A new score has been loaded
113111
* [`cursorPosition`](#event-cursorposition): The cursor position changed
114112
* [`rangeSelection`](#event-rangeSelection): The range selected changed
115113
* [`fullscreen`](#event-fullscreen): The fullscreen state changed
116-
* [`print`](#event-print): The score was printed
117114
* [`play`](#event-play): The score playback started
118115
* [`pause`](#event-pause): The score playback paused
119116
* [`stop`](#event-stop): The score playback stopped
120117
* [`playbackPosition`](#event-playbackposition): The playback slider position changed
121-
* [`edit`](#event-edit): An edition has been made to the document
122118

123119
## Viewer Methods
124120

@@ -433,22 +429,6 @@ embed.focusScore().then(function () {
433429
});
434430
```
435431

436-
### `setNoteColor(noteLocation: object, color: string): Promise(<object, Error>)`
437-
438-
Set the color of the note at the location `noteLocation` (on a specific note).
439-
440-
```js
441-
embed.setNoteColor({
442-
"partIdx": 0,
443-
"voiceIdx": 0,
444-
"measureIdx": 2,
445-
"noteIdx": 1,
446-
"line": 2.5
447-
}, 'red').then(function () {
448-
// Note is now red
449-
});
450-
```
451-
452432
### `getCursorPosition(): Promise(<object, Error>)`
453433

454434
Return the current position of the cursor (on a specific note).
@@ -513,11 +493,6 @@ embed.setEditorConfig({}).then(function (config) {
513493
});
514494
```
515495

516-
### `edit(operations: object): Promise<void, Error>`
517-
518-
**NOTE: This method is now deprecated. Dedicated editing methods will be available in the upcoming weeks.
519-
[Please contact our team](mailto:developers@flat.io) if you are interested in using them.**
520-
521496
## Events API
522497

523498
Events are broadcasted following actions made by the end user or you with the JavaScript API. You can subscribe to an event using the method [`on`](#onevent-string-callback-function-void), and unsubscribe using [`off`](#onevent-string-callback-function-void). When an event includes some data, this data will be available in the first parameter of the listener callback.
@@ -567,10 +542,6 @@ This event is triggered when a range of notes is selected or the selection chang
567542

568543
This event is triggered when the state of the fullscreen changed. The callback will take a boolean as the first parameter that will be `true` if the fullscreen mode is enabled, and `false` is the display is back to normal (fullscreen exited).
569544

570-
### Event: `print`
571-
572-
This event is triggered when you or the end-user prints the score. This event doesn't include any data.
573-
574545
### Event: `play`
575546

576547
This event is triggered when you or the end-user starts the playback. This event doesn't include any data.
@@ -596,27 +567,3 @@ This event is triggered when the playback slider moves. It is usually triggered
596567
"timePerMeasure": 2
597568
}
598569
```
599-
600-
### Event: `edit`
601-
602-
**NOTE: This event format will change in the upcoming weeks for simpler edit information, the current format is now deprecated. [Please contact our team](mailto:developers@flat.io) if you are interested in using the new format.**
603-
604-
This event is triggered when one or multiple modifications ave been made to the document. This one will contain a list of operations made:
605-
606-
```json
607-
[
608-
{
609-
"name": "action.SetTempo",
610-
"opts": {
611-
"startMeasureIdx": 0,
612-
"stopMeasureIdx": 1,
613-
"tempo": {
614-
"bpm": 142,
615-
"qpm": 142,
616-
"durationType": 3,
617-
"nbDots": 0
618-
}
619-
}
620-
}
621-
]
622-
```

‎karma.conf.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = function(config) {
66
client: {
77
mocha: {
88
timeout: '30000ms',
9-
// grep: 'Editor modifications'
9+
// grep: 'GREP'
1010
}
1111
},
1212
files: [
@@ -29,7 +29,7 @@ module.exports = function(config) {
2929
},
3030
singleRun: false,
3131
concurrency: Infinity,
32-
browserNoActivityTimeout: 30000
32+
browserNoActivityTimeout: 60000
3333
};
3434

3535
if (process.env.TRAVIS) {

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
"build:watch": "npm run build --watch",
3535
"test": "npm run eslint && npm run test:unit && npm run test:karma",
3636
"eslint": "./node_modules/.bin/eslint src",
37-
"test:unit": "./node_modules/.bin/mocha --ui exports --reporter spec --slow 150ms --timeout 30000ms test/unit",
38-
"test:karma": "./node_modules/.bin/karma start --single-run"
37+
"test:unit": "./node_modules/.bin/mocha --ui exports --reporter spec --slow 150ms --timeout 30000ms test/unit --exit",
38+
"test:karma": "./node_modules/.bin/karma start --single-run",
39+
"test:karma-watch": "./node_modules/.bin/karma start --single-run=false --auto-watch"
3940
},
4041
"devDependencies": {
4142
"babel-core": "^6.24.1",

‎src/embed.js

-19
Original file line numberDiff line numberDiff line change
@@ -363,25 +363,6 @@ class Embed {
363363
setCursorPosition(position) {
364364
return this.call('setCursorPosition', position);
365365
}
366-
367-
/**
368-
* Call Flat's internal edit methods
369-
*
370-
* @param {operations} The operations to process
371-
*/
372-
edit(operations) {
373-
return this.call('edit', operations);
374-
}
375-
376-
/**
377-
* Set note color
378-
*
379-
* @param {noteLocation} position of the note to change
380-
* @param {color} The color to apply
381-
*/
382-
setNoteColor(noteLocation, color) {
383-
return this.call('setNoteColor', { note: noteLocation, color: color });
384-
}
385366
}
386367

387368
export default Embed;

‎src/lib/embed.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @param {object} parameters
55
*/
66
export function buildIframeUrl(parameters) {
7-
let url = (parameters.baseUrl || 'https://flat.io/embed');
7+
let url = (parameters.baseUrl || 'https://flat-embed.com');
88

99
// Score id or blank embed
1010
url += '/' + (parameters.score || 'blank');

‎test/integration/embed-integration.js

+86-194
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
var APP_ID = '58fa312bea9bbd061b0ea8f3',
2-
BASE_URL = 'https://flat.io/embed',
2+
BASE_URL = 'https://flat-embed.com',
33
PUBLIC_SCORE = '56ae21579a127715a02901a6';
44

55
// APP_ID = '58e90082688f3e99d1244f58';
6-
// BASE_URL = 'http://flat.dev:3000/embed';
7-
// PUBLIC_SCORE = '58f93f70874b3f526d3d45e0';
6+
// BASE_URL = 'http://vincent.ovh:3000/embed';
7+
// PUBLIC_SCORE = '5bcc8e5b32023d903fb5fb26';
88

99
describe('Integration - Embed', () => {
1010
describe('Loading embed', () => {
@@ -115,7 +115,8 @@ describe('Integration - Embed', () => {
115115

116116
it('should plug into an existing iframe', (done) => {
117117
var iframe = document.createElement('iframe');
118-
iframe.setAttribute('src', BASE_URL + '/' + PUBLIC_SCORE + '?jsapi=true&appId=' + APP_ID);
118+
var baseUrl = BASE_URL || 'https://flat-embed.com';
119+
iframe.setAttribute('src', baseUrl + '/' + PUBLIC_SCORE + '?jsapi=true&appId=' + APP_ID);
119120
document.body.appendChild(iframe);
120121

121122
var embed = new Flat.Embed(iframe);
@@ -142,6 +143,10 @@ describe('Integration - Embed', () => {
142143

143144
embed.getJSON().then((json) => {
144145
assert.ok(json['score-partwise']);
146+
return embed.getFlatScoreMetadata();
147+
})
148+
.then((meta) => {
149+
assert.equal(meta.title, 'House of the Rising Sun');
145150
container.parentNode.removeChild(container);
146151
done();
147152
});
@@ -447,6 +452,10 @@ describe('Integration - Embed', () => {
447452
assert.equal(position.voiceIdx, 0);
448453
assert.equal(position.measureIdx, 0);
449454
assert.equal(position.noteIdx, 0);
455+
assert.ok(position.partUuid);
456+
assert.ok(position.staffUuid);
457+
assert.ok(position.measureUuid);
458+
assert.ok(position.voiceUuid);
450459
container.parentNode.removeChild(container);
451460
done();
452461
})
@@ -510,13 +519,11 @@ describe('Integration - Embed', () => {
510519
});
511520

512521
embed.setCursorPosition({
513-
partIdx: 0,
514-
staffIdx: 0,
515-
measureIdx: 2,
516522
noteIdx: 1
517523
})
518524
.catch((error) => {
519-
assert.equal(error.message, '`voiceIdx` should be an integer');
525+
assert.equal(error.code, 'BadPartIdxError');
526+
assert.equal(error.message, 'There is no part at the index [undefined<undefined>].');
520527
container.parentNode.removeChild(container);
521528
done();
522529
});
@@ -537,12 +544,12 @@ describe('Integration - Embed', () => {
537544
embed.setCursorPosition({
538545
partIdx: 0,
539546
staffIdx: 0,
540-
measureIdx: 2,
541-
noteIdx: 1.1,
547+
measureIdx: true,
548+
noteIdx: 0,
542549
voiceIdx: 0
543550
})
544551
.catch((error) => {
545-
assert.equal(error.message, '`noteIdx` should be an integer');
552+
assert.equal(error.message, 'Parameter measureIdx should be a number, not boolean');
546553
container.parentNode.removeChild(container);
547554
done();
548555
});
@@ -601,6 +608,18 @@ describe('Integration - Embed', () => {
601608
assert.ok(Number.isFinite(zoom));
602609
assert.ok(zoom >= 0.5);
603610
assert.ok(zoom < 3);
611+
return embed.getAutoZoom();
612+
})
613+
.then((autoZoom) => {
614+
assert.ok(autoZoom);
615+
return embed.setAutoZoom(false);
616+
})
617+
.then((autoZoom) => {
618+
assert.ok(!autoZoom);
619+
return embed.getAutoZoom();
620+
})
621+
.then((autoZoom) => {
622+
assert.ok(!autoZoom);
604623
container.parentNode.removeChild(container);
605624
done();
606625
});
@@ -620,7 +639,7 @@ describe('Integration - Embed', () => {
620639
});
621640

622641
embed.setZoom(2, (zoom) => {
623-
assert.equal(zoo, 2);
642+
assert.equal(zoom, 2);
624643
done();
625644
})
626645
.then(() => {
@@ -672,11 +691,7 @@ describe('Integration - Embed', () => {
672691
});
673692

674693
embed.on('playbackPosition', (pos) => {
675-
assert.equal(pos.beat, 4);
676-
assert.equal(pos.beatType, 4);
677-
assert.ok(pos.tempo >= 60);
678-
assert.ok(pos.timePerMeasure >= 1);
679-
assert.ok(pos.currentMeasure >= 1); // 1 or 2? Event should be sent for first measure?
694+
assert.ok(pos.currentMeasure >= 0, 'currentMeasure');
680695
container.parentNode.removeChild(container);
681696
done();
682697
});
@@ -729,181 +744,58 @@ describe('Integration - Embed', () => {
729744
});
730745
});
731746

732-
describe('Editor config', () => {
733-
it('should fetch the viewer config', (done) => {
734-
var container = document.createElement('div');
735-
document.body.appendChild(container);
736-
737-
var embed = new Flat.Embed(container, {
738-
score: PUBLIC_SCORE,
739-
baseUrl: BASE_URL,
740-
embedParams: {
741-
appId: APP_ID,
742-
controlsFloating: false,
743-
branding: false
744-
}
745-
});
746-
747-
embed.getEmbedConfig().then((config) => {
748-
assert.equal(config.branding, false);
749-
assert.equal(config.controlsPlay, true);
750-
assert.equal(config.controlsFloating, false);
751-
container.parentNode.removeChild(container);
752-
done();
753-
});
754-
});
755-
756-
it('should use the edit mode and set a tools config', (done) => {
757-
var container = document.createElement('div');
758-
document.body.appendChild(container);
759-
760-
var embed = new Flat.Embed(container, {
761-
baseUrl: BASE_URL,
762-
embedParams: {
763-
appId: APP_ID,
764-
mode: 'edit',
765-
controlsFloating: false,
766-
branding: false
767-
}
768-
});
769-
770-
embed.setEditorConfig({
771-
noteMode: {
772-
durations: true,
773-
tuplet: false
774-
},
775-
articulationMode: false
776-
}).then((config) => {
777-
assert.ok(config.global);
778-
assert.equal(config.articulationMode, false);
779-
assert.equal(config.noteMode.durations, true);
780-
assert.equal(config.noteMode.tuplet, false);
781-
container.parentNode.removeChild(container);
782-
done();
783-
}).catch(done);
784-
});
785-
});
786-
787-
describe('Editor modifications', () => {
788-
it('should make a modification, get the event and get the document updated', (done) => {
789-
var container = document.createElement('div');
790-
document.body.appendChild(container);
791-
792-
var embed = new Flat.Embed(container, {
793-
score: PUBLIC_SCORE,
794-
baseUrl: BASE_URL,
795-
embedParams: {
796-
appId: APP_ID,
797-
mode: 'edit'
798-
}
799-
});
800-
801-
embed.on('edit', (operations) => {
802-
assert.equal(operations.length, 1);
803-
assert.equal(operations[0].name, 'action.SetTempo');
804-
assert.equal(operations[0].opts.startMeasureIdx, 0);
805-
assert.equal(operations[0].opts.stopMeasureIdx, 1);
806-
assert.deepEqual(operations[0].opts.tempo, {
807-
bpm: 142,
808-
qpm: 142,
809-
durationType: 3,
810-
nbDots: 0
811-
});
812-
});
813-
814-
embed.edit([
815-
{
816-
name: 'action.SetTempo',
817-
opts: {
818-
startMeasureIdx: 0,
819-
stopMeasureIdx: 1,
820-
tempo: {
821-
bpm: 142,
822-
qpm: 142,
823-
durationType: 3,
824-
nbDots: 0
825-
}
826-
}
827-
}
828-
]).then(() => {
829-
return embed.getJSON();
830-
}).then((json) => {
831-
assert.equal(json['score-partwise'].part[0].measure[0].sound.$tempo, 142);
832-
container.parentNode.removeChild(container);
833-
done();
834-
}).catch(done);
835-
});
836-
837-
it('should fail to edit with bad ops arguments (edit error)', (done) => {
838-
var container = document.createElement('div');
839-
document.body.appendChild(container);
840-
841-
var embed = new Flat.Embed(container, {
842-
score: PUBLIC_SCORE,
843-
baseUrl: BASE_URL,
844-
embedParams: {
845-
appId: APP_ID,
846-
mode: 'edit'
847-
}
848-
});
849-
850-
embed.edit([
851-
{
852-
name: 'action.SetTempo',
853-
opts: {
854-
startMeasureIdx: 0,
855-
stopMeasureIdx: 1000000,
856-
tempo: {
857-
bpm: 142,
858-
qpm: 142,
859-
durationType: 3,
860-
nbDots: 0
861-
}
862-
}
863-
}
864-
]).then(() => {
865-
return done('Should have fail');
866-
}).catch((error) => {
867-
assert.equal(error.code, 'BadMeasureIdxError');
868-
assert.equal(error.message, 'There is no measure at the index [1000000<number>].');
869-
container.parentNode.removeChild(container);
870-
done();
871-
})
872-
});
873-
874-
it('should fail to edit with bad ops arguments (bad ops format)', (done) => {
875-
var container = document.createElement('div');
876-
document.body.appendChild(container);
877-
878-
var embed = new Flat.Embed(container, {
879-
score: PUBLIC_SCORE,
880-
baseUrl: BASE_URL,
881-
embedParams: {
882-
appId: APP_ID,
883-
mode: 'edit'
884-
}
885-
});
886-
887-
embed.edit({
888-
name: 'action.SetTempo',
889-
opts: {
890-
startMeasureIdx: 0,
891-
stopMeasureIdx: 1000000,
892-
tempo: {
893-
bpm: 142,
894-
qpm: 142,
895-
durationType: 3,
896-
nbDots: 0
897-
}
898-
}
899-
}).then(() => {
900-
return done('Should have fail');
901-
}).catch((error) => {
902-
assert.equal(error.code, 'TypeError');
903-
assert.equal(error.message, 'Operations must be an array of operations');
904-
container.parentNode.removeChild(container);
905-
done();
906-
})
907-
});
908-
});
747+
// describe('Editor config', () => {
748+
// it('should fetch the viewer config', (done) => {
749+
// var container = document.createElement('div');
750+
// document.body.appendChild(container);
751+
752+
// var embed = new Flat.Embed(container, {
753+
// score: PUBLIC_SCORE,
754+
// baseUrl: BASE_URL,
755+
// embedParams: {
756+
// appId: APP_ID,
757+
// controlsFloating: false,
758+
// branding: false
759+
// }
760+
// });
761+
762+
// embed.getEmbedConfig().then((config) => {
763+
// assert.equal(config.branding, false);
764+
// assert.equal(config.controlsPlay, true);
765+
// assert.equal(config.controlsFloating, false);
766+
// container.parentNode.removeChild(container);
767+
// done();
768+
// });
769+
// });
770+
771+
// it('should use the edit mode and set a tools config', (done) => {
772+
// var container = document.createElement('div');
773+
// document.body.appendChild(container);
774+
775+
// var embed = new Flat.Embed(container, {
776+
// baseUrl: BASE_URL,
777+
// embedParams: {
778+
// appId: APP_ID,
779+
// mode: 'edit',
780+
// controlsFloating: false,
781+
// branding: false
782+
// }
783+
// });
784+
785+
// embed.setEditorConfig({
786+
// noteMode: {
787+
// durations: true,
788+
// tuplet: false
789+
// },
790+
// articulationMode: false
791+
// }).then((config) => {
792+
// assert.ok(config.global);
793+
// assert.equal(config.articulationMode, false);
794+
// assert.equal(config.noteMode.durations, true);
795+
// assert.equal(config.noteMode.tuplet, false);
796+
// container.parentNode.removeChild(container);
797+
// done();
798+
// }).catch(done);
799+
// });
800+
// });
909801
});

0 commit comments

Comments
 (0)
Please sign in to comment.