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 "cwindowgui.h"
27 #include "edlsession.h"
30 #include "localsession.h"
31 #include "maincursor.h"
33 #include "mwindowgui.h"
34 #include "mainsession.h"
36 #include "preferences.h"
38 #include "trackcanvas.h"
41 #include "vpatchgui.inc"
45 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
46 : BC_SubWindow(mwindow->theme->mzoom_x,
47 mwindow->theme->mzoom_y,
48 mwindow->theme->mzoom_w,
49 mwindow->theme->mzoom_h)
52 this->mwindow = mwindow;
53 // *** CONTEXT_HELP ***
54 context_help_set_keyword("Zoom Panel");
65 void ZoomBar::create_objects()
67 int xs5 = xS(5), xs10 = xS(10);
68 int x = xS(3), y = get_h()/2 -
69 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h()/2;
71 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
72 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
73 sample_zoom->create_objects();
74 sample_zoom->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->create_objects();
78 amp_zoom->set_tooltip(_("Audio waveform scale"));
79 x += amp_zoom->get_w();
80 atrack_zoom = new ATrackZoomPanel(mwindow, this, x, y);
81 atrack_zoom->create_objects();
82 atrack_zoom->set_tooltip(_("Height of audio tracks"));
83 x += atrack_zoom->get_w() + xs10;
84 vtrack_zoom = new VTrackZoomPanel(mwindow, this, x, y);
85 vtrack_zoom->create_objects();
86 vtrack_zoom->set_tooltip(_("Height of video tracks"));
87 x += vtrack_zoom->get_w() + xs10;
90 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
91 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
92 if( ww > wid ) wid = ww;
94 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
95 auto_type->create_objects();
96 x += auto_type->get_w() + xs10;
97 #define DEFAULT_TEXT "000.00 to 000.00"
98 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
99 x += auto_zoom->get_w();
100 add_subwindow(auto_zoom_text = new ZoomTextBox(mwindow, this, x, y, DEFAULT_TEXT));
101 x += auto_zoom_text->get_w() + xs5;
102 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
104 x += auto_zoom->get_w() + xs5;
106 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
107 x += from_value->get_w() + xs5;
108 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
109 x += length_value->get_w() + xs5;
110 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
111 x += to_value->get_w() + xs5;
112 add_subwindow(title_alpha_bar = new TitleAlphaBar(mwindow, this, x, y));
113 x += title_alpha_bar->get_w() + xs5;
114 add_subwindow(title_alpha_text = new TitleAlphaText(mwindow, this, x, y));
116 update_formatting(from_value);
117 update_formatting(length_value);
118 update_formatting(to_value);
124 void ZoomBar::update_formatting(BC_TextBox *dst)
127 Units::format_to_separators(mwindow->edl->session->time_format));
130 void ZoomBar::resize_event()
132 reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
133 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
134 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
137 void ZoomBar::redraw_time_dependancies()
139 // Recalculate sample zoom menu
140 sample_zoom->update_menu();
141 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
142 update_formatting(from_value);
143 update_formatting(length_value);
144 update_formatting(to_value);
155 void ZoomBar::update_autozoom()
157 update_autozoom(mwindow->edl->local_session->zoombar_showautocolor);
160 void ZoomBar::update_autozoom(int grouptype, int color)
162 mwindow->edl->local_session->zoombar_showautotype = grouptype;
163 update_autozoom(color);
166 void ZoomBar::update_autozoom(int color)
168 char string[BCTEXTLEN];
169 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
170 mwindow->edl->local_session->zoombar_showautocolor = color;
171 if( color < 0 ) color = get_resources()->default_text_color;
172 switch( autogroup_type ) {
173 case AUTOGROUPTYPE_AUDIO_FADE:
174 case AUTOGROUPTYPE_VIDEO_FADE:
175 sprintf(string, "%0.01f to %0.01f\n",
176 mwindow->edl->local_session->automation_mins[autogroup_type],
177 mwindow->edl->local_session->automation_maxs[autogroup_type]);
179 case AUTOGROUPTYPE_ZOOM:
180 case AUTOGROUPTYPE_SPEED:
181 sprintf(string, "%0.03f to %0.03f\n",
182 mwindow->edl->local_session->automation_mins[autogroup_type],
183 mwindow->edl->local_session->automation_maxs[autogroup_type]);
185 case AUTOGROUPTYPE_X:
186 case AUTOGROUPTYPE_Y:
187 sprintf(string, "%0.0f to %.0f\n",
188 mwindow->edl->local_session->automation_mins[autogroup_type],
189 mwindow->edl->local_session->automation_maxs[autogroup_type]);
192 auto_zoom_text->update(string);
193 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
194 auto_type->set_text(group_name);
195 switch( autogroup_type ) {
196 case AUTOGROUPTYPE_ZOOM:
197 case AUTOGROUPTYPE_X:
198 case AUTOGROUPTYPE_Y:
199 CWindowGUI *cgui = mwindow->cwindow->gui;
201 cgui->lock_window("ZoomBar::update_autozoom");
203 cgui->unlock_window();
204 lock_window("ZoomBar::update_autozoom");
210 int ZoomBar::update()
212 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
213 amp_zoom->update(mwindow->edl->local_session->zoom_y);
214 atrack_zoom->update(mwindow->edl->local_session->zoom_atrack);
215 vtrack_zoom->update(mwindow->edl->local_session->zoom_vtrack);
221 int ZoomBar::update_clocks()
223 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
224 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
225 mwindow->edl->local_session->get_selectionstart(1));
226 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
230 TitleAlphaBar::TitleAlphaBar(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
231 : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1.0, mwindow->session->title_bar_alpha, 0)
233 this->mwindow = mwindow;
234 this->zoombar = zoombar;
236 enable_show_value(0);
239 int TitleAlphaBar::handle_event()
241 float v = get_value();
242 mwindow->session->title_bar_alpha = v;
243 zoombar->title_alpha_text->update(v);
244 mwindow->gui->draw_trackmovement();
245 mwindow->gui->flush();
249 TitleAlphaText::TitleAlphaText(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
250 : BC_TextBox(x, y, xS(48), 1, mwindow->session->title_bar_alpha, 0, MEDIUMFONT, 2)
252 this->mwindow = mwindow;
253 this->zoombar = zoombar;
254 set_tooltip(_("Title Alpha"));
257 int TitleAlphaText::handle_event()
259 float v = atof(get_text());
260 mwindow->session->title_bar_alpha = v;
261 zoombar->title_alpha_bar->update(v);
262 mwindow->gui->draw_trackmovement();
263 mwindow->gui->flush();
267 int ZoomBar::resize_event(int w, int h)
269 // don't change anything but y and width
270 reposition_window(0, h - this->get_h(), w, this->get_h());
275 // Values for which_one
281 int ZoomBar::set_selection(int which_one)
283 double start_position = mwindow->edl->local_session->get_selectionstart(1);
284 double end_position = mwindow->edl->local_session->get_selectionend(1);
285 double length = end_position - start_position;
292 start_position = Units::text_to_seconds(from_value->get_text(),
293 mwindow->edl->session->sample_rate,
294 mwindow->edl->session->time_format,
295 mwindow->edl->session->frame_rate,
296 mwindow->edl->session->frames_per_foot);
297 length = Units::text_to_seconds(length_value->get_text(),
298 mwindow->edl->session->sample_rate,
299 mwindow->edl->session->time_format,
300 mwindow->edl->session->frame_rate,
301 mwindow->edl->session->frames_per_foot);
302 end_position = start_position + length;
304 if(end_position < start_position)
306 start_position = end_position;
307 mwindow->edl->local_session->set_selectionend(
308 mwindow->edl->local_session->get_selectionstart(1));
313 start_position = Units::text_to_seconds(from_value->get_text(),
314 mwindow->edl->session->sample_rate,
315 mwindow->edl->session->time_format,
316 mwindow->edl->session->frame_rate,
317 mwindow->edl->session->frames_per_foot);
318 end_position = Units::text_to_seconds(to_value->get_text(),
319 mwindow->edl->session->sample_rate,
320 mwindow->edl->session->time_format,
321 mwindow->edl->session->frame_rate,
322 mwindow->edl->session->frames_per_foot);
324 if(end_position < start_position)
326 end_position = start_position;
327 mwindow->edl->local_session->set_selectionend(
328 mwindow->edl->local_session->get_selectionstart(1));
333 start_position = Units::text_to_seconds(from_value->get_text(),
334 mwindow->edl->session->sample_rate,
335 mwindow->edl->session->time_format,
336 mwindow->edl->session->frame_rate,
337 mwindow->edl->session->frames_per_foot);
338 end_position = Units::text_to_seconds(to_value->get_text(),
339 mwindow->edl->session->sample_rate,
340 mwindow->edl->session->time_format,
341 mwindow->edl->session->frame_rate,
342 mwindow->edl->session->frames_per_foot);
344 if(end_position < start_position)
346 start_position = end_position;
347 mwindow->edl->local_session->set_selectionend(
348 mwindow->edl->local_session->get_selectionstart(1));
353 mwindow->edl->local_session->set_selectionstart(
354 mwindow->edl->align_to_frame(start_position, 1));
355 mwindow->edl->local_session->set_selectionend(
356 mwindow->edl->align_to_frame(end_position, 1));
359 mwindow->gui->update_timebar_highlights();
360 mwindow->gui->hide_cursor(1);
361 mwindow->gui->show_cursor(1);
363 mwindow->sync_parameters(CHANGE_PARAMS);
364 mwindow->gui->flash_canvas(1);
370 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
371 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
372 x, y, xS(130), MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
374 this->mwindow = mwindow;
375 this->zoombar = zoombar;
377 int SampleZoomPanel::handle_event()
379 mwindow->zoom_sample((int64_t)get_value());
384 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
385 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
386 x, y, xS(80), MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
388 this->mwindow = mwindow;
389 this->zoombar = zoombar;
391 int AmpZoomPanel::handle_event()
393 if( zoombar->shift_down() )
394 update(DEFAULT_ZOOM_TRACK);
395 mwindow->zoom_amp((int64_t)get_value());
399 ATrackZoomPanel::ATrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
400 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_atrack,
401 x, y, xS(64), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
403 this->mwindow = mwindow;
404 this->zoombar = zoombar;
406 int ATrackZoomPanel::handle_event()
408 if( zoombar->shift_down() )
409 update(DEFAULT_ZOOM_TRACK);
410 mwindow->zoom_atrack((int64_t)get_value());
411 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
415 VTrackZoomPanel::VTrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
416 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_vtrack,
417 x, y, xS(64), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
419 this->mwindow = mwindow;
420 this->zoombar = zoombar;
422 int VTrackZoomPanel::handle_event()
424 if( zoombar->shift_down() )
425 update(DEFAULT_ZOOM_TRACK);
426 mwindow->zoom_vtrack((int64_t)get_value());
431 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
432 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
434 this->mwindow = mwindow;
435 this->zoombar = zoombar;
436 this->changemax = changemax;
438 set_tooltip(_("Automation range maximum"));
440 set_tooltip(_("Automation range minimum"));
443 int AutoZoom::handle_up_event()
445 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
447 mwindow->gui->zoombar->update_autozoom();
448 mwindow->gui->draw_overlays(0);
449 mwindow->gui->update_patchbay();
450 mwindow->gui->flash_canvas(1);
454 int AutoZoom::handle_down_event()
456 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
458 mwindow->gui->zoombar->update_autozoom();
459 mwindow->gui->draw_overlays(0);
460 mwindow->gui->update_patchbay();
461 mwindow->gui->flash_canvas(1);
467 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
468 : BC_PopupMenu(x, y, wid + xS(24),
469 to_text(mwindow->edl->local_session->zoombar_showautotype), 1, 0, 12)
471 this->mwindow = mwindow;
472 this->zoombar = zoombar;
473 set_tooltip(_("Automation Type"));
476 void AutoTypeMenu::create_objects()
478 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
479 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
480 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
481 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
482 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
483 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
486 const char* AutoTypeMenu::to_text(int mode)
489 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
490 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
491 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
492 case AUTOGROUPTYPE_SPEED: return _("Speed:");
493 case AUTOGROUPTYPE_X: return "X:";
494 case AUTOGROUPTYPE_Y: return "Y:";
499 int AutoTypeMenu::from_text(char *text)
501 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
502 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
503 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
504 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
505 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
506 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
507 return AUTOGROUPTYPE_INT255;
510 int AutoTypeMenu::draw_face(int dx, int color)
512 BC_PopupMenu::draw_face(dx+xS(8), color);
513 color = mwindow->edl->local_session->zoombar_showautocolor;
516 int margin = get_margin();
517 int mx = margin+xS(8), my = 3*margin/8;
518 int bh = get_h() - 2*my;
519 draw_box(mx,my, bh,bh);
524 int AutoTypeMenu::handle_event()
526 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
527 this->zoombar->update_autozoom();
532 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
533 : BC_TextBox(x, y, xS(130), 1, text)
535 this->mwindow = mwindow;
536 this->zoombar = zoombar;
537 set_tooltip(_("Automation range"));
540 int ZoomTextBox::button_press_event()
542 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
543 BC_TextBox::button_press_event();
546 if (!is_event_win()) return 0;
549 if (get_relative_cursor_x() < get_w()/2)
553 if (get_buttonpress() == 4)
554 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
557 if (get_buttonpress() == 5)
558 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
560 mwindow->gui->zoombar->update_autozoom();
561 mwindow->gui->draw_overlays(0);
562 mwindow->gui->update_patchbay();
563 mwindow->gui->flash_canvas(1);
567 int ZoomTextBox::handle_event()
570 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
572 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
573 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
576 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
577 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
578 mwindow->gui->zoombar->update_autozoom();
579 mwindow->gui->draw_overlays(0);
580 mwindow->gui->update_patchbay();
581 mwindow->gui->flash_canvas(1);
584 // TODO: Make the text turn red when it's a bad range..
592 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
593 : BC_TextBox(x, y, xS(90), 1, "")
595 this->mwindow = mwindow;
596 this->zoombar = zoombar;
597 set_tooltip(_("Selection start time"));
600 int FromTextBox::handle_event()
602 if(get_keypress() == NEWLINE)
604 zoombar->set_selection(SET_FROM);
610 int FromTextBox::update_position(double new_position)
612 Units::totext(string,
614 mwindow->edl->session->time_format,
615 mwindow->edl->session->sample_rate,
616 mwindow->edl->session->frame_rate,
617 mwindow->edl->session->frames_per_foot,
618 mwindow->get_timecode_offset());
619 //printf("FromTextBox::update_position %f %s\n", new_position, string);
629 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
630 : BC_TextBox(x, y, xS(90), 1, "")
632 this->mwindow = mwindow;
633 this->zoombar = zoombar;
634 set_tooltip(_("Selection length"));
637 int LengthTextBox::handle_event()
639 if(get_keypress() == NEWLINE)
641 zoombar->set_selection(SET_LENGTH);
647 int LengthTextBox::update_position(double new_position)
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);
663 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
664 : BC_TextBox(x, y, xS(90), 1, "")
666 this->mwindow = mwindow;
667 this->zoombar = zoombar;
668 set_tooltip(_("Selection end time"));
671 int ToTextBox::handle_event()
673 if(get_keypress() == NEWLINE)
675 zoombar->set_selection(SET_TO);
681 int ToTextBox::update_position(double new_position)
683 Units::totext(string, new_position,
684 mwindow->edl->session->time_format,
685 mwindow->edl->session->sample_rate,
686 mwindow->edl->session->frame_rate,
687 mwindow->edl->session->frames_per_foot,
688 mwindow->get_timecode_offset());