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

Fix messages from/to pd

parent 0a2efad2
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.
......@@ -366,7 +366,10 @@ void GdPd::send(String address, Array arguments) {
libpd_start_message(arguments.size()+2);
libpd_add_symbol("gdpd");
libpd_add_symbol(m_applicationNameStr.c_str());
libpd_add_symbol(String(address).utf8().get_data());
Array addrArray = address.split("/");
for(int i=0; i<addrArray.size(); ++i) {
libpd_add_symbol(String(addrArray[i]).utf8().get_data());
}
for(int i=0; i<arguments.size(); ++i) {
switch(arguments[i].get_type()) {
case Variant::INT :
......@@ -401,21 +404,49 @@ void GdPd::_process(double delta) {
void GdPd::handleOSC(const char* path, const char* types,
lo_arg** argv, int argc, lo_message msg) {
Array gdList;
for(int i = 0; i < argc; ++i) {
switch(types[i]) {
case 'f' :
gdList.push_back(argv[i]->f);
break;
case 'i' :
gdList.push_back(argv[i]->i);
break;
case 's' :
gdList.push_back(String(&(argv[i]->s)));
break;
}
}
emit_signal("got_message", String(path), gdList);
if(std::string(path).find("/gdpd/"+m_applicationNameStr)==0) {
Array gdList;
for(int i = 0; i < argc; ++i) {
switch(types[i]) {
case 'f' :
gdList.push_back(argv[i]->f);
break;
case 'i' :
gdList.push_back(argv[i]->i);
break;
case 's' :
gdList.push_back(String(&(argv[i]->s)));
break;
}
}
emit_signal("got_message", String(path), gdList);
}
}
void GdPd::receiveList(const std::string& dest, const pd::List& list) {
if(dest == "to_godot") {
//retrieve address
int nb_addr = list.getFloat(2);
int start_addr = 3;
std::string addr = "/"+std::string(list.getSymbol(0).c_str())
+"/"+std::string(list.getSymbol(1).c_str());
for(int i = start_addr; i < start_addr + nb_addr; ++i) {
addr += "/"+std::string(list.getSymbol(i).c_str());
}
//retrieve agruments
Array gdList;
for(int i = start_addr+nb_addr; i < list.len(); ++i) {
if(list.isFloat(i)) {
gdList.push_back(list.getFloat(i));
}
else if(list.isSymbol(i)) {
String symbStr(list.getSymbol(i).c_str());
gdList.push_back(symbStr);
}
}
emit_signal("got_message", String(addr.c_str()), gdList);
}
}
void GdPd::processAudio(void *outputBuffer, void *inputBuffer,
......@@ -487,8 +518,8 @@ bool GdPd::open_patch() {
// Open the patch
m_patchOpened=false;
pd::Patch p1 = m_pd.openPatch(m_pdPatchStr.c_str(), m_pdDirStr.c_str());
/*
//FIXME fix issue in libpd with itoa in dollarzero
pd::Patch p1 = m_pd.openPatch(m_pdPatchStr, m_pdDirStr);
if(!p1.isValid()) {
print("Could not open patch "+m_pdPatchStr);
return false;
......@@ -498,7 +529,7 @@ bool GdPd::open_patch() {
m_patchOpened=true;
std::string patchStr(pd_patch.utf8().get_data());
m_patchsMap[patchStr] = p1;
}*/
}
return true;
}
......@@ -538,19 +569,6 @@ void GdPd::print(const std::string& message) {
UtilityFunctions::print((std::string("GdPd : ")+message).c_str());
}
void GdPd::receiveList(const std::string& dest, const pd::List& list) {
Array gdList;
for(int i = 0; i < list.len(); ++i) {
if(list.isFloat(i)) {
gdList.push_back(list.getFloat(i));
}
else if(list.isSymbol(i)) {
String symbStr(list.getSymbol(i).c_str());
gdList.push_back(symbStr);
}
}
emit_signal("got_message", String(dest.c_str()), gdList);
}
/* GdPdStream */
GdPdStream::GdPdStream() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment