Embind Interacting with code

I figured out how to use EM_ASM macros with Open Frameworks, which calls Java Script functions from C++. Now I wonder if it is possible to call Open Frameworks functions from Java Script and pass simple data types like integers, floats and strings.

There are the WebIDLBinder and Embind, especially Embind and its val.h class could be a solution,
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#embind
https://emscripten.org/docs/api_reference/val.h.html
Are there any examples how to use Embind with Open Frameworks?

I have an idea, not sure if it makes sense. This example from the embind link above does work:

// quick_example.cpp
#include <emscripten/bind.h>

using namespace emscripten;

float lerp(float a, float b, float t) {
    return (1 - t) * a + t * b;
}

EMSCRIPTEN_BINDINGS(my_module) {
    function("lerp", &lerp);
}

emcc --bind -o quick_example.js quick_example.cpp
If I could use the code in an ofApp.cpp file and compile it like:
emcc --bind -o ofEmbindTest.js ofApp.cpp
then it could be possible to use embind with Open Frameworks?
My problem is if I try to compile it with emcc --bind all the include files are missing (because, in opposite to “emmake make”, there is no makefile involved?). Is there a way to add the missing include paths (like for ofMain.h, ofConstants.h)? Or does it make no sense to try it at all?

Here is a test that calls a c++ function with embind from java script with the (java script) slider value as an argument, which works quite well(with the lerp function from the post above):

<!doctype html>
<html>
  <script>var Module = {onRuntimeInitialized: function(){}}</script>
  <script src="quick_example.js"></script>
    <strong>Sides: </strong>
    <form>
    <input type="range" id="Kaleidoscope2_Sides" name="Kaleidoscope2_Sides_range" min="1" max="32" step="1" value="8"  oninput="calculate(), this.form.Kaleidoscope2_Sides_input.value=this.value"/>
    <input type="number" name="Kaleidoscope2_Sides_input" min="1" max="32" value="8" oninput= "calculate(),this.form.Kaleidoscope2_Sides_range.value=this.value"/>
    </form>
    <br>
  <script>
  function calculate() 
    {
    console.log("Slider value: " + document.getElementById("Kaleidoscope2_Sides").value);
    console.log('Lerp result: ' + Module.lerp(1, parseFloat(document.getElementById("Kaleidoscope2_Sides").value), 0.5));
    }
  </script>
</html>

But calling Open Frameworks functions from Java script with embind seems almost impossible (to me), because Open Frameworks Emscripten is compiled with emmake, while embind is compiled with emcc. Would be nice if I am wrong. The only possibility to get Java Script values into Open Frameworks for now seems to call the EM_ASM macros in Open Frameworks frequently and “grab” the Java Script values that way…
To use --bind with emmake would be a great solution, but I think that is not possible?

Actually it does work if I put the code like this into ofApp.cpp:

#include <emscripten/bind.h>

float lerp(float a, float b, float t) {
    return (1 - t) * a + t * b;
}

EMSCRIPTEN_BINDINGS(my_module) {
 emscripten::function("lerp", &lerp);
}

I have a question, I think it is more of a general beginner question than Emscripten related. I am not sure if I can explain it well: While the above code works and I can send values with Embind to ofxOfelia via Lua or print the result I do not know how I can send values with Embind to another function in ofApp.cpp.
The code below is a part from the ofxPd pdexample, what I want to do is to call playTone() with Embind, but the error message is: playNote() is not defined.
While the same is possible with void ofApp::keyPressed (int key){} Another idea was to call ofApp::playTone{} with embind, but that is also not possible.
Is there an easy way achieve what I want?

void ofApp::playTone(int pitch) {
	pd << StartMessage() << "pitch" << pitch << FinishList("tone") << Bang("tone");
}

//--------------------------------------------------------------
void ofApp::keyPressed (int key) {

	switch(key) {
		
		// musical keyboard
		case 'a':
			playTone(60);
			break;
		case 'w':
			playTone(61);
			break;
		case 's':
			playTone(62);
			break;
		case 'e':
			playTone(63);
			break;
		case 'd':
			playTone(64);
			break;
		case 'f':
			playTone(65);
			break;

		case ' ':
			if(pd.isReceivingSource(*this, "env")) {
				pd.ignoreSource(*this, "env");
				cout << "ignoring env" << endl;
			}
			else {
				pd.receiveSource(*this, "env");
				cout << "receiving from env" << endl;
			}
			break;

		default:
			break;
	}
}
void embind_1(float pitch) { 
  playTone(pitch);
  }
EMSCRIPTEN_BINDINGS(my_module) {    
  emscripten::function("embind_1", &embind_1);  
  }