• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List

AtomLiblo.hpp

00001 /* This file is part of Raul.
00002  * Copyright (C) 2007-2009 David Robillard <http://drobilla.net>
00003  *
00004  * Raul is free software; you can redistribute it and/or modify it under the
00005  * terms of the GNU General Public License as published by the Free Software
00006  * Foundation; either version 2 of the License, or (at your option) any later
00007  * version.
00008  *
00009  * Raul is distributed in the hope that it will be useful, but WITHOUT ANY
00010  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00011  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for details.
00012  *
00013  * You should have received a copy of the GNU General Public License along
00014  * with this program; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
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 } // namespace AtomLiblo
00099 } // namespace Raul
00100 
00101 #endif // RAUL_ATOM_LIBLO_HPP

Generated on Tue Jan 11 2011 18:26:17 for RAUL by  doxygen 1.7.1