Skip to content

Commit

Permalink
Feature/fluidsynth (#6)
Browse files Browse the repository at this point in the history
* midiplayer with fluidsynth support

* updated midiplayer version

* set parcel version fix to 1.12.3 due this bug:
parcel-bundler/parcel#5955

* midi player version up to 9

* midiplayer update

* buffersize, repo url options added

* midiplayer version updated

* * midipayer updated
* audio buffer size option removed

* unused code removed

* midiplayer updated

* midiplayer version updated

* midiplayer updated

* version updated

* deactivated source maps for dev scripts, because it fails to compile, due the js-synthesizer script is loaded using parcels fs process

* midi player version updated

* update test

* version updated

* midiplayer version updated

Co-authored-by: samba <samba@manjaro>
  • Loading branch information
SambaGodschynski and samba authored Mar 24, 2021
1 parent f7c7b71 commit de4cfd4
Show file tree
Hide file tree
Showing 8 changed files with 469 additions and 8,885 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,6 @@ https://jsfiddle.net/aw702vcg/
### `wm-css-url`
Set an url of an css file, to override the default css of the snippet.
https://jsfiddle.net/y53647x8/

### `wm-soundfont-url`
Set the repo url. See [Soundfont Server](https://github.com/werckme/soundfont-server).
9,297 changes: 427 additions & 8,870 deletions package-lock.json

Large diffs are not rendered by default.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
"test": "echo \"Error: no test specified\" && exit 1",
"build": "parcel build --no-source-maps src/werckmeister-components.ts",
"deploy": "rm -rf dist && npm run build && cp package.json dist && cp README.md dist",
"serve-snippet": "parcel test-snippet.html editor.css",
"serve-workspace": "parcel test-workspace.html editor.css"
"serve-snippet": "parcel --no-source-maps test-snippet.html editor.css",
"serve-workspace": "parcel --no-source-maps test-workspace.html editor.css"
},
"staticFiles": {
"staticPath": [
"./node_modules/@werckmeister/compilerjs"
"./node_modules/@werckmeister/compilerjs",
"./node_modules/@werckmeister/midiplayer"
],
"watcherGlob": "*.wasm"
},
Expand All @@ -30,7 +31,7 @@
"@types/codemirror": "0.0.98",
"@types/lodash": "^4.14.164",
"@werckmeister/compilerjs": "^0.1.56-3",
"@werckmeister/midiplayer": "1.0.2-3",
"@werckmeister/midiplayer": "1.0.2-31",
"babel-core": "^6.26.3",
"babel-polyfill": "^6.26.0",
"codemirror": "^5.57.0",
Expand All @@ -43,6 +44,7 @@
"@babel/preset-typescript": "^7.10.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"parcel": "1.12.3",
"parcel-bundler": "^1.12.4",
"parcel-plugin-static-files-copy": "^2.5.0",
"typescript": "^4.0.2"
Expand Down
16 changes: 10 additions & 6 deletions src/components/snippet/Snippet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,10 @@ export class Snippet extends HTMLElement {
async onPlayClicked(ev: MouseEvent) {
try {
await this.stopAllSippets();
this.playerIsFetching = true;
await this.startPlayer(ev);
} catch(ex) {
this.onError(ex.error);
return;
} finally {
this.playerIsFetching = false;
}
}

Expand Down Expand Up @@ -272,7 +269,6 @@ export class Snippet extends HTMLElement {
this.document = await WM_Compiler.compile(files);
} catch(ex) {
this.onError(ex.error);
this.playerIsFetching = true;
return;
}
this.snippetDocumentId = _(this.document.midi.sources)
Expand All @@ -282,7 +278,11 @@ export class Snippet extends HTMLElement {
console.error("werckmeister compiler could not assign main document")
}
WM_Player.tempo = this.document.midi.bpm;
await WM_Player.play(this.document.midi.midiData, ev, this.onMidiEvent.bind(this), this.onPlayerState.bind(this));
try {
await WM_Player.play(this.document.midi.midiData, ev, this.onMidiEvent.bind(this), this.onPlayerState.bind(this));
} finally {
this.playerIsFetching = false;
}
}

/**
Expand Down Expand Up @@ -409,6 +409,10 @@ export class Snippet extends HTMLElement {
const additionalSources = this.attributes.getNamedItem("wm-add-sources");
if (additionalSources) {
this._addSources = additionalSources.value;
}
}
const soundfontRepoUrl = this.attributes.getNamedItem("wm-soundfont-url");
if (soundfontRepoUrl) {
WM_Player.setSoundfontRepoUrl(soundfontRepoUrl.value);
}
}
}
4 changes: 4 additions & 0 deletions src/components/workspace/Workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ export class Workspace extends HTMLElement {
if (cssRefAttr) {
this.loadExternalCss(cssRefAttr.value);
}
const soundfontRepoUrl = this.attributes.getNamedItem("wm-soundfont-url");
if (soundfontRepoUrl) {
WM_Player.setSoundfontRepoUrl(soundfontRepoUrl.value);
}
}

public registerEditor(editor: Editor) {
Expand Down
11 changes: 11 additions & 0 deletions src/player/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export class Player {
private onMidiEvent: MidiEventCallback|null = null;
private onPlayerStateChangedCallback: PlayerStateChangedCallback|null = null;
private state: PlayerState = PlayerState.Stopped;
private repoUrl: string = null;
/**
*
* @param event
Expand All @@ -36,6 +37,9 @@ export class Player {
this._player.initAudioEnvironment(event);
this._player.onMidiEvent = this.onEvent.bind(this);
this._player.onPlayerStateChanged = this._onPlayerStateChanged.bind(this);
if (this.repoUrl) {
this._player.setRepoUrl(this.repoUrl);
}
}
return this._player;
}
Expand Down Expand Up @@ -108,6 +112,13 @@ export class Player {
this.state = PlayerState.Playing;
}

setSoundfontRepoUrl(url: string) {
if(this._player) {
this._player.setRepoUrl(url);
}
this.repoUrl = url;
}

/**
*
*/
Expand Down
11 changes: 7 additions & 4 deletions src/shared/player.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { PlayerState as _PlayerSate} from "@werckmeister/midiplayer";

export enum PlayerState {
Playing,
Stopped,
Paused
}
Stopped = _PlayerSate.Stopped,
Preparing = _PlayerSate.Preparing,
Playing = _PlayerSate.Playing,
Stopping = _PlayerSate.Stopping
}
2 changes: 1 addition & 1 deletion test-snippet.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
wm-data="dXNpbmcgImNob3Jkcy9kZWZhdWx0LmNob3JkcyI7CnRlbXBvOiAxNDA7CmRldmljZTogTXlEZXZpY2UgIG1pZGkgX3VzZVBvcnQ9MDsKaW5zdHJ1b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fCBFLSAgICAgfCAKICAgIEUtICAgICB8IEYjLTdiNSB8IEI3YjkgIHwgRS0gICAgIHwgCiAgICBFLSAgICAgfCBBLTcgICAgfCBENyAgICB8IEdtYWo3ICB8CiAgICBHbWFqNyAgfCBGIy03YjUgfCBCN2I5ICB8IEUtNyBBNyB8IAogICAgRC03IEc3IHwgRiMtN2I1IHwgQjdiOSAgfCBFLSAgICAgfAp9Cl0KCi0tIHRoZSB0ZW1wbGF0ZXMgZGVmaW5lcyB3aGF0IHRoZSBhY2NvbXAgdHJhY2sgaGFzIHRvIHBsYXkKWwp0eXBlOiB0ZW1wbGF0ZTsKbmFtZTogbXlBY2NvbXA7Cmluc3RydW1lbnQ6IHJodHl0aG07CnsKICAgIFxwCiAgICA8SUlJLCBWLCBWSUksIElJPjEgfCAKfQpdCgpbCnR5cGU6IHRlbXBsYXRlOwpuYW1lOiBteUFjY29tcDsKaW5zdHJ1bWVudDogYmFzczsKewogICAgXHAKICAgIEksLDIuIFYsLDQgfAp9Cl0=">
</werckmeister-snippet>

