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 <lo/lo.h>
00022
00023 #include <iostream>
00024
00025 #include "raul/log.hpp"
00026 #include "raul/Atom.hpp"
00027
00028 namespace Raul {
00029
00034 namespace AtomLiblo {
00035
00037 inline void
00038 lo_message_add_atom(lo_message m, const Atom& atom)
00039 {
00040 switch (atom.type()) {
00041 case Atom::INT:
00042 lo_message_add_int32(m, atom.get_int32());
00043 break;
00044 case Atom::FLOAT:
00045 lo_message_add_float(m, atom.get_float());
00046 break;
00047 case Atom::STRING:
00048 lo_message_add_string(m, atom.get_string());
00049 break;
00050 case Atom::URI:
00051 lo_message_add_symbol(m, atom.get_uri());
00052 break;
00053 case Atom::BOOL:
00054 if (atom.get_bool())
00055 lo_message_add_true(m);
00056 else
00057 lo_message_add_false(m);
00058 break;
00059 case Atom::BLOB:
00060 if (atom.data_size() > 0)
00061 lo_message_add_blob(m, lo_blob_new(atom.data_size(), atom.get_blob()));
00062 else
00063 lo_message_add_nil(m);
00064 break;
00065 case Atom::NIL:
00066 default:
00067 lo_message_add_nil(m);
00068 break;
00069 }
00070 }
00071
00072
00074 inline Atom
00075 lo_arg_to_atom(char type, lo_arg* arg)
00076 {
00077 switch (type) {
00078 case 'i':
00079 return Atom(arg->i);
00080 case 'f':
00081 return Atom(arg->f);
00082 case 's':
00083 return Atom(&arg->s);
00084 case 'S':
00085 return Atom(Atom::URI, &arg->S);
00086 case 'T':
00087 return Atom((bool)true);
00088 case 'F':
00089 return Atom((bool)false);
00090 default:
00091 warn << "Unable to convert OSC type '"
00092 << type << "' to Atom" << std::endl;
00093 return Atom();
00094 }
00095 }
00096
00097
00098 }
00099 }
00100
00101 #endif // RAUL_ATOM_LIBLO_HPP