3 #include "edlsession.h"
5 #include "localsession.h"
6 #include "maincursor.h"
8 #include "mwindowgui.h"
9 #include "mainsession.h"
11 #include "preferences.h"
14 #include "trackcanvas.h"
22 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
23 : BC_SubWindow(mwindow->theme->mzoom_x,
24 mwindow->theme->mzoom_y,
25 mwindow->theme->mzoom_w,
26 mwindow->theme->mzoom_h)
29 this->mwindow = mwindow;
40 int ZoomBar::create_objects()
44 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
46 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
47 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
48 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
49 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
50 sample_zoom->create_objects();
51 sample_zoom->zoom_text->set_tooltip(_("Duration visible in the timeline"));
52 sample_zoom->zoom_tumbler->set_tooltip(_("Duration visible in the timeline"));
53 x += sample_zoom->get_w();
54 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
55 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
56 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
57 amp_zoom->create_objects();
58 amp_zoom->zoom_text->set_tooltip(_("Audio waveform scale"));
59 amp_zoom->zoom_tumbler->set_tooltip(_("Audio waveform scale"));
60 x += amp_zoom->get_w();
61 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
62 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
63 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
64 track_zoom->create_objects();
65 track_zoom->zoom_text->set_tooltip(_("Height of tracks in the timeline"));
66 track_zoom->zoom_tumbler->set_tooltip(_("Height of tracks in the timeline"));
67 x += track_zoom->get_w() + 10;
69 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y));
70 auto_type->create_objects();
71 x += auto_type->get_w() + 10;
72 #define DEFAULT_TEXT "000.00 to 000.00"
73 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
74 x += auto_zoom->get_w();
75 add_subwindow(auto_zoom_text = new ZoomTextBox(
81 x += auto_zoom_text->get_w() + 5;
82 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
84 x += auto_zoom->get_w() + 5;
86 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
87 x += from_value->get_w() + 5;
88 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
89 x += length_value->get_w() + 5;
90 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
91 x += to_value->get_w() + 5;
93 update_formatting(from_value);
94 update_formatting(length_value);
95 update_formatting(to_value);
97 add_subwindow(playback_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, RED));
99 add_subwindow(zoom_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, BLACK));
105 void ZoomBar::update_formatting(BC_TextBox *dst)
108 Units::format_to_separators(mwindow->edl->session->time_format));
111 void ZoomBar::resize_event()
113 reposition_window(mwindow->theme->mzoom_x,
114 mwindow->theme->mzoom_y,
115 mwindow->theme->mzoom_w,
116 mwindow->theme->mzoom_h);
118 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
120 // sample_zoom->reposition_window(x, y);
121 // x += sample_zoom->get_w();
122 // amp_zoom->reposition_window(x, y);
123 // x += amp_zoom->get_w();
124 // track_zoom->reposition_window(x, y);
128 void ZoomBar::redraw_time_dependancies()
130 // Recalculate sample zoom menu
131 sample_zoom->update_menu();
132 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
133 update_formatting(from_value);
134 update_formatting(length_value);
135 update_formatting(to_value);
146 void ZoomBar::update_autozoom()
148 char string[BCTEXTLEN];
149 switch (mwindow->edl->local_session->zoombar_showautotype) {
150 case AUTOGROUPTYPE_AUDIO_FADE:
151 case AUTOGROUPTYPE_VIDEO_FADE:
152 sprintf(string, "%0.01f to %0.01f\n",
153 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
154 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
156 case AUTOGROUPTYPE_ZOOM:
157 sprintf(string, "%0.03f to %0.03f\n",
158 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
159 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
161 case AUTOGROUPTYPE_X:
162 case AUTOGROUPTYPE_Y:
163 sprintf(string, "%0.0f to %.0f\n",
164 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
165 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
168 auto_zoom_text->update(string);
171 int ZoomBar::update()
173 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
174 amp_zoom->update(mwindow->edl->local_session->zoom_y);
175 track_zoom->update(mwindow->edl->local_session->zoom_track);
181 int ZoomBar::update_clocks()
183 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
184 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
185 mwindow->edl->local_session->get_selectionstart(1));
186 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
190 int ZoomBar::update_playback(int64_t new_position)
192 if(new_position != old_position)
194 Units::totext(string,
196 mwindow->edl->session->sample_rate,
197 mwindow->edl->session->time_format,
198 mwindow->edl->session->frame_rate,
199 mwindow->edl->session->frames_per_foot);
200 playback_value->update(string);
201 old_position = new_position;
206 int ZoomBar::resize_event(int w, int h)
208 // don't change anything but y and width
209 reposition_window(0, h - this->get_h(), w, this->get_h());
214 // Values for which_one
220 int ZoomBar::set_selection(int which_one)
222 double start_position = mwindow->edl->local_session->get_selectionstart(1);
223 double end_position = mwindow->edl->local_session->get_selectionend(1);
224 double length = end_position - start_position;
231 start_position = Units::text_to_seconds(from_value->get_text(),
232 mwindow->edl->session->sample_rate,
233 mwindow->edl->session->time_format,
234 mwindow->edl->session->frame_rate,
235 mwindow->edl->session->frames_per_foot);
236 length = Units::text_to_seconds(length_value->get_text(),
237 mwindow->edl->session->sample_rate,
238 mwindow->edl->session->time_format,
239 mwindow->edl->session->frame_rate,
240 mwindow->edl->session->frames_per_foot);
241 end_position = start_position + length;
243 if(end_position < start_position)
245 start_position = end_position;
246 mwindow->edl->local_session->set_selectionend(
247 mwindow->edl->local_session->get_selectionstart(1));
252 start_position = Units::text_to_seconds(from_value->get_text(),
253 mwindow->edl->session->sample_rate,
254 mwindow->edl->session->time_format,
255 mwindow->edl->session->frame_rate,
256 mwindow->edl->session->frames_per_foot);
257 end_position = Units::text_to_seconds(to_value->get_text(),
258 mwindow->edl->session->sample_rate,
259 mwindow->edl->session->time_format,
260 mwindow->edl->session->frame_rate,
261 mwindow->edl->session->frames_per_foot);
263 if(end_position < start_position)
265 end_position = start_position;
266 mwindow->edl->local_session->set_selectionend(
267 mwindow->edl->local_session->get_selectionstart(1));
272 start_position = Units::text_to_seconds(from_value->get_text(),
273 mwindow->edl->session->sample_rate,
274 mwindow->edl->session->time_format,
275 mwindow->edl->session->frame_rate,
276 mwindow->edl->session->frames_per_foot);
277 end_position = Units::text_to_seconds(to_value->get_text(),
278 mwindow->edl->session->sample_rate,
279 mwindow->edl->session->time_format,
280 mwindow->edl->session->frame_rate,
281 mwindow->edl->session->frames_per_foot);
283 if(end_position < start_position)
285 start_position = end_position;
286 mwindow->edl->local_session->set_selectionend(
287 mwindow->edl->local_session->get_selectionstart(1));
292 mwindow->edl->local_session->set_selectionstart(
293 mwindow->edl->align_to_frame(start_position, 1));
294 mwindow->edl->local_session->set_selectionend(
295 mwindow->edl->align_to_frame(end_position, 1));
298 mwindow->gui->timebar->update_highlights();
299 mwindow->gui->cursor->hide();
300 mwindow->gui->cursor->show();
302 mwindow->sync_parameters(CHANGE_PARAMS);
303 mwindow->gui->canvas->flash();
319 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
325 mwindow->edl->local_session->zoom_sample,
333 this->mwindow = mwindow;
334 this->zoombar = zoombar;
336 int SampleZoomPanel::handle_event()
338 mwindow->zoom_sample((int64_t)get_value());
352 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
355 mwindow->edl->local_session->zoom_y,
363 this->mwindow = mwindow;
364 this->zoombar = zoombar;
366 int AmpZoomPanel::handle_event()
368 mwindow->zoom_amp((int64_t)get_value());
372 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
375 mwindow->edl->local_session->zoom_track,
383 this->mwindow = mwindow;
384 this->zoombar = zoombar;
386 int TrackZoomPanel::handle_event()
388 mwindow->zoom_track((int64_t)get_value());
389 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
396 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
399 mwindow->theme->get_image_set("zoombar_tumbler"))
401 this->mwindow = mwindow;
402 this->zoombar = zoombar;
403 this->changemax = changemax;
405 set_tooltip(_("Automation range maximum"));
407 set_tooltip(_("Automation range minimum"));
410 int AutoZoom::handle_up_event()
412 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
414 mwindow->gui->zoombar->update_autozoom();
415 mwindow->gui->canvas->draw_overlays();
416 mwindow->gui->patchbay->update();
417 mwindow->gui->canvas->flash();
421 int AutoZoom::handle_down_event()
423 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
425 mwindow->gui->zoombar->update_autozoom();
426 mwindow->gui->canvas->draw_overlays();
427 mwindow->gui->patchbay->update();
428 mwindow->gui->canvas->flash();
434 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
435 : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
437 this->mwindow = mwindow;
438 this->zoombar = zoombar;
439 set_tooltip(_("Automation Type"));
442 void AutoTypeMenu::create_objects()
444 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
445 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
446 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
447 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
448 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
451 char* AutoTypeMenu::to_text(int mode)
455 case AUTOGROUPTYPE_AUDIO_FADE:
456 return _("Audio Fade:");
457 case AUTOGROUPTYPE_VIDEO_FADE:
458 return _("Video Fade:");
459 case AUTOGROUPTYPE_ZOOM:
461 case AUTOGROUPTYPE_X:
463 case AUTOGROUPTYPE_Y:
470 int AutoTypeMenu::from_text(char *text)
472 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE)))
473 return AUTOGROUPTYPE_AUDIO_FADE;
474 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE)))
475 return AUTOGROUPTYPE_VIDEO_FADE;
476 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM)))
477 return AUTOGROUPTYPE_ZOOM;
478 if(!strcmp(text, to_text(AUTOGROUPTYPE_X)))
479 return AUTOGROUPTYPE_X;
480 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y)))
481 return AUTOGROUPTYPE_Y;
484 int AutoTypeMenu::handle_event()
486 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
487 this->zoombar->update_autozoom();
491 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, char *text)
492 : BC_TextBox(x, y, 130, 1, text)
494 this->mwindow = mwindow;
495 this->zoombar = zoombar;
496 set_tooltip(_("Automation range"));
499 int ZoomTextBox::button_press_event()
501 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
502 BC_TextBox::button_press_event();
505 if (!is_event_win()) return 0;
508 if (get_relative_cursor_x() < get_w()/2)
512 if (get_buttonpress() == 4)
513 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
516 if (get_buttonpress() == 5)
517 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
519 mwindow->gui->zoombar->update_autozoom();
520 mwindow->gui->canvas->draw_overlays();
521 mwindow->gui->patchbay->update();
522 mwindow->gui->canvas->flash();
526 int ZoomTextBox::handle_event()
529 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
531 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
532 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
535 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
536 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
537 mwindow->gui->zoombar->update_autozoom();
538 mwindow->gui->canvas->draw_overlays();
539 mwindow->gui->patchbay->update();
540 mwindow->gui->canvas->flash();
543 // TODO: Make the text turn red when it's a bad range..
551 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
552 : BC_TextBox(x, y, 90, 1, "")
554 this->mwindow = mwindow;
555 this->zoombar = zoombar;
556 set_tooltip(_("Selection start time"));
559 int FromTextBox::handle_event()
561 if(get_keypress() == 13)
563 zoombar->set_selection(SET_FROM);
569 int FromTextBox::update_position(double new_position)
571 new_position += mwindow->edl->session->get_frame_offset() /
572 mwindow->edl->session->frame_rate;;
573 Units::totext(string,
575 mwindow->edl->session->time_format,
576 mwindow->edl->session->sample_rate,
577 mwindow->edl->session->frame_rate,
578 mwindow->edl->session->frames_per_foot);
579 //printf("FromTextBox::update_position %f %s\n", new_position, string);
589 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
590 : BC_TextBox(x, y, 90, 1, "")
592 this->mwindow = mwindow;
593 this->zoombar = zoombar;
594 set_tooltip(_("Selection length"));
597 int LengthTextBox::handle_event()
599 if(get_keypress() == 13)
601 zoombar->set_selection(SET_LENGTH);
607 int LengthTextBox::update_position(double new_position)
609 Units::totext(string,
611 mwindow->edl->session->time_format,
612 mwindow->edl->session->sample_rate,
613 mwindow->edl->session->frame_rate,
614 mwindow->edl->session->frames_per_foot);
623 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
624 : BC_TextBox(x, y, 90, 1, "")
626 this->mwindow = mwindow;
627 this->zoombar = zoombar;
628 set_tooltip(_("Selection end time"));
631 int ToTextBox::handle_event()
633 if(get_keypress() == 13)
635 zoombar->set_selection(SET_TO);
641 int ToTextBox::update_position(double new_position)
643 new_position += mwindow->edl->session->get_frame_offset() /
644 mwindow->edl->session->frame_rate;
645 Units::totext(string,
647 mwindow->edl->session->time_format,
648 mwindow->edl->session->sample_rate,
649 mwindow->edl->session->frame_rate,
650 mwindow->edl->session->frames_per_foot);