2 ZynAddSubFX - a software synthesizer
4 EnvelopeParams.C - Parameters for Envelope
5 Copyright (C) 2002-2005 Nasca Octavian Paul
6 Author: Nasca Octavian Paul
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of version 2 of the GNU General Public License
10 as published by the Free Software Foundation.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License (version 2) for more details.
17 You should have received a copy of the GNU General Public License (version 2)
18 along with this program; if not, write to the Free Software Foundation,
19 Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include <math.h> // pow()
27 #include "envelope_parameters.h"
29 EnvelopeParams::EnvelopeParams()
33 for (i
= 0 ; i
< MAX_ENVELOPE_POINTS
; i
++)
39 Penvdt
[0] = 0; // no used
43 m_forced_release
= true;
46 m_attack_duration_index
= -1;
47 m_decay_duration_index
= -1;
48 m_release_duration_index
= -1;
50 m_attack_value_index
= -1;
51 m_decay_value_index
= -1;
52 m_sustain_value_index
= -1;
53 m_release_value_index
= -1;
56 EnvelopeParams::~EnvelopeParams()
60 REALTYPE
EnvelopeParams::getdt(unsigned char i
)
62 return (pow(2.0 , Penvdt
[i
] / 127.0 * 12.0) - 1.0) * 10.0; // miliseconds
65 void EnvelopeParams::set_point_value(int i
, unsigned char value
)
67 m_values_params
[i
] = value
;
71 case ZYN_ENVELOPE_MODE_ADSR
:
74 m_values
[i
] = value
/ 127.0;
78 m_values
[i
] = (1.0 - value
/ 127.0) * MIN_ENVELOPE_DB
;
81 case ZYN_ENVELOPE_MODE_ASR
:
82 m_values
[i
] = (pow(2,6.0 * fabs(value
- 64.0) / 64.0) - 1.0) * 100.0;
85 m_values
[i
] = -m_values
[i
];
88 case ZYN_ENVELOPE_MODE_ADSR_FILTER
:
89 m_values
[i
] = (value
- 64.0) / 64.0 * 6.0; // 6 octaves (filtru)
91 case ZYN_ENVELOPE_MODE_ASR_BW
:
92 m_values
[i
] = (value
- 64.0) / 64.0 * 10;
100 EnvelopeParams::init_adsr(
101 unsigned char stretch
,
103 char attack_duration
,
106 char release_duration
,
110 m_forced_release
= forced_release
;
112 m_mode
= ZYN_ENVELOPE_MODE_ADSR
;
117 set_point_value(0, 0);
119 m_attack_duration_index
= 1;
120 Penvdt
[1] = attack_duration
;
122 set_point_value(1, 127);
124 Penvdt
[2] = decay_duration
;
125 m_decay_duration_index
= 2;
127 set_point_value(2, sustain_value
);
128 m_sustain_value_index
= 2;
130 Penvdt
[3] = release_duration
;
131 m_release_duration_index
= 3;
133 set_point_value(3, 0);
137 EnvelopeParams::init_asr(
138 unsigned char stretch
,
141 char attack_duration
,
143 char release_duration
)
146 m_forced_release
= forced_release
;
147 m_mode
= ZYN_ENVELOPE_MODE_ASR
;
152 set_point_value(0, attack_value
);
153 m_attack_value_index
= 0;
155 Penvdt
[1] = attack_duration
;
156 m_attack_duration_index
= 1;
158 set_point_value(1, 64);
160 set_point_value(2, release_value
);
161 m_release_value_index
= 2;
163 Penvdt
[2] = release_duration
;
164 m_release_duration_index
= 2;
168 EnvelopeParams::init_adsr_filter(
169 unsigned char stretch
,
172 char attack_duration
,
176 char release_duration
)
179 m_forced_release
= forced_release
;
180 m_mode
= ZYN_ENVELOPE_MODE_ADSR_FILTER
;
185 set_point_value(0, attack_value
);
186 m_attack_value_index
= 0;
188 Penvdt
[1] = attack_duration
;
189 m_attack_duration_index
= 1;
191 set_point_value(1, decay_value
);
192 m_decay_value_index
= 1;
194 Penvdt
[2] = decay_duration
;
195 m_decay_duration_index
= 2;
197 set_point_value(2, 64);
199 Penvdt
[3] = release_duration
;
200 m_release_duration_index
= 3;
202 set_point_value(3, release_value
);
203 m_release_value_index
= 3;
207 EnvelopeParams::init_asr_bw(
208 unsigned char stretch
,
211 char attack_duration
,
213 char release_duration
)
216 m_forced_release
= forced_release
;
217 m_mode
= ZYN_ENVELOPE_MODE_ASR_BW
;
222 set_point_value(0, attack_value
);
223 m_attack_value_index
= 0;
225 set_point_value(1, 64);
227 Penvdt
[1] = attack_duration
;
228 m_attack_duration_index
= 1;
230 Penvdt
[2] = release_duration
;
231 m_release_duration_index
= 2;
233 set_point_value(2, release_value
);
234 m_release_value_index
= 2;
238 EnvelopeParams::get_value(
242 assert(index
< MAX_ENVELOPE_POINTS
);
243 return m_values_params
[index
];
247 EnvelopeParams::set_value(
252 assert(index
< MAX_ENVELOPE_POINTS
);
253 set_point_value(index
, value
);
257 EnvelopeParams::get_duration(
261 assert(index
< MAX_ENVELOPE_POINTS
);
262 return Penvdt
[index
];
266 EnvelopeParams::set_duration(
268 unsigned char duration
)
271 assert(index
< MAX_ENVELOPE_POINTS
);
272 Penvdt
[index
] = duration
;