|
|
@ -37,6 +37,15 @@ struct Listener { |
|
|
|
unsigned int message; |
|
|
|
}; |
|
|
|
std::vector<Listener> listeners; |
|
|
|
/* Definition and declaration of the array buffer for received OSC Strings.
|
|
|
|
* All received OSC strings that match a listener are stored here until they are |
|
|
|
* fetched by the calling script. */ |
|
|
|
struct StoredString { |
|
|
|
std::string string; |
|
|
|
int id; |
|
|
|
}; |
|
|
|
std::vector<StoredString> storedStrings; |
|
|
|
const int storedStringsMaxSize = 100; |
|
|
|
/* Handle to the calling window, also indicates if this OSC receiver is "opened" by being != NULL*/ |
|
|
|
HWND hwnd = NULL; |
|
|
|
/* OSC receiving objects and thread.
|
|
|
@ -109,6 +118,7 @@ DLLEXPORT int close(unsigned int clearListeners) |
|
|
|
oscThread = NULL; |
|
|
|
hwnd = NULL; |
|
|
|
if (clearListeners) listeners.clear(); |
|
|
|
storedStrings.clear(); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
@ -140,6 +150,52 @@ DLLEXPORT int removeListener(LPCSTR address_) |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
DLLEXPORT char* getStringData(char* targetString, unsigned int targetSize, unsigned int stringId) |
|
|
|
{ |
|
|
|
for (UINT i = 0; i < storedStrings.size(); i++) |
|
|
|
{ |
|
|
|
if (storedStrings[i].id == stringId) |
|
|
|
{ |
|
|
|
strcpy_s(targetString, targetSize, storedStrings[i].string.c_str()); |
|
|
|
storedStrings.erase(storedStrings.begin() + i); |
|
|
|
return targetString; |
|
|
|
} |
|
|
|
} |
|
|
|
//Return empty string if nothing was found.
|
|
|
|
strcpy_s(targetString, targetSize, "\0"); |
|
|
|
return targetString; |
|
|
|
} |
|
|
|
|
|
|
|
void removeStoredString(int stringId) |
|
|
|
{ |
|
|
|
for (UINT i = 0; i < storedStrings.size(); i++) |
|
|
|
{ |
|
|
|
if (storedStrings[i].id == stringId) |
|
|
|
{ |
|
|
|
storedStrings.erase(storedStrings.begin() + i); |
|
|
|
return; //Every ID is unique in the array, no need to keep searching.
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
int addStoredString(std::string theString) |
|
|
|
{ |
|
|
|
static int storedStringsNextId = 0; |
|
|
|
|
|
|
|
int storedStringsThisId = storedStringsNextId; |
|
|
|
if (storedStringsNextId == INT_MAX) storedStringsNextId = 0; |
|
|
|
else storedStringsNextId++; |
|
|
|
|
|
|
|
//Make sure every ID is unique in the array.
|
|
|
|
removeStoredString(storedStringsThisId); |
|
|
|
//Limit array size to fixed value
|
|
|
|
if (storedStrings.size() >= storedStringsMaxSize) storedStrings.erase(storedStrings.begin()); |
|
|
|
|
|
|
|
storedStrings.push_back(StoredString{ theString, storedStringsThisId }); |
|
|
|
|
|
|
|
return storedStringsThisId; |
|
|
|
} |
|
|
|
|
|
|
|
unsigned int getOscType(osc::ReceivedMessage::const_iterator arg) |
|
|
|
{ |
|
|
|
if (arg->IsBlob()) return OSC_TYPE_BLOB; |
|
|
@ -237,7 +293,9 @@ int handleOscMsg(const osc::ReceivedMessage& m) |
|
|
|
ret++; |
|
|
|
} |
|
|
|
else if (msgType == OSC_TYPE_STRING) { |
|
|
|
OutputDebugString(L"handleOScMsg: String not implemented yet"); //TODO
|
|
|
|
PostMessage(hwnd, listeners[i].message, |
|
|
|
OSC_TYPE_STRING, |
|
|
|
addStoredString( std::string(m.ArgumentsBegin()->AsString()) ) ) ; |
|
|
|
} |
|
|
|
else if (msgType == OSC_TYPE_BLOB) { |
|
|
|
OutputDebugString(L"handleOScMsg: Blob not implemented yet"); //TODO
|
|
|
|