getdetune() coding style cleanup
[zyn.git] / addsynth_component_filter_envelope.cpp
blobdf9bcad4c6641a8d4eda92de2ea53bec68ac6ea3
1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * Copyright (C) 2006,2007,2008,2009 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 "filter_parameters.h"
29 #include "envelope_parameters.h"
30 #include "resonance.h"
31 #include "fft.h"
32 #include "oscillator.h"
33 #include "portamento.h"
34 #include "addsynth_internal.h"
35 #include "log.h"
37 #define envelope_params_ptr ((EnvelopeParams * )context)
39 float
40 zyn_component_filter_envelope_get_float(
41 void * context,
42 unsigned int parameter)
44 switch (parameter)
46 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_VALUE:
47 return percent_from_0_127(
48 envelope_params_ptr->get_value(
49 envelope_params_ptr->m_attack_value_index));
50 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
51 return percent_from_0_127(
52 envelope_params_ptr->get_duration(
53 envelope_params_ptr->m_attack_duration_index));
54 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_VALUE:
55 return percent_from_0_127(
56 envelope_params_ptr->get_value(
57 envelope_params_ptr->m_decay_value_index));
58 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
59 return percent_from_0_127(
60 envelope_params_ptr->get_duration(
61 envelope_params_ptr->m_decay_duration_index));
62 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_VALUE:
63 return percent_from_0_127(
64 envelope_params_ptr->get_value(
65 envelope_params_ptr->m_release_value_index));
66 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
67 return percent_from_0_127(
68 envelope_params_ptr->get_duration(
69 envelope_params_ptr->m_release_duration_index));
70 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
71 return percent_from_0_127(envelope_params_ptr->m_stretch) * 2;
72 default:
73 LOG_ERROR("Unknown filter envelope parameter %u", parameter);
74 assert(0);
78 void
79 zyn_component_filter_envelope_set_float(
80 void * context,
81 unsigned int parameter,
82 float value)
84 switch (parameter)
86 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_VALUE:
87 envelope_params_ptr->set_value(
88 envelope_params_ptr->m_attack_value_index,
89 percent_to_0_127(value));
90 return;
91 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
92 envelope_params_ptr->set_duration(
93 envelope_params_ptr->m_attack_duration_index,
94 percent_to_0_127(value));
95 return;
96 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_VALUE:
97 envelope_params_ptr->set_value(
98 envelope_params_ptr->m_decay_value_index,
99 percent_to_0_127(value));
100 return;
101 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
102 envelope_params_ptr->set_duration(
103 envelope_params_ptr->m_decay_duration_index,
104 percent_to_0_127(value));
105 return;
106 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_VALUE:
107 envelope_params_ptr->set_value(
108 envelope_params_ptr->m_release_value_index,
109 percent_to_0_127(value));
110 return;
111 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
112 envelope_params_ptr->set_duration(
113 envelope_params_ptr->m_release_duration_index,
114 percent_to_0_127(value));
115 return;
116 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
117 envelope_params_ptr->m_stretch = percent_to_0_127(value/2);
118 return;
119 default:
120 LOG_ERROR("Unknown filter envelope parameter %u", parameter);
121 assert(0);
125 signed int
126 zyn_component_filter_envelope_get_int(
127 void * context,
128 unsigned int parameter)
130 assert(0);
131 return 0;
134 void
135 zyn_component_filter_envelope_set_int(
136 void * context,
137 unsigned int parameter,
138 signed int value)
140 assert(0);
143 bool
144 zyn_component_filter_envelope_get_bool(
145 void * context,
146 unsigned int parameter)
148 switch (parameter)
150 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
151 return envelope_params_ptr->m_forced_release;
152 default:
153 LOG_ERROR("Unknown bool filter envelope parameter %u", parameter);
154 assert(0);
158 void
159 zyn_component_filter_envelope_set_bool(
160 void * context,
161 unsigned int parameter,
162 bool value)
164 switch (parameter)
166 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
167 envelope_params_ptr->m_forced_release = value;
168 return;
169 default:
170 LOG_ERROR("Unknown bool filter envelope parameter %u", parameter);
171 assert(0);
175 #undef envelope_params_ptr
177 void
178 zyn_addsynth_component_init_filter_envelope(
179 struct zyn_component_descriptor * component_ptr,
180 EnvelopeParams * envelope_params_ptr)
182 ZYN_INIT_COMPONENT(component_ptr, envelope_params_ptr, zyn_component_filter_envelope_);