2 terminatorX - realtime audio scratching software
3 Copyright (C) 1999-2003 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, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 Description: Header to tX_vtt.cc
23 08 Dec 1999 - added audiofile support
33 #include "tX_vttgui.h"
37 #include "tX_audiofile.h"
38 #include "tX_seqpar.h"
40 #include "tX_ladspa.h"
42 #define EC_MAX_BUFFER 256000
44 #define NEED_FADE_OUT 0
45 #define NEED_FADE_IN 1
47 #define SAMPLE_MAX 32760.0
48 #define SAMPLE_BORDER 30000.0
50 #include <libxml/xmlmemory.h>
51 #include <libxml/parser.h>
57 static int vtt_amount;
58 static list <vtt_class *> main_list;
59 static list <vtt_class *> render_list;
61 static f_prec *mix_buffer;
62 static f_prec *mix_buffer_end;
64 static int16_t *mix_out_buffer;
65 static f_prec mix_max_l;
66 static f_prec mix_max_r;
67 static int samples_in_mix_buffer;
68 static pthread_mutex_t render_lock;
70 static f_prec master_volume;
71 static f_prec res_master_volume;
72 static f_prec vol_channel_adjust;
74 static vtt_class * sync_master;
75 static int master_triggered;
76 static int master_triggered_at;
77 static vtt_class * focused_vtt;
79 static int mix_buffer_size;
80 static int last_sample_rate;
86 /* main object vars */
87 char name[256]; // Turntable's name
88 char filename[PATH_MAX]; // The corresponding audiofile
107 int16_t *buffer; // Actual audio data
108 unsigned int samples_in_buffer; // No. of samples in audio data
111 f_prec *output_buffer;
112 f_prec *end_of_outputbuffer;
113 f_prec samples_in_outputbuffer;
114 f_prec inv_samples_in_outputbuffer;
116 /* main playback vars */
117 f_prec rel_volume; // The (user-selected) relative volume
118 f_prec res_volume; // The resulting volume
119 f_prec rel_pitch; // The (user-selected) relative pitch
123 f_prec pan; // The logical pan value -1 left, 0 center, 1 right
124 f_prec res_volume_left;
125 f_prec res_volume_right;
141 unsigned int pos_i_max;
152 /* seq par mapping for x/y axis */
171 f_prec ec_buffer[EC_MAX_BUFFER];
172 f_prec *ec_output_buffer;
177 f_prec ec_res_length;
181 f_prec ec_volume_left;
182 f_prec ec_volume_right;
184 /* sequenceable parameters */
185 tX_seqpar_vtt_speed sp_speed;
186 tX_seqpar_vtt_volume sp_volume;
187 tX_seqpar_vtt_pitch sp_pitch;
188 tX_seqpar_vtt_pan sp_pan;
189 tX_seqpar_vtt_trigger sp_trigger;
190 tX_seqpar_vtt_loop sp_loop;
191 tX_seqpar_vtt_sync_client sp_sync_client;
192 tX_seqpar_vtt_sync_cycles sp_sync_cycles;
193 tX_seqpar_vtt_lp_enable sp_lp_enable;
194 tX_seqpar_vtt_lp_gain sp_lp_gain;
195 tX_seqpar_vtt_lp_reso sp_lp_reso;
196 tX_seqpar_vtt_lp_freq sp_lp_freq;
197 tX_seqpar_vtt_ec_enable sp_ec_enable;
198 tX_seqpar_vtt_ec_length sp_ec_length;
199 tX_seqpar_vtt_ec_feedback sp_ec_feedback;
200 tX_seqpar_vtt_ec_pan sp_ec_pan;
201 tX_seqpar_vtt_ec_volume sp_ec_volume;
202 tX_seqpar_vtt_mute sp_mute;
203 tX_seqpar_spin sp_spin;
205 tx_audiofile *audiofile;
206 f_prec audiofile_pitch_correction;
208 list <vtt_fx *> fx_list;
215 static int get_mix_buffer_size() { return mix_buffer_size; }
217 /* Parameter setup methods */
218 void set_name(char *);
219 int set_output_buffer_size(int);
221 void set_volume(f_prec);
222 void recalc_volume();
224 void set_pan(f_prec);
225 void adjust_to_master_pitch(int master_cycles, int cycles, bool create_event);
226 void set_pitch(f_prec);
229 void set_autotrigger(int);
234 void set_y_input_parameter(tX_seqpar *);
235 void set_x_input_parameter(tX_seqpar *);
238 void lp_set_enable(int);
239 void lp_set_gain(f_prec);
240 void lp_set_reso(f_prec);
241 void lp_set_freq(f_prec);
242 void lp_setup(f_prec, f_prec, f_prec);
244 void ec_set_enable(int);
245 void ec_set_length(f_prec);
246 void ec_set_feedback(f_prec);
247 void ec_set_volume(f_prec);
248 void ec_set_pan(f_prec);
249 void ec_clear_buffer();
251 void set_sync_master(int);
252 void set_sync_client(int, int);
253 void set_sync_client_ug(int, int); // and update gui
255 void set_scratch(int);
256 void xy_input(f_prec, f_prec);
258 vtt_fx_ladspa * add_effect(LADSPA_Plugin *);
262 void forward_turntable();
264 static int16_t *render_all_turntables();
265 static void forward_all_turntables();
267 static int set_mix_buffer_size(int);
268 static void set_master_volume(f_prec);
269 static void set_master_pitch(f_prec);
270 static void focus_no(int);
271 static void focus_next();
272 static void unfocus();
273 static void set_sample_rate(int samplerate);
275 int trigger(bool need_lock=true);
279 bool cleanup_required;
280 bool needs_cleaning_up() { return cleanup_required; }
282 int save(FILE *, gzFile rz, char *indent);
283 static int save_all(FILE *, gzFile rz);
284 int load(xmlDocPtr, xmlNodePtr);
285 static int load_all(xmlDocPtr doc, char *fname);
286 static void delete_all();
288 #ifdef ENABLE_TX_LEGACY
295 static int load_all_10(FILE *, char *fname); /* fname is for display only*/
296 static int load_all_11(FILE *, char *fname); /* fname is for display only*/
297 static int load_all_12(FILE *, char *fname); /* fname is for display only*/
298 static int load_all_13(FILE *, char *fname); /* fname is for display only*/
299 static int load_all_14(FILE *, char *fname); /* fname is for display only*/
302 tX_audio_error load_file(char *name);
304 void render_scratch();
308 void effect_up(vtt_fx *effect);
309 void effect_down(vtt_fx *effect);
310 void effect_remove(vtt_fx_ladspa *effect);
312 void hide_audio(bool);
313 void hide_control(bool);
315 void set_mix_mute(int newstate);
316 void set_mix_solo(int newstate);
317 static int get_last_sample_rate() { return last_sample_rate; }
320 res_mute=((mute) || (mix_mute && (!mix_solo)) || ((solo_ctr>0)&&(!mix_solo)));
323 static f_prec *get_mix_buffer() { return mix_buffer; }