I hope I have the right terms for my question.
So normally I would declare variables in the class of the ofApp.h file or inside ofApp::functions in the ofApp.cpp file. In this case I have Emscripten bindings in ofApp.cpp for some functions of the ofApp.h file.
All variables that need to be accessed from both need to be declared in the ofApp.cpp file outside of the class.
I also tried to put the bindings in the .h file, but its not allowed to declare two ofApp classes in one file.
My question is, should I avoid declaring variables like that? And is there a better way to achieve that?
Before I was using notify, but this attempt seems more direct.
This is the basic part of the code in ofApp.cpp:
That is the error I get, if I try to define the bindings in ofApp.h: "Cannot register public name 'ofApp' twice"
If rename it to Test, I get this: "Cannot register public name 'Test' twice"
Hi, it shouldn’t be a problem to declare variables outside of the class in the cpp file, although, these will behave somehow as a static variable and you shouldn’t be able to access it from a class on a different file. I am not sure why you would want to declare two ofApp classes but it sounds like a bad idea. It is just calling for confusion.
There are several ways of allowing each class to see the other but I am not sure what it is taht you want to achieve. can you clarify please
?
Edit: Here is a new attempt without two ofApp classes, I still need to declare the shared variables outside the ofApp class in the ofApp.cpp file (because I do not have an idea how to solve this better…):
I see. you can use std::bind to bind a function member class to its instance and pass it to emscripten::function(...) already binded.
should look something like he following. emscripten::function("bla",std::bind(&ofApp::someClassFunction, this, std::placeholders::_1)))
Hi @Jona! I’ve been following along with some of your recent threads, including this one. So what happens if you put these three in ofApp (and include headers as needed), with the most recent attempt (just above)? Also hi @roymacdonald! Fun to see you in the forum and I’ve missed your frequent posts.
I’ve been thinking about this today. I thought maybe a lambda might be a good way to do this. But also maybe emscripten::function() needs to have the video player as well as the string:
// in ofApp.h
#include ofxEmscriptenVideoPlayer.h
ofxEmscriptenVideoPlayer videoPlayer; // maybe this isn't even needed?
// in ofApp
void loadVideoUrl(ofxEmscriptenVideoPlayer& player, std::string url){
player.load(url);
player.play();
}
// in ofApp::setup()
// use a lambda
emscripten::function("loadVideoUrl", [this](ofxEmscriptenVideoPlaye& p, std::string s){loadVideoUrl(p, s);});
I wish I could be more help with this. I don’t know emscripten at all and how it works, and I don’t have it set up anywhere so that I can test it out. The fact that I can’t add ofxEmscripten to a project on macOS makes me think that the addon only gets used by emscripten itself, and isn’t intended to be used by ofApp. Anyhow, I’ll keep following this thread and one day I hope to give emscripten a try.
Edit: If you try this and it fails, also try a const params, though this seems like it would not work because of changing the state of the video player. But, just in case it works for some reason:
Hi @TimChi I’ve been super busy, that’s why I have not been very active here. @Jona
Ah, the problem has to do with the function type.
Does something like the following, where loadViewUrl is an ofApp member function?
@roymacdonald thank you, thats the solution.
In ofApp.cpp I had to do: emscripten::function("loadMidiInDevices", this->loadMidiInDevices);
And in ofApp.h I had to make the function static: static void loadMidiInDevices(std::string string);
I still would like to know, if it is possible to bind to a non-static member (because other problems appear because of the static members).
Similar methods are mentioned in this thread, but it does not seem to work in my case.