Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 2014 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #include "controller.h" 00020 00021 #include <oscpack/osc/OscOutboundPacketStream.h> 00022 00023 namespace Marsyas { 00024 namespace RealTime { 00025 00026 Controller::Controller( size_t queue_size ): 00027 OscQueueProvider(&m_queue), 00028 m_queue(queue_size) 00029 {} 00030 00031 00032 template <typename T> 00033 void write_osc_packet( char *buffer, size_t capacity, 00034 packet_queue & queue, 00035 const char * path, const T & value ) 00036 { 00037 osc::OutboundPacketStream packet( buffer, capacity ); 00038 try 00039 { 00040 packet << osc::BeginMessage(path); 00041 packet << value; 00042 packet << osc::EndMessage; 00043 } 00044 catch ( std::exception & e ) 00045 { 00046 MRSWARN("OSC sender: " << e.what()); 00047 return; 00048 } 00049 queue.push( packet.Data(), packet.Size() ); 00050 } 00051 00052 void Controller::set( const char * path, bool value ) 00053 { 00054 write_osc_packet(m_buffer, m_buffer_size, m_queue, path, value); 00055 } 00056 00057 void Controller::set( const char * path, int value ) 00058 { 00059 write_osc_packet(m_buffer, m_buffer_size, m_queue, path, value); 00060 } 00061 00062 void Controller::set( const char * path, float value ) 00063 { 00064 write_osc_packet(m_buffer, m_buffer_size, m_queue, path, value); 00065 } 00066 00067 void Controller::set( const char * path, double value ) 00068 { 00069 write_osc_packet(m_buffer, m_buffer_size, m_queue, path, value); 00070 } 00071 00072 void Controller::set( const char * path, const char * value ) 00073 { 00074 write_osc_packet(m_buffer, m_buffer_size, m_queue, path, value); 00075 } 00076 00077 } 00078 }