Add some foaf and doap info to zynadd.ttl
[zyn.git] / addsynth_component_amp_envelope.cpp
blobe2071b417135a9a17ba8e2d66684c9d0fc016158
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_amp_envelope_get_float(
50 void * context,
51 unsigned int parameter)
53 switch (parameter)
55 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
56 return percent_from_0_127(
57 envelope_params_ptr->get_duration(
58 envelope_params_ptr->m_attack_duration_index));
59 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
60 return percent_from_0_127(
61 envelope_params_ptr->get_duration(
62 envelope_params_ptr->m_decay_duration_index));
63 case ZYNADD_PARAMETER_FLOAT_ENV_SUSTAIN_VALUE:
64 return percent_from_0_127(
65 envelope_params_ptr->get_value(
66 envelope_params_ptr->m_sustain_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(
73 envelope_params_ptr->m_stretch) * 2;
74 default:
75 LOG_ERROR("Unknown amplitude envelope parameter %u", parameter);
76 assert(0);
80 void
81 zyn_component_amp_envelope_set_float(
82 void * context,
83 unsigned int parameter,
84 float value)
86 switch (parameter)
88 case ZYNADD_PARAMETER_FLOAT_ENV_ATTACK_DURATION:
89 envelope_params_ptr->set_duration(
90 envelope_params_ptr->m_attack_duration_index,
91 percent_to_0_127(value));
92 return;
93 case ZYNADD_PARAMETER_FLOAT_ENV_DECAY_DURATION:
94 envelope_params_ptr->set_duration(
95 envelope_params_ptr->m_decay_duration_index,
96 percent_to_0_127(value));
97 return;
98 case ZYNADD_PARAMETER_FLOAT_ENV_SUSTAIN_VALUE:
99 envelope_params_ptr->set_value(
100 envelope_params_ptr->m_sustain_value_index,
101 percent_to_0_127(value));
102 return;
103 case ZYNADD_PARAMETER_FLOAT_ENV_RELEASE_DURATION:
104 envelope_params_ptr->set_duration(
105 envelope_params_ptr->m_release_duration_index,
106 percent_to_0_127(value));
107 return;
108 case ZYNADD_PARAMETER_FLOAT_ENV_STRETCH:
109 envelope_params_ptr->m_stretch = percent_to_0_127(value/2);
110 return;
111 default:
112 LOG_ERROR("Unknown amplitude envelope parameter %u", parameter);
113 assert(0);
117 signed int
118 zyn_component_amp_envelope_get_int(
119 void * context,
120 unsigned int parameter)
122 assert(0);
123 return 0;
126 void
127 zyn_component_amp_envelope_set_int(
128 void * context,
129 unsigned int parameter,
130 signed int value)
132 assert(0);
135 bool
136 zyn_component_amp_envelope_get_bool(
137 void * context,
138 unsigned int parameter)
140 switch (parameter)
142 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
143 return envelope_params_ptr->m_forced_release;
144 case ZYNADD_PARAMETER_BOOL_ENV_LINEAR:
145 return envelope_params_ptr->m_linear;
146 default:
147 LOG_ERROR("Unknown bool amplitude envelope parameter %u", parameter);
148 assert(0);
152 void
153 zyn_component_amp_envelope_set_bool(
154 void * context,
155 unsigned int parameter,
156 bool value)
158 switch (parameter)
160 case ZYNADD_PARAMETER_BOOL_ENV_FORCED_RELEASE:
161 envelope_params_ptr->m_forced_release = value;
162 return;
163 case ZYNADD_PARAMETER_BOOL_ENV_LINEAR:
164 envelope_params_ptr->m_linear = value;
165 return;
166 default:
167 LOG_ERROR("Unknown bool amplitude envelope parameter %u", parameter);
168 assert(0);
172 #undef envelope_params_ptr
174 void
175 zyn_addsynth_component_init_amp_envelope(
176 struct zyn_component_descriptor * component_ptr,
177 EnvelopeParams * envelope_params_ptr)
179 ZYN_INIT_COMPONENT(component_ptr, envelope_params_ptr, zyn_component_amp_envelope_);