Firstly, credit where credit is due for Julien Pommier making the oscpkt package.
Ok, here's how I have it working for me.....
Add to your project and include oscpkt.hh and udp.hh in your plugin header file, from the oscpkt package -
http://gruntthepeon.free.fr/oscpkt/.
In my main plugin.h file i added:
Code:
oscpkt::UdpSocket SendSocket;
oscpkt::UdpSocket ReceiveSocket;
oscpkt::PacketReader pktreceive;
oscpkt::PacketWriter pktsend;
oscpkt::Message *OscReceiveMessage;
oscpkt::Message OscSendMessage;
Next, in my main plugin.cpp constructor I placed -
Code:
if (!SendSocket.connectTo("localhost", 10001) {
SendSocket.close();
OscSendConnectedFlag = false; // flag I have to tell me if connection is made
}
else {
OscSendConnectedFlag = true;
}
if (!ReceiveSocket.bindTo(10000)) {
ReceiveSocket.close();
OscReceiveConnectedFlag = false; // flag I have to tell me if connection is made
}
else {
OscReceiveConnectedFlag = true;
}
OscConnectionFlag = false;
Next, in ProcessDoubleReplacing, a call to ParseOscInput() - defined in main plugin header file
Code:
SampleCounter = ParsingRefreshRate; // a rate for parsing set somewhere else. Easy to invent your own based on samples.
for (int s = 0; s < nFrames; ++s, ++in1, ++in2)
{
if (SampleCounter == ParsingRefreshRate && (GetGUI())) {
ParseOscInput();
}
SampleCounter = 0;
}
SampleCounter++;
}
And the parsing function (excerpt from my code where I am shaking hands with the remote connection software, generally an iPad or maxmsp.
Code:
void MyPlugin::ParseOscInput()
{
if (ReceiveSocket.receiveNextPacket(0)) {
pktreceive.init(ReceiveSocket.packetData(), ReceiveSocket.packetSize());
while (pktreceive.isOk() && (OscReceiveMessage = pktreceive.popMessage()) != 0) {
// match incoming message, in this case with no args. See oscpkt files for receiving int/float/string
if (OscReceiveMessage->match("/RemoteOscHandshakeConfirmed").isOkNoMoreArgs()) {
// Sample output message
pktsend.init();
pktsend.startBundle();
pktsend.addMessage(OscSendMessage.init("/RemoteOscConnectedFlag").pushBool(true));
pktsend.endBundle();
SendSocket.sendPacket(pktsend.packetData(), pktsend.packetSize());
}
}
}
Please be warned though, and I remind you, this works for my purposes, there's no thought about potential threading issues, I have only compiled for Mac, using Xcode latest and osx10.5 sdk, and a version of wdl-ol.
I hope this makes sense and I haven't missed something. tbh these code snippets are cut and pasted from rather a more complicated setup,where I have text boxes to set host name and ports.
Anyone with any thoughts, or remarks feel free to chime in ('ding dong, you done it all wrong') !
Have fun,
Leigh