openframeworks / openframeworks/openFrameworks
About webMidi and Emscripten
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 10.4k
- Forks
- 2.6k
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 9
Description
I added webMidi to OF / Emscripten and search for a better implementation.
This is how I did it:
Add PLATFORM_LDFLAGS += --post-js $(OF_ADDONS_PATH)/ofxEmscripten/libs/html5audio/lib/emscripten/library_webMidi.js
to config.emscripten.default.mk.
This is the webMidi library that I use: https://github.com/Jonathhhan/openFrameworks/blob/AudioWorklet/addons/ofxEmscripten/libs/html5audio/lib/emscripten/library_webMidi.js
And this is the original file (I added output): https://github.com/cwilso/midi-synth/blob/master/js/midi.js
And I had to add this:
<b>Input Ports: </b><select id="midiIn"><option>-no MIDI-</option></select><br></p>
<b>Outputs Ports: </b><select id="midiOut"><option>-no MIDI-</option></select></p>
to template.html (for recognizing and selecting midi devices).
Then I can just send MIDI from ofApp.cpp to the MIDI device like this (for example):
int array[3] = {val_0, val_1, val_2};
size_t lengthOfArray = sizeof array / sizeof array[0];
EM_ASM_(
var data = new Uint32Array(HEAPU32.buffer, $0, $1);
sendMIDI(data), array, lengthOfArray);
The most crucial part is how to select the MIDI devices (it all happens on the JS side now), but also other parts can be optimized. I guess, all in all it should not be very difficult to implement.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review config.emscripten.default.mk, the proposed library_webMidi.js under ofxEmscripten/libs/html5audio/lib/emscripten, and template.html to understand the current MIDI integration points. Compare the example ofApp.cpp EM_ASM_ usage with the linked implementation; done should include selecting MIDI input and output devices in the browser and sending MIDI from an openFrameworks app.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, javascript
- Domain
- audio-video-rtc, build-system, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100