2 #include "automation.h"
9 #include "edlsession.h"
14 #include "localsession.h"
19 #include "mainsession.h"
22 #include "trackcanvas.h"
24 #include "transportque.inc"
28 Tracks::Tracks(EDL *edl)
50 void Tracks::equivalent_output(Tracks *tracks, double *result)
52 if(total_playable_vtracks() != tracks->total_playable_vtracks())
58 Track *current = first;
59 Track *that_current = tracks->first;
60 while(current || that_current)
62 // Get next video track
63 while(current && current->data_type != TRACK_VIDEO)
66 while(that_current && that_current->data_type != TRACK_VIDEO)
67 that_current = that_current->next;
69 // One doesn't exist but the other does
70 if((!current && that_current) ||
71 (current && !that_current))
78 if(current && that_current)
80 current->equivalent_output(that_current, result);
82 that_current = that_current->next;
91 void Tracks::get_affected_edits(ArrayList<Edit*> *drag_edits, double position, Track *start_track)
93 drag_edits->remove_all();
95 for(Track *track = start_track;
99 //printf("Tracks::get_affected_edits 1 %p %d %d\n", track, track->data_type, track->record);
102 for(Edit *edit = track->edits->first; edit; edit = edit->next)
104 double startproject = track->from_units(edit->startproject);
105 //printf("Tracks::get_affected_edits 1 %d\n", edl->equivalent(startproject, position));
106 if(edl->equivalent(startproject, position))
108 drag_edits->append(edit);
117 void Tracks::get_automation_extents(float *min,
125 int coords_undefined = 1;
126 for(Track *current = first; current; current = NEXT)
130 current->automation->get_extents(min,
133 current->to_units(start, 0),
134 current->to_units(end, 1),
141 void Tracks::copy_from(Tracks *tracks)
146 for(Track *current = tracks->first; current; current = NEXT)
148 switch(current->data_type)
151 new_track = add_audio_track(0, 0);
154 new_track = add_video_track(0, 0);
157 new_track->copy_from(current);
161 Tracks& Tracks::operator=(Tracks &tracks)
163 printf("Tracks::operator= 1\n");
168 int Tracks::load(FileXML *xml, int &track_offset, uint32_t load_flags)
170 // add the appropriate type of track
171 char string[BCTEXTLEN];
175 xml->tag.get_property("TYPE", string);
177 if((load_flags & LOAD_ALL) == LOAD_ALL ||
178 (load_flags & LOAD_EDITS))
180 if(!strcmp(string, "VIDEO"))
182 add_video_track(0, 0);
186 add_audio_track(0, 0); // default to audio
192 track = get_item_number(track_offset);
197 if(track) track->load(xml, track_offset, load_flags);
202 Track* Tracks::add_audio_track(int above, Track *dst_track)
205 ATrack* new_track = new ATrack(edl, this);
208 dst_track = (above ? first : last);
213 insert_before(dst_track, (Track*)new_track);
217 insert_after(dst_track, (Track*)new_track);
218 // Shift effects referenced below the destination track
221 // Shift effects referenced below the new track
222 for(Track *track = last;
223 track && track != new_track;
224 track = track->previous)
226 change_modules(number_of(track) - 1, number_of(track), 0);
230 new_track->create_objects();
231 new_track->set_default_title();
234 for(Track *current = first;
235 current != (Track*)new_track;
238 if(current->data_type == TRACK_AUDIO) current_pan++;
239 if(current_pan >= edl->session->audio_channels) current_pan = 0;
245 (PanAuto*)new_track->automation->autos[AUTOMATION_PAN]->default_auto;
246 pan_auto->values[current_pan] = 1.0;
248 BC_Pan::calculate_stick_position(edl->session->audio_channels,
249 edl->session->achannel_positions,
258 Track* Tracks::add_video_track(int above, Track *dst_track)
261 VTrack* new_track = new VTrack(edl, this);
263 dst_track = (above ? first : last);
267 insert_before(dst_track, (Track*)new_track);
271 insert_after(dst_track, (Track*)new_track);
276 // Shift effects referenced below the new track
277 for(Track *track = last;
278 track && track != new_track;
279 track = track->previous)
281 change_modules(number_of(track) - 1, number_of(track), 0);
286 new_track->create_objects();
287 new_track->set_default_title();
292 int Tracks::delete_track(Track *track)
297 int old_location = number_of(track);
298 detach_shared_effects(old_location);
300 // Shift effects referencing effects below the deleted track
301 for(Track *current = track;
305 change_modules(number_of(current), number_of(current) - 1, 0);
307 if(track) delete track;
312 int Tracks::detach_shared_effects(int module)
314 for(Track *current = first; current; current = NEXT)
316 current->detach_shared_effects(module);
322 int Tracks::total_of(int type)
325 IntAuto *mute_keyframe = 0;
327 for(Track *current = first; current; current = NEXT)
329 long unit_start = current->to_units(edl->local_session->get_selectionstart(1), 0);
331 (IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_prev_auto(
334 (Auto* &)mute_keyframe);
337 (current->play && type == PLAY) ||
338 (current->record && type == RECORD) ||
339 (current->gang && type == GANG) ||
340 (current->draw && type == DRAW) ||
341 (mute_keyframe->value && type == MUTE) ||
342 (current->expand_view && type == EXPAND);
347 int Tracks::recordable_audio_tracks()
350 for(Track *current = first; current; current = NEXT)
351 if(current->data_type == TRACK_AUDIO && current->record) result++;
355 int Tracks::recordable_video_tracks()
358 for(Track *current = first; current; current = NEXT)
360 if(current->data_type == TRACK_VIDEO && current->record) result++;
366 int Tracks::playable_audio_tracks()
370 for(Track *current = first; current; current = NEXT)
372 if(current->data_type == TRACK_AUDIO && current->play)
381 int Tracks::playable_video_tracks()
385 for(Track *current = first; current; current = NEXT)
387 if(current->data_type == TRACK_VIDEO && current->play)
395 int Tracks::total_audio_tracks()
398 for(Track *current = first; current; current = NEXT)
399 if(current->data_type == TRACK_AUDIO) result++;
403 int Tracks::total_video_tracks()
406 for(Track *current = first; current; current = NEXT)
407 if(current->data_type == TRACK_VIDEO) result++;
411 double Tracks::total_playable_length()
414 for(Track *current = first; current; current = NEXT)
416 double length = current->get_length();
417 if(length > total) total = length;
422 double Tracks::total_recordable_length()
425 for(Track *current = first; current; current = NEXT)
429 double length = current->get_length();
430 if(length > total) total = length;
436 double Tracks::total_length()
439 for(Track *current = first; current; current = NEXT)
441 if(current->get_length() > total) total = current->get_length();
446 double Tracks::total_audio_length()
449 for(Track *current = first; current; current = NEXT)
451 if(current->data_type == TRACK_AUDIO &&
452 current->get_length() > total) total = current->get_length();
457 double Tracks::total_video_length()
460 for(Track *current = first; current; current = NEXT)
462 if(current->data_type == TRACK_VIDEO &&
463 current->get_length() > total) total = current->get_length();
468 double Tracks::total_length_framealigned(double fps)
470 if (total_audio_tracks() && total_video_tracks())
471 return MIN(floor(total_audio_length() * fps), floor(total_video_length() * fps)) / fps;
473 if (total_audio_tracks())
474 return floor(total_audio_length() * fps) / fps;
476 if (total_video_tracks())
477 return floor(total_video_length() * fps) / fps;
482 void Tracks::translate_camera(float offset_x, float offset_y)
484 for(Track *current = first; current; current = NEXT)
486 if(current->data_type == TRACK_VIDEO)
488 ((VTrack*)current)->translate(offset_x, offset_y, 1);
492 void Tracks::translate_projector(float offset_x, float offset_y)
494 for(Track *current = first; current; current = NEXT)
496 if(current->data_type == TRACK_VIDEO)
498 ((VTrack*)current)->translate(offset_x, offset_y, 0);
503 void Tracks::update_y_pixels(Theme *theme)
505 int y = -edl->local_session->track_start;
506 for(Track *current = first; current; current = NEXT)
508 //printf("Tracks::update_y_pixels %d\n", y);
509 current->y_pixel = y;
510 y += current->vertical_span(theme);
516 for(Track* current = first; current; current = NEXT)
518 printf(" Track: %x\n", current);
525 void Tracks::select_all(int type,
528 for(Track* current = first; current; current = NEXT)
530 double position = edl->local_session->get_selectionstart(1);
532 if(type == PLAY) current->play = value;
533 if(type == RECORD) current->record = value;
534 if(type == GANG) current->gang = value;
535 if(type == DRAW) current->draw = value;
539 ((IntAuto*)current->automation->autos[AUTOMATION_MUTE]->get_auto_for_editing(position))->value = value;
542 if(type == EXPAND) current->expand_view = value;
587 // ===================================== file operations
589 int Tracks::popup_transition(int cursor_x, int cursor_y)
592 for(Track* current = first; current && !result; current = NEXT)
594 result = current->popup_transition(cursor_x, cursor_y);
600 int Tracks::change_channels(int oldchannels, int newchannels)
602 for(Track *current = first; current; current = NEXT)
603 { current->change_channels(oldchannels, newchannels); }
609 int Tracks::totalpixels()
612 for(Track* current = first; current; current = NEXT)
614 result += edl->local_session->zoom_track;
619 int Tracks::number_of(Track *track)
622 for(Track *current = first; current && current != track; current = NEXT)
629 Track* Tracks::number(int number)
633 for(current = first; current && i < number; current = NEXT)
641 int Tracks::total_playable_vtracks()
644 for(Track *current = first; current; current = NEXT)
646 if(current->data_type == TRACK_VIDEO && current->play) result++;