Now I can answer my own question
Loading an ofImage from a Lua table with pixel values from a .bmp works like that:
ofelia d $0-embindReceiveBitmap;
function embind_6(w, h, buf);
testImage:allocate(w, h, OF_IMAGE_COLOR_ALPHA);
print("bitmap size:", #buf, "bitmap width:", w, "bitmap height:", h);
local count = 0;
for i = 0, h - 1 do;
count = count + w -((w >> 2) << 2);
for j = 0, w - 1 do;
testImage:setColor(j, h - i, ofColor(buf[(i * w + j) * 3 + 54 + count], buf[(i * w + j) * 3 + 55 + count], buf[(i * w + j) * 3 + 56 + count], 200));
So, now it is possible with Emscripten and Ofelia to load and manipulate .bmp and .wav data in the internet...
And to control the patch with webMIDI (or just Java Script).
And to output (MIDI) data.
I seperated the MIDI and audio example:
And I have some ideas and suggestions how to optimize this:
- It would be nice to make a better basic webMIDI Java Script interface template, which is easy to connect to any Emscripten Pure Data Patch.
- It would be really nice if the [ofelia define] object could return a value through the outlet if an embind function is called from C++ / Java Script.
At the moment the values are banged from a 10ms [metro], which is not optimal...
- it would be great to directly load userdata from java script to Emscripten Ofelia, so the conversion to and from arrays would not be necessary.
- I would like to get rid of the security warnings, that appear because of webMIDI and webAudio...
- Another idea is to have the Ofelia Window fullscreen on a subpage that is controllable from a Java Script interfache on the main page.
- And, because I am not very experienced, it is possible that there are some bad mistakes in my code.
But I tried my best, and it seems to work.
Would be nice if somebody more experienced can have a look.
Of course there are some disadvantages compared to a desktop app:
- MIDI is not as tight (but quite good for the internet, still - it could be optimized).
- Loading a picture or a big sound file while audio is running drops the audio.
- It accepts only .bmp images.
- the size is more limited.