|
libpsynth 0.2.1
|
00001 /*************************************************************************** 00002 * * 00003 * PSYCHOSYNTH * 00004 * =========== * 00005 * * 00006 * Copyright (C) 2007 Juan Pedro Bolivar Puente * 00007 * * 00008 * This program is free software: you can redistribute it and/or modify * 00009 * it under the terms of the GNU General Public License as published by * 00010 * the Free Software Foundation, either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This program is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/>. * 00020 * * 00021 ***************************************************************************/ 00022 00023 #ifndef PSYNTH_OSCCONTROLLER_H 00024 #define PSYNTH_OSCCONTROLLER_H 00025 00026 #include <map> 00027 00028 #include <psynth/world/world.hpp> 00029 #include <psynth/net/osc_misc.hpp> 00030 #include <psynth/net/osc_broadcast.hpp> 00031 00032 namespace psynth 00033 { 00034 00035 class osc_controller : public world_listener, 00036 public world_node_listener, 00037 public osc_broadcast 00038 { 00039 std::map<std::pair<int,int>, int> m_local_id; 00040 std::map<int, std::pair<int,int> > m_net_id; 00041 world* m_world; 00042 int m_skip; 00043 int m_id; 00044 bool m_activated; 00045 bool m_broadcast; 00046 00047 LO_HANDLER (osc_controller, add); 00048 LO_HANDLER (osc_controller, delete); 00049 LO_HANDLER (osc_controller, param); 00050 LO_HANDLER (osc_controller, activate); 00051 LO_HANDLER (osc_controller, deactivate); 00052 00053 void add_to_world (world* world) { 00054 world->add_world_listener (this); 00055 world->add_world_node_listener (this); 00056 } 00057 00058 void delete_from_world (world* world) { 00059 world->delete_world_listener (this); 00060 world->delete_world_node_listener (this); 00061 } 00062 00063 public: 00064 osc_controller (bool broadcast = false); 00065 ~osc_controller (); 00066 00067 void set_id (int id) { 00068 m_id = id; 00069 } 00070 00071 void set_world (world* world) { 00072 deactivate (); 00073 m_world = world; 00074 } 00075 00076 world* get_world () { 00077 return m_world; 00078 } 00079 00080 void activate () { 00081 if (!m_activated && m_world) { 00082 m_activated = true; 00083 add_to_world (m_world); 00084 } 00085 } 00086 00087 void deactivate () { 00088 if (m_activated && m_world) { 00089 m_activated = false; 00090 delete_from_world (m_world); 00091 } 00092 } 00093 00094 void clear () { 00095 deactivate(); 00096 m_local_id.clear(); 00097 m_net_id.clear(); 00098 m_skip = 0; 00099 osc_broadcast::clear(); 00100 } 00101 00102 void add_methods (lo_server s); 00103 00104 void handle_add_node (world_node& obj); 00105 void handle_delete_node (world_node& obj); 00106 void handle_activate_node (world_node& obj); 00107 void handle_deactivate_node (world_node& obj); 00108 void handle_set_param_node (world_node& ob, int param_id); 00109 }; 00110 00111 } /* namespace psynth */ 00112 00113 #endif /* PSYNTH_OSCCONTROLLER_H */
1.7.4