libpsynth 0.2.1
/home/raskolnikov/dev/psynth/trunk/src/psynth/graph/node_mixer.hpp
Go to the documentation of this file.
00001 /***************************************************************************
00002  *                                                                         *
00003  *   PSYCHOSYNTH                                                           *
00004  *   ===========                                                           *
00005  *                                                                         *
00006  *   Copyright (C) Juan Pedro Bolivar Puente 2007                          *
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_OBJECTMIXER_H
00024 #define PSYNTH_OBJECTMIXER_H
00025 
00026 #include <psynth/graph/node_types.hpp>
00027 #include <psynth/graph/node.hpp>
00028 #include <psynth/graph/node_factory.hpp>
00029 
00030 namespace psynth
00031 {
00032 namespace graph
00033 {
00034 
00035 class node_mixer : public node
00036 {
00037 public:
00038        /*enum {
00039       N_IN_A_SOCKETS
00040       };*/
00041         
00042     enum in_control_socket_id {
00043         IN_C_AMPLITUDE,
00044         N_IN_C_SOCKETS
00045     };
00046 
00047     enum param_id {
00048         PARAM_AMPLITUDE = node::N_COMMON_PARAMS,
00049         PARAM_MIXOP,
00050         N_PARAM
00051     };
00052 
00053     enum mix_op {
00054         MIX_SUM,
00055         MIX_PRODUCT,
00056         N_MIXOPS
00057     };
00058 
00059 
00060 protected:
00061     size_t m_numchan;
00062 
00063     void mix (sample* dest, const sample* src, size_t n_samples);
00064     
00065     void mix (sample* dest, const sample* src,
00066              const sample* ampl, size_t n_samples);
00067 
00068     void mix (sample* dest, const sample* src,
00069              link_envelope& env, size_t n_samples);
00070 
00071     void mix (sample* dest, const sample* src, const sample* ampl,
00072               link_envelope& env, link_envelope& ctrl_env,
00073               size_t n_samples);
00074     
00075     void init (sample* dest, size_t n_samples);
00076     
00077 private:
00078     float m_param_ampl;
00079     int m_param_mixop;    
00080     
00081 public:
00082     node_mixer (const audio_info& info,
00083                 int obj_type,
00084                 const std::string& name,
00085                 int num_audio_out,
00086                 int num_ctrl_out,
00087                 int num_in = 2);
00088 };
00089 
00090 class node_audio_mixer : public node_mixer
00091 {
00092 public:
00093     enum out_audio_socket_id {
00094         OUT_A_OUTPUT,
00095         N_OUT_A_SOCKETS
00096     };
00097 
00098     enum out_control_socket_id {
00099         N_OUT_C_SOCKETS
00100     };
00101     
00102 private:
00103     void do_update (const node* caller, int caller_port_type, int caller_port);
00104     void do_advance () {}
00105     void on_info_change () {}
00106     
00107 public:  
00108     node_audio_mixer (const audio_info& prop, int n_chan = 2) :
00109         node_mixer (prop,
00110                     NODE_MIXER,
00111                     "audio_mixer",
00112                     N_OUT_A_SOCKETS,
00113                     N_OUT_C_SOCKETS,
00114                     n_chan)
00115         {}
00116 };
00117 
00118 class node_control_mixer : public graph::node_mixer
00119 {
00120 public:
00121     enum out_audio_socket_id {
00122         N_OUT_A_SOCKETS
00123     };
00124 
00125     enum out_control_socket_id {
00126         OUT_C_OUTPUT,
00127         N_OUT_C_SOCKETS
00128     };
00129     
00130 private:
00131     void do_update (const node* caller, int caller_port_type, int caller_port);
00132     void do_advance () {}
00133     void on_info_change () {}
00134     
00135 public:  
00136     node_control_mixer (const audio_info& prop, int n_chan = 2) :
00137         node_mixer (prop,
00138                     NODE_CONTROLMIXER,
00139                     "control_mixer",
00140                     N_OUT_A_SOCKETS,
00141                     N_OUT_C_SOCKETS,
00142                     n_chan)
00143         {}
00144 };
00145 
00146 PSYNTH_DECLARE_NODE_FACTORY (node_control_mixer, "control_mixer");
00147 PSYNTH_DECLARE_NODE_FACTORY (node_audio_mixer, "audio_mixer");
00148 
00149 } /* namespace graph */
00150 } /* namespace psynth */
00151 
00152 #endif /* PSYNTH_OBJECTMIXER_H */