2 * Modulation matrix boilerplate code.
4 * Copyright (C) 2009 Krzysztof Foltman
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_MODMATRIX_H
22 #define __CALF_MODMATRIX_H
29 /// Single entry in modulation matrix
30 struct modulation_entry
34 /// Source mapping mode
35 calf_plugins::mod_matrix_metadata::mapping_mode mapping
;
36 /// Unmapped modulating source
40 /// Modulation destination
46 modulation_entry(int _src1
, calf_plugins::mod_matrix_metadata::mapping_mode _mapping
, int _src2
, float _amount
, int _dest
) {
54 /// Reset the row to default
58 mapping
= calf_plugins::mod_matrix_metadata::map_positive
;
66 namespace calf_plugins
{
71 dsp::modulation_entry
*matrix
;
72 mod_matrix_metadata
*metadata
;
73 unsigned int matrix_rows
;
74 /// Polynomials for different scaling modes (1, x, x^2)
75 static const float scaling_coeffs
[calf_plugins::mod_matrix_metadata::map_type_count
][3];
78 mod_matrix_impl(dsp::modulation_entry
*_matrix
, calf_plugins::mod_matrix_metadata
*_metadata
);
80 /// Process modulation matrix, calculate outputs from inputs
81 inline void calculate_modmatrix(float *moddest
, int moddest_count
, float *modsrc
)
83 for (int i
= 0; i
< moddest_count
; i
++)
85 for (unsigned int i
= 0; i
< matrix_rows
; ++i
)
87 dsp::modulation_entry
&slot
= matrix
[i
];
89 float value
= modsrc
[slot
.src1
];
90 const float *c
= scaling_coeffs
[slot
.mapping
];
91 value
= c
[0] + c
[1] * value
+ c
[2] * value
* value
;
92 moddest
[slot
.dest
] += value
* modsrc
[slot
.src2
] * slot
.amount
;
96 void send_configures(send_configure_iface
*);
97 char *configure(const char *key
, const char *value
);
99 virtual const dsp::modulation_entry
*get_default_mod_matrix_value(int row
) const
103 std::string
get_cell(int row
, int column
) const;
104 void set_cell(int row
, int column
, const std::string
&src
, std::string
&error
);