20 #define thisTTClass OSC
21 #define thisTTClassName "OSC"
22 #define thisTTClassTags "network, protocol, osc"
24 #define thisProtocolVersion "0.1"
25 #define thisProtocolAuthor "Theo de la Hogue"
26 #define thisProtocolGet NO
27 #define thisProtocolSet YES
28 #define thisProtocolListen NO
29 #define thisProtocolDiscover NO
30 #define thisProtocolDiscoverAll NO
32 extern "C" TT_EXTENSION_EXPORT
TTErr TTLoadJamomaExtension_OSC(
void)
58 mDistantApplicationOscReceivers.getKeys(keys);
59 for (i = 0; i < keys.
size(); i++) {
61 distantApplicationName = keys[i];
62 Stop(distantApplicationName, out);
66 Stop(kTTValNONE, out);
70 delete mSenderManager;
96 if (inputValue.
size() == 0) {
103 mApplicationParameters.getKeys(keys);
105 if (Run(keys[i], outputValue))
115 if (inputValue.
size() == 1) {
119 applicationName = inputValue[0];
126 mSenderManager =
new OSCSenderManager();
130 if (applicationName == mLocalApplicationName) {
135 mLocalApplicationOscReceiver =
TTObject(
"osc.receive");
137 if (mLocalApplicationOscReceiver.valid()) {
144 ApplicationSelectLocal();
145 oscProtocol.get(
"port", v);
149 err = mLocalApplicationOscReceiver.
set(
"port", port);
154 mLocalApplicationOscReceiver.registerObserverForNotifications(oscProtocol);
158 TTLogMessage(
"OSC::Run : connected to port %ld for local application\n", port);
167 TTLogError(
"OSC::Run : unable to connect to port %ld for local application\n", port);
180 TTObject anOscReceiver, returnMessageCallback;
185 if (!mDistantApplicationOscReceivers.lookup(applicationName, v))
189 err = mApplicationParameters.lookup(applicationName, v);
200 if (!err && v.
size() == 2) {
203 receptionPort = v[1];
206 returnMessageCallback =
TTObject(
"callback");
209 returnMessageCallback.
set(kTTSym_baton, returnMessageBaton);
214 anOscReceiver =
TTObject(
"osc.receive", returnMessageCallback);
216 if (anOscReceiver.
valid()) {
218 err = anOscReceiver.
set(
"port", receptionPort);
225 mDistantApplicationOscReceivers.append(applicationName, anOscReceiver);
229 TTLogMessage(
"OSC::Run : connected to port %ld for %s application\n", receptionPort, applicationName.
c_str());
236 outputValue.
append(receptionPort);
238 TTLogError(
"OSC::Run : unable to connect to port %ld for %s application\n", receptionPort, applicationName.
c_str());
256 if (inputValue.
size() == 0) {
261 Stop(mLocalApplicationName, out);
264 mApplicationParameters.getKeys(keys);
274 if (inputValue.
size() == 1) {
278 applicationName = inputValue[0];
285 delete mSenderManager;
286 mSenderManager = NULL;
290 if (applicationName == mLocalApplicationName) {
295 mLocalApplicationOscReceiver =
TTObject();
309 if (!mDistantApplicationOscReceivers.lookup(applicationName, v)) {
312 mDistantApplicationOscReceivers.remove(applicationName);
398 if (address == mReceivedAddress && to == mReceivedFrom)
401 #ifdef TT_PROTOCOL_DEBUG
402 std::cout <<
"OSC::SendSetRequest : to " << address.
c_str() << std::endl;
408 return sendMessage(to, address, value);
501 TTErr err = mApplicationParameters.lookup(applicationName, v);
510 if (errIp || errPort)
514 message.append((
TTPtr)&arguments);
516 err = mSenderManager->send(applicationName, vIp, vPort, message);
529 ActivityOutMessage(v);
547 if (mActivity) ActivityInMessage(message);
549 aSymbol = message[0];
550 headerString = aSymbol.string();
553 if (headerString[0] ==
'/')
558 #ifdef TT_PROTOCOL_DEBUG
559 cout <<
"OSC::receivedMessage : at " << whereTo.
c_str() << endl;
562 return ReceiveSetRequest(kTTSymEmpty, whereTo, arguments);
571 OSCPtr anOscProtocol;
579 anOscProtocol = (OSCPtr)o.
instance();
583 anOscProtocol->mReceivedFrom = kTTSymEmpty;
584 anOscProtocol->mReceivedAddress = kTTAdrsEmpty;
590 if (anOscProtocol->mActivity) anOscProtocol->ActivityInMessage(data);
593 headerString = aSymbol.string();
596 if (headerString[0] ==
'/')
599 anOscProtocol->mReceivedFrom = from;
601 if (anOscProtocol->mReceivedAddress.getAttribute() == NO_ATTRIBUTE)
602 anOscProtocol->mReceivedAddress = anOscProtocol->mReceivedAddress.
appendAttribute(kTTSym_value);
606 #ifdef TT_PROTOCOL_DEBUG
607 cout <<
"OSCReceiveMessageCallback : from " << from.
c_str() <<
" at " << anOscProtocol->mReceivedAddress.c_str() << endl;
610 err = anOscProtocol->ReceiveListenAnswer(from, anOscProtocol->mReceivedAddress, arguments);
613 anOscProtocol->mReceivedFrom = kTTSymEmpty;
614 anOscProtocol->mReceivedAddress = kTTAdrsEmpty;
TTErr sendMessage(const TTSymbol name)
TODO: Document this function.
bool TTBoolean
Boolean flag, same as Boolean on the Mac.
std::uint16_t TTUInt16
16 bit unsigned integer
#define TT_PROTOCOL_INITIALIZE
Declares all members needed by any protocol class.
TTAddress appendAttribute(TTSymbol anAttribute)
Return a new TTAddress with attribute part.
TTErr lookup(const TTSymbol key, TTValue &value)
Find the value for the given key.
We build a directory of TTNodes, and you can request a pointer for any TTNode, or add an observer to ...
void copyFrom(const TTValue &obj, TTUInt16 index)
Copy a value starting from an index until the last element.
The TTAddress class is used to represent a string and efficiently pass and compare that string...
Create and use Jamoma object instances.
size_type size() const noexcept
Return the number of elements.
Maintain a collection of TTValue objects indexed by TTSymbol pointers.
TTErr OSCReceiveMessageCallback(const TTValue &baton, const TTValue &data)
16-bit unsigned integer, range is 0 through 65,535.
void prepend(const TTValue &aValueToPrepend)
Insert another TTValue before the first element.
void append(const T &anElementValueToAppend)
Insert a single TTElement at the end.
void * TTPtr
A generic pointer.
TTErr set(const TTSymbol aName, T aValue)
Set an attribute value for an object.
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
void TTFOUNDATION_EXPORT TTLogError(TTImmutableCString message,...)
Platform and host independent method for posting errors.
TTSymbol & getAttribute()
Get the attribute part.
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
const char * c_str() const
Return a pointer to the internal string as a C-string.
void clear()
Clear all values from the vector, leaving with size of 0.
void set(const TTUInt16 index, const T &anElementValue)
DEPRECATED.
void TTFOUNDATION_EXPORT TTLogMessage(TTImmutableCString message,...)
Platform and host independent method for posting log messages.
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
std::uint32_t TTUInt32
32 bit unsigned integer
TTObjectBase * instance() const
Return a direct pointer to the internal instance.
#define TT_PROTOCOL_CONSTRUCTOR
Declares instantiation and registration methods to add the protocol class as any TTObject class...
#define addAttributeAsProtocolParameter(name, type)
Add a protocol parameter as an attribute of the class.
TTAddress removeAttribute()
Return a new TTAddress without attribute part.
The TTString class is used to represent a string.
TTBoolean valid() const
Determine if the object contained by this TTObject is truly ready for use.
[doxygenAppendixC_copyExample]
unsigned char TTUInt8
8 bit unsigned integer (char)
#define addMessageProperty(messageName, propertyName, initialValue)
A convenience macro to be used for registering properties of messages.