4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "apatchgui.inc"
25 #include "edlsession.h"
27 #include "localsession.h"
28 #include "maincursor.h"
30 #include "mwindowgui.h"
31 #include "mainsession.h"
33 #include "preferences.h"
35 #include "trackcanvas.h"
38 #include "vpatchgui.inc"
44 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
45 : BC_SubWindow(mwindow->theme->mzoom_x,
46 mwindow->theme->mzoom_y,
47 mwindow->theme->mzoom_w,
48 mwindow->theme->mzoom_h)
51 this->mwindow = mwindow;
62 void ZoomBar::create_objects()
66 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h() / 2;
68 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
69 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
70 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
71 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
72 sample_zoom->create_objects();
73 sample_zoom->zoom_text->set_tooltip(_("Duration visible in the timeline"));
74 sample_zoom->zoom_tumbler->set_tooltip(_("Duration visible in the timeline"));
75 x += sample_zoom->get_w();
76 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
77 amp_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
78 amp_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
79 amp_zoom->create_objects();
80 amp_zoom->zoom_text->set_tooltip(_("Audio waveform scale"));
81 amp_zoom->zoom_tumbler->set_tooltip(_("Audio waveform scale"));
82 x += amp_zoom->get_w();
83 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
84 track_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
85 track_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
86 track_zoom->create_objects();
87 track_zoom->zoom_text->set_tooltip(_("Height of tracks in the timeline"));
88 track_zoom->zoom_tumbler->set_tooltip(_("Height of tracks in the timeline"));
89 x += track_zoom->get_w() + 10;
92 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
93 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
94 if( ww > wid ) wid = ww;
96 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
97 auto_type->create_objects();
98 x += auto_type->get_w() + 10;
99 #define DEFAULT_TEXT "000.00 to 000.00"
100 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
101 x += auto_zoom->get_w();
102 add_subwindow(auto_zoom_text = new ZoomTextBox(
108 x += auto_zoom_text->get_w() + 5;
109 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
111 x += auto_zoom->get_w() + 5;
113 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
114 x += from_value->get_w() + 5;
115 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
116 x += length_value->get_w() + 5;
117 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
118 x += to_value->get_w() + 5;
120 update_formatting(from_value);
121 update_formatting(length_value);
122 update_formatting(to_value);
124 add_subwindow(playback_value = new BC_Title(x, 100, "--", MEDIUMFONT, RED));
126 add_subwindow(zoom_value = new BC_Title(x, 100, "--", MEDIUMFONT, BLACK));
131 void ZoomBar::update_formatting(BC_TextBox *dst)
134 Units::format_to_separators(mwindow->edl->session->time_format));
137 void ZoomBar::resize_event()
139 reposition_window(mwindow->theme->mzoom_x,
140 mwindow->theme->mzoom_y,
141 mwindow->theme->mzoom_w,
142 mwindow->theme->mzoom_h);
144 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
146 if (sample_zoom) delete sample_zoom;
147 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
148 sample_zoom->set_menu_images(mwindow->theme->get_image_set("zoombar_menu", 0));
149 sample_zoom->set_tumbler_images(mwindow->theme->get_image_set("zoombar_tumbler", 0));
150 sample_zoom->create_objects();
151 // x += sample_zoom->get_w();
152 // amp_zoom->reposition_window(x, y);
153 // x += amp_zoom->get_w();
154 // track_zoom->reposition_window(x, y);
158 void ZoomBar::redraw_time_dependancies()
160 // Recalculate sample zoom menu
161 sample_zoom->update_menu();
162 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
163 update_formatting(from_value);
164 update_formatting(length_value);
165 update_formatting(to_value);
176 void ZoomBar::update_autozoom()
178 char string[BCTEXTLEN];
179 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
180 switch( autogroup_type ) {
181 case AUTOGROUPTYPE_AUDIO_FADE:
182 case AUTOGROUPTYPE_VIDEO_FADE:
183 sprintf(string, "%0.01f to %0.01f\n",
184 mwindow->edl->local_session->automation_mins[autogroup_type],
185 mwindow->edl->local_session->automation_maxs[autogroup_type]);
187 case AUTOGROUPTYPE_ZOOM:
188 case AUTOGROUPTYPE_SPEED:
189 sprintf(string, "%0.03f to %0.03f\n",
190 mwindow->edl->local_session->automation_mins[autogroup_type],
191 mwindow->edl->local_session->automation_maxs[autogroup_type]);
193 case AUTOGROUPTYPE_X:
194 case AUTOGROUPTYPE_Y:
195 sprintf(string, "%0.0f to %.0f\n",
196 mwindow->edl->local_session->automation_mins[autogroup_type],
197 mwindow->edl->local_session->automation_maxs[autogroup_type]);
200 auto_zoom_text->update(string);
201 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
202 auto_type->set_text(group_name);
205 int ZoomBar::update()
207 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
208 amp_zoom->update(mwindow->edl->local_session->zoom_y);
209 track_zoom->update(mwindow->edl->local_session->zoom_track);
215 int ZoomBar::update_clocks()
217 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
218 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
219 mwindow->edl->local_session->get_selectionstart(1));
220 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
224 int ZoomBar::update_playback(int64_t new_position)
226 if(new_position != old_position)
228 Units::totext(string,
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 playback_value->update(string);
235 old_position = new_position;
240 int ZoomBar::resize_event(int w, int h)
242 // don't change anything but y and width
243 reposition_window(0, h - this->get_h(), w, this->get_h());
248 // Values for which_one
254 int ZoomBar::set_selection(int which_one)
256 double start_position = mwindow->edl->local_session->get_selectionstart(1);
257 double end_position = mwindow->edl->local_session->get_selectionend(1);
258 double length = end_position - start_position;
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 length = Units::text_to_seconds(length_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);
275 end_position = start_position + length;
277 if(end_position < start_position)
279 start_position = end_position;
280 mwindow->edl->local_session->set_selectionend(
281 mwindow->edl->local_session->get_selectionstart(1));
286 start_position = Units::text_to_seconds(from_value->get_text(),
287 mwindow->edl->session->sample_rate,
288 mwindow->edl->session->time_format,
289 mwindow->edl->session->frame_rate,
290 mwindow->edl->session->frames_per_foot);
291 end_position = Units::text_to_seconds(to_value->get_text(),
292 mwindow->edl->session->sample_rate,
293 mwindow->edl->session->time_format,
294 mwindow->edl->session->frame_rate,
295 mwindow->edl->session->frames_per_foot);
297 if(end_position < start_position)
299 end_position = start_position;
300 mwindow->edl->local_session->set_selectionend(
301 mwindow->edl->local_session->get_selectionstart(1));
306 start_position = Units::text_to_seconds(from_value->get_text(),
307 mwindow->edl->session->sample_rate,
308 mwindow->edl->session->time_format,
309 mwindow->edl->session->frame_rate,
310 mwindow->edl->session->frames_per_foot);
311 end_position = Units::text_to_seconds(to_value->get_text(),
312 mwindow->edl->session->sample_rate,
313 mwindow->edl->session->time_format,
314 mwindow->edl->session->frame_rate,
315 mwindow->edl->session->frames_per_foot);
317 if(end_position < start_position)
319 start_position = end_position;
320 mwindow->edl->local_session->set_selectionend(
321 mwindow->edl->local_session->get_selectionstart(1));
326 mwindow->edl->local_session->set_selectionstart(
327 mwindow->edl->align_to_frame(start_position, 1));
328 mwindow->edl->local_session->set_selectionend(
329 mwindow->edl->align_to_frame(end_position, 1));
332 mwindow->gui->update_timebar_highlights();
333 mwindow->gui->hide_cursor(1);
334 mwindow->gui->show_cursor(1);
336 mwindow->sync_parameters(CHANGE_PARAMS);
337 mwindow->gui->flash_canvas(1);
353 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
359 mwindow->edl->local_session->zoom_sample,
367 this->mwindow = mwindow;
368 this->zoombar = zoombar;
370 int SampleZoomPanel::handle_event()
372 mwindow->zoom_sample((int64_t)get_value());
377 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
380 mwindow->edl->local_session->zoom_y,
388 this->mwindow = mwindow;
389 this->zoombar = zoombar;
391 int AmpZoomPanel::handle_event()
393 mwindow->zoom_amp((int64_t)get_value());
397 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
400 mwindow->edl->local_session->zoom_track,
408 this->mwindow = mwindow;
409 this->zoombar = zoombar;
411 int TrackZoomPanel::handle_event()
413 mwindow->zoom_track((int64_t)get_value());
414 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
421 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
424 mwindow->theme->get_image_set("zoombar_tumbler"))
426 this->mwindow = mwindow;
427 this->zoombar = zoombar;
428 this->changemax = changemax;
430 set_tooltip(_("Automation range maximum"));
432 set_tooltip(_("Automation range minimum"));
435 int AutoZoom::handle_up_event()
437 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
439 mwindow->gui->zoombar->update_autozoom();
440 mwindow->gui->draw_overlays(0);
441 mwindow->gui->update_patchbay();
442 mwindow->gui->flash_canvas(1);
446 int AutoZoom::handle_down_event()
448 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
450 mwindow->gui->zoombar->update_autozoom();
451 mwindow->gui->draw_overlays(0);
452 mwindow->gui->update_patchbay();
453 mwindow->gui->flash_canvas(1);
459 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
460 : BC_PopupMenu(x, y, wid, to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
462 this->mwindow = mwindow;
463 this->zoombar = zoombar;
464 set_tooltip(_("Automation Type"));
467 void AutoTypeMenu::create_objects()
469 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
470 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
471 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
472 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
473 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
474 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
477 const char* AutoTypeMenu::to_text(int mode)
480 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
481 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
482 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
483 case AUTOGROUPTYPE_SPEED: return _("Speed:");
484 case AUTOGROUPTYPE_X: return "X:";
485 case AUTOGROUPTYPE_Y: return "Y:";
490 int AutoTypeMenu::from_text(char *text)
492 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
493 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
494 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
495 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
496 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
497 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
498 return AUTOGROUPTYPE_INT255;
501 int AutoTypeMenu::handle_event()
503 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
504 this->zoombar->update_autozoom();
509 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
510 : BC_TextBox(x, y, 130, 1, text)
512 this->mwindow = mwindow;
513 this->zoombar = zoombar;
514 set_tooltip(_("Automation range"));
517 int ZoomTextBox::button_press_event()
519 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
520 BC_TextBox::button_press_event();
523 if (!is_event_win()) return 0;
526 if (get_relative_cursor_x() < get_w()/2)
530 if (get_buttonpress() == 4)
531 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
534 if (get_buttonpress() == 5)
535 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
537 mwindow->gui->zoombar->update_autozoom();
538 mwindow->gui->draw_overlays(0);
539 mwindow->gui->update_patchbay();
540 mwindow->gui->flash_canvas(1);
544 int ZoomTextBox::handle_event()
547 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
549 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
550 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
553 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
554 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
555 mwindow->gui->zoombar->update_autozoom();
556 mwindow->gui->draw_overlays(0);
557 mwindow->gui->update_patchbay();
558 mwindow->gui->flash_canvas(1);
561 // TODO: Make the text turn red when it's a bad range..
569 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
570 : BC_TextBox(x, y, 90, 1, "")
572 this->mwindow = mwindow;
573 this->zoombar = zoombar;
574 set_tooltip(_("Selection start time"));
577 int FromTextBox::handle_event()
579 if(get_keypress() == 13)
581 zoombar->set_selection(SET_FROM);
587 int FromTextBox::update_position(double new_position)
589 new_position += mwindow->edl->session->get_frame_offset() /
590 mwindow->edl->session->frame_rate;;
591 Units::totext(string,
593 mwindow->edl->session->time_format,
594 mwindow->edl->session->sample_rate,
595 mwindow->edl->session->frame_rate,
596 mwindow->edl->session->frames_per_foot);
597 //printf("FromTextBox::update_position %f %s\n", new_position, string);
607 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
608 : BC_TextBox(x, y, 90, 1, "")
610 this->mwindow = mwindow;
611 this->zoombar = zoombar;
612 set_tooltip(_("Selection length"));
615 int LengthTextBox::handle_event()
617 if(get_keypress() == 13)
619 zoombar->set_selection(SET_LENGTH);
625 int LengthTextBox::update_position(double new_position)
627 Units::totext(string,
629 mwindow->edl->session->time_format,
630 mwindow->edl->session->sample_rate,
631 mwindow->edl->session->frame_rate,
632 mwindow->edl->session->frames_per_foot);
641 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
642 : BC_TextBox(x, y, 90, 1, "")
644 this->mwindow = mwindow;
645 this->zoombar = zoombar;
646 set_tooltip(_("Selection end time"));
649 int ToTextBox::handle_event()
651 if(get_keypress() == 13)
653 zoombar->set_selection(SET_TO);
659 int ToTextBox::update_position(double new_position)
661 new_position += mwindow->edl->session->get_frame_offset() /
662 mwindow->edl->session->frame_rate;
663 Units::totext(string,
665 mwindow->edl->session->time_format,
666 mwindow->edl->session->sample_rate,
667 mwindow->edl->session->frame_rate,
668 mwindow->edl->session->frames_per_foot);