[SCM] calf/master: + Mod Matrix: add mapping type (max. 2nd order polynomials), normalize sources to 0..100%
js at users.alioth.debian.org
js at users.alioth.debian.org
Tue May 7 15:39:33 UTC 2013
The following commit has been merged in the master branch:
commit 6e3d515969a14a6683b58f7b618afc0f090f6aed
Author: Krzysztof Foltman <wdev at foltman.com>
Date: Sat May 23 23:06:21 2009 +0100
+ Mod Matrix: add mapping type (max. 2nd order polynomials), normalize sources to 0..100%
diff --git a/src/calf/modmatrix.h b/src/calf/modmatrix.h
index 88cbba2..96f7d16 100644
--- a/src/calf/modmatrix.h
+++ b/src/calf/modmatrix.h
@@ -28,6 +28,7 @@ namespace dsp {
struct modulation_entry
{
int src1, src2;
+ int mapping;
float amount;
int dest;
};
@@ -39,7 +40,12 @@ namespace calf_plugins {
class mod_matrix: public table_edit_iface
{
protected:
- table_column_info table_columns[5];
+ enum modulation_mode { mod_positive, mod_bipolar, mod_negative, mod_squared, mod_squared_bipolar, mod_antisquared, mod_antisquared_bipolar, mod_parabola, mod_type_count };
+ /// Polynomials for different scaling modes (1, x, x^2)
+ static const float scaling_coeffs[mod_type_count][3];
+ /// Column descriptions for table widget
+ table_column_info table_columns[6];
+
dsp::modulation_entry *matrix;
unsigned int matrix_rows;
const char **mod_src_names, **mod_dest_names;
@@ -59,8 +65,13 @@ public:
for (unsigned int i = 0; i < matrix_rows; i++)
{
dsp::modulation_entry &slot = matrix[i];
- if (slot.dest)
- moddest[slot.dest] += modsrc[slot.src1] * modsrc[slot.src2] * slot.amount;
+ if (slot.dest) {
+ float value = modsrc[slot.src1] * modsrc[slot.src2];
+ value = dsp::clip<float>(value, 0, 1);
+ const float *c = scaling_coeffs[slot.mapping];
+ value = c[0] + c[1] * value + c[2] * value * value;
+ moddest[slot.dest] += value * slot.amount;
+ }
}
}
};
diff --git a/src/modmatrix.cpp b/src/modmatrix.cpp
index 90db2d2..85569a6 100644
--- a/src/modmatrix.cpp
+++ b/src/modmatrix.cpp
@@ -26,15 +26,29 @@ using namespace std;
using namespace dsp;
using namespace calf_plugins;
+const char *mod_mapping_names[] = { "0..1", "-1..1", "-1..0", "x^2", "2x^2-1", "ASqr", "ASqrBip", "Para", NULL };
+
+const float mod_matrix::scaling_coeffs[mod_matrix::mod_type_count][3] = {
+ { 0, 1, 0 },
+ { -1, 2, 0 },
+ { -1, 1, 0 },
+ { 0, 0, 1 },
+ { -1, 0, 1 },
+ { 0, 2, -1 },
+ { -1, 4, -2 },
+ { 0, 4, -4 },
+};
+
mod_matrix::mod_matrix(modulation_entry *_matrix, unsigned int _rows, const char **_src_names, const char **_dest_names)
: matrix(_matrix)
, matrix_rows(_rows)
, mod_src_names(_src_names)
, mod_dest_names(_dest_names)
{
- table_column_info tci[5] = {
+ table_column_info tci[6] = {
{ "Source", TCT_ENUM, 0, 0, 0, mod_src_names },
{ "Modulator", TCT_ENUM, 0, 0, 0, mod_src_names },
+ { "Mapping", TCT_ENUM, 0, 0, 0, mod_mapping_names },
{ "Amount", TCT_FLOAT, 0, 1, 1, NULL},
{ "Destination", TCT_ENUM, 0, 0, 0, mod_dest_names },
{ NULL }
@@ -62,9 +76,11 @@ std::string mod_matrix::get_cell(int param, int row, int column)
return mod_src_names[slot.src1];
case 1: // source 2
return mod_src_names[slot.src2];
- case 2: // amount
+ case 2: // mapping mode
+ return mod_mapping_names[slot.mapping];
+ case 3: // amount
return calf_utils::f2s(slot.amount);
- case 3: // destination
+ case 4: // destination
return mod_dest_names[slot.dest];
default:
assert(0);
@@ -76,47 +92,43 @@ void mod_matrix::set_cell(int param, int row, int column, const std::string &src
{
assert(row >= 0 && row < (int)matrix_rows);
modulation_entry &slot = matrix[row];
+ const char **arr = mod_src_names;
+ if (column == 2)
+ arr = mod_mapping_names;
+ if (column == 4)
+ arr = mod_dest_names;
switch(column) {
case 0:
case 1:
+ case 2:
+ case 4:
{
- for (int i = 0; mod_src_names[i]; i++)
+ for (int i = 0; arr[i]; i++)
{
- if (src == mod_src_names[i])
+ if (src == arr[i])
{
if (column == 0)
slot.src1 = i;
- else
+ else if (column == 1)
slot.src2 = i;
+ else if (column == 2)
+ slot.mapping = i;
+ else if (column == 4)
+ slot.dest = i;
error.clear();
return;
}
}
- error = "Invalid source name";
+ error = "Invalid name: " + src;
return;
}
- case 2:
+ case 3:
{
stringstream ss(src);
ss >> slot.amount;
error.clear();
return;
}
- case 3:
- {
- for (int i = 0; mod_dest_names[i]; i++)
- {
- if (src == mod_dest_names[i])
- {
- slot.dest = i;
- error.clear();
- return;
- }
- }
- error = "Invalid destination name";
- return;
- }
-
}
}
diff --git a/src/monosynth.cpp b/src/monosynth.cpp
index 528b011..db62a39 100644
--- a/src/monosynth.cpp
+++ b/src/monosynth.cpp
@@ -68,6 +68,7 @@ monosynth_audio_module::monosynth_audio_module()
dsp::modulation_entry &slot = mod_matrix_data[i];
slot.src1 = modsrc_none;
slot.src2 = modsrc_none;
+ slot.mapping = mod_matrix::mod_positive;
slot.amount = 0.f;
slot.dest = moddest_none;
}
@@ -405,7 +406,7 @@ void monosynth_audio_module::delayed_note_on()
}
envelope.advance();
queue_note_on = -1;
- float modsrc[modsrc_count] = { 1, velocity, inertia_pressure.get_last(), modwheel_value, 0, last_lfov};
+ float modsrc[modsrc_count] = { 1, velocity, inertia_pressure.get_last(), modwheel_value, 0, 0.5+0.5*last_lfov};
calculate_modmatrix(moddest, moddest_count, modsrc);
}
@@ -460,7 +461,7 @@ void monosynth_audio_module::calculate_step()
// mod matrix
// this should be optimized heavily; I think I'll do it when MIDI in Ardour 3 gets stable :>
- float modsrc[modsrc_count] = { 1, velocity, inertia_pressure.get(), modwheel_value, env, lfov};
+ float modsrc[modsrc_count] = { 1, velocity, inertia_pressure.get(), modwheel_value, env, 0.5+0.5*lfov};
calculate_modmatrix(moddest, moddest_count, modsrc);
inertia_cutoff.set_inertia(*params[par_cutoff]);
--
calf audio plugins packaging
More information about the pkg-multimedia-commits
mailing list