Expose all 8 voices
[zyn.git] / addsynth_component_frequency_envelope.cpp
blob98923dd48e40c24e038b47b6188b5fca11296a3e
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_frequency_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_RELEASE_VALUE:
55 return percent_from_0_127(
56 envelope_params_ptr->get_value(
57 envelope_params_ptr->m_release_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(envelope_params_ptr->m_stretch) * 2;
64 default:
65 LOG_ERROR("Unknown frequency envelope parameter %u", parameter);
66 assert(0);
70 void
71 zyn_component_frequency_envelope_set_float(
72 void * context,
73 unsigned int parameter,
74 float value)
76 switch (parameter)
78 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_VALUE:
79 envelope_params_ptr->set_value(
80 envelope_params_ptr->m_attack_value_index,
81 percent_to_0_127(value));
82 return;
83 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
84 envelope_params_ptr->set_duration(
85 envelope_params_ptr->m_attack_duration_index,
86 percent_to_0_127(value));
87 return;
88 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_VALUE:
89 envelope_params_ptr->set_value(
90 envelope_params_ptr->m_release_value_index,
91 percent_to_0_127(value));
92 return;
93 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
94 envelope_params_ptr->set_duration(
95 envelope_params_ptr->m_release_duration_index,
96 percent_to_0_127(value));
97 return;
98 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
99 envelope_params_ptr->m_stretch = percent_to_0_127(value/2);
100 return;
101 default:
102 LOG_ERROR("Unknown frequency envelope parameter %u", parameter);
103 assert(0);
107 signed int
108 zyn_component_frequency_envelope_get_int(
109 void * context,
110 unsigned int parameter)
112 assert(0);
113 return 0;
116 void
117 zyn_component_frequency_envelope_set_int(
118 void * context,
119 unsigned int parameter,
120 signed int value)
122 assert(0);
125 bool
126 zyn_component_frequency_envelope_get_bool(
127 void * context,
128 unsigned int parameter)
130 switch (parameter)
132 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
133 return envelope_params_ptr->m_forced_release;
134 default:
135 LOG_ERROR("Unknown bool frequency envelope parameter %u", parameter);
136 assert(0);
140 void
141 zyn_component_frequency_envelope_set_bool(
142 void * context,
143 unsigned int parameter,
144 bool value)
146 switch (parameter)
148 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
149 envelope_params_ptr->m_forced_release = value;
150 return;
151 default:
152 LOG_ERROR("Unknown bool frequency envelope parameter %u", parameter);
153 assert(0);
157 #undef envelope_params_ptr
159 void
160 zyn_addsynth_component_init_frequency_envelope(
161 struct zyn_component_descriptor * component_ptr,
162 EnvelopeParams * envelope_params_ptr)
164 ZYN_INIT_COMPONENT(component_ptr, envelope_params_ptr, zyn_component_frequency_envelope_);