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, int sense)
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 = sense >= 0 ? sense :
124 edit->is_selected ? 0 : 1;
131 void Tracks::get_selected_edits(ArrayList<Edit*> *drag_edits)
133 drag_edits->remove_all();
134 for( Track *track=first; track; track=track->next ) {
135 if( !track->record ) continue;
136 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
137 if( !edit->is_selected ) continue;
138 drag_edits->append(edit);
143 void Tracks::get_automation_extents(float *min,
151 int coords_undefined = 1;
152 for(Track *current = first; current; current = NEXT)
156 current->automation->get_extents(min,
159 current->to_units(start, 0),
160 current->to_units(end, 1),
167 void Tracks::copy_from(Tracks *tracks)
169 Track *new_track = 0;
172 for(Track *current = tracks->first; current; current = NEXT)
174 switch(current->data_type)
177 new_track = add_audio_track(0, 0);
180 new_track = add_video_track(0, 0);
183 new_track = add_subttl_track(0, 0);
188 new_track->copy_from(current);
192 Tracks& Tracks::operator=(Tracks &tracks)
194 printf("Tracks::operator= 1\n");
199 int Tracks::load(FileXML *xml,
203 // add the appropriate type of track
204 char string[BCTEXTLEN];
208 xml->tag.get_property("TYPE", string);
210 if((load_flags & LOAD_ALL) == LOAD_ALL ||
211 (load_flags & LOAD_EDITS)) {
212 if(!strcmp(string, "VIDEO")) {
213 track = add_video_track(0, 0);
215 else if(!strcmp(string, "SUBTTL")) {
216 track = add_subttl_track(0, 0);
219 track = add_audio_track(0, 0); // default to audio
223 track = get_item_number(track_offset++);
227 if( track ) track->load(xml, track_offset, load_flags);
232 Track* Tracks::add_audio_track(int above, Track *dst_track)
234 ATrack* new_track = new ATrack(edl, this);
237 dst_track = (above ? first : last);
242 insert_before(dst_track, (Track*)new_track);
246 insert_after(dst_track, (Track*)new_track);
247 // Shift effects referenced below the destination track
250 // Shift effects referenced below the new track
251 for(Track *track = last;
252 track && track != new_track;
253 track = track->previous)
255 change_modules(number_of(track) - 1, number_of(track), 0);
259 new_track->create_objects();
260 new_track->set_default_title();
263 for(Track *current = first;
264 current != (Track*)new_track;
267 if(current->data_type == TRACK_AUDIO) current_pan++;
268 if(current_pan >= edl->session->audio_channels) current_pan = 0;
274 (PanAuto*)new_track->automation->autos[AUTOMATION_PAN]->default_auto;
275 pan_auto->values[current_pan] = 1.0;
277 BC_Pan::calculate_stick_position(edl->session->audio_channels,
278 edl->session->achannel_positions,
287 Track* Tracks::add_video_track(int above, Track *dst_track)
289 VTrack* new_track = new VTrack(edl, this);
291 dst_track = (above ? first : last);
293 insert_before(dst_track, (Track*)new_track);
295 insert_after(dst_track, (Track*)new_track);
297 for(Track *track = last; track && track != new_track; track = track->previous)
298 change_modules(number_of(track) - 1, number_of(track), 0);
300 new_track->create_objects();
301 new_track->set_default_title();
306 Track* Tracks::add_subttl_track(int above, Track *dst_track)
308 STrack* new_track = new STrack(edl, this);
310 dst_track = (above ? first : last);
313 insert_before(dst_track, (Track*)new_track);
315 insert_after(dst_track, (Track*)new_track);
317 for(Track *track = last; track && track != new_track; track = track->previous)
318 change_modules(number_of(track) - 1, number_of(track), 0);
320 new_track->create_objects();
321 new_track->set_default_title();
322 // new_track->paste_silence(0,total_length(),0);
327 int Tracks::delete_track(Track *track)
332 int old_location = number_of(track);
333 detach_shared_effects(old_location);
335 // Shift effects referencing effects below the deleted track
336 for(Track *current = track;
340 change_modules(number_of(current), number_of(current) - 1, 0);
342 if(track) delete track;
347 int Tracks::detach_shared_effects(int module)
349 for(Track *current = first; current; current = NEXT)
351 current->detach_shared_effects(module);
357 int Tracks::total_of(int type)
361 for(Track *current = first; current; current = NEXT)
363 long unit_start = current->to_units(edl->local_session->get_selectionstart(1), 0);
364 Auto *mute_keyframe = 0;
365 current->automation->autos[AUTOMATION_MUTE]->
366 get_prev_auto(unit_start, PLAY_FORWARD, mute_keyframe);
367 IntAuto *mute_auto = (IntAuto *)mute_keyframe;
370 (current->play && type == PLAY) ||
371 (current->record && type == RECORD) ||
372 (current->gang && type == GANG) ||
373 (current->draw && type == DRAW) ||
374 (mute_auto->value && type == MUTE) ||
375 (current->expand_view && type == EXPAND);
380 int Tracks::recordable_audio_tracks()
383 for(Track *current = first; current; current = NEXT)
384 if(current->data_type == TRACK_AUDIO && current->record) result++;
388 int Tracks::recordable_video_tracks()
391 for(Track *current = first; current; current = NEXT)
393 if(current->data_type == TRACK_VIDEO && current->record) result++;
399 int Tracks::playable_audio_tracks()
403 for(Track *current = first; current; current = NEXT)
405 if(current->data_type == TRACK_AUDIO && current->play)
414 int Tracks::playable_video_tracks()
418 for(Track *current = first; current; current = NEXT)
420 if(current->data_type == TRACK_VIDEO && current->play)
428 int Tracks::total_audio_tracks()
431 for(Track *current = first; current; current = NEXT)
432 if(current->data_type == TRACK_AUDIO) result++;
436 int Tracks::total_video_tracks()
439 for(Track *current = first; current; current = NEXT)
440 if(current->data_type == TRACK_VIDEO) result++;
444 double Tracks::total_playable_length()
447 for(Track *current = first; current; current = NEXT)
451 double length = current->get_length();
452 if(length > total) total = length;
458 double Tracks::total_recordable_length()
461 for(Track *current = first; current; current = NEXT)
465 double length = current->get_length();
466 if(length > total) total = length;
472 double Tracks::total_length()
475 for(Track *current = first; current; current = NEXT)
477 double length = current->get_length();
478 if(length > total) total = length;
483 double Tracks::total_audio_length()
486 for(Track *current = first; current; current = NEXT)
488 if(current->data_type == TRACK_AUDIO &&
489 current->get_length() > total) total = current->get_length();
494 double Tracks::total_video_length()
497 for(Track *current = first; current; current = NEXT)
499 if(current->data_type == TRACK_VIDEO &&
500 current->get_length() > total) total = current->get_length();
505 double Tracks::total_length_framealigned(double fps)
507 if (total_audio_tracks() && total_video_tracks())
508 return MIN(floor(total_audio_length() * fps), floor(total_video_length() * fps)) / fps;
510 if (total_audio_tracks())
511 return floor(total_audio_length() * fps) / fps;
513 if (total_video_tracks())
514 return floor(total_video_length() * fps) / fps;
519 void Tracks::translate_projector(float offset_x, float offset_y)
521 for(Track *current = first; current; current = NEXT)
523 if(current->data_type == TRACK_VIDEO)
525 ((VTrack*)current)->translate(offset_x, offset_y, 0);
530 void Tracks::update_y_pixels(Theme *theme)
532 // int y = -edl->local_session->track_start;
534 for(Track *current = first; current; current = NEXT)
536 //printf("Tracks::update_y_pixels %d\n", y);
537 current->y_pixel = y;
538 y += current->vertical_span(theme);
542 int Tracks::dump(FILE *fp)
544 for(Track* current = first; current; current = NEXT)
546 fprintf(fp," Track: %p\n", current);
553 void Tracks::select_all(int type,
556 for(Track* current = first; current; current = NEXT)
558 double position = edl->local_session->get_selectionstart(1);
560 if(type == PLAY) current->play = value;
561 if(type == RECORD) current->record = value;
562 if(type == GANG) current->gang = value;
563 if(type == DRAW) current->draw = value;
567 ((IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_auto_for_editing(position))->value = value;
570 if(type == EXPAND) current->expand_view = value;
574 // ===================================== file operations
576 int Tracks::popup_transition(int cursor_x, int cursor_y)
579 for(Track* current = first; current && !result; current = NEXT)
581 result = current->popup_transition(cursor_x, cursor_y);
587 int Tracks::change_channels(int oldchannels, int newchannels)
589 for(Track *current = first; current; current = NEXT)
590 { current->change_channels(oldchannels, newchannels); }
596 int Tracks::totalpixels()
599 for(Track* current = first; current; current = NEXT)
601 result += edl->local_session->zoom_track;
606 int Tracks::number_of(Track *track)
609 for(Track *current = first; current && current != track; current = NEXT)
616 Track* Tracks::number(int number)
620 for(current = first; current && i < number; current = NEXT)
628 int Tracks::total_playable_vtracks()
631 for(Track *current = first; current; current = NEXT)
633 if(current->data_type == TRACK_VIDEO && current->play) result++;
638 int Tracks::plugin_exists(Plugin *plugin)
640 for(Track *track = first; track; track = track->next)
642 if(track->plugin_exists(plugin)) return 1;
647 int Tracks::track_exists(Track *track)
649 for(Track *current = first; current; current = NEXT)
651 if(current == track) return 1;
656 int Tracks::new_group(int id)
659 for( Track *track=first; track; track=track->next ) {
660 if( !track->record ) continue;
661 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
662 if( !edit->is_selected ) continue;
670 int Tracks::set_group_selected(int id, int v)
673 for( Track *track=first; track; track=track->next ) {
674 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
675 if( edit->group_id != id ) continue;
676 edit->is_selected = v >= 0 ? v : !edit->is_selected ? 1 : 0;
683 int Tracks::del_group(int id)
686 for( Track *track=first; track; track=track->next ) {
687 for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
688 if( edit->group_id != id ) continue;
689 edit->is_selected = 1;
697 Track *Tracks::get(int idx, int data_type)
699 for(Track *current = first; current; current = NEXT)
701 if( current->data_type != data_type ) continue;
702 if( --idx < 0 ) return current;