.gitignore file
[zyn.git] / addsynth_component_frequency_envelope.cpp
blob2c211e11f5cc5ec0da7a911654eb934a2505e287
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_frequency_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_RELEASE_VALUE:
64 return percent_from_0_127(
65 envelope_params_ptr->get_value(
66 envelope_params_ptr->m_release_value_index));
67 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
68 return percent_from_0_127(
69 envelope_params_ptr->get_duration(
70 envelope_params_ptr->m_release_duration_index));
71 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
72 return percent_from_0_127(envelope_params_ptr->m_stretch) * 2;
73 default:
74 LOG_ERROR("Unknown frequency envelope parameter %u", parameter);
75 assert(0);
79 void
80 zyn_component_frequency_envelope_set_float(
81 void * context,
82 unsigned int parameter,
83 float value)
85 switch (parameter)
87 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_VALUE:
88 envelope_params_ptr->set_value(
89 envelope_params_ptr->m_attack_value_index,
90 percent_to_0_127(value));
91 return;
92 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
93 envelope_params_ptr->set_duration(
94 envelope_params_ptr->m_attack_duration_index,
95 percent_to_0_127(value));
96 return;
97 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_VALUE:
98 envelope_params_ptr->set_value(
99 envelope_params_ptr->m_release_value_index,
100 percent_to_0_127(value));
101 return;
102 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
103 envelope_params_ptr->set_duration(
104 envelope_params_ptr->m_release_duration_index,
105 percent_to_0_127(value));
106 return;
107 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
108 envelope_params_ptr->m_stretch = percent_to_0_127(value/2);
109 return;
110 default:
111 LOG_ERROR("Unknown frequency envelope parameter %u", parameter);
112 assert(0);
116 signed int
117 zyn_component_frequency_envelope_get_int(
118 void * context,
119 unsigned int parameter)
121 assert(0);
122 return 0;
125 void
126 zyn_component_frequency_envelope_set_int(
127 void * context,
128 unsigned int parameter,
129 signed int value)
131 assert(0);
134 bool
135 zyn_component_frequency_envelope_get_bool(
136 void * context,
137 unsigned int parameter)
139 switch (parameter)
141 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
142 return envelope_params_ptr->m_forced_release;
143 default:
144 LOG_ERROR("Unknown bool frequency envelope parameter %u", parameter);
145 assert(0);
149 void
150 zyn_component_frequency_envelope_set_bool(
151 void * context,
152 unsigned int parameter,
153 bool value)
155 switch (parameter)
157 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
158 envelope_params_ptr->m_forced_release = value;
159 return;
160 default:
161 LOG_ERROR("Unknown bool frequency envelope parameter %u", parameter);
162 assert(0);
166 #undef envelope_params_ptr
168 void
169 zyn_addsynth_component_init_frequency_envelope(
170 struct zyn_component_descriptor * component_ptr,
171 EnvelopeParams * envelope_params_ptr)
173 ZYN_INIT_COMPONENT(component_ptr, envelope_params_ptr, zyn_component_frequency_envelope_);