+ Filterclavier: added gain control for bandpasses
[calf.git] / src / calf / modules_dev.h
blobf9162c5ebbe4baf0300f2c9e2530d10360680114
1 /* Calf DSP Library
2 * Prototype audio modules
4 * Copyright (C) 2008 Thor Harald Johansen <thj@thj.no>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 * Boston, MA 02111-1307, USA.
21 #ifndef __CALF_MODULES_DEV_H
22 #define __CALF_MODULES_DEV_H
24 #include <calf/metadata.h>
25 #include <calf/modules.h>
27 namespace calf_plugins {
29 #if ENABLE_EXPERIMENTAL
31 /// Filterclavier --- MIDI controlled filter
32 // TODO: add bandpass (set_bp_rbj)
33 class filterclavier_audio_module:
34 public audio_module<filterclavier_metadata>,
35 public filter_module_with_inertia<biquad_filter_module, filterclavier_metadata>,
36 public line_graph_iface
38 const float min_resonance;
39 const float max_resonance;
40 const float min_gain;
41 const float max_gain;
43 int last_note;
45 public:
46 filterclavier_audio_module()
48 min_resonance(0.707),
49 max_resonance(20.0),
50 min_gain(1.0),
51 max_gain(32.0),
52 last_note(-1) {}
54 void params_changed()
56 inertia_filter_module::calculate_filter();
59 void activate()
61 inertia_filter_module::activate();
64 void set_sample_rate(uint32_t sr)
66 inertia_filter_module::set_sample_rate(sr);
70 void deactivate()
72 inertia_filter_module::deactivate();
75 /// MIDI control
76 virtual void note_on(int note, int vel)
78 last_note = note;
79 inertia_filter_module::inertia_cutoff.set_inertia(
80 note_to_hz(note + *params[par_transpose], *params[par_detune]));
82 inertia_filter_module::inertia_resonance.set_inertia(
83 (float(vel) / 127.0) * (max_resonance - min_resonance)
84 + min_resonance);
86 int mode = dsp::fastf2i_drm(*params[par_mode]);
87 // for bandpasses: boost gain for velocities > 0
88 if ( (mode_12db_bp <= mode) && (mode <= mode_36db_bp) ) {
89 // gain for velocity 0: 1.0
90 // gain for velocity 127: 32.0
91 float mode_max_gain = max_gain;
92 // max_gain is right for mode_12db_bp
93 if (mode == mode_24db_bp)
94 mode_max_gain /= 6.0;
95 if (mode == mode_36db_bp)
96 mode_max_gain /= 10.5;
98 inertia_filter_module::inertia_gain.set_inertia(
99 (float(vel) / 127.0) * (mode_max_gain - min_gain) + min_gain);
100 } else {
101 inertia_filter_module::inertia_gain.set_inertia(min_gain);
104 inertia_filter_module::calculate_filter();
107 virtual void note_off(int note, int vel)
109 if (note == last_note) {
110 inertia_filter_module::inertia_resonance.set_inertia(min_resonance);
111 inertia_filter_module::inertia_gain.set_inertia(min_gain);
112 inertia_filter_module::calculate_filter();
116 bool get_graph(int index, int subindex, float *data, int points, cairo_iface *context);
117 bool get_gridline(int index, int subindex, float &pos, bool &vertical, std::string &legend, cairo_iface *context);
120 #endif
124 #endif