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"
28 #include "localsession.h"
29 #include "maincursor.h"
31 #include "mwindowgui.h"
32 #include "mainsession.h"
34 #include "preferences.h"
36 #include "trackcanvas.h"
39 #include "vpatchgui.inc"
43 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
44 : BC_SubWindow(mwindow->theme->mzoom_x,
45 mwindow->theme->mzoom_y,
46 mwindow->theme->mzoom_w,
47 mwindow->theme->mzoom_h)
50 this->mwindow = mwindow;
60 void ZoomBar::create_objects()
62 int xs5 = xS(5), xs10 = xS(10);
63 int x = xS(3), y = get_h()/2 -
64 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h()/2;
66 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
67 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
68 sample_zoom->create_objects();
69 sample_zoom->set_tooltip(_("Duration visible in the timeline"));
70 x += sample_zoom->get_w();
71 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
72 amp_zoom->create_objects();
73 amp_zoom->set_tooltip(_("Audio waveform scale"));
74 x += amp_zoom->get_w();
75 track_zoom = new TrackZoomPanel(mwindow, this, x, y);
76 track_zoom->create_objects();
77 track_zoom->set_tooltip(_("Height of tracks in the timeline"));
78 x += track_zoom->get_w() + xs10;
81 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
82 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
83 if( ww > wid ) wid = ww;
85 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
86 auto_type->create_objects();
87 x += auto_type->get_w() + xs10;
88 #define DEFAULT_TEXT "000.00 to 000.00"
89 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
90 x += auto_zoom->get_w();
91 add_subwindow(auto_zoom_text = new ZoomTextBox(
97 x += auto_zoom_text->get_w() + xs5;
98 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
100 x += auto_zoom->get_w() + xs5;
102 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
103 x += from_value->get_w() + xs5;
104 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
105 x += length_value->get_w() + xs5;
106 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
107 x += to_value->get_w() + xs5;
108 add_subwindow(title_alpha_bar = new TitleAlphaBar(mwindow, this, x, y));
109 x += title_alpha_bar->get_w() + xs5;
110 add_subwindow(title_alpha_text = new TitleAlphaText(mwindow, this, x, y));
112 update_formatting(from_value);
113 update_formatting(length_value);
114 update_formatting(to_value);
120 void ZoomBar::update_formatting(BC_TextBox *dst)
123 Units::format_to_separators(mwindow->edl->session->time_format));
126 void ZoomBar::resize_event()
128 reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
129 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
130 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
133 void ZoomBar::redraw_time_dependancies()
135 // Recalculate sample zoom menu
136 sample_zoom->update_menu();
137 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
138 update_formatting(from_value);
139 update_formatting(length_value);
140 update_formatting(to_value);
151 void ZoomBar::update_autozoom()
153 update_autozoom(mwindow->edl->local_session->zoombar_showautocolor);
156 void ZoomBar::update_autozoom(int grouptype, int color)
158 mwindow->edl->local_session->zoombar_showautotype = grouptype;
159 update_autozoom(color);
162 void ZoomBar::update_autozoom(int color)
164 char string[BCTEXTLEN];
165 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
166 mwindow->edl->local_session->zoombar_showautocolor = color;
167 if( color < 0 ) color = get_resources()->default_text_color;
168 switch( autogroup_type ) {
169 case AUTOGROUPTYPE_AUDIO_FADE:
170 case AUTOGROUPTYPE_VIDEO_FADE:
171 sprintf(string, "%0.01f to %0.01f\n",
172 mwindow->edl->local_session->automation_mins[autogroup_type],
173 mwindow->edl->local_session->automation_maxs[autogroup_type]);
175 case AUTOGROUPTYPE_ZOOM:
176 case AUTOGROUPTYPE_SPEED:
177 sprintf(string, "%0.03f to %0.03f\n",
178 mwindow->edl->local_session->automation_mins[autogroup_type],
179 mwindow->edl->local_session->automation_maxs[autogroup_type]);
181 case AUTOGROUPTYPE_X:
182 case AUTOGROUPTYPE_Y:
183 sprintf(string, "%0.0f to %.0f\n",
184 mwindow->edl->local_session->automation_mins[autogroup_type],
185 mwindow->edl->local_session->automation_maxs[autogroup_type]);
188 auto_zoom_text->update(string);
189 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
190 auto_type->set_text(group_name);
194 int ZoomBar::update()
196 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
197 amp_zoom->update(mwindow->edl->local_session->zoom_y);
198 track_zoom->update(mwindow->edl->local_session->zoom_track);
204 int ZoomBar::update_clocks()
206 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
207 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
208 mwindow->edl->local_session->get_selectionstart(1));
209 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
213 TitleAlphaBar::TitleAlphaBar(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
214 : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1.0, mwindow->session->title_bar_alpha, 0)
216 this->mwindow = mwindow;
217 this->zoombar = zoombar;
219 enable_show_value(0);
222 int TitleAlphaBar::handle_event()
224 float v = get_value();
225 mwindow->session->title_bar_alpha = v;
226 zoombar->title_alpha_text->update(v);
227 mwindow->gui->draw_trackmovement();
228 mwindow->gui->flush();
232 TitleAlphaText::TitleAlphaText(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
233 : BC_TextBox(x, y, xS(48), 1, mwindow->session->title_bar_alpha, 0, MEDIUMFONT, 2)
235 this->mwindow = mwindow;
236 this->zoombar = zoombar;
237 set_tooltip(_("Title Alpha"));
240 int TitleAlphaText::handle_event()
242 float v = atof(get_text());
243 mwindow->session->title_bar_alpha = v;
244 zoombar->title_alpha_bar->update(v);
245 mwindow->gui->draw_trackmovement();
246 mwindow->gui->flush();
250 int ZoomBar::resize_event(int w, int h)
252 // don't change anything but y and width
253 reposition_window(0, h - this->get_h(), w, this->get_h());
258 // Values for which_one
264 int ZoomBar::set_selection(int which_one)
266 double start_position = mwindow->edl->local_session->get_selectionstart(1);
267 double end_position = mwindow->edl->local_session->get_selectionend(1);
268 double length = end_position - start_position;
275 start_position = Units::text_to_seconds(from_value->get_text(),
276 mwindow->edl->session->sample_rate,
277 mwindow->edl->session->time_format,
278 mwindow->edl->session->frame_rate,
279 mwindow->edl->session->frames_per_foot);
280 length = Units::text_to_seconds(length_value->get_text(),
281 mwindow->edl->session->sample_rate,
282 mwindow->edl->session->time_format,
283 mwindow->edl->session->frame_rate,
284 mwindow->edl->session->frames_per_foot);
285 end_position = start_position + length;
287 if(end_position < start_position)
289 start_position = end_position;
290 mwindow->edl->local_session->set_selectionend(
291 mwindow->edl->local_session->get_selectionstart(1));
296 start_position = Units::text_to_seconds(from_value->get_text(),
297 mwindow->edl->session->sample_rate,
298 mwindow->edl->session->time_format,
299 mwindow->edl->session->frame_rate,
300 mwindow->edl->session->frames_per_foot);
301 end_position = Units::text_to_seconds(to_value->get_text(),
302 mwindow->edl->session->sample_rate,
303 mwindow->edl->session->time_format,
304 mwindow->edl->session->frame_rate,
305 mwindow->edl->session->frames_per_foot);
307 if(end_position < start_position)
309 end_position = start_position;
310 mwindow->edl->local_session->set_selectionend(
311 mwindow->edl->local_session->get_selectionstart(1));
316 start_position = Units::text_to_seconds(from_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);
321 end_position = Units::text_to_seconds(to_value->get_text(),
322 mwindow->edl->session->sample_rate,
323 mwindow->edl->session->time_format,
324 mwindow->edl->session->frame_rate,
325 mwindow->edl->session->frames_per_foot);
327 if(end_position < start_position)
329 start_position = end_position;
330 mwindow->edl->local_session->set_selectionend(
331 mwindow->edl->local_session->get_selectionstart(1));
336 mwindow->edl->local_session->set_selectionstart(
337 mwindow->edl->align_to_frame(start_position, 1));
338 mwindow->edl->local_session->set_selectionend(
339 mwindow->edl->align_to_frame(end_position, 1));
342 mwindow->gui->update_timebar_highlights();
343 mwindow->gui->hide_cursor(1);
344 mwindow->gui->show_cursor(1);
346 mwindow->sync_parameters(CHANGE_PARAMS);
347 mwindow->gui->flash_canvas(1);
353 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
354 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
355 x, y, xS(130), MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
357 this->mwindow = mwindow;
358 this->zoombar = zoombar;
360 int SampleZoomPanel::handle_event()
362 mwindow->zoom_sample((int64_t)get_value());
367 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
368 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
369 x, y, xS(100), MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
371 this->mwindow = mwindow;
372 this->zoombar = zoombar;
374 int AmpZoomPanel::handle_event()
376 mwindow->zoom_amp((int64_t)get_value());
380 TrackZoomPanel::TrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
381 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_track,
382 x, y, xS(90), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
384 this->mwindow = mwindow;
385 this->zoombar = zoombar;
387 int TrackZoomPanel::handle_event()
389 mwindow->zoom_track((int64_t)get_value());
390 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
397 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
398 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
400 this->mwindow = mwindow;
401 this->zoombar = zoombar;
402 this->changemax = changemax;
404 set_tooltip(_("Automation range maximum"));
406 set_tooltip(_("Automation range minimum"));
409 int AutoZoom::handle_up_event()
411 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
413 mwindow->gui->zoombar->update_autozoom();
414 mwindow->gui->draw_overlays(0);
415 mwindow->gui->update_patchbay();
416 mwindow->gui->flash_canvas(1);
420 int AutoZoom::handle_down_event()
422 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
424 mwindow->gui->zoombar->update_autozoom();
425 mwindow->gui->draw_overlays(0);
426 mwindow->gui->update_patchbay();
427 mwindow->gui->flash_canvas(1);
433 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
434 : BC_PopupMenu(x, y, wid + xS(24),
435 to_text(mwindow->edl->local_session->zoombar_showautotype), 1, 0, 12)
437 this->mwindow = mwindow;
438 this->zoombar = zoombar;
439 set_tooltip(_("Automation Type"));
442 void AutoTypeMenu::create_objects()
444 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
445 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
446 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
447 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
448 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
449 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
452 const char* AutoTypeMenu::to_text(int mode)
455 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
456 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
457 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
458 case AUTOGROUPTYPE_SPEED: return _("Speed:");
459 case AUTOGROUPTYPE_X: return "X:";
460 case AUTOGROUPTYPE_Y: return "Y:";
465 int AutoTypeMenu::from_text(char *text)
467 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
468 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
469 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
470 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
471 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
472 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
473 return AUTOGROUPTYPE_INT255;
476 int AutoTypeMenu::draw_face(int dx, int color)
478 BC_PopupMenu::draw_face(dx+xS(8), color);
479 color = mwindow->edl->local_session->zoombar_showautocolor;
482 int margin = get_margin();
483 int mx = margin+xS(8), my = 3*margin/8;
484 int bh = get_h() - 2*my;
485 draw_box(mx,my, bh,bh);
490 int AutoTypeMenu::handle_event()
492 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
493 this->zoombar->update_autozoom();
498 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
499 : BC_TextBox(x, y, xS(130), 1, text)
501 this->mwindow = mwindow;
502 this->zoombar = zoombar;
503 set_tooltip(_("Automation range"));
506 int ZoomTextBox::button_press_event()
508 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
509 BC_TextBox::button_press_event();
512 if (!is_event_win()) return 0;
515 if (get_relative_cursor_x() < get_w()/2)
519 if (get_buttonpress() == 4)
520 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
523 if (get_buttonpress() == 5)
524 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
526 mwindow->gui->zoombar->update_autozoom();
527 mwindow->gui->draw_overlays(0);
528 mwindow->gui->update_patchbay();
529 mwindow->gui->flash_canvas(1);
533 int ZoomTextBox::handle_event()
536 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
538 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
539 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
542 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
543 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
544 mwindow->gui->zoombar->update_autozoom();
545 mwindow->gui->draw_overlays(0);
546 mwindow->gui->update_patchbay();
547 mwindow->gui->flash_canvas(1);
550 // TODO: Make the text turn red when it's a bad range..
558 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
559 : BC_TextBox(x, y, xS(90), 1, "")
561 this->mwindow = mwindow;
562 this->zoombar = zoombar;
563 set_tooltip(_("Selection start time"));
566 int FromTextBox::handle_event()
568 if(get_keypress() == NEWLINE)
570 zoombar->set_selection(SET_FROM);
576 int FromTextBox::update_position(double new_position)
578 Units::totext(string,
580 mwindow->edl->session->time_format,
581 mwindow->edl->session->sample_rate,
582 mwindow->edl->session->frame_rate,
583 mwindow->edl->session->frames_per_foot);
584 //printf("FromTextBox::update_position %f %s\n", new_position, string);
594 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
595 : BC_TextBox(x, y, xS(90), 1, "")
597 this->mwindow = mwindow;
598 this->zoombar = zoombar;
599 set_tooltip(_("Selection length"));
602 int LengthTextBox::handle_event()
604 if(get_keypress() == NEWLINE)
606 zoombar->set_selection(SET_LENGTH);
612 int LengthTextBox::update_position(double new_position)
614 Units::totext(string,
616 mwindow->edl->session->time_format,
617 mwindow->edl->session->sample_rate,
618 mwindow->edl->session->frame_rate,
619 mwindow->edl->session->frames_per_foot);
628 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
629 : BC_TextBox(x, y, xS(90), 1, "")
631 this->mwindow = mwindow;
632 this->zoombar = zoombar;
633 set_tooltip(_("Selection end time"));
636 int ToTextBox::handle_event()
638 if(get_keypress() == NEWLINE)
640 zoombar->set_selection(SET_TO);
646 int ToTextBox::update_position(double new_position)
648 Units::totext(string, new_position,
649 mwindow->edl->session->time_format,
650 mwindow->edl->session->sample_rate,
651 mwindow->edl->session->frame_rate,
652 mwindow->edl->session->frames_per_foot);