modded version CNMAT/OSC https://github.com/CNMAT/OSC

Dependents:   CVtoOSCConverter

Fork of osc-cnmat by Asperius van Hansen

Committer:
aspeteRakete
Date:
Sat May 17 12:42:29 2014 +0000
Revision:
3:f58c63b78853
Child:
4:107c23eb31b6
init. Compiles, not tested. OSCMessage::send(Print &p) and OSC::Bundle::send(Print &p) commented out

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aspeteRakete 3:f58c63b78853 1 /*
aspeteRakete 3:f58c63b78853 2 Written by Yotam Mann, The Center for New Music and Audio Technologies,
aspeteRakete 3:f58c63b78853 3 University of California, Berkeley. Copyright (c) 2012, 2013, The Regents of
aspeteRakete 3:f58c63b78853 4 the University of California (Regents).
aspeteRakete 3:f58c63b78853 5
aspeteRakete 3:f58c63b78853 6 Permission to use, copy, modify, distribute, and distribute modified versions
aspeteRakete 3:f58c63b78853 7 of this software and its documentation without fee and without a signed
aspeteRakete 3:f58c63b78853 8 licensing agreement, is hereby granted, provided that the above copyright
aspeteRakete 3:f58c63b78853 9 notice, this paragraph and the following two paragraphs appear in all copies,
aspeteRakete 3:f58c63b78853 10 modifications, and distributions.
aspeteRakete 3:f58c63b78853 11
aspeteRakete 3:f58c63b78853 12 IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
aspeteRakete 3:f58c63b78853 13 SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING
aspeteRakete 3:f58c63b78853 14 OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF REGENTS HAS
aspeteRakete 3:f58c63b78853 15 BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
aspeteRakete 3:f58c63b78853 16
aspeteRakete 3:f58c63b78853 17 REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
aspeteRakete 3:f58c63b78853 18 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
aspeteRakete 3:f58c63b78853 19 PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED
aspeteRakete 3:f58c63b78853 20 HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO OBLIGATION TO PROVIDE
aspeteRakete 3:f58c63b78853 21 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
aspeteRakete 3:f58c63b78853 22
aspeteRakete 3:f58c63b78853 23
aspeteRakete 3:f58c63b78853 24 */
aspeteRakete 3:f58c63b78853 25
aspeteRakete 3:f58c63b78853 26 #ifndef OSCBUNDLE_h
aspeteRakete 3:f58c63b78853 27 #define OSCBUNDLE_h
aspeteRakete 3:f58c63b78853 28
aspeteRakete 3:f58c63b78853 29 #include "OSCMessage.h"
aspeteRakete 3:f58c63b78853 30
aspeteRakete 3:f58c63b78853 31 class OSCBundle
aspeteRakete 3:f58c63b78853 32 {
aspeteRakete 3:f58c63b78853 33
aspeteRakete 3:f58c63b78853 34 private:
aspeteRakete 3:f58c63b78853 35
aspeteRakete 3:f58c63b78853 36 /*=============================================================================
aspeteRakete 3:f58c63b78853 37 PRIVATE VARIABLES
aspeteRakete 3:f58c63b78853 38 =============================================================================*/
aspeteRakete 3:f58c63b78853 39
aspeteRakete 3:f58c63b78853 40 //the array of messages contained in the bundle
aspeteRakete 3:f58c63b78853 41 OSCMessage ** messages;
aspeteRakete 3:f58c63b78853 42
aspeteRakete 3:f58c63b78853 43 //the number of messages in the array
aspeteRakete 3:f58c63b78853 44 int numMessages;
aspeteRakete 3:f58c63b78853 45
aspeteRakete 3:f58c63b78853 46 uint64_t timetag;
aspeteRakete 3:f58c63b78853 47
aspeteRakete 3:f58c63b78853 48 //error codes
aspeteRakete 3:f58c63b78853 49 OSCErrorCode error;
aspeteRakete 3:f58c63b78853 50
aspeteRakete 3:f58c63b78853 51 /*=============================================================================
aspeteRakete 3:f58c63b78853 52 DECODING INCOMING BYTES
aspeteRakete 3:f58c63b78853 53 =============================================================================*/
aspeteRakete 3:f58c63b78853 54
aspeteRakete 3:f58c63b78853 55 //the decoding states for incoming bytes
aspeteRakete 3:f58c63b78853 56 enum DecodeState {
aspeteRakete 3:f58c63b78853 57 STANDBY,
aspeteRakete 3:f58c63b78853 58 HEADER,
aspeteRakete 3:f58c63b78853 59 TIMETAG,
aspeteRakete 3:f58c63b78853 60 MESSAGE_SIZE,
aspeteRakete 3:f58c63b78853 61 MESSAGE,
aspeteRakete 3:f58c63b78853 62 } decodeState;
aspeteRakete 3:f58c63b78853 63
aspeteRakete 3:f58c63b78853 64 //stores incoming bytes until they can be decoded
aspeteRakete 3:f58c63b78853 65 uint8_t * incomingBuffer;
aspeteRakete 3:f58c63b78853 66 int incomingBufferSize;
aspeteRakete 3:f58c63b78853 67
aspeteRakete 3:f58c63b78853 68 //the size of the incoming message
aspeteRakete 3:f58c63b78853 69 int incomingMessageSize;
aspeteRakete 3:f58c63b78853 70
aspeteRakete 3:f58c63b78853 71 //adds a byte to the buffer
aspeteRakete 3:f58c63b78853 72 void addToIncomingBuffer(uint8_t);
aspeteRakete 3:f58c63b78853 73 //clears the incoming buffer
aspeteRakete 3:f58c63b78853 74 void clearIncomingBuffer();
aspeteRakete 3:f58c63b78853 75
aspeteRakete 3:f58c63b78853 76 //decoding functions
aspeteRakete 3:f58c63b78853 77 void decode(uint8_t);
aspeteRakete 3:f58c63b78853 78 void decodeTimetag();
aspeteRakete 3:f58c63b78853 79 void decodeHeader();
aspeteRakete 3:f58c63b78853 80 void decodeMessage(uint8_t);
aspeteRakete 3:f58c63b78853 81
aspeteRakete 3:f58c63b78853 82 //just a placeholder while filling
aspeteRakete 3:f58c63b78853 83 OSCMessage & add();
aspeteRakete 3:f58c63b78853 84
aspeteRakete 3:f58c63b78853 85
aspeteRakete 3:f58c63b78853 86 public:
aspeteRakete 3:f58c63b78853 87
aspeteRakete 3:f58c63b78853 88 /*=============================================================================
aspeteRakete 3:f58c63b78853 89 CONSTRUCTORS / DESTRUCTOR
aspeteRakete 3:f58c63b78853 90 =============================================================================*/
aspeteRakete 3:f58c63b78853 91
aspeteRakete 3:f58c63b78853 92 //default timetag of 1
aspeteRakete 3:f58c63b78853 93 OSCBundle(uint64_t = 1);
aspeteRakete 3:f58c63b78853 94
aspeteRakete 3:f58c63b78853 95 //DESTRUCTOR
aspeteRakete 3:f58c63b78853 96 ~OSCBundle();
aspeteRakete 3:f58c63b78853 97
aspeteRakete 3:f58c63b78853 98 //clears all of the OSCMessages inside
aspeteRakete 3:f58c63b78853 99 void empty();
aspeteRakete 3:f58c63b78853 100
aspeteRakete 3:f58c63b78853 101 /*=============================================================================
aspeteRakete 3:f58c63b78853 102 SETTERS
aspeteRakete 3:f58c63b78853 103 =============================================================================*/
aspeteRakete 3:f58c63b78853 104
aspeteRakete 3:f58c63b78853 105 //start a new OSC Message in the bundle
aspeteRakete 3:f58c63b78853 106 OSCMessage & add( char * address);
aspeteRakete 3:f58c63b78853 107 //add with nothing in it produces an invalid osc message
aspeteRakete 3:f58c63b78853 108 //copies an existing message into the bundle
aspeteRakete 3:f58c63b78853 109 OSCMessage & add(OSCMessage & msg);
aspeteRakete 3:f58c63b78853 110
aspeteRakete 3:f58c63b78853 111 template <typename T>
aspeteRakete 3:f58c63b78853 112 void setTimetag(T t){
aspeteRakete 3:f58c63b78853 113 timetag = (uint64_t) t;
aspeteRakete 3:f58c63b78853 114 }
aspeteRakete 3:f58c63b78853 115 //sets the timetag from a buffer
aspeteRakete 3:f58c63b78853 116 void setTimetag(uint8_t * buff){
aspeteRakete 3:f58c63b78853 117 memcpy(&timetag, buff, 8);
aspeteRakete 3:f58c63b78853 118 }
aspeteRakete 3:f58c63b78853 119
aspeteRakete 3:f58c63b78853 120 /*=============================================================================
aspeteRakete 3:f58c63b78853 121 GETTERS
aspeteRakete 3:f58c63b78853 122 =============================================================================*/
aspeteRakete 3:f58c63b78853 123
aspeteRakete 3:f58c63b78853 124 //gets the message the matches the address string
aspeteRakete 3:f58c63b78853 125 //will do regex matching
aspeteRakete 3:f58c63b78853 126 OSCMessage * getOSCMessage(char * addr);
aspeteRakete 3:f58c63b78853 127
aspeteRakete 3:f58c63b78853 128 //get message by position
aspeteRakete 3:f58c63b78853 129 OSCMessage * getOSCMessage(int position);
aspeteRakete 3:f58c63b78853 130
aspeteRakete 3:f58c63b78853 131 /*=============================================================================
aspeteRakete 3:f58c63b78853 132 MATCHING
aspeteRakete 3:f58c63b78853 133 =============================================================================*/
aspeteRakete 3:f58c63b78853 134
aspeteRakete 3:f58c63b78853 135 //if the bundle contains a message that matches the pattern,
aspeteRakete 3:f58c63b78853 136 //call the function callback on that message
aspeteRakete 3:f58c63b78853 137 bool dispatch(const char * pattern, void (*callback)(OSCMessage&), int = 0);
aspeteRakete 3:f58c63b78853 138
aspeteRakete 3:f58c63b78853 139 //like dispatch, but allows for partial matches
aspeteRakete 3:f58c63b78853 140 //the address match offset is sent as an argument to the callback
aspeteRakete 3:f58c63b78853 141 bool route(const char * pattern, void (*callback)(OSCMessage&, int), int = 0);
aspeteRakete 3:f58c63b78853 142
aspeteRakete 3:f58c63b78853 143 /*=============================================================================
aspeteRakete 3:f58c63b78853 144 SIZE
aspeteRakete 3:f58c63b78853 145 =============================================================================*/
aspeteRakete 3:f58c63b78853 146 //returns the number of messages in the bundle;
aspeteRakete 3:f58c63b78853 147 int size();
aspeteRakete 3:f58c63b78853 148
aspeteRakete 3:f58c63b78853 149 /*=============================================================================
aspeteRakete 3:f58c63b78853 150 ERROR
aspeteRakete 3:f58c63b78853 151 =============================================================================*/
aspeteRakete 3:f58c63b78853 152
aspeteRakete 3:f58c63b78853 153 bool hasError();
aspeteRakete 3:f58c63b78853 154
aspeteRakete 3:f58c63b78853 155 OSCErrorCode getError();
aspeteRakete 3:f58c63b78853 156
aspeteRakete 3:f58c63b78853 157 /*=============================================================================
aspeteRakete 3:f58c63b78853 158 SENDING
aspeteRakete 3:f58c63b78853 159 =============================================================================*/
aspeteRakete 3:f58c63b78853 160
aspeteRakete 3:f58c63b78853 161 //void send(Print &p);
aspeteRakete 3:f58c63b78853 162
aspeteRakete 3:f58c63b78853 163 /*=============================================================================
aspeteRakete 3:f58c63b78853 164 FILLING
aspeteRakete 3:f58c63b78853 165 =============================================================================*/
aspeteRakete 3:f58c63b78853 166
aspeteRakete 3:f58c63b78853 167 void fill(uint8_t incomingByte);
aspeteRakete 3:f58c63b78853 168
aspeteRakete 3:f58c63b78853 169 void fill(uint8_t * incomingBytes, int length);
aspeteRakete 3:f58c63b78853 170 };
aspeteRakete 3:f58c63b78853 171
aspeteRakete 3:f58c63b78853 172 #endif