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 switch (mwindow->edl->local_session->zoombar_showautotype) {
180 case AUTOGROUPTYPE_AUDIO_FADE:
181 case AUTOGROUPTYPE_VIDEO_FADE:
182 sprintf(string, "%0.01f to %0.01f\n",
183 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
184 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
186 case AUTOGROUPTYPE_ZOOM:
187 case AUTOGROUPTYPE_SPEED:
188 sprintf(string, "%0.03f to %0.03f\n",
189 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
190 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
192 case AUTOGROUPTYPE_X:
193 case AUTOGROUPTYPE_Y:
194 sprintf(string, "%0.0f to %.0f\n",
195 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype],
196 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype]);
199 auto_zoom_text->update(string);
202 int ZoomBar::update()
204 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
205 amp_zoom->update(mwindow->edl->local_session->zoom_y);
206 track_zoom->update(mwindow->edl->local_session->zoom_track);
212 int ZoomBar::update_clocks()
214 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
215 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
216 mwindow->edl->local_session->get_selectionstart(1));
217 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
221 int ZoomBar::update_playback(int64_t new_position)
223 if(new_position != old_position)
225 Units::totext(string,
227 mwindow->edl->session->sample_rate,
228 mwindow->edl->session->time_format,
229 mwindow->edl->session->frame_rate,
230 mwindow->edl->session->frames_per_foot);
231 playback_value->update(string);
232 old_position = new_position;
237 int ZoomBar::resize_event(int w, int h)
239 // don't change anything but y and width
240 reposition_window(0, h - this->get_h(), w, this->get_h());
245 // Values for which_one
251 int ZoomBar::set_selection(int which_one)
253 double start_position = mwindow->edl->local_session->get_selectionstart(1);
254 double end_position = mwindow->edl->local_session->get_selectionend(1);
255 double length = end_position - start_position;
262 start_position = Units::text_to_seconds(from_value->get_text(),
263 mwindow->edl->session->sample_rate,
264 mwindow->edl->session->time_format,
265 mwindow->edl->session->frame_rate,
266 mwindow->edl->session->frames_per_foot);
267 length = Units::text_to_seconds(length_value->get_text(),
268 mwindow->edl->session->sample_rate,
269 mwindow->edl->session->time_format,
270 mwindow->edl->session->frame_rate,
271 mwindow->edl->session->frames_per_foot);
272 end_position = start_position + length;
274 if(end_position < start_position)
276 start_position = end_position;
277 mwindow->edl->local_session->set_selectionend(
278 mwindow->edl->local_session->get_selectionstart(1));
283 start_position = Units::text_to_seconds(from_value->get_text(),
284 mwindow->edl->session->sample_rate,
285 mwindow->edl->session->time_format,
286 mwindow->edl->session->frame_rate,
287 mwindow->edl->session->frames_per_foot);
288 end_position = Units::text_to_seconds(to_value->get_text(),
289 mwindow->edl->session->sample_rate,
290 mwindow->edl->session->time_format,
291 mwindow->edl->session->frame_rate,
292 mwindow->edl->session->frames_per_foot);
294 if(end_position < start_position)
296 end_position = start_position;
297 mwindow->edl->local_session->set_selectionend(
298 mwindow->edl->local_session->get_selectionstart(1));
303 start_position = Units::text_to_seconds(from_value->get_text(),
304 mwindow->edl->session->sample_rate,
305 mwindow->edl->session->time_format,
306 mwindow->edl->session->frame_rate,
307 mwindow->edl->session->frames_per_foot);
308 end_position = Units::text_to_seconds(to_value->get_text(),
309 mwindow->edl->session->sample_rate,
310 mwindow->edl->session->time_format,
311 mwindow->edl->session->frame_rate,
312 mwindow->edl->session->frames_per_foot);
314 if(end_position < start_position)
316 start_position = end_position;
317 mwindow->edl->local_session->set_selectionend(
318 mwindow->edl->local_session->get_selectionstart(1));
323 mwindow->edl->local_session->set_selectionstart(
324 mwindow->edl->align_to_frame(start_position, 1));
325 mwindow->edl->local_session->set_selectionend(
326 mwindow->edl->align_to_frame(end_position, 1));
329 mwindow->gui->update_timebar_highlights();
330 mwindow->gui->hide_cursor(1);
331 mwindow->gui->show_cursor(1);
333 mwindow->sync_parameters(CHANGE_PARAMS);
334 mwindow->gui->flash_canvas(1);
350 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow,
356 mwindow->edl->local_session->zoom_sample,
364 this->mwindow = mwindow;
365 this->zoombar = zoombar;
367 int SampleZoomPanel::handle_event()
369 mwindow->zoom_sample((int64_t)get_value());
374 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
377 mwindow->edl->local_session->zoom_y,
385 this->mwindow = mwindow;
386 this->zoombar = zoombar;
388 int AmpZoomPanel::handle_event()
390 mwindow->zoom_amp((int64_t)get_value());
394 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
397 mwindow->edl->local_session->zoom_track,
405 this->mwindow = mwindow;
406 this->zoombar = zoombar;
408 int TrackZoomPanel::handle_event()
410 mwindow->zoom_track((int64_t)get_value());
411 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
418 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
421 mwindow->theme->get_image_set("zoombar_tumbler"))
423 this->mwindow = mwindow;
424 this->zoombar = zoombar;
425 this->changemax = changemax;
427 set_tooltip(_("Automation range maximum"));
429 set_tooltip(_("Automation range minimum"));
432 int AutoZoom::handle_up_event()
434 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
436 mwindow->gui->zoombar->update_autozoom();
437 mwindow->gui->draw_overlays(0);
438 mwindow->gui->update_patchbay();
439 mwindow->gui->flash_canvas(1);
443 int AutoZoom::handle_down_event()
445 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
447 mwindow->gui->zoombar->update_autozoom();
448 mwindow->gui->draw_overlays(0);
449 mwindow->gui->update_patchbay();
450 mwindow->gui->flash_canvas(1);
456 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
457 : BC_PopupMenu(x, y, wid, to_text(mwindow->edl->local_session->zoombar_showautotype), 1)
459 this->mwindow = mwindow;
460 this->zoombar = zoombar;
461 set_tooltip(_("Automation Type"));
464 void AutoTypeMenu::create_objects()
466 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
467 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
468 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
469 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
470 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
471 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
474 const char* AutoTypeMenu::to_text(int mode)
477 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
478 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
479 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
480 case AUTOGROUPTYPE_SPEED: return _("Speed:");
481 case AUTOGROUPTYPE_X: return "X:";
482 case AUTOGROUPTYPE_Y: return "Y:";
487 int AutoTypeMenu::from_text(char *text)
489 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
490 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
491 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
492 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
493 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
494 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
495 return AUTOGROUPTYPE_INT255;
498 int AutoTypeMenu::handle_event()
500 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
501 this->zoombar->update_autozoom();
506 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
507 : BC_TextBox(x, y, 130, 1, text)
509 this->mwindow = mwindow;
510 this->zoombar = zoombar;
511 set_tooltip(_("Automation range"));
514 int ZoomTextBox::button_press_event()
516 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
517 BC_TextBox::button_press_event();
520 if (!is_event_win()) return 0;
523 if (get_relative_cursor_x() < get_w()/2)
527 if (get_buttonpress() == 4)
528 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
531 if (get_buttonpress() == 5)
532 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
534 mwindow->gui->zoombar->update_autozoom();
535 mwindow->gui->draw_overlays(0);
536 mwindow->gui->update_patchbay();
537 mwindow->gui->flash_canvas(1);
541 int ZoomTextBox::handle_event()
544 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
546 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
547 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
550 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
551 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
552 mwindow->gui->zoombar->update_autozoom();
553 mwindow->gui->draw_overlays(0);
554 mwindow->gui->update_patchbay();
555 mwindow->gui->flash_canvas(1);
558 // TODO: Make the text turn red when it's a bad range..
566 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
567 : BC_TextBox(x, y, 90, 1, "")
569 this->mwindow = mwindow;
570 this->zoombar = zoombar;
571 set_tooltip(_("Selection start time"));
574 int FromTextBox::handle_event()
576 if(get_keypress() == 13)
578 zoombar->set_selection(SET_FROM);
584 int FromTextBox::update_position(double new_position)
586 new_position += mwindow->edl->session->get_frame_offset() /
587 mwindow->edl->session->frame_rate;;
588 Units::totext(string,
590 mwindow->edl->session->time_format,
591 mwindow->edl->session->sample_rate,
592 mwindow->edl->session->frame_rate,
593 mwindow->edl->session->frames_per_foot);
594 //printf("FromTextBox::update_position %f %s\n", new_position, string);
604 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
605 : BC_TextBox(x, y, 90, 1, "")
607 this->mwindow = mwindow;
608 this->zoombar = zoombar;
609 set_tooltip(_("Selection length"));
612 int LengthTextBox::handle_event()
614 if(get_keypress() == 13)
616 zoombar->set_selection(SET_LENGTH);
622 int LengthTextBox::update_position(double new_position)
624 Units::totext(string,
626 mwindow->edl->session->time_format,
627 mwindow->edl->session->sample_rate,
628 mwindow->edl->session->frame_rate,
629 mwindow->edl->session->frames_per_foot);
638 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
639 : BC_TextBox(x, y, 90, 1, "")
641 this->mwindow = mwindow;
642 this->zoombar = zoombar;
643 set_tooltip(_("Selection end time"));
646 int ToTextBox::handle_event()
648 if(get_keypress() == 13)
650 zoombar->set_selection(SET_TO);
656 int ToTextBox::update_position(double new_position)
658 new_position += mwindow->edl->session->get_frame_offset() /
659 mwindow->edl->session->frame_rate;
660 Units::totext(string,
662 mwindow->edl->session->time_format,
663 mwindow->edl->session->sample_rate,
664 mwindow->edl->session->frame_rate,
665 mwindow->edl->session->frames_per_foot);