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;
110 void Tracks::get_affected_edits(ArrayList<Edit*> *drag_edits, double position, Track *start_track)
112 drag_edits->remove_all();
114 for(Track *track = start_track;
118 //printf("Tracks::get_affected_edits 1 %p %d %d\n", track, track->data_type, track->record);
121 for(Edit *edit = track->edits->first; edit; edit = edit->next)
123 double startproject = track->from_units(edit->startproject);
124 //printf("Tracks::get_affected_edits 1 %d\n", edl->equivalent(startproject, position));
125 if(edl->equivalent(startproject, position))
127 drag_edits->append(edit);
136 void Tracks::get_automation_extents(float *min,
144 int coords_undefined = 1;
145 for(Track *current = first; current; current = NEXT)
149 current->automation->get_extents(min,
152 current->to_units(start, 0),
153 current->to_units(end, 1),
160 void Tracks::copy_from(Tracks *tracks)
162 Track *new_track = 0;
165 for(Track *current = tracks->first; current; current = NEXT)
167 switch(current->data_type)
170 new_track = add_audio_track(0, 0);
173 new_track = add_video_track(0, 0);
176 new_track = add_subttl_track(0, 0);
181 new_track->copy_from(current);
185 Tracks& Tracks::operator=(Tracks &tracks)
187 printf("Tracks::operator= 1\n");
192 int Tracks::load(FileXML *xml,
196 // add the appropriate type of track
197 char string[BCTEXTLEN];
201 xml->tag.get_property("TYPE", string);
203 if((load_flags & LOAD_ALL) == LOAD_ALL ||
204 (load_flags & LOAD_EDITS))
206 if(!strcmp(string, "VIDEO"))
208 add_video_track(0, 0);
211 if(!strcmp(string, "SUBTTL"))
213 add_subttl_track(0, 0);
217 add_audio_track(0, 0); // default to audio
223 track = get_item_number(track_offset);
228 if(track) track->load(xml, track_offset, load_flags);
233 Track* Tracks::add_audio_track(int above, Track *dst_track)
235 ATrack* new_track = new ATrack(edl, this);
238 dst_track = (above ? first : last);
243 insert_before(dst_track, (Track*)new_track);
247 insert_after(dst_track, (Track*)new_track);
248 // Shift effects referenced below the destination track
251 // Shift effects referenced below the new track
252 for(Track *track = last;
253 track && track != new_track;
254 track = track->previous)
256 change_modules(number_of(track) - 1, number_of(track), 0);
260 new_track->create_objects();
261 new_track->set_default_title();
264 for(Track *current = first;
265 current != (Track*)new_track;
268 if(current->data_type == TRACK_AUDIO) current_pan++;
269 if(current_pan >= edl->session->audio_channels) current_pan = 0;
275 (PanAuto*)new_track->automation->autos[AUTOMATION_PAN]->default_auto;
276 pan_auto->values[current_pan] = 1.0;
278 BC_Pan::calculate_stick_position(edl->session->audio_channels,
279 edl->session->achannel_positions,
288 Track* Tracks::add_video_track(int above, Track *dst_track)
291 if(debug) printf("Tracks::add_video_track %d\n", __LINE__);
292 VTrack* new_track = new VTrack(edl, this);
293 if(debug) printf("Tracks::add_video_track %d\n", __LINE__);
295 dst_track = (above ? first : last);
297 if(debug) printf("Tracks::add_video_track %d\n", __LINE__);
300 insert_before(dst_track, (Track*)new_track);
304 insert_after(dst_track, (Track*)new_track);
306 if(debug) printf("Tracks::add_video_track %d\n", __LINE__);
310 // Shift effects referenced below the new track
311 for(Track *track = last;
312 track && track != new_track;
313 track = track->previous)
315 change_modules(number_of(track) - 1, number_of(track), 0);
318 if(debug) printf("Tracks::add_video_track %d\n", __LINE__);
321 new_track->create_objects();
322 if(debug) printf("Tracks::add_video_track %d\n", __LINE__);
323 new_track->set_default_title();
324 if(debug) printf("Tracks::add_video_track %d\n", __LINE__);
329 Track* Tracks::add_subttl_track(int above, Track *dst_track)
332 if(debug) printf("Tracks::add_subttl_track %d\n", __LINE__);
333 STrack* new_track = new STrack(edl, this);
334 if(debug) printf("Tracks::add_subttl_track %d\n", __LINE__);
336 dst_track = (above ? first : last);
338 if(debug) printf("Tracks::add_subttl_track %d\n", __LINE__);
341 insert_before(dst_track, (Track*)new_track);
345 insert_after(dst_track, (Track*)new_track);
347 if(debug) printf("Tracks::add_subttl_track %d\n", __LINE__);
351 // Shift effects referenced below the new track
352 for(Track *track = last;
353 track && track != new_track;
354 track = track->previous)
356 change_modules(number_of(track) - 1, number_of(track), 0);
359 if(debug) printf("Tracks::add_subttl_track %d\n", __LINE__);
362 new_track->create_objects();
363 if(debug) printf("Tracks::add_subttl_track %d\n", __LINE__);
364 new_track->set_default_title();
365 if(debug) printf("Tracks::add_subttl_track %d\n", __LINE__);
367 // new_track->paste_silence(0,total_length(),0);
372 int Tracks::delete_track(Track *track)
377 int old_location = number_of(track);
378 detach_shared_effects(old_location);
380 // Shift effects referencing effects below the deleted track
381 for(Track *current = track;
385 change_modules(number_of(current), number_of(current) - 1, 0);
387 if(track) delete track;
392 int Tracks::detach_shared_effects(int module)
394 for(Track *current = first; current; current = NEXT)
396 current->detach_shared_effects(module);
402 int Tracks::total_of(int type)
405 IntAuto *mute_keyframe = 0;
407 for(Track *current = first; current; current = NEXT)
409 long unit_start = current->to_units(edl->local_session->get_selectionstart(1), 0);
411 (IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_prev_auto(
414 (Auto* &)mute_keyframe);
417 (current->play && type == PLAY) ||
418 (current->record && type == RECORD) ||
419 (current->gang && type == GANG) ||
420 (current->draw && type == DRAW) ||
421 (mute_keyframe->value && type == MUTE) ||
422 (current->expand_view && type == EXPAND);
427 int Tracks::recordable_audio_tracks()
430 for(Track *current = first; current; current = NEXT)
431 if(current->data_type == TRACK_AUDIO && current->record) result++;
435 int Tracks::recordable_video_tracks()
438 for(Track *current = first; current; current = NEXT)
440 if(current->data_type == TRACK_VIDEO && current->record) result++;
446 int Tracks::playable_audio_tracks()
450 for(Track *current = first; current; current = NEXT)
452 if(current->data_type == TRACK_AUDIO && current->play)
461 int Tracks::playable_video_tracks()
465 for(Track *current = first; current; current = NEXT)
467 if(current->data_type == TRACK_VIDEO && current->play)
475 int Tracks::total_audio_tracks()
478 for(Track *current = first; current; current = NEXT)
479 if(current->data_type == TRACK_AUDIO) result++;
483 int Tracks::total_video_tracks()
486 for(Track *current = first; current; current = NEXT)
487 if(current->data_type == TRACK_VIDEO) result++;
491 double Tracks::total_playable_length()
494 for(Track *current = first; current; current = NEXT)
496 double length = current->get_length();
497 if(length > total) total = length;
502 double Tracks::total_recordable_length()
505 for(Track *current = first; current; current = NEXT)
509 double length = current->get_length();
510 if(length > total) total = length;
516 double Tracks::total_length()
519 for(Track *current = first; current; current = NEXT)
521 if(current->get_length() > total) total = current->get_length();
526 double Tracks::total_audio_length()
529 for(Track *current = first; current; current = NEXT)
531 if(current->data_type == TRACK_AUDIO &&
532 current->get_length() > total) total = current->get_length();
537 double Tracks::total_video_length()
540 for(Track *current = first; current; current = NEXT)
542 if(current->data_type == TRACK_VIDEO &&
543 current->get_length() > total) total = current->get_length();
548 double Tracks::total_length_framealigned(double fps)
550 if (total_audio_tracks() && total_video_tracks())
551 return MIN(floor(total_audio_length() * fps), floor(total_video_length() * fps)) / fps;
553 if (total_audio_tracks())
554 return floor(total_audio_length() * fps) / fps;
556 if (total_video_tracks())
557 return floor(total_video_length() * fps) / fps;
562 void Tracks::translate_projector(float offset_x, float offset_y)
564 for(Track *current = first; current; current = NEXT)
566 if(current->data_type == TRACK_VIDEO)
568 ((VTrack*)current)->translate(offset_x, offset_y, 0);
573 void Tracks::update_y_pixels(Theme *theme)
575 // int y = -edl->local_session->track_start;
577 for(Track *current = first; current; current = NEXT)
579 //printf("Tracks::update_y_pixels %d\n", y);
580 current->y_pixel = y;
581 y += current->vertical_span(theme);
585 int Tracks::dump(FILE *fp)
587 for(Track* current = first; current; current = NEXT)
589 fprintf(fp," Track: %p\n", current);
596 void Tracks::select_all(int type,
599 for(Track* current = first; current; current = NEXT)
601 double position = edl->local_session->get_selectionstart(1);
603 if(type == PLAY) current->play = value;
604 if(type == RECORD) current->record = value;
605 if(type == GANG) current->gang = value;
606 if(type == DRAW) current->draw = value;
610 ((IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_auto_for_editing(position))->value = value;
613 if(type == EXPAND) current->expand_view = value;
617 // ===================================== file operations
619 int Tracks::popup_transition(int cursor_x, int cursor_y)
622 for(Track* current = first; current && !result; current = NEXT)
624 result = current->popup_transition(cursor_x, cursor_y);
630 int Tracks::change_channels(int oldchannels, int newchannels)
632 for(Track *current = first; current; current = NEXT)
633 { current->change_channels(oldchannels, newchannels); }
639 int Tracks::totalpixels()
642 for(Track* current = first; current; current = NEXT)
644 result += edl->local_session->zoom_track;
649 int Tracks::number_of(Track *track)
652 for(Track *current = first; current && current != track; current = NEXT)
659 Track* Tracks::number(int number)
663 for(current = first; current && i < number; current = NEXT)
671 int Tracks::total_playable_vtracks()
674 for(Track *current = first; current; current = NEXT)
676 if(current->data_type == TRACK_VIDEO && current->play) result++;
681 int Tracks::plugin_exists(Plugin *plugin)
683 for(Track *track = first; track; track = track->next)
685 if(track->plugin_exists(plugin)) return 1;
690 int Tracks::track_exists(Track *track)
692 for(Track *current = first; current; current = NEXT)
694 if(current == track) return 1;
700 Track *Tracks::get(int idx, int data_type)
702 for(Track *current = first; current; current = NEXT)
704 if( current->data_type != data_type ) continue;
705 if( --idx < 0 ) return current;