|
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_OBJECTOSCILLATOR_H 00024 #define PSYNTH_OBJECTOSCILLATOR_H 00025 00026 #include <iostream> 00027 #include <cmath> 00028 00029 #include <boost/variant.hpp> 00030 #include <psynth/graph/node.hpp> 00031 #include <psynth/graph/node_factory.hpp> 00032 #include <psynth/graph/node_types.hpp> 00033 #include <psynth/synth/oscillator.hpp> 00034 00035 namespace psynth 00036 { 00037 namespace graph 00038 { 00039 00040 class node_oscillator : public node 00041 { 00042 public: 00043 enum in_audio_socket_id { 00044 N_IN_A_SOCKETS 00045 }; 00046 00047 enum in_control_socket_id { 00048 IN_C_FREQUENCY, 00049 IN_C_AMPLITUDE, 00050 IN_C_TRIGGER, 00051 N_IN_C_SOCKETS 00052 }; 00053 00054 enum wave_type { 00055 OSC_SINE, 00056 OSC_SQUARE, 00057 OSC_TRIANGLE, 00058 OSC_SAWTOOTH, 00059 OSC_MOOGSAW, 00060 OSC_EXP, 00061 N_OSC_TYPES 00062 }; 00063 00064 enum mod_type { 00065 MOD_FM = 0, 00066 MOD_AM, 00067 MOD_PM, 00068 N_MOD_TYPES 00069 }; 00070 00071 enum param_id { 00072 PARAM_WAVE = node::N_COMMON_PARAMS, 00073 PARAM_MODULATOR, 00074 PARAM_FREQUENCY, 00075 PARAM_AMPLITUDE, 00076 N_PARAM 00077 }; 00078 00079 static constexpr float DEFAULT_FREQ = 110.0f; 00080 static constexpr float DEFAULT_AMPL = 0.4f; 00081 00082 protected: 00083 typedef boost::variant<synth::oscillator<synth::sine_generator>, 00084 synth::oscillator<synth::square_generator>, 00085 synth::oscillator<synth::triangle_generator>, 00086 synth::oscillator<synth::sawtooth_generator>, 00087 synth::oscillator<synth::moogsaw_generator>, 00088 synth::oscillator<synth::exp_generator> 00089 > any_oscillator; 00090 00091 any_oscillator m_oscillator; 00092 00093 void update_osc_params (); 00094 void update_osc (sample* out); 00095 00096 // FIXME: THIS IS DIRTY HACK 00097 public: 00098 int m_param_wave; 00099 int m_param_wave_new; 00100 int m_param_mod; 00101 float m_param_freq; 00102 float m_param_ampl; 00103 bool m_restart; 00104 00105 public: 00106 node_oscillator (const audio_info& prop, 00107 int obj_type, 00108 const std::string& name, 00109 int n_audio_out, 00110 int n_control_out); 00111 00112 ~node_oscillator (); 00113 }; 00114 00115 class node_audio_oscillator : public node_oscillator 00116 { 00117 public: 00118 enum out_audio_socket_id { 00119 OUT_A_OUTPUT, 00120 N_OUT_A_SOCKETS 00121 }; 00122 00123 private: 00124 void do_update (const node* caller, int caller_port_type, int caller_port); 00125 void do_advance () {} 00126 void on_info_change () {} 00127 00128 public: 00129 node_audio_oscillator (const audio_info& prop) : 00130 node_oscillator (prop, 00131 NODE_OSCILLATOR, 00132 "oscillator", 00133 N_OUT_A_SOCKETS, 00134 0) 00135 {}; 00136 }; 00137 00138 class node_lfo : public node_oscillator 00139 { 00140 public: 00141 enum out_control_socket_id { 00142 OUT_C_OUTPUT, 00143 N_OUT_C_SOCKETS 00144 }; 00145 00146 private: 00147 void do_update (const node* caller, int caller_port_type, int caller_port); 00148 void do_advance () {} 00149 void on_info_change () {} 00150 00151 public: 00152 node_lfo(const audio_info& prop) : 00153 node_oscillator(prop, 00154 NODE_LFO, 00155 "lfo", 00156 0, 00157 N_OUT_C_SOCKETS) 00158 {}; 00159 }; 00160 00161 PSYNTH_DECLARE_NODE_FACTORY (node_lfo, "lfo"); 00162 PSYNTH_DECLARE_NODE_FACTORY (node_audio_oscillator, "oscillator"); 00163 00164 } /* namespace graph */ 00165 } /* namespace psynth */ 00166 00167 #endif /* PSYNTH_OBJECTOSCILLATOR_H */
1.7.4