00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef RAUL_ATOM_LIBLO_HPP
00019 #define RAUL_ATOM_LIBLO_HPP
00020
00021 #include <iostream>
00022 #include <lo/lo.h>
00023 #include "raul/Atom.hpp"
00024
00025 namespace Raul {
00026
00031 namespace AtomLiblo {
00032
00034 inline void
00035 lo_message_add_atom(lo_message m, const Atom& atom)
00036 {
00037 switch (atom.type()) {
00038 case Atom::INT:
00039 lo_message_add_int32(m, atom.get_int32());
00040 break;
00041 case Atom::FLOAT:
00042 lo_message_add_float(m, atom.get_float());
00043 break;
00044 case Atom::STRING:
00045 lo_message_add_string(m, atom.get_string());
00046 break;
00047 case Atom::URI:
00048 lo_message_add_symbol(m, atom.get_uri());
00049 break;
00050 case Atom::BOOL:
00051 if (atom.get_bool())
00052 lo_message_add_true(m);
00053 else
00054 lo_message_add_false(m);
00055 break;
00056 case Atom::BLOB:
00057 if (atom.data_size() > 0)
00058 lo_message_add_blob(m, lo_blob_new(atom.data_size(), atom.get_blob()));
00059 else
00060 lo_message_add_nil(m);
00061 break;
00062 case Atom::NIL:
00063 default:
00064 lo_message_add_nil(m);
00065 break;
00066 }
00067 }
00068
00069
00071 inline Atom
00072 lo_arg_to_atom(char type, lo_arg* arg)
00073 {
00074 switch (type) {
00075 case 'i':
00076 return Atom(arg->i);
00077 case 'f':
00078 return Atom(arg->f);
00079 case 's':
00080 return Atom(&arg->s);
00081 case 'S':
00082 return Atom(Atom::URI, &arg->S);
00083 case 'T':
00084 return Atom((bool)true);
00085 case 'F':
00086 return Atom((bool)false);
00087 default:
00088 std::cerr << "WARNING: Unable to convert OSC type '"
00089 << type << "' to Atom" << std::endl;
00090 return Atom();
00091 }
00092 }
00093
00094
00095 }
00096 }
00097
00098 #endif // RAUL_ATOM_LIBLO_HPP