root/trunk/libffado/src/libosc/OscMessage.cpp

Revision 445, 4.6 kB (checked in by pieterpalmers, 17 years ago)

* name change from FreeBoB to FFADO
* replaced tabs by 4 spaces
* got rid of end-of-line spaces
* made all license and copyrights conform

library becomes LGPL, apps become GPL
explicitly state LGPL v2.1 and GPL v2 (don't like v3 draft)

copyrights are 2005-2007 Daniel & Pieter
except for the MotU stuff (C) Jonathan, Pieter

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