3 * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "automation.h"
28 #include "edlsession.h"
33 #include "localsession.h"
38 #include "mainsession.h"
42 #include "trackcanvas.h"
44 #include "transportque.inc"
48 Tracks::Tracks(EDL *edl)
69 void Tracks::equivalent_output(Tracks *tracks, double *result)
71 if(total_playable_vtracks() != tracks->total_playable_vtracks())
77 Track *current = first;
78 Track *that_current = tracks->first;
79 while(current || that_current)
81 // Get next video track
82 while(current && current->data_type != TRACK_VIDEO)
85 while(that_current && that_current->data_type != TRACK_VIDEO)
86 that_current = that_current->next;
88 // One doesn't exist but the other does
89 if((!current && that_current) ||
90 (current && !that_current))
97 if(current && that_current)
99 current->equivalent_output(that_current, result);
101 that_current = that_current->next;
108 void Tracks::clear_selected_edits()
110 for( Track *track=first; track; track=track->next ) {
111 for( Edit *edit=track->edits->first; edit; edit=edit->next )
112 edit->is_selected = 0;
116 void Tracks::select_affected_edits(double position, Track *start_track)
118 for( Track *track=start_track; track; track=track->next ) {
119 if( !track->record ) continue;
120 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
121 double startproject = track->from_units(edit->startproject);
122 if( edl->equivalent(startproject, position) ) {
123 edit->is_selected = 1;
130 void Tracks::get_selected_edits(ArrayList<Edit*> *drag_edits)
132 drag_edits->remove_all();
133 for( Track *track=first; track; track=track->next ) {
134 if( !track->record ) continue;
135 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
136 if( !edit->is_selected ) continue;
137 drag_edits->append(edit);
142 void Tracks::get_automation_extents(float *min,
150 int coords_undefined = 1;
151 for(Track *current = first; current; current = NEXT)
155 current->automation->get_extents(min,
158 current->to_units(start, 0),
159 current->to_units(end, 1),
166 void Tracks::copy_from(Tracks *tracks)
168 Track *new_track = 0;
171 for(Track *current = tracks->first; current; current = NEXT)
173 switch(current->data_type)
176 new_track = add_audio_track(0, 0);
179 new_track = add_video_track(0, 0);
182 new_track = add_subttl_track(0, 0);
187 new_track->copy_from(current);
191 Tracks& Tracks::operator=(Tracks &tracks)
193 printf("Tracks::operator= 1\n");
198 int Tracks::load(FileXML *xml,
202 // add the appropriate type of track
203 char string[BCTEXTLEN];
207 xml->tag.get_property("TYPE", string);
209 if((load_flags & LOAD_ALL) == LOAD_ALL ||
210 (load_flags & LOAD_EDITS)) {
211 if(!strcmp(string, "VIDEO")) {
212 track = add_video_track(0, 0);
214 else if(!strcmp(string, "SUBTTL")) {
215 track = add_subttl_track(0, 0);
218 track = add_audio_track(0, 0); // default to audio
222 track = get_item_number(track_offset++);
226 if( track ) track->load(xml, track_offset, load_flags);
231 Track* Tracks::add_audio_track(int above, Track *dst_track)
233 ATrack* new_track = new ATrack(edl, this);
236 dst_track = (above ? first : last);
241 insert_before(dst_track, (Track*)new_track);
245 insert_after(dst_track, (Track*)new_track);
246 // Shift effects referenced below the destination track
249 // Shift effects referenced below the new track
250 for(Track *track = last;
251 track && track != new_track;
252 track = track->previous)
254 change_modules(number_of(track) - 1, number_of(track), 0);
258 new_track->create_objects();
259 new_track->set_default_title();
262 for(Track *current = first;
263 current != (Track*)new_track;
266 if(current->data_type == TRACK_AUDIO) current_pan++;
267 if(current_pan >= edl->session->audio_channels) current_pan = 0;
273 (PanAuto*)new_track->automation->autos[AUTOMATION_PAN]->default_auto;
274 pan_auto->values[current_pan] = 1.0;
276 BC_Pan::calculate_stick_position(edl->session->audio_channels,
277 edl->session->achannel_positions,
286 Track* Tracks::add_video_track(int above, Track *dst_track)
288 VTrack* new_track = new VTrack(edl, this);
290 dst_track = (above ? first : last);
292 insert_before(dst_track, (Track*)new_track);
294 insert_after(dst_track, (Track*)new_track);
296 for(Track *track = last; track && track != new_track; track = track->previous)
297 change_modules(number_of(track) - 1, number_of(track), 0);
299 new_track->create_objects();
300 new_track->set_default_title();
305 Track* Tracks::add_subttl_track(int above, Track *dst_track)
307 STrack* new_track = new STrack(edl, this);
309 dst_track = (above ? first : last);
312 insert_before(dst_track, (Track*)new_track);
314 insert_after(dst_track, (Track*)new_track);
316 for(Track *track = last; track && track != new_track; track = track->previous)
317 change_modules(number_of(track) - 1, number_of(track), 0);
319 new_track->create_objects();
320 new_track->set_default_title();
321 // new_track->paste_silence(0,total_length(),0);
326 int Tracks::delete_track(Track *track)
331 int old_location = number_of(track);
332 detach_shared_effects(old_location);
334 // Shift effects referencing effects below the deleted track
335 for(Track *current = track;
339 change_modules(number_of(current), number_of(current) - 1, 0);
341 if(track) delete track;
346 int Tracks::detach_shared_effects(int module)
348 for(Track *current = first; current; current = NEXT)
350 current->detach_shared_effects(module);
356 int Tracks::total_of(int type)
360 for(Track *current = first; current; current = NEXT)
362 long unit_start = current->to_units(edl->local_session->get_selectionstart(1), 0);
363 Auto *mute_keyframe = 0;
364 current->automation->autos[AUTOMATION_MUTE]->
365 get_prev_auto(unit_start, PLAY_FORWARD, mute_keyframe);
366 IntAuto *mute_auto = (IntAuto *)mute_keyframe;
369 (current->play && type == PLAY) ||
370 (current->record && type == RECORD) ||
371 (current->gang && type == GANG) ||
372 (current->draw && type == DRAW) ||
373 (mute_auto->value && type == MUTE) ||
374 (current->expand_view && type == EXPAND);
379 int Tracks::recordable_audio_tracks()
382 for(Track *current = first; current; current = NEXT)
383 if(current->data_type == TRACK_AUDIO && current->record) result++;
387 int Tracks::recordable_video_tracks()
390 for(Track *current = first; current; current = NEXT)
392 if(current->data_type == TRACK_VIDEO && current->record) result++;
398 int Tracks::playable_audio_tracks()
402 for(Track *current = first; current; current = NEXT)
404 if(current->data_type == TRACK_AUDIO && current->play)
413 int Tracks::playable_video_tracks()
417 for(Track *current = first; current; current = NEXT)
419 if(current->data_type == TRACK_VIDEO && current->play)
427 int Tracks::total_audio_tracks()
430 for(Track *current = first; current; current = NEXT)
431 if(current->data_type == TRACK_AUDIO) result++;
435 int Tracks::total_video_tracks()
438 for(Track *current = first; current; current = NEXT)
439 if(current->data_type == TRACK_VIDEO) result++;
443 double Tracks::total_playable_length()
446 for(Track *current = first; current; current = NEXT)
450 double length = current->get_length();
451 if(length > total) total = length;
457 double Tracks::total_recordable_length()
460 for(Track *current = first; current; current = NEXT)
464 double length = current->get_length();
465 if(length > total) total = length;
471 double Tracks::total_length()
474 for(Track *current = first; current; current = NEXT)
476 double length = current->get_length();
477 if(length > total) total = length;
482 double Tracks::total_audio_length()
485 for(Track *current = first; current; current = NEXT)
487 if(current->data_type == TRACK_AUDIO &&
488 current->get_length() > total) total = current->get_length();
493 double Tracks::total_video_length()
496 for(Track *current = first; current; current = NEXT)
498 if(current->data_type == TRACK_VIDEO &&
499 current->get_length() > total) total = current->get_length();
504 double Tracks::total_length_framealigned(double fps)
506 if (total_audio_tracks() && total_video_tracks())
507 return MIN(floor(total_audio_length() * fps), floor(total_video_length() * fps)) / fps;
509 if (total_audio_tracks())
510 return floor(total_audio_length() * fps) / fps;
512 if (total_video_tracks())
513 return floor(total_video_length() * fps) / fps;
518 void Tracks::translate_projector(float offset_x, float offset_y)
520 for(Track *current = first; current; current = NEXT)
522 if(current->data_type == TRACK_VIDEO)
524 ((VTrack*)current)->translate(offset_x, offset_y, 0);
529 void Tracks::update_y_pixels(Theme *theme)
531 // int y = -edl->local_session->track_start;
533 for(Track *current = first; current; current = NEXT)
535 //printf("Tracks::update_y_pixels %d\n", y);
536 current->y_pixel = y;
537 y += current->vertical_span(theme);
541 int Tracks::dump(FILE *fp)
543 for(Track* current = first; current; current = NEXT)
545 fprintf(fp," Track: %p\n", current);
552 void Tracks::select_all(int type,
555 for(Track* current = first; current; current = NEXT)
557 double position = edl->local_session->get_selectionstart(1);
559 if(type == PLAY) current->play = value;
560 if(type == RECORD) current->record = value;
561 if(type == GANG) current->gang = value;
562 if(type == DRAW) current->draw = value;
566 ((IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_auto_for_editing(position))->value = value;
569 if(type == EXPAND) current->expand_view = value;
573 // ===================================== file operations
575 int Tracks::popup_transition(int cursor_x, int cursor_y)
578 for(Track* current = first; current && !result; current = NEXT)
580 result = current->popup_transition(cursor_x, cursor_y);
586 int Tracks::change_channels(int oldchannels, int newchannels)
588 for(Track *current = first; current; current = NEXT)
589 { current->change_channels(oldchannels, newchannels); }
595 int Tracks::totalpixels()
598 for(Track* current = first; current; current = NEXT)
600 result += edl->local_session->zoom_track;
605 int Tracks::number_of(Track *track)
608 for(Track *current = first; current && current != track; current = NEXT)
615 Track* Tracks::number(int number)
619 for(current = first; current && i < number; current = NEXT)
627 int Tracks::total_playable_vtracks()
630 for(Track *current = first; current; current = NEXT)
632 if(current->data_type == TRACK_VIDEO && current->play) result++;
637 int Tracks::plugin_exists(Plugin *plugin)
639 for(Track *track = first; track; track = track->next)
641 if(track->plugin_exists(plugin)) return 1;
646 int Tracks::track_exists(Track *track)
648 for(Track *current = first; current; current = NEXT)
650 if(current == track) return 1;
655 int Tracks::new_group(int id)
658 for( Track *track=first; track; track=track->next ) {
659 if( !track->record ) continue;
660 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
661 if( !edit->is_selected ) continue;
669 int Tracks::set_group_selected(int id, int v)
672 for( Track *track=first; track; track=track->next ) {
673 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
674 if( edit->group_id != id ) continue;
675 edit->is_selected = v;
682 int Tracks::del_group(int id)
685 for( Track *track=first; track; track=track->next ) {
686 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
687 if( edit->group_id != id ) continue;
688 edit->is_selected = 1;
696 Track *Tracks::get(int idx, int data_type)
698 for(Track *current = first; current; current = NEXT)
700 if( current->data_type != data_type ) continue;
701 if( --idx < 0 ) return current;