Button: emit slopes (fix for stuck modulaor plug-ins)
[calf.git] / src / calf / modmatrix.h
blob6d7fe269220e66ea6d82161dafd729f9b7b1e85c
1 /* Calf DSP Library
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
24 #include "giface.h"
25 #include <stdio.h>
27 namespace dsp {
29 /// Single entry in modulation matrix
30 struct modulation_entry
32 /// Mapped source
33 int src1;
34 /// Source mapping mode
35 calf_plugins::mod_matrix_metadata::mapping_mode mapping;
36 /// Unmapped modulating source
37 int src2;
38 /// Modulation amount
39 float amount;
40 /// Modulation destination
41 int dest;
43 modulation_entry() {
44 reset();
46 modulation_entry(int _src1, calf_plugins::mod_matrix_metadata::mapping_mode _mapping, int _src2, float _amount, int _dest) {
47 src1 = _src1;
48 mapping = _mapping;
49 src2 = _src2;
50 amount = _amount;
51 dest = _dest;
54 /// Reset the row to default
55 void reset() {
56 src1 = 0;
57 src2 = 0;
58 mapping = calf_plugins::mod_matrix_metadata::map_positive;
59 amount = 0.f;
60 dest = 0;
66 namespace calf_plugins {
68 class mod_matrix_impl
70 protected:
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];
77 public:
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++)
84 moddest[i] = 0;
85 for (unsigned int i = 0; i < matrix_rows; ++i)
87 dsp::modulation_entry &slot = matrix[i];
88 if (slot.dest) {
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
100 { return NULL; }
102 private:
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);
109 #endif