root/branches/streaming-rework/src/libosc/OscMessage.cpp

Revision 432, 4.7 kB (checked in by pieterpalmers, 17 years ago)

- extended OSC support

Line 
1 /* $Id$ */
2
3 /*
4  *   FreeBob Streaming API
5  *   FreeBob = Firewire (pro-)audio for linux
6  *
7  *   http://freebob.sf.net
8  *
9  *   Copyright (C) 2007 Pieter Palmers <pieterpalmers@users.sourceforge.net>
10  *
11  *   This program is free software {} you can redistribute it and/or modify
12  *   it under the terms of the GNU General Public License as published by
13  *   the Free Software Foundation {} either version 2 of the License, or
14  *   (at your option) any later version.
15  *
16  *   This program is distributed in the hope that it will be useful,
17  *   but WITHOUT ANY WARRANTY {} without even the implied warranty of
18  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *   GNU General Public License for more details.
20  *
21  *   You should have received a copy of the GNU General Public License
22  *   along with this program {} if not, write to the Free Software
23  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  *
25  *
26  *
27  */
28
29 #include "OscMessage.h"
30
31 namespace OSC {
32
33 IMPL_DEBUG_MODULE( OscMessage, OscMessage, DEBUG_LEVEL_VERBOSE );
34
35 OscMessage::OscMessage()
36     : m_Path("")
37 {
38
39 }
40
41 OscMessage::OscMessage(string path, const char* types, lo_arg** argv, int argc)
42     : m_Path(path)
43 {
44     for (int i=0; i < argc; ++i) {
45         switch (lo_type(types[i])) {
46             /* basic OSC types */
47             /** 32 bit signed integer. */
48             case LO_INT32:
49                 addArgument((int32_t)(argv[i]->i));
50                 break;
51             /** 32 bit IEEE-754 float. */
52             case LO_FLOAT:
53                 addArgument(argv[i]->f);
54                 break;
55             /** Standard C, NULL terminated string. */
56             case LO_STRING:
57                 addArgument(string(&(argv[i]->s)));
58                 break;
59             /* extended OSC types */
60             /** 64 bit signed integer. */
61             case LO_INT64:
62                 addArgument((int64_t)(argv[i]->h));
63                 break;
64            
65             /* unsupported types */
66             /** OSC binary blob type. Accessed using the lo_blob_*() functions. */
67             case LO_BLOB:
68             /** OSC TimeTag type, represented by the lo_timetag structure. */
69             case LO_TIMETAG:
70             /** 64 bit IEEE-754 double. */
71             case LO_DOUBLE:
72             /** Standard C, NULL terminated, string. Used in systems which
73               * distinguish strings and symbols. */
74             case LO_SYMBOL:
75             /** Standard C, 8 bit, char variable. */
76             case LO_CHAR:
77             /** A 4 byte MIDI packet. */
78             case LO_MIDI:
79             /** Sybol representing the value True. */
80             case LO_TRUE:
81             /** Sybol representing the value False. */
82             case LO_FALSE:
83             /** Sybol representing the value Nil. */
84             case LO_NIL:
85             /** Sybol representing the value Infinitum. */
86             case LO_INFINITUM:
87             default:
88                 debugOutput(DEBUG_LEVEL_NORMAL,
89                             "unsupported osc type: %c\n", lo_type(types[i]));
90         }
91     }
92
93 }
94
95 OscMessage::~OscMessage() {
96
97 }
98
99 lo_message
100 OscMessage::makeLoMessage() {
101     lo_message m=lo_message_new();
102     for ( OscArgumentVectorIterator it = m_arguments.begin();
103     it != m_arguments.end();
104     ++it )
105     {
106         if((*it).isInt()) {
107             lo_message_add_int32(m,(*it).getInt());
108         }
109         if((*it).isInt64()) {
110             lo_message_add_int64(m,(*it).getInt64());
111         }
112         if((*it).isFloat()) {
113             lo_message_add_float(m,(*it).getFloat());
114         }
115         if((*it).isString()) {
116             lo_message_add_string(m,(*it).getString().c_str());
117         }
118     }
119     return m;
120 }
121
122 void
123 OscMessage::setPath(string p) {
124     m_Path=p;
125 }
126
127 OscArgument&
128 OscMessage::getArgument(unsigned int idx) {
129     return m_arguments.at(idx);
130 }
131
132 unsigned int
133 OscMessage::nbArguments() {
134     return m_arguments.size();
135 }
136
137 void
138 OscMessage::addArgument(int32_t v) {
139     debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Adding int argument %ld\n", v);
140     m_arguments.push_back(OscArgument(v));
141 }
142
143 void
144 OscMessage::addArgument(int64_t v) {
145     debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Adding long int argument %lld\n", v);
146     m_arguments.push_back(OscArgument(v));
147 }
148
149 void
150 OscMessage::addArgument(float v) {
151     debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Adding float argument: %f\n",v);
152     m_arguments.push_back(OscArgument(v));
153 }
154
155 void
156 OscMessage::addArgument(string v) {
157     debugOutput(DEBUG_LEVEL_VERY_VERBOSE,"Adding string argument: %s\n",v.c_str());
158     m_arguments.push_back(OscArgument(v));
159 }
160
161 void
162 OscMessage::print() {
163     debugOutput(DEBUG_LEVEL_NORMAL, "Message on: %s\n", m_Path.c_str());
164     for ( OscArgumentVectorIterator it = m_arguments.begin();
165     it != m_arguments.end();
166     ++it )
167     {
168         (*it).print();
169     }
170 }
171
172 } // end of namespace OSC
Note: See TracBrowser for help on using the browser.