|
libpsynth 0.2.1
|
00001 00011 /* 00012 * Copyright (C) 2011 Juan Pedro BolĂvar Puente 00013 * 00014 * This file is part of Psychosynth. 00015 * 00016 * Psychosynth is free software: you can redistribute it and/or modify 00017 * it under the terms of the GNU General Public License as published by 00018 * the Free Software Foundation, either version 3 of the License, or 00019 * (at your option) any later version. 00020 * 00021 * Psychosynth is distributed in the hope that it will be useful, 00022 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00024 * GNU General Public License for more details. 00025 * 00026 * You should have received a copy of the GNU General Public License 00027 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00028 * 00029 */ 00030 00031 #ifndef PSYNTH_GRAPH_CORE_PATCH_PORT_HPP_ 00032 #define PSYNTH_GRAPH_CORE_PATCH_PORT_HPP_ 00033 00034 #include <psynth/new_graph/node.hpp> 00035 #include <psynth/new_graph/port.hpp> 00036 #include <psynth/new_graph/buffer_port.hpp> 00037 #include <psynth/new_graph/soft_buffer_port.hpp> 00038 #include <psynth/new_graph/control.hpp> 00039 00040 namespace psynth 00041 { 00042 namespace graph 00043 { 00044 namespace core 00045 { 00046 00047 class patch_in_port_base : public node 00048 { 00049 public: 00050 virtual in_port_base& patch_port () = 0; 00051 00052 protected: 00053 void rt_do_process (rt_process_context& ctx); 00054 }; 00055 00056 typedef std::shared_ptr<patch_in_port_base> patch_in_port_base_ptr; 00057 00058 struct patch_output_hook_tag; 00059 typedef boost::intrusive::list_member_hook< 00060 boost::intrusive::tag<patch_output_hook_tag> 00061 > 00062 patch_output_hook; 00063 00064 class patch_out_port_base : public node 00065 { 00066 public: 00067 patch_output_hook _patch_output_hook; 00068 00069 virtual out_port_base& patch_port () = 0; 00070 00071 protected: 00072 void rt_do_process (rt_process_context& ctx); 00073 }; 00074 00075 typedef std::shared_ptr<patch_out_port_base> patch_out_port_base_ptr; 00076 00077 namespace detail 00078 { 00079 00080 template <class Base> 00081 class port_name_control : in_control<std::string> 00082 { 00083 typedef in_control<std::string> base_type; 00084 00085 public: 00086 port_name_control (std::string name, node* owner, const std::string val) 00087 : base_type (name, owner, val) {} 00088 00089 void set (const std::string& name); 00090 }; 00091 00092 extern template class port_name_control<patch_in_port_base>; 00093 extern template class port_name_control<patch_out_port_base>; 00094 00095 } /* namespace detail */ 00096 00097 template <class ForwardPort> 00098 class patch_in_port_impl : public patch_in_port_base 00099 { 00100 public: 00101 typedef typename ForwardPort::port_type port_type; 00102 00103 patch_in_port_impl () 00104 : _ctl_port_name ("port-name", this, "input") 00105 , _forward_port ("input", "output", 0, this) 00106 {} 00107 00108 in_port<port_type>& patch_port () 00109 { return _forward_port; } 00110 00111 private: 00112 detail::port_name_control<patch_in_port_base> _ctl_port_name; 00113 ForwardPort _forward_port; 00114 }; 00115 00116 00117 template <class T> 00118 struct patch_in_port 00119 : public patch_in_port_impl <forward_port<T> > 00120 { 00121 }; 00122 00123 template <class T> 00124 struct patch_buffer_in_port 00125 : public patch_in_port_impl <buffer_forward_port<T> > 00126 { 00127 }; 00128 00129 template <class T> 00130 struct patch_soft_buffer_in_port 00131 : public patch_in_port_impl <soft_buffer_forward_port<T> > 00132 { 00133 }; 00134 00135 template <class ForwardPort> 00136 class patch_out_port_impl : public patch_out_port_base 00137 { 00138 public: 00139 typedef typename ForwardPort::port_type port_type; 00140 00141 patch_out_port_impl () 00142 : _ctl_port_name ("port-name", this, "output") 00143 , _forward_port ("input", "output", this, 0) 00144 {} 00145 00146 out_port<port_type>& patch_port () 00147 { return _forward_port; } 00148 00149 private: 00150 detail::port_name_control<patch_out_port_base> _ctl_port_name; 00151 ForwardPort _forward_port; 00152 }; 00153 00154 template <class T> 00155 struct patch_out_port 00156 : public patch_out_port_impl <forward_port<T> > 00157 { 00158 }; 00159 00160 template <class T> 00161 struct patch_buffer_out_port 00162 : public patch_out_port_impl <buffer_forward_port<T> > 00163 { 00164 }; 00165 00166 template <class T> 00167 struct patch_soft_buffer_out_port 00168 : public patch_out_port_impl <soft_buffer_forward_port<T> > 00169 { 00170 }; 00171 00172 typedef patch_buffer_out_port<audio_buffer> audio_patch_out_port; 00173 typedef patch_buffer_in_port<audio_buffer> audio_patch_in_port; 00174 typedef patch_soft_buffer_out_port<audio_buffer> audio_patch_soft_out_port; 00175 typedef patch_soft_buffer_in_port<audio_buffer> audio_patch_soft_in_port; 00176 typedef patch_buffer_out_port<sample_buffer> sample_patch_out_port; 00177 typedef patch_buffer_in_port<sample_buffer> sample_patch_in_port; 00178 typedef patch_soft_buffer_out_port<sample_buffer> sample_patch_soft_out_port; 00179 typedef patch_soft_buffer_in_port<sample_buffer> sample_patch_soft_in_port; 00180 00181 } /* namespace core */ 00182 } /* namespace graph */ 00183 } /* namespace psynth */ 00184 00185 #endif /* PSYNTH_GRAPH_CORE_PATCH_PORT_HPP_ */ 00186
1.7.4