2 * Modulation matrix boilerplate code.
4 * Copyright (C) 2001-2007 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 02110-1301 USA
21 #include <calf/modmatrix.h>
22 #include <calf/utils.h>
28 using namespace calf_plugins
;
29 using namespace calf_utils
;
31 mod_matrix_impl::mod_matrix_impl(dsp::modulation_entry
*_matrix
, mod_matrix_metadata
*_metadata
)
35 matrix_rows
= metadata
->get_table_rows();
36 for (unsigned int i
= 0; i
< matrix_rows
; i
++)
40 const float mod_matrix_impl::scaling_coeffs
[mod_matrix_metadata::map_type_count
][3] = {
51 std::string
mod_matrix_impl::get_cell(int row
, int column
) const
53 assert(row
>= 0 && row
< (int)matrix_rows
);
54 modulation_entry
&slot
= matrix
[row
];
55 const char **arr
= metadata
->get_table_columns()[column
].values
;
58 return arr
[slot
.src1
];
59 case 1: // mapping mode
60 return arr
[slot
.mapping
];
62 return arr
[slot
.src2
];
64 return calf_utils::f2s(slot
.amount
);
65 case 4: // destination
66 return arr
[slot
.dest
];
73 void mod_matrix_impl::set_cell(int row
, int column
, const std::string
&src
, std::string
&error
)
75 assert(row
>= 0 && row
< (int)matrix_rows
);
76 modulation_entry
&slot
= matrix
[row
];
77 const char **arr
= metadata
->get_table_columns()[column
].values
;
84 for (int i
= 0; arr
[i
]; i
++)
91 slot
.mapping
= (mod_matrix_metadata::mapping_mode
)i
;
100 error
= "Invalid name: " + src
;
105 stringstream
ss(src
);
113 void mod_matrix_impl::send_configures(send_configure_iface
*sci
)
115 for (int i
= 0; i
< (int)matrix_rows
; i
++)
117 for (int j
= 0; j
< 5; j
++)
119 string key
= "mod_matrix:" + i2s(i
) + "," + i2s(j
);
120 sci
->send_configure(key
.c_str(), get_cell(i
, j
).c_str());
125 char *mod_matrix_impl::configure(const char *key
, const char *value
)
129 if (!parse_table_key(key
, "mod_matrix:", is_rows
, row
, column
))
132 return strdup("Unexpected key");
134 if (row
!= -1 && column
!= -1)
140 const modulation_entry
*src
= get_default_mod_matrix_value(row
);
143 modulation_entry
&slot
= matrix
[row
];
146 case 0: slot
.src1
= src
->src1
; break;
147 case 1: slot
.mapping
= src
->mapping
; break;
148 case 2: slot
.src2
= src
->src2
; break;
149 case 3: slot
.amount
= src
->amount
; break;
150 case 4: slot
.dest
= src
->dest
; break;
154 const table_column_info
&ci
= metadata
->get_table_columns()[column
];
155 if (ci
.type
== TCT_ENUM
)
156 value_text
= ci
.values
[(int)ci
.def_value
];
158 if (ci
.type
== TCT_FLOAT
)
159 value_text
= f2s(ci
.def_value
);
160 value
= value_text
.c_str();
162 set_cell(row
, column
, value
, error
);
164 return strdup(error
.c_str());