Expose all 8 voices
[zyn.git] / addsynth_component_amp_envelope.cpp
blobc4b23751141991274334f4f0772bfaa0d18ffc01
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_amp_envelope_get_float(
41 void * context,
42 unsigned int parameter)
44 switch (parameter)
46 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
47 return percent_from_0_127(
48 envelope_params_ptr->get_duration(
49 envelope_params_ptr->m_attack_duration_index));
50 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
51 return percent_from_0_127(
52 envelope_params_ptr->get_duration(
53 envelope_params_ptr->m_decay_duration_index));
54 case ZYNADD_PARAMETER_FLOAT_ENV_SUSTAIN_VALUE:
55 return percent_from_0_127(
56 envelope_params_ptr->get_value(
57 envelope_params_ptr->m_sustain_value_index));
58 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
59 return percent_from_0_127(
60 envelope_params_ptr->get_duration(
61 envelope_params_ptr->m_release_duration_index));
62 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
63 return percent_from_0_127(
64 envelope_params_ptr->m_stretch) * 2;
65 default:
66 LOG_ERROR("Unknown amplitude envelope parameter %u", parameter);
67 assert(0);
71 void
72 zyn_component_amp_envelope_set_float(
73 void * context,
74 unsigned int parameter,
75 float value)
77 switch (parameter)
79 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
80 envelope_params_ptr->set_duration(
81 envelope_params_ptr->m_attack_duration_index,
82 percent_to_0_127(value));
83 return;
84 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
85 envelope_params_ptr->set_duration(
86 envelope_params_ptr->m_decay_duration_index,
87 percent_to_0_127(value));
88 return;
89 case ZYNADD_PARAMETER_FLOAT_ENV_SUSTAIN_VALUE:
90 envelope_params_ptr->set_value(
91 envelope_params_ptr->m_sustain_value_index,
92 percent_to_0_127(value));
93 return;
94 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
95 envelope_params_ptr->set_duration(
96 envelope_params_ptr->m_release_duration_index,
97 percent_to_0_127(value));
98 return;
99 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
100 envelope_params_ptr->m_stretch = percent_to_0_127(value/2);
101 return;
102 default:
103 LOG_ERROR("Unknown amplitude envelope parameter %u", parameter);
104 assert(0);
108 signed int
109 zyn_component_amp_envelope_get_int(
110 void * context,
111 unsigned int parameter)
113 assert(0);
114 return 0;
117 void
118 zyn_component_amp_envelope_set_int(
119 void * context,
120 unsigned int parameter,
121 signed int value)
123 assert(0);
126 bool
127 zyn_component_amp_envelope_get_bool(
128 void * context,
129 unsigned int parameter)
131 switch (parameter)
133 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
134 return envelope_params_ptr->m_forced_release;
135 case ZYNADD_PARAMETER_BOOL_ENV_LINEAR:
136 return envelope_params_ptr->m_linear;
137 default:
138 LOG_ERROR("Unknown bool amplitude envelope parameter %u", parameter);
139 assert(0);
143 void
144 zyn_component_amp_envelope_set_bool(
145 void * context,
146 unsigned int parameter,
147 bool value)
149 switch (parameter)
151 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
152 envelope_params_ptr->m_forced_release = value;
153 return;
154 case ZYNADD_PARAMETER_BOOL_ENV_LINEAR:
155 envelope_params_ptr->m_linear = value;
156 return;
157 default:
158 LOG_ERROR("Unknown bool amplitude envelope parameter %u", parameter);
159 assert(0);
163 #undef envelope_params_ptr
165 void
166 zyn_addsynth_component_init_amp_envelope(
167 struct zyn_component_descriptor * component_ptr,
168 EnvelopeParams * envelope_params_ptr)
170 ZYN_INIT_COMPONENT(component_ptr, envelope_params_ptr, zyn_component_amp_envelope_);