#include <controls.hh>
Use a Controls object to connect MIDI knobs and faders to Module inputs.
For example, to add a volume knob to your project, you can do
Note that a controls object is a Container, just like the synth Container above. Thus, it can receive events from the MidiInput object. However, you must explicitly tell the synth container to propagate events to the controls container.
Using the example above, you can now turn the knob on your controller with MIDI id 123 and modulate the amlitude of the gain module. The controls object maps the MIDI value, which ranges from 0 to 127, to the interval [0,1]. By default, this mapping is linear. But you can make it exponential if you want more sensititvy at the low end. For example,
Here, the mapping between the MIDI knob position and the amplitude will follow
\(\frac{(y-x)b^{m/127-1}}{b-1}+x\)
where x and y are the minimum and maximum value of the control, b is the base of the exponential (1e4 in this example), and m is the MIDI value.
This is easy to see graphically. In the image below, the control output ranges from 2.0 to 5.0 and the response to the MIDI input is shown for various bases.
A complete example is listed below using a custom module to display the value of each control in real time as the associated knob is adjusted.
Public Member Functions | |
void | init () |
void | update () |
Controls & | map (Fader &fader, int midi_id) |
Controls & | map (Module &module, string name, double min, double max, int midi_id) |
Controls & | map (Module &module, int index, double min, double max, int midi_id) |
Controls & | map (Module &module, string name, json spec) |
Controls & | set_tracking_gain (double x) |
Controls & | linear () |
Set the most recently added control's response to linear. | |
Controls & | exponential (double base) |
void | randomize () |
Randomly assign a value to all controls. | |
![]() | |
void | init () |
void | update () |
Container & | add (Module &module) |
Container & | add_if_new (Module &module) |
Container & | propagate_to (EventManager &em) |
void | run (int num_steps) |
void | run_again (int num_steps) |
void | stop () |
Container & | connect (Module &source, string output, Module &dest, string input) |
Container & | connect (Module &source, string output, Module &dest, int input) |
Container & | connect (AutoLoad &loader, string category, Module &module) |
Container & | connect (Module &source, Module &dest) |
Container & | path (Module &a, Module &b, Module &c) |
Container & | path (Module &a, Module &b, Module &c, Module &d) |
Container & | path (Module &a, Module &b, Module &c, Module &d, Module &e) |
Container & | disconnect (Module &source, string output, Module &dest, string input) |
bool | connected (Module *module, string input_name) |
Container & | equate_input (string input, Module &sub_module, string sub_input) |
Container & | attach_inputs (std::vector< std::tuple< string, Module &, string > > attachments) |
Container & | equate_output (string output, Module &sub_module, string sub_output) |
Container & | attach_outputs (std::vector< std::tuple< string, Module &, string > > attachments) |
Container & | set_thread_number (int n) |
EXPERIMENTAL. | |
Container & | add (Module &module, int n) |
EXPERIMENTAL. | |
void | run_threaded (int num_steps) |
EXPERIMENTAL. | |
void | update_threaded () |
EXPERIMENTAL. | |
void | thread_loop (int i) |
EXPERIMENTAL. | |
![]() | |
virtual void | init ()=0 |
virtual void | update ()=0 |
int | add_input (string name) |
int | add_output (string name) |
int | get_input_index (string name) const |
string | get_input_name (int index) const |
string | get_output_name (int index) const |
int | get_output_index (string name) const |
void | set_input (string name, double value) |
void | set_input (int index, double value) |
double | get_input (int index) const |
double | get_input (string name) const |
double | get_output (string name) const |
double | get_output (int index) const |
void | set_output (int index, double value) |
void | copy_inputs (const Module &source) |
void | copy_outputs (Module &destination) const |
void | configure (std::vector< std::tuple< string, double > > assignments) |
int | num_inputs () const |
int | num_outputs () const |
void | emit (Event e) |
void | set_ts (double s) |
double | get_ts () |
![]() | |
EventManager () | |
Make a new event manager. | |
void | process_events (vector< Module * > &modules) |
void | respond_to (const Event &event) |
EventManager & | listen (int event_type, function< void(const Event &)> handler) |
EventManager & | listen (int event_type, int port, function< void(const Event &)> handler) |
Controls & yase::Controls::exponential | ( | double | base | ) |
Set the most recently added control's response to exponential with the given base
base | The base of the exponential response. |
|
virtual |
This method should be overridden by derived classes. It will usually be called once, after all modules and connections objects have been added to a synthesizer, but before the synthesizer starts running.
Reimplemented from yase::Container.
Associate a controller with an input of a module.
module | The target module |
index | The index of the target module's input |
min | The minimum output of the control |
max | The minimum maximum value of the control |
midi_id | The MIDI id of the knob or fader on your MIDI controller |
Controls & yase::Controls::map | ( | Module & | module, |
string | name, | ||
double | min, | ||
double | max, | ||
int | midi_id | ||
) |
Associate a controller with an input of a module.
module | The target module |
name | The name of the target module's input |
min | The minimum output of the control |
max | The minimum maximum value of the control |
midi_id | The MIDI id of the knob or fader on your MIDI controller |
Associate a controller with an input of a module.
module | The target module |
name | The name of the target module's input |
spec | A json object containing fields min, max, mid, type, and base (if type is exponential) |
This version of the control method can be called with a json specification of the control, which is especially useful when setting up controls from json files. For example, if a json file called "config.json" had
in it. Then you could do
Controls & yase::Controls::set_tracking_gain | ( | double | x | ) |
Sets the tracking gain of the most recently added control. See Fader::set_tracking_gain(double x).
x | The new tracking gain (e.g. 0.1*FADER_GAIN) |
|
virtual |
This method should be overridden by derived classes. It will be called repeatedly by a synthesizer at a frequency determined by SAMPLE_RATE.
Reimplemented from yase::Container.