RAUL  0.8.0
AtomLiblo.hpp
1 /* This file is part of Raul.
2  * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
3  *
4  * Raul is free software; you can redistribute it and/or modify it under the
5  * terms of the GNU General Public License as published by the Free Software
6  * Foundation; either version 2 of the License, or (at your option) any later
7  * version.
8  *
9  * Raul is distributed in the hope that it will be useful, but WITHOUT ANY
10  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for details.
12  *
13  * You should have received a copy of the GNU General Public License along
14  * with this program; if not, write to the Free Software Foundation, Inc.,
15  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
16  */
17 
18 #ifndef RAUL_ATOM_LIBLO_HPP
19 #define RAUL_ATOM_LIBLO_HPP
20 
21 #include <lo/lo.h>
22 
23 #include <iostream>
24 
25 #include "raul/log.hpp"
26 #include "raul/Atom.hpp"
27 
28 namespace Raul {
29 
34 namespace AtomLiblo {
35 
37 inline void
38 lo_message_add_atom(lo_message m, const Atom& atom)
39 {
40  switch (atom.type()) {
41  case Atom::INT:
42  lo_message_add_int32(m, atom.get_int32());
43  break;
44  case Atom::FLOAT:
45  lo_message_add_float(m, atom.get_float());
46  break;
47  case Atom::STRING:
48  lo_message_add_string(m, atom.get_string());
49  break;
50  case Atom::URI:
51  lo_message_add_symbol(m, atom.get_uri());
52  break;
53  case Atom::BOOL:
54  if (atom.get_bool())
55  lo_message_add_true(m);
56  else
57  lo_message_add_false(m);
58  break;
59  case Atom::BLOB:
60  if (atom.data_size() > 0)
61  lo_message_add_blob(m, lo_blob_new(atom.data_size(), atom.get_blob()));
62  else
63  lo_message_add_nil(m);
64  break;
65  case Atom::NIL:
66  default:
67  lo_message_add_nil(m);
68  break;
69  }
70 }
71 
72 
74 inline Atom
75 lo_arg_to_atom(char type, lo_arg* arg)
76 {
77  switch (type) {
78  case 'i':
79  return Atom(arg->i);
80  case 'f':
81  return Atom(arg->f);
82  case 's':
83  return Atom(&arg->s);
84  case 'S':
85  return Atom(Atom::URI, &arg->S);
86  case 'T':
87  return Atom((bool)true);
88  case 'F':
89  return Atom((bool)false);
90  default:
91  warn << "Unable to convert OSC type '"
92  << type << "' to Atom" << std::endl;
93  return Atom();
94  }
95 }
96 
97 
98 } // namespace AtomLiblo
99 } // namespace Raul
100 
101 #endif // RAUL_ATOM_LIBLO_HPP
A piece of data with some type.
Definition: Atom.hpp:43
void lo_message_add_atom(lo_message m, const Atom &atom)
Append a Raul Atom as a parameter to a liblo message.
Definition: AtomLiblo.hpp:38
Definition: Array.hpp:26
Type type() const
Type of this atom.
Definition: Atom.hpp:165
Atom lo_arg_to_atom(char type, lo_arg *arg)
Convert a liblo argument to a Raul::Atom.
Definition: AtomLiblo.hpp:75