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;
63 void ZoomBar::create_objects()
65 int xs5 = xS(5), xs10 = xS(10);
66 int x = xS(3), y = get_h()/2 -
67 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h()/2;
69 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
70 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
71 sample_zoom->create_objects();
72 sample_zoom->set_tooltip(_("Duration visible in the timeline"));
73 x += sample_zoom->get_w();
74 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
75 amp_zoom->create_objects();
76 amp_zoom->set_tooltip(_("Audio waveform scale"));
77 x += amp_zoom->get_w();
78 atrack_zoom = new ATrackZoomPanel(mwindow, this, x, y);
79 atrack_zoom->create_objects();
80 atrack_zoom->set_tooltip(_("Height of audio tracks"));
81 x += atrack_zoom->get_w() + xs10;
82 vtrack_zoom = new VTrackZoomPanel(mwindow, this, x, y);
83 vtrack_zoom->create_objects();
84 vtrack_zoom->set_tooltip(_("Height of video tracks"));
85 x += vtrack_zoom->get_w() + xs10;
88 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
89 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
90 if( ww > wid ) wid = ww;
92 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
93 auto_type->create_objects();
94 x += auto_type->get_w() + xs10;
95 #define DEFAULT_TEXT "000.00 to 000.00"
96 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
97 x += auto_zoom->get_w();
98 add_subwindow(auto_zoom_text = new ZoomTextBox(mwindow, this, x, y, DEFAULT_TEXT));
99 x += auto_zoom_text->get_w() + xs5;
100 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
102 x += auto_zoom->get_w() + xs5;
104 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
105 x += from_value->get_w() + xs5;
106 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
107 x += length_value->get_w() + xs5;
108 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
109 x += to_value->get_w() + xs5;
110 add_subwindow(title_alpha_bar = new TitleAlphaBar(mwindow, this, x, y));
111 x += title_alpha_bar->get_w() + xs5;
112 add_subwindow(title_alpha_text = new TitleAlphaText(mwindow, this, x, y));
114 update_formatting(from_value);
115 update_formatting(length_value);
116 update_formatting(to_value);
122 void ZoomBar::update_formatting(BC_TextBox *dst)
125 Units::format_to_separators(mwindow->edl->session->time_format));
128 void ZoomBar::resize_event()
130 reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
131 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
132 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
135 void ZoomBar::redraw_time_dependancies()
137 // Recalculate sample zoom menu
138 sample_zoom->update_menu();
139 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
140 update_formatting(from_value);
141 update_formatting(length_value);
142 update_formatting(to_value);
153 void ZoomBar::update_autozoom()
155 update_autozoom(mwindow->edl->local_session->zoombar_showautocolor);
158 void ZoomBar::update_autozoom(int grouptype, int color)
160 mwindow->edl->local_session->zoombar_showautotype = grouptype;
161 update_autozoom(color);
164 void ZoomBar::update_autozoom(int color)
166 char string[BCTEXTLEN];
167 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
168 mwindow->edl->local_session->zoombar_showautocolor = color;
169 if( color < 0 ) color = get_resources()->default_text_color;
170 switch( autogroup_type ) {
171 case AUTOGROUPTYPE_AUDIO_FADE:
172 case AUTOGROUPTYPE_VIDEO_FADE:
173 sprintf(string, "%0.01f to %0.01f\n",
174 mwindow->edl->local_session->automation_mins[autogroup_type],
175 mwindow->edl->local_session->automation_maxs[autogroup_type]);
177 case AUTOGROUPTYPE_ZOOM:
178 case AUTOGROUPTYPE_SPEED:
179 sprintf(string, "%0.03f to %0.03f\n",
180 mwindow->edl->local_session->automation_mins[autogroup_type],
181 mwindow->edl->local_session->automation_maxs[autogroup_type]);
183 case AUTOGROUPTYPE_X:
184 case AUTOGROUPTYPE_Y:
185 sprintf(string, "%0.0f to %.0f\n",
186 mwindow->edl->local_session->automation_mins[autogroup_type],
187 mwindow->edl->local_session->automation_maxs[autogroup_type]);
190 auto_zoom_text->update(string);
191 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
192 auto_type->set_text(group_name);
193 switch( autogroup_type ) {
194 case AUTOGROUPTYPE_ZOOM:
195 case AUTOGROUPTYPE_X:
196 case AUTOGROUPTYPE_Y:
197 CWindowGUI *cgui = mwindow->cwindow->gui;
199 cgui->lock_window("ZoomBar::update_autozoom");
201 cgui->unlock_window();
202 lock_window("ZoomBar::update_autozoom");
208 int ZoomBar::update()
210 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
211 amp_zoom->update(mwindow->edl->local_session->zoom_y);
212 atrack_zoom->update(mwindow->edl->local_session->zoom_atrack);
213 vtrack_zoom->update(mwindow->edl->local_session->zoom_vtrack);
219 int ZoomBar::update_clocks()
221 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
222 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
223 mwindow->edl->local_session->get_selectionstart(1));
224 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
228 TitleAlphaBar::TitleAlphaBar(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
229 : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1.0, mwindow->session->title_bar_alpha, 0)
231 this->mwindow = mwindow;
232 this->zoombar = zoombar;
234 enable_show_value(0);
237 int TitleAlphaBar::handle_event()
239 float v = get_value();
240 mwindow->session->title_bar_alpha = v;
241 zoombar->title_alpha_text->update(v);
242 mwindow->gui->draw_trackmovement();
243 mwindow->gui->flush();
247 TitleAlphaText::TitleAlphaText(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
248 : BC_TextBox(x, y, xS(48), 1, mwindow->session->title_bar_alpha, 0, MEDIUMFONT, 2)
250 this->mwindow = mwindow;
251 this->zoombar = zoombar;
252 set_tooltip(_("Title Alpha"));
255 int TitleAlphaText::handle_event()
257 float v = atof(get_text());
258 mwindow->session->title_bar_alpha = v;
259 zoombar->title_alpha_bar->update(v);
260 mwindow->gui->draw_trackmovement();
261 mwindow->gui->flush();
265 int ZoomBar::resize_event(int w, int h)
267 // don't change anything but y and width
268 reposition_window(0, h - this->get_h(), w, this->get_h());
273 // Values for which_one
279 int ZoomBar::set_selection(int which_one)
281 double start_position = mwindow->edl->local_session->get_selectionstart(1);
282 double end_position = mwindow->edl->local_session->get_selectionend(1);
283 double length = end_position - start_position;
290 start_position = Units::text_to_seconds(from_value->get_text(),
291 mwindow->edl->session->sample_rate,
292 mwindow->edl->session->time_format,
293 mwindow->edl->session->frame_rate,
294 mwindow->edl->session->frames_per_foot);
295 length = Units::text_to_seconds(length_value->get_text(),
296 mwindow->edl->session->sample_rate,
297 mwindow->edl->session->time_format,
298 mwindow->edl->session->frame_rate,
299 mwindow->edl->session->frames_per_foot);
300 end_position = start_position + length;
302 if(end_position < start_position)
304 start_position = end_position;
305 mwindow->edl->local_session->set_selectionend(
306 mwindow->edl->local_session->get_selectionstart(1));
311 start_position = Units::text_to_seconds(from_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);
316 end_position = Units::text_to_seconds(to_value->get_text(),
317 mwindow->edl->session->sample_rate,
318 mwindow->edl->session->time_format,
319 mwindow->edl->session->frame_rate,
320 mwindow->edl->session->frames_per_foot);
322 if(end_position < start_position)
324 end_position = start_position;
325 mwindow->edl->local_session->set_selectionend(
326 mwindow->edl->local_session->get_selectionstart(1));
331 start_position = Units::text_to_seconds(from_value->get_text(),
332 mwindow->edl->session->sample_rate,
333 mwindow->edl->session->time_format,
334 mwindow->edl->session->frame_rate,
335 mwindow->edl->session->frames_per_foot);
336 end_position = Units::text_to_seconds(to_value->get_text(),
337 mwindow->edl->session->sample_rate,
338 mwindow->edl->session->time_format,
339 mwindow->edl->session->frame_rate,
340 mwindow->edl->session->frames_per_foot);
342 if(end_position < start_position)
344 start_position = end_position;
345 mwindow->edl->local_session->set_selectionend(
346 mwindow->edl->local_session->get_selectionstart(1));
351 mwindow->edl->local_session->set_selectionstart(
352 mwindow->edl->align_to_frame(start_position, 1));
353 mwindow->edl->local_session->set_selectionend(
354 mwindow->edl->align_to_frame(end_position, 1));
357 mwindow->gui->update_timebar_highlights();
358 mwindow->gui->hide_cursor(1);
359 mwindow->gui->show_cursor(1);
361 mwindow->sync_parameters(CHANGE_PARAMS);
362 mwindow->gui->flash_canvas(1);
368 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
369 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
370 x, y, xS(130), MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
372 this->mwindow = mwindow;
373 this->zoombar = zoombar;
375 int SampleZoomPanel::handle_event()
377 mwindow->zoom_sample((int64_t)get_value());
382 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
383 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
384 x, y, xS(80), MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
386 this->mwindow = mwindow;
387 this->zoombar = zoombar;
389 int AmpZoomPanel::handle_event()
391 mwindow->zoom_amp((int64_t)get_value());
395 ATrackZoomPanel::ATrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
396 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_atrack,
397 x, y, xS(64), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
399 this->mwindow = mwindow;
400 this->zoombar = zoombar;
402 int ATrackZoomPanel::handle_event()
404 mwindow->zoom_atrack((int64_t)get_value());
405 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
409 VTrackZoomPanel::VTrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
410 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_vtrack,
411 x, y, xS(64), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
413 this->mwindow = mwindow;
414 this->zoombar = zoombar;
416 int VTrackZoomPanel::handle_event()
418 mwindow->zoom_vtrack((int64_t)get_value());
423 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
424 : BC_Tumbler(x, y, 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 + xS(24),
461 to_text(mwindow->edl->local_session->zoombar_showautotype), 1, 0, 12)
463 this->mwindow = mwindow;
464 this->zoombar = zoombar;
465 set_tooltip(_("Automation Type"));
468 void AutoTypeMenu::create_objects()
470 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
471 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
472 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
473 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
474 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
475 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
478 const char* AutoTypeMenu::to_text(int mode)
481 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
482 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
483 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
484 case AUTOGROUPTYPE_SPEED: return _("Speed:");
485 case AUTOGROUPTYPE_X: return "X:";
486 case AUTOGROUPTYPE_Y: return "Y:";
491 int AutoTypeMenu::from_text(char *text)
493 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
494 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
495 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
496 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
497 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
498 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
499 return AUTOGROUPTYPE_INT255;
502 int AutoTypeMenu::draw_face(int dx, int color)
504 BC_PopupMenu::draw_face(dx+xS(8), color);
505 color = mwindow->edl->local_session->zoombar_showautocolor;
508 int margin = get_margin();
509 int mx = margin+xS(8), my = 3*margin/8;
510 int bh = get_h() - 2*my;
511 draw_box(mx,my, bh,bh);
516 int AutoTypeMenu::handle_event()
518 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
519 this->zoombar->update_autozoom();
524 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
525 : BC_TextBox(x, y, xS(130), 1, text)
527 this->mwindow = mwindow;
528 this->zoombar = zoombar;
529 set_tooltip(_("Automation range"));
532 int ZoomTextBox::button_press_event()
534 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
535 BC_TextBox::button_press_event();
538 if (!is_event_win()) return 0;
541 if (get_relative_cursor_x() < get_w()/2)
545 if (get_buttonpress() == 4)
546 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
549 if (get_buttonpress() == 5)
550 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
552 mwindow->gui->zoombar->update_autozoom();
553 mwindow->gui->draw_overlays(0);
554 mwindow->gui->update_patchbay();
555 mwindow->gui->flash_canvas(1);
559 int ZoomTextBox::handle_event()
562 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
564 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
565 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
568 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
569 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
570 mwindow->gui->zoombar->update_autozoom();
571 mwindow->gui->draw_overlays(0);
572 mwindow->gui->update_patchbay();
573 mwindow->gui->flash_canvas(1);
576 // TODO: Make the text turn red when it's a bad range..
584 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
585 : BC_TextBox(x, y, xS(90), 1, "")
587 this->mwindow = mwindow;
588 this->zoombar = zoombar;
589 set_tooltip(_("Selection start time"));
592 int FromTextBox::handle_event()
594 if(get_keypress() == NEWLINE)
596 zoombar->set_selection(SET_FROM);
602 int FromTextBox::update_position(double new_position)
604 Units::totext(string,
606 mwindow->edl->session->time_format,
607 mwindow->edl->session->sample_rate,
608 mwindow->edl->session->frame_rate,
609 mwindow->edl->session->frames_per_foot);
610 //printf("FromTextBox::update_position %f %s\n", new_position, string);
620 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
621 : BC_TextBox(x, y, xS(90), 1, "")
623 this->mwindow = mwindow;
624 this->zoombar = zoombar;
625 set_tooltip(_("Selection length"));
628 int LengthTextBox::handle_event()
630 if(get_keypress() == NEWLINE)
632 zoombar->set_selection(SET_LENGTH);
638 int LengthTextBox::update_position(double new_position)
640 Units::totext(string,
642 mwindow->edl->session->time_format,
643 mwindow->edl->session->sample_rate,
644 mwindow->edl->session->frame_rate,
645 mwindow->edl->session->frames_per_foot);
654 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
655 : BC_TextBox(x, y, xS(90), 1, "")
657 this->mwindow = mwindow;
658 this->zoombar = zoombar;
659 set_tooltip(_("Selection end time"));
662 int ToTextBox::handle_event()
664 if(get_keypress() == NEWLINE)
666 zoombar->set_selection(SET_TO);
672 int ToTextBox::update_position(double new_position)
674 Units::totext(string, new_position,
675 mwindow->edl->session->time_format,
676 mwindow->edl->session->sample_rate,
677 mwindow->edl->session->frame_rate,
678 mwindow->edl->session->frames_per_foot);