3 #include "edlsession.h"
5 #include "localsession.h"
6 #include "maincursor.h"
8 #include "mwindowgui.h"
9 #include "mainsession.h"
11 #include "preferences.h"
13 #include "trackcanvas.h"
21 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
22 : BC_SubWindow(mwindow->theme->mzoom_x,
23 mwindow->theme->mzoom_y,
24 mwindow->theme->mzoom_w,
25 mwindow->theme->mzoom_h)
28 this->mwindow = mwindow;
39 int ZoomBar::create_objects()
43 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
45 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
46 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
47 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
48 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
49 sample_zoom->create_objects();
50 x += sample_zoom->get_w();
51 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
52 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
53 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
54 amp_zoom->create_objects();
55 x += amp_zoom->get_w();
56 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
57 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
58 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
59 track_zoom->create_objects();
60 x += track_zoom->get_w() + 10;
62 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y));
63 auto_type->create_objects();
64 x += auto_type->get_w() + 10;
65 #define DEFAULT_TEXT "000.00 to 000.00"
66 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
67 x += auto_zoom->get_w();
68 add_subwindow(auto_zoom_text = new ZoomTextBox(
74 x += auto_zoom_text->get_w() + 5;
75 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
77 x += auto_zoom->get_w() + 5;
79 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
80 x += from_value->get_w() + 5;
81 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
82 x += length_value->get_w() + 5;
83 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
84 x += to_value->get_w() + 5;
86 update_formatting(from_value);
87 update_formatting(length_value);
88 update_formatting(to_value);
90 add_subwindow(playback_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, RED));
92 add_subwindow(zoom_value = new BC_Title(x, 100, _("--"), MEDIUMFONT, BLACK));
98 void ZoomBar::update_formatting(BC_TextBox *dst)
101 Units::format_to_separators(mwindow->edl->session->time_format));
104 void ZoomBar::resize_event()
106 reposition_window(mwindow->theme->mzoom_x,
107 mwindow->theme->mzoom_y,
108 mwindow->theme->mzoom_w,
109 mwindow->theme->mzoom_h);
111 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
113 // sample_zoom->reposition_window(x, y);
114 // x += sample_zoom->get_w();
115 // amp_zoom->reposition_window(x, y);
116 // x += amp_zoom->get_w();
117 // track_zoom->reposition_window(x, y);
121 void ZoomBar::redraw_time_dependancies()
123 // Recalculate sample zoom menu
124 sample_zoom->update_menu();
125 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
126 update_formatting(from_value);
127 update_formatting(length_value);
128 update_formatting(to_value);
139 void ZoomBar::update_autozoom()
141 char string[BCTEXTLEN];
142 switch (mwindow->edl->local_session->zoombar_showautotype) {
143 case AUTOGROUPTYPE_AUDIO_FADE:
144 case AUTOGROUPTYPE_VIDEO_FADE:
145 sprintf(string, "%0.01f to %0.01f\n",
146 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
147 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
149 case AUTOGROUPTYPE_ZOOM:
150 sprintf(string, "%0.03f to %0.03f\n",
151 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
152 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
154 case AUTOGROUPTYPE_X:
155 case AUTOGROUPTYPE_Y:
156 sprintf(string, "%0.0f to %.0f\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]);
161 auto_zoom_text->update(string);
164 int ZoomBar::update()
166 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
167 amp_zoom->update(mwindow->edl->local_session->zoom_y);
168 track_zoom->update(mwindow->edl->local_session->zoom_track);
174 int ZoomBar::update_clocks()
176 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
177 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
178 mwindow->edl->local_session->get_selectionstart(1));
179 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
183 int ZoomBar::update_playback(int64_t new_position)
185 if(new_position != old_position)
187 Units::totext(string,
189 mwindow->edl->session->sample_rate,
190 mwindow->edl->session->time_format,
191 mwindow->edl->session->frame_rate,
192 mwindow->edl->session->frames_per_foot);
193 playback_value->update(string);
194 old_position = new_position;
199 int ZoomBar::resize_event(int w, int h)
201 // don't change anything but y and width
202 reposition_window(0, h - this->get_h(), w, this->get_h());
207 // Values for which_one
213 int ZoomBar::set_selection(int which_one)
215 double start_position = mwindow->edl->local_session->get_selectionstart(1);
216 double end_position = mwindow->edl->local_session->get_selectionend(1);
217 double length = end_position - start_position;
224 start_position = Units::text_to_seconds(from_value->get_text(),
225 mwindow->edl->session->sample_rate,
226 mwindow->edl->session->time_format,
227 mwindow->edl->session->frame_rate,
228 mwindow->edl->session->frames_per_foot);
229 length = Units::text_to_seconds(length_value->get_text(),
230 mwindow->edl->session->sample_rate,
231 mwindow->edl->session->time_format,
232 mwindow->edl->session->frame_rate,
233 mwindow->edl->session->frames_per_foot);
234 end_position = start_position + length;
236 if(end_position < start_position)
238 start_position = end_position;
239 mwindow->edl->local_session->set_selectionend(
240 mwindow->edl->local_session->get_selectionstart(1));
245 start_position = Units::text_to_seconds(from_value->get_text(),
246 mwindow->edl->session->sample_rate,
247 mwindow->edl->session->time_format,
248 mwindow->edl->session->frame_rate,
249 mwindow->edl->session->frames_per_foot);
250 end_position = Units::text_to_seconds(to_value->get_text(),
251 mwindow->edl->session->sample_rate,
252 mwindow->edl->session->time_format,
253 mwindow->edl->session->frame_rate,
254 mwindow->edl->session->frames_per_foot);
256 if(end_position < start_position)
258 end_position = start_position;
259 mwindow->edl->local_session->set_selectionend(
260 mwindow->edl->local_session->get_selectionstart(1));
265 start_position = Units::text_to_seconds(from_value->get_text(),
266 mwindow->edl->session->sample_rate,
267 mwindow->edl->session->time_format,
268 mwindow->edl->session->frame_rate,
269 mwindow->edl->session->frames_per_foot);
270 end_position = Units::text_to_seconds(to_value->get_text(),
271 mwindow->edl->session->sample_rate,
272 mwindow->edl->session->time_format,
273 mwindow->edl->session->frame_rate,
274 mwindow->edl->session->frames_per_foot);
276 if(end_position < start_position)
278 start_position = end_position;
279 mwindow->edl->local_session->set_selectionend(
280 mwindow->edl->local_session->get_selectionstart(1));
285 mwindow->edl->local_session->set_selectionstart(
286 mwindow->edl->align_to_frame(start_position, 1));
287 mwindow->edl->local_session->set_selectionend(
288 mwindow->edl->align_to_frame(end_position, 1));
291 mwindow->gui->timebar->update_highlights();
292 mwindow->gui->cursor->hide();
293 mwindow->gui->cursor->show();
295 mwindow->sync_parameters(CHANGE_PARAMS);
296 mwindow->gui->canvas->flash();
312 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
318 mwindow->edl->local_session->zoom_sample,
326 this->mwindow = mwindow;
327 this->zoombar = zoombar;
329 int SampleZoomPanel::handle_event()
331 mwindow->zoom_sample((int64_t)get_value());
345 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
348 mwindow->edl->local_session->zoom_y,
356 this->mwindow = mwindow;
357 this->zoombar = zoombar;
359 int AmpZoomPanel::handle_event()
361 mwindow->zoom_amp((int64_t)get_value());
365 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
368 mwindow->edl->local_session->zoom_track,
376 this->mwindow = mwindow;
377 this->zoombar = zoombar;
379 int TrackZoomPanel::handle_event()
381 mwindow->zoom_track((int64_t)get_value());
382 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
389 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
392 mwindow->theme->get_image_set("zoombar_tumbler"))
394 this->mwindow = mwindow;
395 this->zoombar = zoombar;
396 this->changemax = changemax;
399 int AutoZoom::handle_up_event()
401 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
403 mwindow->gui->zoombar->update_autozoom();
404 mwindow->gui->canvas->draw_overlays();
405 mwindow->gui->canvas->flash();
409 int AutoZoom::handle_down_event()
411 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
413 mwindow->gui->zoombar->update_autozoom();
414 mwindow->gui->canvas->draw_overlays();
415 mwindow->gui->canvas->flash();
421 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
422 : BC_PopupMenu(x, y, 120,to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
424 this->mwindow = mwindow;
425 this->zoombar = zoombar;
428 void AutoTypeMenu::create_objects()
430 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
431 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
432 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
433 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
434 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
437 char* AutoTypeMenu::to_text(int mode)
441 case AUTOGROUPTYPE_AUDIO_FADE:
442 return _("Audio Fade:");
443 case AUTOGROUPTYPE_VIDEO_FADE:
444 return _("Video Fade:");
445 case AUTOGROUPTYPE_ZOOM:
447 case AUTOGROUPTYPE_X:
449 case AUTOGROUPTYPE_Y:
456 int AutoTypeMenu::from_text(char *text)
458 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE)))
459 return AUTOGROUPTYPE_AUDIO_FADE;
460 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE)))
461 return AUTOGROUPTYPE_VIDEO_FADE;
462 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM)))
463 return AUTOGROUPTYPE_ZOOM;
464 if(!strcmp(text, to_text(AUTOGROUPTYPE_X)))
465 return AUTOGROUPTYPE_X;
466 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y)))
467 return AUTOGROUPTYPE_Y;
470 int AutoTypeMenu::handle_event()
472 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
473 this->zoombar->update_autozoom();
477 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, char *text)
478 : BC_TextBox(x, y, 130, 1, text)
480 this->mwindow = mwindow;
481 this->zoombar = zoombar;
484 int ZoomTextBox::button_press_event()
486 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
487 BC_TextBox::button_press_event();
490 if (!is_event_win()) return 0;
493 if (get_relative_cursor_x() < get_w()/2)
497 if (get_buttonpress() == 4)
498 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
501 if (get_buttonpress() == 5)
502 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
504 mwindow->gui->zoombar->update_autozoom();
505 mwindow->gui->canvas->draw_overlays();
506 mwindow->gui->canvas->flash();
510 int ZoomTextBox::handle_event()
513 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
516 && ( mwindow->edl->local_session->zoombar_showautotype != AUTOGROUPTYPE_ZOOM
517 || (max >= 0.000 && min >= 0.000) )
520 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
521 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
522 mwindow->gui->zoombar->update_autozoom();
523 mwindow->gui->canvas->draw_overlays();
524 mwindow->gui->canvas->flash();
526 // TODO: Make the text turn red when it's a bad range..
534 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
535 : BC_TextBox(x, y, 90, 1, "")
537 this->mwindow = mwindow;
538 this->zoombar = zoombar;
541 int FromTextBox::handle_event()
543 if(get_keypress() == 13)
545 zoombar->set_selection(SET_FROM);
551 int FromTextBox::update_position(double new_position)
553 new_position += mwindow->edl->session->get_frame_offset() /
554 mwindow->edl->session->frame_rate;;
555 Units::totext(string,
557 mwindow->edl->session->time_format,
558 mwindow->edl->session->sample_rate,
559 mwindow->edl->session->frame_rate,
560 mwindow->edl->session->frames_per_foot);
561 //printf("FromTextBox::update_position %f %s\n", new_position, string);
571 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
572 : BC_TextBox(x, y, 90, 1, "")
574 this->mwindow = mwindow;
575 this->zoombar = zoombar;
578 int LengthTextBox::handle_event()
580 if(get_keypress() == 13)
582 zoombar->set_selection(SET_LENGTH);
588 int LengthTextBox::update_position(double new_position)
590 Units::totext(string,
592 mwindow->edl->session->time_format,
593 mwindow->edl->session->sample_rate,
594 mwindow->edl->session->frame_rate,
595 mwindow->edl->session->frames_per_foot);
604 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
605 : BC_TextBox(x, y, 90, 1, "")
607 this->mwindow = mwindow;
608 this->zoombar = zoombar;
611 int ToTextBox::handle_event()
613 if(get_keypress() == 13)
615 zoombar->set_selection(SET_TO);
621 int ToTextBox::update_position(double new_position)
623 new_position += mwindow->edl->session->get_frame_offset() /
624 mwindow->edl->session->frame_rate;
625 Units::totext(string,
627 mwindow->edl->session->time_format,
628 mwindow->edl->session->sample_rate,
629 mwindow->edl->session->frame_rate,
630 mwindow->edl->session->frames_per_foot);