Skip to content
Snippets Groups Projects
Commit 0a2efad2 authored by Florent Berthaut's avatar Florent Berthaut
Browse files

Update for reverberations

parent 445b278d
No related branches found
No related tags found
No related merge requests found
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
...@@ -63,6 +63,17 @@ void GdPd::_bind_methods() { ...@@ -63,6 +63,17 @@ void GdPd::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_pd_patch"), ClassDB::bind_method(D_METHOD("get_pd_patch"),
&GdPd::get_pd_patch); &GdPd::get_pd_patch);
ClassDB::bind_method(D_METHOD("set_addon_patches_folder",
"p_addon_patches_folder"),
&GdPd::set_addon_patches_folder);
ClassDB::bind_method(D_METHOD("get_addon_patches_folder"),
&GdPd::get_addon_patches_folder);
ClassDB::bind_method(D_METHOD("set_application_name",
"p_application_name"),
&GdPd::set_application_name);
ClassDB::bind_method(D_METHOD("get_application_name"),
&GdPd::get_application_name);
ClassDB::bind_method(D_METHOD("send"), &GdPd::send); ClassDB::bind_method(D_METHOD("send"), &GdPd::send);
...@@ -75,6 +86,10 @@ void GdPd::_bind_methods() { ...@@ -75,6 +86,10 @@ void GdPd::_bind_methods() {
"set_osc_address", "get_osc_address"); "set_osc_address", "get_osc_address");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "pd_patch", PROPERTY_HINT_FILE), ADD_PROPERTY(PropertyInfo(Variant::STRING, "pd_patch", PROPERTY_HINT_FILE),
"set_pd_patch", "get_pd_patch"); "set_pd_patch", "get_pd_patch");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "addon_patches_folder"),
"set_addon_patches_folder", "get_addon_patches_folder");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "application_name"),
"set_application_name", "get_application_name");
ADD_SIGNAL(MethodInfo("got_message", ADD_SIGNAL(MethodInfo("got_message",
PropertyInfo(Variant::STRING, "address"), PropertyInfo(Variant::STRING, "address"),
...@@ -88,6 +103,8 @@ GdPd::GdPd() { ...@@ -88,6 +103,8 @@ GdPd::GdPd() {
m_rtDefaults=true; m_rtDefaults=true;
m_player=NULL; m_player=NULL;
osc_address = String(MULTICAST_ADDRESS.c_str()); osc_address = String(MULTICAST_ADDRESS.c_str());
addon_patches_folder = "res://addons/gdpd/patches";
m_applicationNameStr = "patch";
} }
GdPd::~GdPd() {} GdPd::~GdPd() {}
...@@ -95,7 +112,7 @@ GdPd::~GdPd() {} ...@@ -95,7 +112,7 @@ GdPd::~GdPd() {}
int GdPd::audioCallback(void *outputBuffer, void *inputBuffer, int GdPd::audioCallback(void *outputBuffer, void *inputBuffer,
unsigned int nBufferFrames, double streamTime, unsigned int nBufferFrames, double streamTime,
RtAudioStreamStatus status, void *userData){ RtAudioStreamStatus status, void *userData) {
GdPd* gdpd = static_cast<GdPd*>(userData); GdPd* gdpd = static_cast<GdPd*>(userData);
gdpd->processAudio(outputBuffer, inputBuffer, nBufferFrames); gdpd->processAudio(outputBuffer, inputBuffer, nBufferFrames);
return 0; return 0;
...@@ -184,8 +201,8 @@ int GdPd::start() { ...@@ -184,8 +201,8 @@ int GdPd::start() {
//FIXME add local port in addition to multicast //FIXME add local port in addition to multicast
m_receiver = lo_server_new_multicast( m_receiver = lo_server_new_multicast(
MULTICAST_ADDRESS.c_str(), MULTICAST_ADDRESS.c_str(),
std::to_string(RECEIVER_PORT).c_str(), std::to_string(RECEIVER_PORT).c_str(),NULL);
errorHandler); //errorHandler);
/* /*
m_receiver = lo_server_new_with_proto( m_receiver = lo_server_new_with_proto(
std::to_string(RECEIVER_PORT).c_str(), std::to_string(RECEIVER_PORT).c_str(),
...@@ -342,13 +359,13 @@ void GdPd::send(String address, Array arguments) { ...@@ -342,13 +359,13 @@ void GdPd::send(String address, Array arguments) {
} }
std::string addrStr(address.utf8().get_data()); std::string addrStr(address.utf8().get_data());
addrStr = std::string("/gdpd/patch/")+addrStr; addrStr = std::string("/gdpd/")+m_applicationNameStr+"/"+addrStr;
lo_send_message(m_destination, addrStr.c_str(), msg); lo_send_message(m_destination, addrStr.c_str(), msg);
} }
else { else {
libpd_start_message(arguments.size()+2); libpd_start_message(arguments.size()+2);
libpd_add_symbol("gdpd"); libpd_add_symbol("gdpd");
libpd_add_symbol("patch"); libpd_add_symbol(m_applicationNameStr.c_str());
libpd_add_symbol(String(address).utf8().get_data()); libpd_add_symbol(String(address).utf8().get_data());
for(int i=0; i<arguments.size(); ++i) { for(int i=0; i<arguments.size(); ++i) {
switch(arguments[i].get_type()) { switch(arguments[i].get_type()) {
...@@ -372,10 +389,9 @@ void GdPd::_process(double delta) { ...@@ -372,10 +389,9 @@ void GdPd::_process(double delta) {
if(!m_init) { if(!m_init) {
return; return;
} }
if(mode==OSC) { if(mode==OSC) {
if(m_receiver!=NULL) { if(m_receiver!=NULL) {
lo_server_recv_noblock(m_receiver, 1); lo_server_recv_noblock(m_receiver, 10);
} }
} }
else { else {
...@@ -410,22 +426,21 @@ void GdPd::processAudio(void *outputBuffer, void *inputBuffer, ...@@ -410,22 +426,21 @@ void GdPd::processAudio(void *outputBuffer, void *inputBuffer,
} }
bool GdPd::open_patch() { bool GdPd::open_patch() {
std::string pdPatchStr;
std::string pdDirStr;
//If opening from editor, just set the paths //If opening from editor, just set the paths
if(OS::get_singleton()->has_feature("editor")) { if(OS::get_singleton()->has_feature("editor")) {
print("Loading patch from editor");
String fullpath = ProjectSettings::get_singleton() String fullpath = ProjectSettings::get_singleton()
->globalize_path(pd_patch); ->globalize_path(pd_patch);
String pat = fullpath.get_slice("/",fullpath.get_slice_count("/")-1); String pat = fullpath.get_slice("/",fullpath.get_slice_count("/")-1);
String dir = fullpath.trim_suffix(pat); String dir = fullpath.trim_suffix(pat);
pdPatchStr = std::string(pat.utf8().get_data()); m_pdPatchStr = std::string(pat.utf8().get_data());
pdDirStr = std::string(dir.utf8().get_data()); m_pdDirStr = std::string(dir.utf8().get_data());
print("Loading patch "+m_pdPatchStr
+" from editor at path "
+m_pdDirStr);
} }
else { else {
// Otherwise, copy the files to user folder // Otherwise, copy the files to user folder
...@@ -435,9 +450,11 @@ bool GdPd::open_patch() { ...@@ -435,9 +450,11 @@ bool GdPd::open_patch() {
if(OS::get_singleton()->get_name() == "Android") { if(OS::get_singleton()->get_name() == "Android") {
print("On Android, so start copying files to user folder"); print("On Android, so start copying files to user folder");
String packageName = "com.example.gdpd"; String packageName = ProjectSettings::get_singleton()
->globalize_path("user://").trim_suffix("/").rsplit("/")[2];
print(packageName.utf8().get_data());
//FIXME get Android package name
userPath = String("/sdcard/Android/data/") userPath = String("/sdcard/Android/data/")
+ packageName + packageName
+ String("/files/"); + String("/files/");
...@@ -454,39 +471,38 @@ bool GdPd::open_patch() { ...@@ -454,39 +471,38 @@ bool GdPd::open_patch() {
//Recursively copy this folder from res to user directory //Recursively copy this folder from res to user directory
recurseCopy("res://"+patchDir, userPath+patchDir); recurseCopy("res://"+patchDir, userPath+patchDir);
//Also copy gdpd patches //Also copy gdpd patches from patches folder
std::vector<String> gdpdFiles{"gdpd.pd", "gdpd_send.pd", std::vector<String> gdpdFiles{"gdpd.pd", "gdpd_send.pd",
"gdpd_receive.pd"}; "gdpd_receive.pd"};
for(auto& f : gdpdFiles) { for(auto& f : gdpdFiles) {
Ref<DirAccess> diracc = DirAccess::open("res://"); Ref<DirAccess> diracc = DirAccess::open("res://");
diracc->copy("res://addons/gdpd/patches/"+f, diracc->copy(addon_patches_folder+"/"+f,
userPath+patchDir+"/"+f); userPath+patchDir+"/"+f);
} }
//Define new paths //Define new paths
pdPatchStr = std::string(patch.utf8().get_data()); m_pdPatchStr = std::string(patch.utf8().get_data());
pdDirStr = std::string((userPath+patchDir).utf8().get_data()); m_pdDirStr = std::string((userPath+patchDir).utf8().get_data());
} }
// Open the patch // Open the patch
m_patchOpened=false; m_patchOpened=false;
pd::Patch p1 = m_pd.openPatch(pdPatchStr.c_str(), pdDirStr.c_str()); pd::Patch p1 = m_pd.openPatch(m_pdPatchStr.c_str(), m_pdDirStr.c_str());
/*
if(!p1.isValid()) { if(!p1.isValid()) {
print("Could not open patch "+pdPatchStr); print("Could not open patch "+m_pdPatchStr);
return false; return false;
} }
else { else {
print("Opened patch "+pdPatchStr); print("Opened patch "+m_pdPatchStr);
m_patchOpened=true; m_patchOpened=true;
std::string patchStr(pd_patch.utf8().get_data()); std::string patchStr(pd_patch.utf8().get_data());
m_patchsMap[patchStr] = p1; m_patchsMap[patchStr] = p1;
} }*/
return true; return true;
} }
void GdPd::recurseCopy(String fromPath, String toPath) { void GdPd::recurseCopy(String fromPath, String toPath) {
//Create the toPath folder //Create the toPath folder
DirAccess::make_dir_absolute(toPath); DirAccess::make_dir_absolute(toPath);
...@@ -505,7 +521,6 @@ void GdPd::recurseCopy(String fromPath, String toPath) { ...@@ -505,7 +521,6 @@ void GdPd::recurseCopy(String fromPath, String toPath) {
String dirName = dirs[i]; String dirName = dirs[i];
recurseCopy(fromPath+"/"+dirName, toPath+"/"+dirName); recurseCopy(fromPath+"/"+dirName, toPath+"/"+dirName);
} }
} }
void GdPd::close_patch() { void GdPd::close_patch() {
......
...@@ -58,7 +58,6 @@ protected: ...@@ -58,7 +58,6 @@ protected:
lo_arg ** argv, lo_arg ** argv,
int argc, lo_message msg, void *user_data) { int argc, lo_message msg, void *user_data) {
GdPd* gdpd = (GdPd*)user_data; GdPd* gdpd = (GdPd*)user_data;
std::cout<<"got osc message"<<std::endl;
gdpd->handleOSC(path, types, argv, argc, msg); gdpd->handleOSC(path, types, argv, argc, msg);
return 0; return 0;
} }
...@@ -97,6 +96,12 @@ private: ...@@ -97,6 +96,12 @@ private:
String pd_patch; String pd_patch;
String pd_folder; String pd_folder;
bool m_patchOpened; bool m_patchOpened;
String addon_patches_folder;
std::string m_pdPatchStr;
std::string m_pdDirStr;
String application_name;
std::string m_applicationNameStr;
const int SENDER_PORT = 9211; const int SENDER_PORT = 9211;
const int RECEIVER_PORT = 9212; const int RECEIVER_PORT = 9212;
...@@ -133,6 +138,16 @@ public: ...@@ -133,6 +138,16 @@ public:
inline String get_pd_folder() const{return pd_folder;} inline String get_pd_folder() const{return pd_folder;}
inline void set_pd_patch(const String p_patch){pd_patch=p_patch;} inline void set_pd_patch(const String p_patch){pd_patch=p_patch;}
inline String get_pd_patch() const{return pd_patch;} inline String get_pd_patch() const{return pd_patch;}
inline void set_addon_patches_folder(const String p_addon_patches_folder){
addon_patches_folder=p_addon_patches_folder;
}
inline String get_addon_patches_folder() const{return addon_patches_folder;}
inline void set_application_name(const String p_application_name){
application_name=p_application_name;
m_applicationNameStr = application_name.utf8().get_data();
}
inline String get_application_name() const{return application_name;}
inline void set_osc_address(const String p_osc_address) { inline void set_osc_address(const String p_osc_address) {
osc_address = p_osc_address; osc_address = p_osc_address;
......
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment