openframeworks / openframeworks/openFrameworks

About webMidi and Emscripten

Open
#7,221 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

emscripten
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:&nbsp;</b><select id="midiIn"><option>-no MIDI-</option></select><br></p>
<b>Outputs Ports:&nbsp;</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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.