Jamoma API  0.6.0.a19
TTOscSend.cpp
1 /*
2  * Jamoma OSC Sender
3  * Copyright © 2011, Théo de la Hogue
4  *
5  * License: This code is licensed under the terms of the "New BSD License"
6  * http://creativecommons.org/licenses/BSD/
7  */
8 
9 #include "TTOscSend.h"
10 
11 #define thisTTClass TTOscSend
12 #define thisTTClassName "osc.send"
13 #define thisTTClassTags "network, send"
14 
15 
17 mAddress(kTTSymEmpty),
18 mPort(0),
19 mSocket(NULL)
20 {
23 
25 }
26 
27 TTOscSend::~TTOscSend()
28 {
29  delete mSocket;
30 }
31 
32 void TTOscSend::connect()
33 {
34  if (mAddress && mPort && (mAddress != kTTSymEmpty)) {
35 
36  delete mSocket;
37  mSocket = new TTOscSocket(mAddress.c_str(), mPort);
38  }
39 }
40 
41 TTErr TTOscSend::setAddress(const TTValue& newValue)
42 {
43  TTSymbol newAddress = newValue;
44  TTErr err = kTTErrNone;
45 
46  if (mAddress != newAddress) {
47  mAddress = newAddress;
48  connect();
49  }
50  return err;
51 }
52 
53 TTErr TTOscSend::setPort(const TTValue& newValue)
54 {
55  TTUInt16 newPort = newValue;
56  TTErr err = kTTErrNone;
57 
58  if (mPort != newPort) {
59  mPort = newPort;
60  connect();
61  }
62  return err;
63 }
64 
65 TTErr TTOscSend::send(const TTValue& value, TTValue& unusedOutput)
66 {
67  TTSymbol message;
68  TTValuePtr arguments;
69 
70  if (mSocket) {
71 
72  // set all application parameters using a TTHash
73  if (value.size() == 2 ) {
74 
75  if (value[0].type() == kTypeSymbol && value[1].type() == kTypePointer) {
76 
77  message = value[0];
78  arguments = TTValuePtr((TTPtr)value[1]);
79 
80  return mSocket->SendMessage(message, *arguments);
81  }
82  }
83  }
84 
85  return kTTErrGeneric;
86 }
std::uint16_t TTUInt16
16 bit unsigned integer
Definition: TTBase.h:176
size_type size() const noexcept
Return the number of elements.
Symbol type.
Definition: TTBase.h:282
16-bit unsigned integer, range is 0 through 65,535.
Definition: TTBase.h:276
void * TTPtr
A generic pointer.
Definition: TTBase.h:248
TTOscSocket is ...
Definition: TTOscSocket.h:39
The TTSymbol class is used to represent a string and efficiently pass and compare that string...
Definition: TTSymbol.h:26
#define addMessageWithArguments(name)
A convenience macro to be used by subclasses for registering messages.
Definition: TTMessage.h:27
const char * c_str() const
Return a pointer to the internal string as a C-string.
Definition: TTSymbol.h:77
Something went wrong, but what exactly is not known. Typically used for context-specific problems...
Definition: TTBase.h:344
TTErr
Jamoma Error Codes Enumeration of error codes that might be returned by any of the TTBlue functions a...
Definition: TTBase.h:342
Pointer type.
Definition: TTBase.h:284
#define addAttributeWithSetter(name, type)
A convenience macro to be used by subclasses for registering attributes with a custom setter...
Definition: TTAttribute.h:47
No Error.
Definition: TTBase.h:343
TT_OBJECT_CONSTRUCTOR
Constructor macro.
[doxygenAppendixC_copyExample]
Definition: TTValue.h:34