Add some foaf and doap info to zynadd.ttl
[zyn.git] / addsynth_component_filter_envelope.cpp
blob963cfa05ea16524c9babb319bc15d074c0ed845e
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Copyright (C) 2006,2007 Nedko Arnaudov <nedko@arnaudov.name>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *****************************************************************************/
21 #include <stdbool.h>
22 #include <assert.h>
24 #include "common.h"
25 #include "globals.h"
26 #include "addsynth.h"
27 #include "lfo_parameters.h"
28 #include "lfo.h"
29 #include "filter_parameters.h"
30 #include "filter_base.h"
31 #include "filter_common.h"
32 #include "analog_filter.h"
33 #include "sv_filter.h"
34 #include "formant_filter.h"
35 #include "filter.h"
36 #include "envelope_parameters.h"
37 #include "envelope.h"
38 #include "addnote.h"
39 #include "resonance.h"
40 #include "fft.h"
41 #include "oscillator.h"
42 #include "portamento.h"
43 #include "addsynth_internal.h"
44 #include "log.h"
46 #define envelope_params_ptr ((EnvelopeParams * )context)
48 float
49 zyn_component_filter_envelope_get_float(
50 void * context,
51 unsigned int parameter)
53 switch (parameter)
55 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_VALUE:
56 return percent_from_0_127(
57 envelope_params_ptr->get_value(
58 envelope_params_ptr->m_attack_value_index));
59 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
60 return percent_from_0_127(
61 envelope_params_ptr->get_duration(
62 envelope_params_ptr->m_attack_duration_index));
63 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_VALUE:
64 return percent_from_0_127(
65 envelope_params_ptr->get_value(
66 envelope_params_ptr->m_decay_value_index));
67 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
68 return percent_from_0_127(
69 envelope_params_ptr->get_duration(
70 envelope_params_ptr->m_decay_duration_index));
71 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_VALUE:
72 return percent_from_0_127(
73 envelope_params_ptr->get_value(
74 envelope_params_ptr->m_release_value_index));
75 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
76 return percent_from_0_127(
77 envelope_params_ptr->get_duration(
78 envelope_params_ptr->m_release_duration_index));
79 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
80 return percent_from_0_127(envelope_params_ptr->m_stretch) * 2;
81 default:
82 LOG_ERROR("Unknown filter envelope parameter %u", parameter);
83 assert(0);
87 void
88 zyn_component_filter_envelope_set_float(
89 void * context,
90 unsigned int parameter,
91 float value)
93 switch (parameter)
95 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_VALUE:
96 envelope_params_ptr->set_value(
97 envelope_params_ptr->m_attack_value_index,
98 percent_to_0_127(value));
99 return;
100 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
101 envelope_params_ptr->set_duration(
102 envelope_params_ptr->m_attack_duration_index,
103 percent_to_0_127(value));
104 return;
105 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_VALUE:
106 envelope_params_ptr->set_value(
107 envelope_params_ptr->m_decay_value_index,
108 percent_to_0_127(value));
109 return;
110 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
111 envelope_params_ptr->set_duration(
112 envelope_params_ptr->m_decay_duration_index,
113 percent_to_0_127(value));
114 return;
115 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_VALUE:
116 envelope_params_ptr->set_value(
117 envelope_params_ptr->m_release_value_index,
118 percent_to_0_127(value));
119 return;
120 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
121 envelope_params_ptr->set_duration(
122 envelope_params_ptr->m_release_duration_index,
123 percent_to_0_127(value));
124 return;
125 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
126 envelope_params_ptr->m_stretch = percent_to_0_127(value/2);
127 return;
128 default:
129 LOG_ERROR("Unknown filter envelope parameter %u", parameter);
130 assert(0);
134 signed int
135 zyn_component_filter_envelope_get_int(
136 void * context,
137 unsigned int parameter)
139 assert(0);
140 return 0;
143 void
144 zyn_component_filter_envelope_set_int(
145 void * context,
146 unsigned int parameter,
147 signed int value)
149 assert(0);
152 bool
153 zyn_component_filter_envelope_get_bool(
154 void * context,
155 unsigned int parameter)
157 switch (parameter)
159 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
160 return envelope_params_ptr->m_forced_release;
161 default:
162 LOG_ERROR("Unknown bool filter envelope parameter %u", parameter);
163 assert(0);
167 void
168 zyn_component_filter_envelope_set_bool(
169 void * context,
170 unsigned int parameter,
171 bool value)
173 switch (parameter)
175 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
176 envelope_params_ptr->m_forced_release = value;
177 return;
178 default:
179 LOG_ERROR("Unknown bool filter envelope parameter %u", parameter);
180 assert(0);
184 #undef envelope_params_ptr
186 void
187 zyn_addsynth_component_init_filter_envelope(
188 struct zyn_component_descriptor * component_ptr,
189 EnvelopeParams * envelope_params_ptr)
191 ZYN_INIT_COMPONENT(component_ptr, envelope_params_ptr, zyn_component_filter_envelope_);