libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/world/patcher.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   PSYCHOSYNTH                                                           *
00004  *   ===========                                                           *
00005  *                                                                         *
00006  *   Copyright (C) 2007 by 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_PATCHER_H
00024 #define PSYNTH_PATCHER_H
00025 
00026 #include <map>
00027 #include <set>
00028 
00029 #include <psynth/graph/node.hpp>
00030 
00031 namespace psynth
00032 {
00033 
00034 struct patcher_event {
00035     graph::node* src;
00036     graph::node* dest;
00037     int src_socket;
00038     int dest_socket;
00039     int socket_type;
00040 
00041     patcher_event (graph::node* s, graph::node* d, int ss, int ds, int st):
00042         src(s), dest(d), src_socket(ss), dest_socket(ds), socket_type(st) {};
00043 };
00044 
00045 class patcher_listener {
00046 public:
00047     virtual ~patcher_listener () {};
00048     virtual void handle_link_added (const patcher_event& ev) = 0;
00049     virtual void handle_link_deleted (const patcher_event& ev) = 0;
00050 };
00051 
00052 class patcher_subject {
00053     std::list<patcher_listener*> m_list;
00054 
00055 protected:
00056     void notify_link_added (const patcher_event& ev) {
00057         for (std::list<patcher_listener*>::iterator it = m_list.begin ();
00058              it != m_list.end(); )
00059             (*it++)->handle_link_added (ev);
00060     };
00061     
00062     void notify_link_deleted (const patcher_event& ev) {
00063         for (std::list<patcher_listener*>::iterator it = m_list.begin();
00064              it != m_list.end(); )
00065             (*it++)->handle_link_deleted (ev);
00066     };
00067     
00068 public:
00069     void add_listener (patcher_listener* l) {
00070         m_list.push_back (l);
00071     };
00072     
00073     void delete_listener (patcher_listener* l) {
00074         m_list.remove (l);
00075     };
00076 };
00077 
00078 class patcher : public patcher_subject
00079 {
00080 public:
00081     virtual ~patcher () {};
00082     
00083     virtual bool add_node (graph::node* obj) = 0;
00084     virtual bool delete_node (graph::node* obj) = 0;
00085     virtual void set_param_node (graph::node* obj, int param) = 0;
00086     virtual void update () = 0;
00087     virtual void clear () = 0;
00088 };
00089 
00090 } /* namespace psynth */
00091 
00092 #endif /* PSYNTH_PATCHER_H */