LineGraph: z axis for lo and hi pass handles
[calf.git] / src / calf / modules_dev.h
bloba8e14b7b2394bdceac1a8a3a346dea48723e40f0
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., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02111-1307, USA.
21 #ifndef __CALF_MODULES_DEV_H
22 #define __CALF_MODULES_DEV_H
24 #include <calf/metadata.h>
26 #if ENABLE_EXPERIMENTAL
27 #include <fluidsynth.h>
28 #endif
30 namespace calf_plugins {
32 #if ENABLE_EXPERIMENTAL
34 /// Tiny wrapper for fluidsynth
35 class fluidsynth_audio_module: public audio_module<fluidsynth_metadata>
37 protected:
38 /// Current sample rate
39 uint32_t srate;
40 /// FluidSynth Settings object
41 fluid_settings_t *settings;
42 /// FluidSynth Synth object
43 fluid_synth_t *synth;
44 /// Soundfont filename
45 std::string soundfont;
46 /// Soundfont filename (as received from Fluidsynth)
47 std::string soundfont_name;
48 /// TAB-separated preset list (preset+128*bank TAB preset name LF)
49 std::string soundfont_preset_list;
50 /// FluidSynth assigned SoundFont ID
51 int sfid;
52 /// Map of preset+128*bank to preset name
53 std::map<uint32_t, std::string> sf_preset_names;
54 /// Last selected preset+128*bank in each channel
55 uint32_t last_selected_presets[16];
56 /// Serial number of status data
57 volatile int status_serial;
58 /// Preset number to set on next process() call
59 volatile int set_presets[16];
60 volatile bool soundfont_loaded;
62 /// Update last_selected_preset based on synth object state
63 void update_preset_num(int channel);
64 /// Send a bank/program change sequence for a specific channel/preset combo
65 void select_preset_in_channel(int ch, int new_preset);
66 /// Create a fluidsynth object and load the current soundfont
67 fluid_synth_t *create_synth(int &new_sfid);
68 public:
69 /// Constructor to initialize handles to NULL
70 fluidsynth_audio_module();
72 void post_instantiate(uint32_t sr);
73 void set_sample_rate(uint32_t sr) { srate = sr; }
74 /// Handle MIDI Note On message (by sending it to fluidsynth)
75 void note_on(int channel, int note, int vel);
76 /// Handle MIDI Note Off message (by sending it to fluidsynth)
77 void note_off(int channel, int note, int vel);
78 /// Handle pitch bend message.
79 inline void pitch_bend(int channel, int value)
81 fluid_synth_pitch_bend(synth, 0, value + 0x2000);
83 /// Handle control change messages.
84 void control_change(int channel, int controller, int value);
85 /// Handle program change messages.
86 void program_change(int channel, int program);
88 /// Update variables from control ports.
89 void params_changed() {
91 void activate();
92 void deactivate();
93 /// No CV inputs for now
94 bool is_cv(int param_no) { return false; }
95 /// Practically all the stuff here is noisy... for now
96 bool is_noisy(int param_no) { return true; }
97 /// Main processing function
98 uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask);
99 /// DSSI-style configure function for handling string port data
100 char *configure(const char *key, const char *value);
101 void send_configures(send_configure_iface *sci);
102 int send_status_updates(send_updates_iface *sui, int last_serial);
103 uint32_t message_run(const void *valid_inputs, void *output_ports) {
104 // silence a default printf (which is kind of a warning about unhandled message_run)
105 return 0;
107 ~fluidsynth_audio_module();
112 #endif
116 #endif