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 if (sample_zoom) delete sample_zoom;
121 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
122 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
123 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
124 sample_zoom->create_objects();
125 // x += sample_zoom->get_w();
126 // amp_zoom->reposition_window(x, y);
127 // x += amp_zoom->get_w();
128 // track_zoom->reposition_window(x, y);
132 void ZoomBar::redraw_time_dependancies()
134 // Recalculate sample zoom menu
135 sample_zoom->update_menu();
136 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
137 update_formatting(from_value);
138 update_formatting(length_value);
139 update_formatting(to_value);
150 void ZoomBar::update_autozoom()
152 char string[BCTEXTLEN];
153 switch (mwindow->edl->local_session->zoombar_showautotype) {
154 case AUTOGROUPTYPE_AUDIO_FADE:
155 case AUTOGROUPTYPE_VIDEO_FADE:
156 sprintf(string, "%0.01f to %0.01f\n",
157 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
158 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
160 case AUTOGROUPTYPE_ZOOM:
161 sprintf(string, "%0.03f to %0.03f\n",
162 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
163 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
165 case AUTOGROUPTYPE_X:
166 case AUTOGROUPTYPE_Y:
167 sprintf(string, "%0.0f to %.0f\n",
168 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
169 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
172 auto_zoom_text->update(string);
175 int ZoomBar::update()
177 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
178 amp_zoom->update(mwindow->edl->local_session->zoom_y);
179 track_zoom->update(mwindow->edl->local_session->zoom_track);
185 int ZoomBar::update_clocks()
187 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
188 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
189 mwindow->edl->local_session->get_selectionstart(1));
190 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
194 int ZoomBar::update_playback(int64_t new_position)
196 if(new_position != old_position)
198 Units::totext(string,
200 mwindow->edl->session->sample_rate,
201 mwindow->edl->session->time_format,
202 mwindow->edl->session->frame_rate,
203 mwindow->edl->session->frames_per_foot);
204 playback_value->update(string);
205 old_position = new_position;
210 int ZoomBar::resize_event(int w, int h)
212 // don't change anything but y and width
213 reposition_window(0, h - this->get_h(), w, this->get_h());
218 // Values for which_one
224 int ZoomBar::set_selection(int which_one)
226 double start_position = mwindow->edl->local_session->get_selectionstart(1);
227 double end_position = mwindow->edl->local_session->get_selectionend(1);
228 double length = end_position - start_position;
235 start_position = Units::text_to_seconds(from_value->get_text(),
236 mwindow->edl->session->sample_rate,
237 mwindow->edl->session->time_format,
238 mwindow->edl->session->frame_rate,
239 mwindow->edl->session->frames_per_foot);
240 length = Units::text_to_seconds(length_value->get_text(),
241 mwindow->edl->session->sample_rate,
242 mwindow->edl->session->time_format,
243 mwindow->edl->session->frame_rate,
244 mwindow->edl->session->frames_per_foot);
245 end_position = start_position + length;
247 if(end_position < start_position)
249 start_position = end_position;
250 mwindow->edl->local_session->set_selectionend(
251 mwindow->edl->local_session->get_selectionstart(1));
256 start_position = Units::text_to_seconds(from_value->get_text(),
257 mwindow->edl->session->sample_rate,
258 mwindow->edl->session->time_format,
259 mwindow->edl->session->frame_rate,
260 mwindow->edl->session->frames_per_foot);
261 end_position = Units::text_to_seconds(to_value->get_text(),
262 mwindow->edl->session->sample_rate,
263 mwindow->edl->session->time_format,
264 mwindow->edl->session->frame_rate,
265 mwindow->edl->session->frames_per_foot);
267 if(end_position < start_position)
269 end_position = start_position;
270 mwindow->edl->local_session->set_selectionend(
271 mwindow->edl->local_session->get_selectionstart(1));
276 start_position = Units::text_to_seconds(from_value->get_text(),
277 mwindow->edl->session->sample_rate,
278 mwindow->edl->session->time_format,
279 mwindow->edl->session->frame_rate,
280 mwindow->edl->session->frames_per_foot);
281 end_position = Units::text_to_seconds(to_value->get_text(),
282 mwindow->edl->session->sample_rate,
283 mwindow->edl->session->time_format,
284 mwindow->edl->session->frame_rate,
285 mwindow->edl->session->frames_per_foot);
287 if(end_position < start_position)
289 start_position = end_position;
290 mwindow->edl->local_session->set_selectionend(
291 mwindow->edl->local_session->get_selectionstart(1));
296 mwindow->edl->local_session->set_selectionstart(
297 mwindow->edl->align_to_frame(start_position, 1));
298 mwindow->edl->local_session->set_selectionend(
299 mwindow->edl->align_to_frame(end_position, 1));
302 mwindow->gui->timebar->update_highlights();
303 mwindow->gui->cursor->hide();
304 mwindow->gui->cursor->show();
306 mwindow->sync_parameters(CHANGE_PARAMS);
307 mwindow->gui->canvas->flash();
323 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
329 mwindow->edl->local_session->zoom_sample,
337 this->mwindow = mwindow;
338 this->zoombar = zoombar;
340 int SampleZoomPanel::handle_event()
342 mwindow->zoom_sample((int64_t)get_value());
356 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
359 mwindow->edl->local_session->zoom_y,
367 this->mwindow = mwindow;
368 this->zoombar = zoombar;
370 int AmpZoomPanel::handle_event()
372 mwindow->zoom_amp((int64_t)get_value());
376 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
379 mwindow->edl->local_session->zoom_track,
387 this->mwindow = mwindow;
388 this->zoombar = zoombar;
390 int TrackZoomPanel::handle_event()
392 mwindow->zoom_track((int64_t)get_value());
393 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
400 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
403 mwindow->theme->get_image_set("zoombar_tumbler"))
405 this->mwindow = mwindow;
406 this->zoombar = zoombar;
407 this->changemax = changemax;
409 set_tooltip(_("Automation range maximum"));
411 set_tooltip(_("Automation range minimum"));
414 int AutoZoom::handle_up_event()
416 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
418 mwindow->gui->zoombar->update_autozoom();
419 mwindow->gui->canvas->draw_overlays();
420 mwindow->gui->patchbay->update();
421 mwindow->gui->canvas->flash();
425 int AutoZoom::handle_down_event()
427 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
429 mwindow->gui->zoombar->update_autozoom();
430 mwindow->gui->canvas->draw_overlays();
431 mwindow->gui->patchbay->update();
432 mwindow->gui->canvas->flash();
438 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
439 : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
441 this->mwindow = mwindow;
442 this->zoombar = zoombar;
443 set_tooltip(_("Automation Type"));
446 void AutoTypeMenu::create_objects()
448 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
449 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
450 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
451 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
452 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
455 char* AutoTypeMenu::to_text(int mode)
459 case AUTOGROUPTYPE_AUDIO_FADE:
460 return _("Audio Fade:");
461 case AUTOGROUPTYPE_VIDEO_FADE:
462 return _("Video Fade:");
463 case AUTOGROUPTYPE_ZOOM:
465 case AUTOGROUPTYPE_X:
467 case AUTOGROUPTYPE_Y:
474 int AutoTypeMenu::from_text(char *text)
476 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE)))
477 return AUTOGROUPTYPE_AUDIO_FADE;
478 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE)))
479 return AUTOGROUPTYPE_VIDEO_FADE;
480 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM)))
481 return AUTOGROUPTYPE_ZOOM;
482 if(!strcmp(text, to_text(AUTOGROUPTYPE_X)))
483 return AUTOGROUPTYPE_X;
484 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y)))
485 return AUTOGROUPTYPE_Y;
488 int AutoTypeMenu::handle_event()
490 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
491 this->zoombar->update_autozoom();
495 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, char *text)
496 : BC_TextBox(x, y, 130, 1, text)
498 this->mwindow = mwindow;
499 this->zoombar = zoombar;
500 set_tooltip(_("Automation range"));
503 int ZoomTextBox::button_press_event()
505 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
506 BC_TextBox::button_press_event();
509 if (!is_event_win()) return 0;
512 if (get_relative_cursor_x() < get_w()/2)
516 if (get_buttonpress() == 4)
517 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
520 if (get_buttonpress() == 5)
521 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
523 mwindow->gui->zoombar->update_autozoom();
524 mwindow->gui->canvas->draw_overlays();
525 mwindow->gui->patchbay->update();
526 mwindow->gui->canvas->flash();
530 int ZoomTextBox::handle_event()
533 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
535 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
536 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
539 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
540 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
541 mwindow->gui->zoombar->update_autozoom();
542 mwindow->gui->canvas->draw_overlays();
543 mwindow->gui->patchbay->update();
544 mwindow->gui->canvas->flash();
547 // TODO: Make the text turn red when it's a bad range..
555 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
556 : BC_TextBox(x, y, 90, 1, "")
558 this->mwindow = mwindow;
559 this->zoombar = zoombar;
560 set_tooltip(_("Selection start time"));
563 int FromTextBox::handle_event()
565 if(get_keypress() == 13)
567 zoombar->set_selection(SET_FROM);
573 int FromTextBox::update_position(double new_position)
575 new_position += mwindow->edl->session->get_frame_offset() /
576 mwindow->edl->session->frame_rate;;
577 Units::totext(string,
579 mwindow->edl->session->time_format,
580 mwindow->edl->session->sample_rate,
581 mwindow->edl->session->frame_rate,
582 mwindow->edl->session->frames_per_foot);
583 //printf("FromTextBox::update_position %f %s\n", new_position, string);
593 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
594 : BC_TextBox(x, y, 90, 1, "")
596 this->mwindow = mwindow;
597 this->zoombar = zoombar;
598 set_tooltip(_("Selection length"));
601 int LengthTextBox::handle_event()
603 if(get_keypress() == 13)
605 zoombar->set_selection(SET_LENGTH);
611 int LengthTextBox::update_position(double new_position)
613 Units::totext(string,
615 mwindow->edl->session->time_format,
616 mwindow->edl->session->sample_rate,
617 mwindow->edl->session->frame_rate,
618 mwindow->edl->session->frames_per_foot);
627 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
628 : BC_TextBox(x, y, 90, 1, "")
630 this->mwindow = mwindow;
631 this->zoombar = zoombar;
632 set_tooltip(_("Selection end time"));
635 int ToTextBox::handle_event()
637 if(get_keypress() == 13)
639 zoombar->set_selection(SET_TO);
645 int ToTextBox::update_position(double new_position)
647 new_position += mwindow->edl->session->get_frame_offset() /
648 mwindow->edl->session->frame_rate;
649 Units::totext(string,
651 mwindow->edl->session->time_format,
652 mwindow->edl->session->sample_rate,
653 mwindow->edl->session->frame_rate,
654 mwindow->edl->session->frames_per_foot);