<werckmeister-snippet wm-add-sources="W3sicGF0aCI6ImNvbXBpbmcudGVtcGxhdGUiLCJkYXRhIjoiW1xudHlwZTogdGVtcGxhdGU7XG5uYW1lOiBteUFjY29tcDtcbmluc3RydW1lbnQ6IHJodHl0aG07XG57XG4gICAgXFxwXG4gICAgPElJSSwgViwgVklJLCBJST4xIHwgXG59XG5dXG5cbltcbnR5cGU6IHRlbXBsYXRlO1xubmFtZTogbXlBY2NvbXA7XG5pbnN0cnVtZW50OiBiYXNzO1xue1xuICAgIFxccFxuICAgIEksLDIuIFYsLDQgfFxufVxuXSJ9XQ=="
<werckmeister-snippet wm-audiobuffer-size="1024" wm-add-sources="W3sicGF0aCI6ImNvbXBpbmcudGVtcGxhdGUiLCJkYXRhIjoiW1xudHlwZTogdGVtcGxhdGU7XG5uYW1lOiBteUFjY29tcDtcbmluc3RydW1lbnQ6IHJodHl0aG07XG57XG4gICAgXFxwXG4gICAgPElJSSwgViwgVklJLCBJST4xIHwgXG59XG5dXG5cbltcbnR5cGU6IHRlbXBsYXRlO1xubmFtZTogbXlBY2NvbXA7XG5pbnN0cnVtZW50OiBiYXNzO1xue1xuICAgIFxccFxuICAgIEksLDIuIFYsLDQgfFxufVxuXSJ9XQ=="
wm-def="dXNpbmcgImNob3Jkcy9kZWZhdWx0LmNob3JkcyI7DQp1c2luZyAiY29tcGluZy50ZW1wbGF0ZSI7DQp0ZW1wbzogMTQwOw0KZGV2aWNlOiBNeURldmljZSAgbWlkaSBfdXNlUG9ydD0wOw0KaW5zdHJ1bWVudERlZjpsZWFkICAgIF9vbkRldmljZT1NeURldmljZSAgX2NoPTAgX3BjPTA7DQppbnN0cnVtZW50RGVmOnJodHl0aG0gX29uRGV2aWNlPU15RGV2aWNlICBfY2g9MSBfcGM9MDsNCmluc3RydW1lbnREZWY6YmFzcyAgICBfb25EZXZpY2U9TXlEZXZpY2UgIF9jaD0yIF9wYz0wOw0K">
<![CDATA[[
{
Expand Down

0 comments on commit de4cfd4

Please sign in to comment.