2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2016 Alexander König
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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, see <http://www.gnu.org/licenses/>.
20 Description: Header to tX_vtt.cc
22 08 Dec 1999 - added audiofile support
32 #include "tX_vttgui.h"
36 #include "tX_audiofile.h"
37 #include "tX_seqpar.h"
39 #include "tX_ladspa.h"
41 #define EC_MAX_BUFFER 256000
43 #define NEED_FADE_OUT 0
44 #define NEED_FADE_IN 1
46 #define SAMPLE_MAX 32760.0
47 #define SAMPLE_BORDER 30000.0
49 #include <libxml/xmlmemory.h>
50 #include <libxml/parser.h>
56 static int vtt_amount;
57 static list <vtt_class *> main_list;
58 static list <vtt_class *> render_list;
60 static f_prec *mix_buffer;
61 static f_prec *mix_buffer_end;
63 static int16_t *mix_out_buffer;
64 static f_prec mix_max_l;
65 static f_prec mix_max_r;
66 static int samples_in_mix_buffer;
67 static pthread_mutex_t render_lock;
69 static f_prec master_volume;
70 static f_prec res_master_volume;
71 static f_prec vol_channel_adjust;
73 static vtt_class * sync_master;
74 static int master_triggered;
75 static int master_triggered_at;
76 static vtt_class * focused_vtt;
78 static int mix_buffer_size;
79 static int last_sample_rate;
85 /* main object vars */
86 char name[256]; // Turntable's name
87 char filename[PATH_MAX]; // The corresponding audiofile
99 double control_scroll_adjustment;
108 int16_t *buffer; // Actual audio data
109 unsigned int samples_in_buffer; // No. of samples in audio data
112 f_prec *output_buffer;
113 f_prec *end_of_outputbuffer;
115 f_prec *output_buffer2; // 2nd audio channel
117 f_prec samples_in_outputbuffer;
118 f_prec inv_samples_in_outputbuffer;
120 /* main playback vars */
121 f_prec rel_volume; // The (user-selected) relative volume
122 f_prec res_volume; // The resulting volume
123 f_prec rel_pitch; // The (user-selected) relative pitch
127 f_prec pan; // The logical pan value -1 left, 0 center, 1 right
128 f_prec res_volume_left;
129 f_prec res_volume_right;
145 unsigned int pos_i_max;
156 /* seq par mapping for x/y axis */
175 f_prec ec_buffer[EC_MAX_BUFFER];
176 f_prec *ec_output_buffer;
181 f_prec ec_res_length;
185 f_prec ec_volume_left;
186 f_prec ec_volume_right;
188 /* sequenceable parameters */
189 tX_seqpar_vtt_speed sp_speed;
190 tX_seqpar_vtt_volume sp_volume;
191 tX_seqpar_vtt_pitch sp_pitch;
192 tX_seqpar_vtt_pan sp_pan;
193 tX_seqpar_vtt_trigger sp_trigger;
194 tX_seqpar_vtt_loop sp_loop;
195 tX_seqpar_vtt_sync_client sp_sync_client;
196 tX_seqpar_vtt_sync_cycles sp_sync_cycles;
197 tX_seqpar_vtt_lp_enable sp_lp_enable;
198 tX_seqpar_vtt_lp_gain sp_lp_gain;
199 tX_seqpar_vtt_lp_reso sp_lp_reso;
200 tX_seqpar_vtt_lp_freq sp_lp_freq;
201 tX_seqpar_vtt_ec_enable sp_ec_enable;
202 tX_seqpar_vtt_ec_length sp_ec_length;
203 tX_seqpar_vtt_ec_feedback sp_ec_feedback;
204 tX_seqpar_vtt_ec_pan sp_ec_pan;
205 tX_seqpar_vtt_ec_volume sp_ec_volume;
206 tX_seqpar_vtt_mute sp_mute;
207 tX_seqpar_spin sp_spin;
209 tx_audiofile *audiofile;
210 f_prec audiofile_pitch_correction;
212 list <vtt_fx *> fx_list;
213 list <vtt_fx_stereo_ladspa *> stereo_fx_list;
220 static int get_mix_buffer_size() { return mix_buffer_size; }
222 /* Parameter setup methods */
223 void set_name(char *);
224 int set_output_buffer_size(int);
226 void set_volume(f_prec);
227 void recalc_volume();
229 void set_pan(f_prec);
230 void adjust_to_master_pitch(int master_cycles, int cycles, bool create_event);
231 void set_pitch(f_prec);
234 void set_autotrigger(int);
239 void set_y_input_parameter(tX_seqpar *);
240 void set_x_input_parameter(tX_seqpar *);
243 void lp_set_enable(int);
244 void lp_set_gain(f_prec);
245 void lp_set_reso(f_prec);
246 void lp_set_freq(f_prec);
247 void lp_setup(f_prec, f_prec, f_prec);
249 void ec_set_enable(int);
250 void ec_set_length(f_prec);
251 void ec_set_feedback(f_prec);
252 void ec_set_volume(f_prec);
253 void ec_set_pan(f_prec);
254 void ec_clear_buffer();
256 void set_sync_master(int);
257 void set_sync_client(int, int);
258 void set_sync_client_ug(int, int); // and update gui
260 void set_scratch(int);
261 void xy_input(f_prec, f_prec);
263 vtt_fx_ladspa * add_effect(LADSPA_Plugin *);
264 vtt_fx_stereo_ladspa * add_stereo_effect (LADSPA_Stereo_Plugin *plugin);
268 void forward_turntable();
270 static int16_t *render_all_turntables();
271 static void forward_all_turntables();
273 static int set_mix_buffer_size(int);
274 static void set_master_volume(f_prec);
275 static void set_master_pitch(f_prec);
276 static void focus_no(int);
277 static void focus_next();
278 static void unfocus();
279 static void set_sample_rate(int samplerate);
281 int trigger(bool need_lock=true);
285 bool cleanup_required;
286 bool needs_cleaning_up() { return cleanup_required; }
288 int save(FILE *, gzFile rz, char *indent);
289 static int save_all(FILE *, gzFile rz);
290 int load(xmlDocPtr, xmlNodePtr);
291 static int load_all(xmlDocPtr doc, char *fname);
292 static void delete_all();
294 #ifdef ENABLE_TX_LEGACY
301 static int load_all_10(FILE *, char *fname); /* fname is for display only*/
302 static int load_all_11(FILE *, char *fname); /* fname is for display only*/
303 static int load_all_12(FILE *, char *fname); /* fname is for display only*/
304 static int load_all_13(FILE *, char *fname); /* fname is for display only*/
305 static int load_all_14(FILE *, char *fname); /* fname is for display only*/
308 tX_audio_error load_file(char *name);
310 void render_scratch();
314 void effect_up(vtt_fx *effect);
315 void effect_down(vtt_fx *effect);
316 void effect_remove(vtt_fx_ladspa *effect);
318 void hide_audio(bool);
319 void hide_control(bool);
321 void set_mix_mute(int newstate);
322 void set_mix_solo(int newstate);
323 static int get_last_sample_rate() { return last_sample_rate; }
326 res_mute=((mute) || (mix_mute && (!mix_solo)) || ((solo_ctr>0)&&(!mix_solo)));
329 static f_prec *get_mix_buffer() { return mix_buffer; }