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