Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can jsmidgen work in the browser ?? #26

Closed
sksar opened this issue Nov 23, 2016 · 2 comments
Closed

Can jsmidgen work in the browser ?? #26

sksar opened this issue Nov 23, 2016 · 2 comments

Comments

@sksar
Copy link

sksar commented Nov 23, 2016

I want to use jsmidgen in the web browser ?? is it possible ??

@sksar sksar closed this as completed Nov 25, 2016
@sksar sksar reopened this Nov 25, 2016
@walmik
Copy link
Contributor

walmik commented Jan 28, 2017

You cannot do this without some additional workarounds.

If all you want to do is to play MIDI in the browser, then you can directly use the Web MIDI API (on Chrome) to do so. But if you want to play MIDI in the browser or create a MIDI file in the browser and then have it saved as a .mid file using jsmidgen, then you ll have to do a bit of work. jsmidgen works is a Node.js module and outputs binary data that you can hand write to a MIDI file.

To have it do this in the browser, I d imagine you'd need to

  • Use something like browserify to first make jsmidgen run in the browser
  • parse the incoming MIDI messages from the Web MIDI API to jsmidgen's noteOn noteOff messages on the Track object
  • Use the DOM File API (on Chrome) to construct files from bytes returned by jsmidgen

For instance, if you 'listen' to incoming MIDI data using the Web MIDI API, you ll get something like [144, 60, 127] for pressing the C4 (60) note at the highest velocity (127). In there, 144 signifies noteOn. So you ll need to convert each such message (made up of a status byte and upto 2 data bytes) into something like,

track.addNote(0, 'c4', <derive duration>);

Once you chain all the noteOn and noteOff events, you can use the getBytes method in jsdmidgen (on the File object) and use that alongside DOM File API of the (Chrome) browser to save a file to the user's disc.

@sksar
Copy link
Author

sksar commented Jan 28, 2017

it works perfectly fine with filesaver.js
I have tested myself and its working just fine.

@sksar sksar closed this as completed Jan 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants