@@ -107,26 +107,31 @@ void AudioStreamPlaybackMPT::set_current_row(int32_t row) const {
107
107
108
108
float AudioStreamPlaybackMPT::get_current_channel_vu_left (int32_t channel) const {
109
109
CHECK_MOD_LOADED_RET (0 .0f );
110
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0 .0f );
110
111
return this ->mpt_module ->get_current_channel_vu_left (channel);
111
112
}
112
113
113
114
float AudioStreamPlaybackMPT::get_current_channel_vu_mono (int32_t channel) const {
114
115
CHECK_MOD_LOADED_RET (0 .0f );
116
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0 .0f );
115
117
return this ->mpt_module ->get_current_channel_vu_mono (channel);
116
118
}
117
119
118
120
float AudioStreamPlaybackMPT::get_current_channel_vu_rear_left (int32_t channel) const {
119
121
CHECK_MOD_LOADED_RET (0 .0f );
122
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0 .0f );
120
123
return this ->mpt_module ->get_current_channel_vu_rear_left (channel);
121
124
}
122
125
123
126
float AudioStreamPlaybackMPT::get_current_channel_vu_rear_right (int32_t channel) const {
124
127
CHECK_MOD_LOADED_RET (0 .0f );
128
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0 .0f );
125
129
return this ->mpt_module ->get_current_channel_vu_rear_right (channel);
126
130
}
127
131
128
132
float AudioStreamPlaybackMPT::get_current_channel_vu_right (int32_t channel) const {
129
133
CHECK_MOD_LOADED_RET (0 .0f );
134
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0 .0f );
130
135
return this ->mpt_module ->get_current_channel_vu_right (channel);
131
136
}
132
137
@@ -137,6 +142,7 @@ double AudioStreamPlaybackMPT::get_current_estimated_bpm() const {
137
142
138
143
void AudioStreamPlaybackMPT::select_subsong (int32_t subsong) {
139
144
CHECK_MOD_LOADED_RETV ();
145
+ ERR_FAIL_COND (subsong < -1 || subsong >= this ->mpt_module ->get_num_subsongs ());
140
146
this ->mpt_module ->select_subsong (subsong);
141
147
}
142
148
@@ -147,7 +153,7 @@ int32_t AudioStreamPlaybackMPT::get_selected_subsong() const {
147
153
148
154
void AudioStreamPlaybackMPT::set_current_speed (int32_t speed) {
149
155
CHECK_INT_LOADED_RETV ();
150
- this ->mpt_interactive ->set_current_speed (speed);
156
+ this ->mpt_interactive ->set_current_speed (Math::clamp ( speed, 1 , 65535 ) );
151
157
}
152
158
153
159
int32_t AudioStreamPlaybackMPT::get_current_speed () const {
@@ -157,7 +163,7 @@ int32_t AudioStreamPlaybackMPT::get_current_speed() const {
157
163
158
164
void AudioStreamPlaybackMPT::set_current_tempo (double tempo) {
159
165
CHECK_INT3_LOADED_RETV ();
160
- return this ->mpt_interactive3 ->set_current_tempo2 (tempo);
166
+ return this ->mpt_interactive3 ->set_current_tempo2 (Math::clamp ( tempo, 32.0 , 512.0 ) );
161
167
}
162
168
163
169
double AudioStreamPlaybackMPT::get_current_tempo () const {
@@ -167,7 +173,7 @@ double AudioStreamPlaybackMPT::get_current_tempo() const {
167
173
168
174
void AudioStreamPlaybackMPT::set_tempo_factor (double factor) {
169
175
CHECK_INT_LOADED_RETV ();
170
- this ->mpt_interactive ->set_tempo_factor (factor);
176
+ this ->mpt_interactive ->set_tempo_factor (Math::clamp ( factor, 0.00001 , 4.0 ) );
171
177
}
172
178
173
179
double AudioStreamPlaybackMPT::get_tempo_factor () const {
@@ -177,7 +183,7 @@ double AudioStreamPlaybackMPT::get_tempo_factor() const {
177
183
178
184
void AudioStreamPlaybackMPT::set_pitch_factor (double factor) {
179
185
CHECK_INT_LOADED_RETV ();
180
- this ->mpt_interactive ->set_pitch_factor (factor);
186
+ this ->mpt_interactive ->set_pitch_factor (Math::clamp ( factor, 0.00001 , 4.0 ) );
181
187
}
182
188
183
189
double AudioStreamPlaybackMPT::get_pitch_factor () const {
@@ -187,7 +193,7 @@ double AudioStreamPlaybackMPT::get_pitch_factor() const {
187
193
188
194
void AudioStreamPlaybackMPT::set_global_volume (double volume) {
189
195
CHECK_INT_LOADED_RETV ();
190
- this ->mpt_interactive ->set_global_volume (volume);
196
+ this ->mpt_interactive ->set_global_volume (Math::clamp ( volume, 0.0 , 1.0 ) );
191
197
}
192
198
193
199
double AudioStreamPlaybackMPT::get_global_volume () const {
@@ -197,71 +203,85 @@ double AudioStreamPlaybackMPT::get_global_volume() const {
197
203
198
204
void AudioStreamPlaybackMPT::set_channel_volume (int32_t channel, double volume) {
199
205
CHECK_INT_LOADED_RETV ();
200
- this ->mpt_interactive ->set_channel_volume (channel, volume);
206
+ ERR_FAIL_INDEX (channel, this ->mpt_module ->get_num_channels ());
207
+ this ->mpt_interactive ->set_channel_volume (channel, Math::clamp (volume, 0.0 , 1.0 ));
201
208
}
202
209
203
210
double AudioStreamPlaybackMPT::get_channel_volume (int32_t channel) const {
204
211
CHECK_INT_LOADED_RET (0.0 );
212
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0.0 );
205
213
return this ->mpt_interactive ->get_channel_volume (channel);
206
214
}
207
215
208
216
void AudioStreamPlaybackMPT::set_channel_mute_status (int32_t channel, bool mute) {
209
217
CHECK_INT_LOADED_RETV ();
218
+ ERR_FAIL_INDEX (channel, this ->mpt_module ->get_num_channels ());
210
219
this ->mpt_interactive ->set_channel_mute_status (channel, mute);
211
220
}
212
221
213
222
bool AudioStreamPlaybackMPT::get_channel_mute_status (int32_t channel) const {
214
223
CHECK_INT_LOADED_RET (false );
224
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), false );
215
225
return this ->mpt_interactive ->get_channel_mute_status (channel);
216
226
}
217
227
218
228
void AudioStreamPlaybackMPT::set_instrument_mute_status (int32_t instrument, bool mute) {
219
229
CHECK_INT_LOADED_RETV ();
230
+ ERR_FAIL_INDEX (instrument, this ->mpt_module ->get_num_instruments ());
220
231
this ->mpt_interactive ->set_instrument_mute_status (instrument, mute);
221
232
}
222
233
223
234
bool AudioStreamPlaybackMPT::get_instrument_mute_status (int32_t instrument) const {
224
235
CHECK_INT_LOADED_RET (false );
236
+ ERR_FAIL_INDEX_V (instrument, this ->mpt_module ->get_num_instruments (), false );
225
237
return this ->mpt_interactive ->get_instrument_mute_status (instrument);
226
238
}
227
239
228
240
int32_t AudioStreamPlaybackMPT::play_note (int32_t instrument, int32_t note, double volume, double panning) {
229
241
CHECK_INT_LOADED_RET (-1 );
230
- return this ->mpt_interactive ->play_note (instrument, note, volume, panning);
242
+ ERR_FAIL_INDEX_V (instrument, this ->mpt_module ->get_num_instruments (), -1 );
243
+ return this ->mpt_interactive ->play_note (instrument, Math::clamp (note, 0 , 119 ), Math::clamp (volume, 0.0 , 1.0 ), Math::clamp (panning, -1.0 , 1.0 ));
231
244
}
232
245
233
246
void AudioStreamPlaybackMPT::stop_note (int32_t channel) {
234
247
CHECK_INT_LOADED_RETV ();
248
+ ERR_FAIL_INDEX (channel, this ->mpt_module ->get_num_channels ());
235
249
this ->mpt_interactive ->stop_note (channel);
236
250
}
237
251
238
252
void AudioStreamPlaybackMPT::note_off (int32_t channel) {
239
253
CHECK_INT2_LOADED_RETV ();
254
+ ERR_FAIL_INDEX (channel, this ->mpt_module ->get_num_channels ());
240
255
this ->mpt_interactive2 ->note_off (channel);
241
256
}
242
257
243
258
void AudioStreamPlaybackMPT::note_fade (int32_t channel) {
244
259
CHECK_INT2_LOADED_RETV ();
260
+ ERR_FAIL_INDEX (channel, this ->mpt_module ->get_num_channels ());
245
261
this ->mpt_interactive2 ->note_fade (channel);
246
262
}
247
263
248
264
void AudioStreamPlaybackMPT::set_channel_panning (int32_t channel, double panning) {
249
265
CHECK_INT2_LOADED_RETV ();
250
- this ->mpt_interactive2 ->set_channel_panning (channel, panning);
266
+ ERR_FAIL_INDEX (channel, this ->mpt_module ->get_num_channels ());
267
+ this ->mpt_interactive2 ->set_channel_panning (channel, Math::clamp (panning, -1.0 , 1.0 ));
251
268
}
252
269
253
270
double AudioStreamPlaybackMPT::get_channel_panning (int32_t channel) const {
254
271
CHECK_INT2_LOADED_RET (0.0 );
272
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0.0 );
255
273
return this ->mpt_interactive2 ->get_channel_panning (channel);
256
274
}
257
275
258
276
void AudioStreamPlaybackMPT::set_note_finetune (int32_t channel, double finetune) {
259
277
CHECK_INT2_LOADED_RETV ();
260
- this ->mpt_interactive2 ->set_note_finetune (channel, finetune);
278
+ ERR_FAIL_INDEX (channel, this ->mpt_module ->get_num_channels ());
279
+ this ->mpt_interactive2 ->set_note_finetune (channel, Math::clamp (finetune, -1.0 , 1.0 ));
261
280
}
262
281
263
282
double AudioStreamPlaybackMPT::get_note_finetune (int32_t channel) const {
264
283
CHECK_INT2_LOADED_RET (0.0 );
284
+ ERR_FAIL_INDEX_V (channel, this ->mpt_module ->get_num_channels (), 0.0 );
265
285
return this ->mpt_interactive2 ->get_note_finetune (channel);
266
286
}
267
287
@@ -459,6 +479,7 @@ const PackedByteArray& AudioStreamMPT::get_data() const {
459
479
460
480
void AudioStreamMPT::select_subsong (int32_t subsong) {
461
481
CHECK_MOD_LOADED_RETV ();
482
+ ERR_FAIL_COND (subsong < -1 || subsong >= this ->mpt_module ->get_num_subsongs ());
462
483
this ->mpt_module ->select_subsong (subsong);
463
484
}
464
485
0 commit comments