RAUL  0.5.1
AtomLiblo.hpp
1 /* This file is part of Raul.
2  * Copyright (C) 2007 Dave 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 <iostream>
22 #include <lo/lo.h>
23 #include <raul/Atom.hpp>
24 
25 namespace Raul {
26 
31 namespace AtomLiblo {
32 
34 inline void
35 lo_message_add_atom(lo_message m, const Atom& atom)
36 {
37  switch (atom.type()) {
38  case Atom::INT:
39  lo_message_add_int32(m, atom.get_int32());
40  break;
41  case Atom::FLOAT:
42  lo_message_add_float(m, atom.get_float());
43  break;
44  case Atom::STRING:
45  lo_message_add_string(m, atom.get_string());
46  break;
47  case Atom::BOOL:
48  if (atom.get_bool())
49  lo_message_add_true(m);
50  else
51  lo_message_add_false(m);
52  break;
53  case Atom::BLOB:
54  lo_message_add_blob(m, lo_blob_new(atom.data_size(), atom.get_blob()));
55  break;
56  case Atom::NIL:
57  default:
58  lo_message_add_nil(m);
59  break;
60  }
61 }
62 
63 
65 inline Atom
66 lo_arg_to_atom(char type, lo_arg* arg)
67 {
68  switch (type) {
69  case 'i':
70  return Atom(arg->i);
71  case 'f':
72  return Atom(arg->f);
73  case 's':
74  return Atom(&arg->s);
75  case 'T':
76  return Atom((bool)true);
77  case 'F':
78  return Atom((bool)false);
79  default:
80  std::cerr << "WARNING: Unable to convert OSC type '"
81  << type << "' to Atom" << std::endl;
82  return Atom();
83  }
84 }
85 
86 
87 } // namespace AtomLiblo
88 } // namespace Raul
89 
90 #endif // RAUL_ATOM_LIBLO_HPP
An OSC atom (fundamental data types OSC messages are composed of).
Definition: Atom.hpp:39
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:35
Definition: Array.hpp:26
Type type() const
Type of this atom.
Definition: Atom.hpp:161
Atom lo_arg_to_atom(char type, lo_arg *arg)
Convert a liblo argument to a Raul::Atom.
Definition: AtomLiblo.hpp:66