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;
62 void ZoomBar::create_objects()
64 int xs5 = xS(5), xs10 = xS(10);
65 int x = xS(3), y = get_h()/2 -
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->create_objects();
71 sample_zoom->set_tooltip(_("Duration visible in the timeline"));
72 x += sample_zoom->get_w();
73 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
74 amp_zoom->create_objects();
75 amp_zoom->set_tooltip(_("Audio waveform scale"));
76 x += amp_zoom->get_w();
77 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
78 track_zoom->create_objects();
79 track_zoom->set_tooltip(_("Height of tracks in the timeline"));
80 x += track_zoom->get_w() + xs10;
83 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
84 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
85 if( ww > wid ) wid = ww;
87 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
88 auto_type->create_objects();
89 x += auto_type->get_w() + xs10;
90 #define DEFAULT_TEXT "000.00 to 000.00"
91 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
92 x += auto_zoom->get_w();
93 add_subwindow(auto_zoom_text = new ZoomTextBox(
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 track_zoom->update(mwindow->edl->local_session->zoom_track);
218 int ZoomBar::update_clocks()
220 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
221 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
222 mwindow->edl->local_session->get_selectionstart(1));
223 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
227 TitleAlphaBar::TitleAlphaBar(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
228 : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1.0, mwindow->session->title_bar_alpha, 0)
230 this->mwindow = mwindow;
231 this->zoombar = zoombar;
233 enable_show_value(0);
236 int TitleAlphaBar::handle_event()
238 float v = get_value();
239 mwindow->session->title_bar_alpha = v;
240 zoombar->title_alpha_text->update(v);
241 mwindow->gui->draw_trackmovement();
242 mwindow->gui->flush();
246 TitleAlphaText::TitleAlphaText(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
247 : BC_TextBox(x, y, xS(48), 1, mwindow->session->title_bar_alpha, 0, MEDIUMFONT, 2)
249 this->mwindow = mwindow;
250 this->zoombar = zoombar;
251 set_tooltip(_("Title Alpha"));
254 int TitleAlphaText::handle_event()
256 float v = atof(get_text());
257 mwindow->session->title_bar_alpha = v;
258 zoombar->title_alpha_bar->update(v);
259 mwindow->gui->draw_trackmovement();
260 mwindow->gui->flush();
264 int ZoomBar::resize_event(int w, int h)
266 // don't change anything but y and width
267 reposition_window(0, h - this->get_h(), w, this->get_h());
272 // Values for which_one
278 int ZoomBar::set_selection(int which_one)
280 double start_position = mwindow->edl->local_session->get_selectionstart(1);
281 double end_position = mwindow->edl->local_session->get_selectionend(1);
282 double length = end_position - start_position;
289 start_position = Units::text_to_seconds(from_value->get_text(),
290 mwindow->edl->session->sample_rate,
291 mwindow->edl->session->time_format,
292 mwindow->edl->session->frame_rate,
293 mwindow->edl->session->frames_per_foot);
294 length = Units::text_to_seconds(length_value->get_text(),
295 mwindow->edl->session->sample_rate,
296 mwindow->edl->session->time_format,
297 mwindow->edl->session->frame_rate,
298 mwindow->edl->session->frames_per_foot);
299 end_position = start_position + length;
301 if(end_position < start_position)
303 start_position = end_position;
304 mwindow->edl->local_session->set_selectionend(
305 mwindow->edl->local_session->get_selectionstart(1));
310 start_position = Units::text_to_seconds(from_value->get_text(),
311 mwindow->edl->session->sample_rate,
312 mwindow->edl->session->time_format,
313 mwindow->edl->session->frame_rate,
314 mwindow->edl->session->frames_per_foot);
315 end_position = Units::text_to_seconds(to_value->get_text(),
316 mwindow->edl->session->sample_rate,
317 mwindow->edl->session->time_format,
318 mwindow->edl->session->frame_rate,
319 mwindow->edl->session->frames_per_foot);
321 if(end_position < start_position)
323 end_position = start_position;
324 mwindow->edl->local_session->set_selectionend(
325 mwindow->edl->local_session->get_selectionstart(1));
330 start_position = Units::text_to_seconds(from_value->get_text(),
331 mwindow->edl->session->sample_rate,
332 mwindow->edl->session->time_format,
333 mwindow->edl->session->frame_rate,
334 mwindow->edl->session->frames_per_foot);
335 end_position = Units::text_to_seconds(to_value->get_text(),
336 mwindow->edl->session->sample_rate,
337 mwindow->edl->session->time_format,
338 mwindow->edl->session->frame_rate,
339 mwindow->edl->session->frames_per_foot);
341 if(end_position < start_position)
343 start_position = end_position;
344 mwindow->edl->local_session->set_selectionend(
345 mwindow->edl->local_session->get_selectionstart(1));
350 mwindow->edl->local_session->set_selectionstart(
351 mwindow->edl->align_to_frame(start_position, 1));
352 mwindow->edl->local_session->set_selectionend(
353 mwindow->edl->align_to_frame(end_position, 1));
356 mwindow->gui->update_timebar_highlights();
357 mwindow->gui->hide_cursor(1);
358 mwindow->gui->show_cursor(1);
360 mwindow->sync_parameters(CHANGE_PARAMS);
361 mwindow->gui->flash_canvas(1);
367 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
368 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
369 x, y, xS(130), MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
371 this->mwindow = mwindow;
372 this->zoombar = zoombar;
374 int SampleZoomPanel::handle_event()
376 mwindow->zoom_sample((int64_t)get_value());
381 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
382 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
383 x, y, xS(100), MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
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)
395 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_track,
396 x, y, xS(90), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
398 this->mwindow = mwindow;
399 this->zoombar = zoombar;
401 int TrackZoomPanel::handle_event()
403 mwindow->zoom_track((int64_t)get_value());
404 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
411 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
412 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
414 this->mwindow = mwindow;
415 this->zoombar = zoombar;
416 this->changemax = changemax;
418 set_tooltip(_("Automation range maximum"));
420 set_tooltip(_("Automation range minimum"));
423 int AutoZoom::handle_up_event()
425 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
427 mwindow->gui->zoombar->update_autozoom();
428 mwindow->gui->draw_overlays(0);
429 mwindow->gui->update_patchbay();
430 mwindow->gui->flash_canvas(1);
434 int AutoZoom::handle_down_event()
436 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
438 mwindow->gui->zoombar->update_autozoom();
439 mwindow->gui->draw_overlays(0);
440 mwindow->gui->update_patchbay();
441 mwindow->gui->flash_canvas(1);
447 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
448 : BC_PopupMenu(x, y, wid + xS(24),
449 to_text(mwindow->edl->local_session->zoombar_showautotype), 1, 0, 12)
451 this->mwindow = mwindow;
452 this->zoombar = zoombar;
453 set_tooltip(_("Automation Type"));
456 void AutoTypeMenu::create_objects()
458 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
459 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
460 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
461 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
462 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
463 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
466 const char* AutoTypeMenu::to_text(int mode)
469 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
470 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
471 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
472 case AUTOGROUPTYPE_SPEED: return _("Speed:");
473 case AUTOGROUPTYPE_X: return "X:";
474 case AUTOGROUPTYPE_Y: return "Y:";
479 int AutoTypeMenu::from_text(char *text)
481 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
482 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
483 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
484 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
485 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
486 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
487 return AUTOGROUPTYPE_INT255;
490 int AutoTypeMenu::draw_face(int dx, int color)
492 BC_PopupMenu::draw_face(dx+xS(8), color);
493 color = mwindow->edl->local_session->zoombar_showautocolor;
496 int margin = get_margin();
497 int mx = margin+xS(8), my = 3*margin/8;
498 int bh = get_h() - 2*my;
499 draw_box(mx,my, bh,bh);
504 int AutoTypeMenu::handle_event()
506 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
507 this->zoombar->update_autozoom();
512 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
513 : BC_TextBox(x, y, xS(130), 1, text)
515 this->mwindow = mwindow;
516 this->zoombar = zoombar;
517 set_tooltip(_("Automation range"));
520 int ZoomTextBox::button_press_event()
522 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
523 BC_TextBox::button_press_event();
526 if (!is_event_win()) return 0;
529 if (get_relative_cursor_x() < get_w()/2)
533 if (get_buttonpress() == 4)
534 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
537 if (get_buttonpress() == 5)
538 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
540 mwindow->gui->zoombar->update_autozoom();
541 mwindow->gui->draw_overlays(0);
542 mwindow->gui->update_patchbay();
543 mwindow->gui->flash_canvas(1);
547 int ZoomTextBox::handle_event()
550 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
552 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
553 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
556 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
557 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
558 mwindow->gui->zoombar->update_autozoom();
559 mwindow->gui->draw_overlays(0);
560 mwindow->gui->update_patchbay();
561 mwindow->gui->flash_canvas(1);
564 // TODO: Make the text turn red when it's a bad range..
572 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
573 : BC_TextBox(x, y, xS(90), 1, "")
575 this->mwindow = mwindow;
576 this->zoombar = zoombar;
577 set_tooltip(_("Selection start time"));
580 int FromTextBox::handle_event()
582 if(get_keypress() == NEWLINE)
584 zoombar->set_selection(SET_FROM);
590 int FromTextBox::update_position(double new_position)
592 Units::totext(string,
594 mwindow->edl->session->time_format,
595 mwindow->edl->session->sample_rate,
596 mwindow->edl->session->frame_rate,
597 mwindow->edl->session->frames_per_foot);
598 //printf("FromTextBox::update_position %f %s\n", new_position, string);
608 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
609 : BC_TextBox(x, y, xS(90), 1, "")
611 this->mwindow = mwindow;
612 this->zoombar = zoombar;
613 set_tooltip(_("Selection length"));
616 int LengthTextBox::handle_event()
618 if(get_keypress() == NEWLINE)
620 zoombar->set_selection(SET_LENGTH);
626 int LengthTextBox::update_position(double new_position)
628 Units::totext(string,
630 mwindow->edl->session->time_format,
631 mwindow->edl->session->sample_rate,
632 mwindow->edl->session->frame_rate,
633 mwindow->edl->session->frames_per_foot);
642 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
643 : BC_TextBox(x, y, xS(90), 1, "")
645 this->mwindow = mwindow;
646 this->zoombar = zoombar;
647 set_tooltip(_("Selection end time"));
650 int ToTextBox::handle_event()
652 if(get_keypress() == NEWLINE)
654 zoombar->set_selection(SET_TO);
660 int ToTextBox::update_position(double new_position)
662 Units::totext(string, new_position,
663 mwindow->edl->session->time_format,
664 mwindow->edl->session->sample_rate,
665 mwindow->edl->session->frame_rate,
666 mwindow->edl->session->frames_per_foot);