4 * Copyright (C) 1997-2014 Adam Williams <broadcast at earthling dot net>
5 * Copyright (C) 2003-2016 Cinelerra CV contributors
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "apatchgui.inc"
26 #include "cwindowgui.h"
28 #include "edlsession.h"
31 #include "localsession.h"
32 #include "maincursor.h"
34 #include "mwindowgui.h"
35 #include "mainsession.h"
37 #include "preferences.h"
39 #include "trackcanvas.h"
42 #include "vpatchgui.inc"
46 ZoomBar::ZoomBar(MWindow *mwindow, MWindowGUI *gui)
47 : BC_SubWindow(mwindow->theme->mzoom_x,
48 mwindow->theme->mzoom_y,
49 mwindow->theme->mzoom_w,
50 mwindow->theme->mzoom_h)
53 this->mwindow = mwindow;
54 // *** CONTEXT_HELP ***
55 context_help_set_keyword("Zoom Panel");
66 void ZoomBar::create_objects()
68 int xs5 = xS(5), xs10 = xS(10);
69 int x = xS(3), y = get_h()/2 -
70 mwindow->theme->get_image_set("zoombar_menu", 0)[0]->get_h()/2;
72 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
73 sample_zoom = new SampleZoomPanel(mwindow, this, x, y);
74 sample_zoom->create_objects();
75 sample_zoom->set_tooltip(_("Duration visible in the timeline"));
76 x += sample_zoom->get_w();
77 amp_zoom = new AmpZoomPanel(mwindow, this, x, y);
78 amp_zoom->create_objects();
79 amp_zoom->set_tooltip(_("Audio waveform scale"));
80 x += amp_zoom->get_w();
81 atrack_zoom = new ATrackZoomPanel(mwindow, this, x, y);
82 atrack_zoom->create_objects();
83 atrack_zoom->set_tooltip(_("Height of audio tracks"));
84 x += atrack_zoom->get_w() + xs10;
85 vtrack_zoom = new VTrackZoomPanel(mwindow, this, x, y);
86 vtrack_zoom->create_objects();
87 vtrack_zoom->set_tooltip(_("Height of video tracks"));
88 x += vtrack_zoom->get_w() + xs10;
91 for( int i=AUTOGROUPTYPE_AUDIO_FADE; i<=AUTOGROUPTYPE_Y; ++i ) {
92 int ww = BC_GenericButton::calculate_w(this, AutoTypeMenu::to_text(i));
93 if( ww > wid ) wid = ww;
95 add_subwindow(auto_type = new AutoTypeMenu(mwindow, this, x, y, wid));
96 auto_type->create_objects();
97 x += auto_type->get_w() + xs10;
98 #define DEFAULT_TEXT "000.00 to 000.00"
99 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 0));
100 x += auto_zoom->get_w();
101 add_subwindow(auto_zoom_text = new ZoomTextBox(mwindow, this, x, y, DEFAULT_TEXT));
102 x += auto_zoom_text->get_w() + xs5;
103 add_subwindow(auto_zoom = new AutoZoom(mwindow, this, x, y, 1));
105 x += auto_zoom->get_w() + xs5;
107 add_subwindow(from_value = new FromTextBox(mwindow, this, x, y));
108 x += from_value->get_w() + xs5;
109 add_subwindow(length_value = new LengthTextBox(mwindow, this, x, y));
110 x += length_value->get_w() + xs5;
111 add_subwindow(to_value = new ToTextBox(mwindow, this, x, y));
112 x += to_value->get_w() + xs5;
113 add_subwindow(title_alpha_bar = new TitleAlphaBar(mwindow, this, x, y));
114 x += title_alpha_bar->get_w() + xs5;
115 add_subwindow(title_alpha_text = new TitleAlphaText(mwindow, this, x, y));
117 update_formatting(from_value);
118 update_formatting(length_value);
119 update_formatting(to_value);
125 void ZoomBar::update_formatting(BC_TextBox *dst)
128 Units::format_to_separators(mwindow->edl->session->time_format));
131 void ZoomBar::resize_event()
133 reposition_window(mwindow->theme->mzoom_x, mwindow->theme->mzoom_y,
134 mwindow->theme->mzoom_w, mwindow->theme->mzoom_h);
135 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
138 void ZoomBar::redraw_time_dependancies()
140 // Recalculate sample zoom menu
141 sample_zoom->update_menu();
142 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
143 update_formatting(from_value);
144 update_formatting(length_value);
145 update_formatting(to_value);
156 void ZoomBar::update_autozoom()
158 update_autozoom(mwindow->edl->local_session->zoombar_showautocolor);
161 void ZoomBar::update_autozoom(int grouptype, int color)
163 mwindow->edl->local_session->zoombar_showautotype = grouptype;
164 update_autozoom(color);
167 void ZoomBar::update_autozoom(int color)
169 char string[BCTEXTLEN];
170 int autogroup_type = mwindow->edl->local_session->zoombar_showautotype;
171 mwindow->edl->local_session->zoombar_showautocolor = color;
172 if( color < 0 ) color = get_resources()->default_text_color;
173 switch( autogroup_type ) {
174 case AUTOGROUPTYPE_AUDIO_FADE:
175 case AUTOGROUPTYPE_VIDEO_FADE:
176 sprintf(string, "%0.01f to %0.01f\n",
177 mwindow->edl->local_session->automation_mins[autogroup_type],
178 mwindow->edl->local_session->automation_maxs[autogroup_type]);
180 case AUTOGROUPTYPE_ZOOM:
181 case AUTOGROUPTYPE_SPEED:
182 sprintf(string, "%0.03f to %0.03f\n",
183 mwindow->edl->local_session->automation_mins[autogroup_type],
184 mwindow->edl->local_session->automation_maxs[autogroup_type]);
186 case AUTOGROUPTYPE_X:
187 case AUTOGROUPTYPE_Y:
188 sprintf(string, "%0.0f to %.0f\n",
189 mwindow->edl->local_session->automation_mins[autogroup_type],
190 mwindow->edl->local_session->automation_maxs[autogroup_type]);
193 auto_zoom_text->update(string);
194 const char *group_name = AutoTypeMenu::to_text(autogroup_type);
195 auto_type->set_text(group_name);
196 switch( autogroup_type ) {
197 case AUTOGROUPTYPE_ZOOM:
198 case AUTOGROUPTYPE_X:
199 case AUTOGROUPTYPE_Y:
200 CWindowGUI *cgui = mwindow->cwindow->gui;
202 cgui->lock_window("ZoomBar::update_autozoom");
204 cgui->unlock_window();
205 lock_window("ZoomBar::update_autozoom");
211 int ZoomBar::update()
213 sample_zoom->update(mwindow->edl->local_session->zoom_sample);
214 amp_zoom->update(mwindow->edl->local_session->zoom_y);
215 atrack_zoom->update(mwindow->edl->local_session->zoom_atrack);
216 vtrack_zoom->update(mwindow->edl->local_session->zoom_vtrack);
222 int ZoomBar::update_clocks()
224 from_value->update_position(mwindow->edl->local_session->get_selectionstart(1));
225 length_value->update_position(mwindow->edl->local_session->get_selectionend(1) -
226 mwindow->edl->local_session->get_selectionstart(1));
227 to_value->update_position(mwindow->edl->local_session->get_selectionend(1));
231 TitleAlphaBar::TitleAlphaBar(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
232 : BC_FSlider(x, y, 0, xS(150), xS(200), 0, 1.0, mwindow->session->title_bar_alpha, 0)
234 this->mwindow = mwindow;
235 this->zoombar = zoombar;
237 enable_show_value(0);
240 int TitleAlphaBar::handle_event()
242 float v = get_value();
243 mwindow->session->title_bar_alpha = v;
244 zoombar->title_alpha_text->update(v);
245 mwindow->gui->draw_trackmovement();
246 mwindow->gui->flush();
250 TitleAlphaText::TitleAlphaText(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
251 : BC_TextBox(x, y, xS(48), 1, mwindow->session->title_bar_alpha, 0, MEDIUMFONT, 2)
253 this->mwindow = mwindow;
254 this->zoombar = zoombar;
255 set_tooltip(_("Title Alpha"));
258 int TitleAlphaText::handle_event()
260 float v = atof(get_text());
261 mwindow->session->title_bar_alpha = v;
262 zoombar->title_alpha_bar->update(v);
263 mwindow->gui->draw_trackmovement();
264 mwindow->gui->flush();
268 int ZoomBar::resize_event(int w, int h)
270 // don't change anything but y and width
271 reposition_window(0, h - this->get_h(), w, this->get_h());
276 // Values for which_one
282 int ZoomBar::set_selection(int which_one)
284 double start_position = mwindow->edl->local_session->get_selectionstart(1);
285 double end_position = mwindow->edl->local_session->get_selectionend(1);
286 double length = end_position - start_position;
293 start_position = Units::text_to_seconds(from_value->get_text(),
294 mwindow->edl->session->sample_rate,
295 mwindow->edl->session->time_format,
296 mwindow->edl->session->frame_rate,
297 mwindow->edl->session->frames_per_foot);
298 length = Units::text_to_seconds(length_value->get_text(),
299 mwindow->edl->session->sample_rate,
300 mwindow->edl->session->time_format,
301 mwindow->edl->session->frame_rate,
302 mwindow->edl->session->frames_per_foot);
303 end_position = start_position + length;
305 if(end_position < start_position)
307 start_position = end_position;
308 mwindow->edl->local_session->set_selectionend(
309 mwindow->edl->local_session->get_selectionstart(1));
314 start_position = Units::text_to_seconds(from_value->get_text(),
315 mwindow->edl->session->sample_rate,
316 mwindow->edl->session->time_format,
317 mwindow->edl->session->frame_rate,
318 mwindow->edl->session->frames_per_foot);
319 end_position = Units::text_to_seconds(to_value->get_text(),
320 mwindow->edl->session->sample_rate,
321 mwindow->edl->session->time_format,
322 mwindow->edl->session->frame_rate,
323 mwindow->edl->session->frames_per_foot);
325 if(end_position < start_position)
327 end_position = start_position;
328 mwindow->edl->local_session->set_selectionend(
329 mwindow->edl->local_session->get_selectionstart(1));
334 start_position = Units::text_to_seconds(from_value->get_text(),
335 mwindow->edl->session->sample_rate,
336 mwindow->edl->session->time_format,
337 mwindow->edl->session->frame_rate,
338 mwindow->edl->session->frames_per_foot);
339 end_position = Units::text_to_seconds(to_value->get_text(),
340 mwindow->edl->session->sample_rate,
341 mwindow->edl->session->time_format,
342 mwindow->edl->session->frame_rate,
343 mwindow->edl->session->frames_per_foot);
345 if(end_position < start_position)
347 start_position = end_position;
348 mwindow->edl->local_session->set_selectionend(
349 mwindow->edl->local_session->get_selectionstart(1));
354 mwindow->edl->local_session->set_selectionstart(
355 mwindow->edl->align_to_frame(start_position, 1));
356 mwindow->edl->local_session->set_selectionend(
357 mwindow->edl->align_to_frame(end_position, 1));
360 mwindow->gui->update_timebar_highlights();
361 mwindow->gui->hide_cursor(1);
362 mwindow->gui->show_cursor(1);
364 mwindow->sync_parameters(CHANGE_PARAMS);
365 mwindow->gui->flash_canvas(1);
371 SampleZoomPanel::SampleZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
372 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_sample,
373 x, y, xS(130), MIN_ZOOM_TIME, MAX_ZOOM_TIME, ZOOM_TIME)
375 this->mwindow = mwindow;
376 this->zoombar = zoombar;
378 int SampleZoomPanel::handle_event()
380 mwindow->zoom_sample((int64_t)get_value());
385 AmpZoomPanel::AmpZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
386 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_y,
387 x, y, xS(80), MIN_AMP_ZOOM, MAX_AMP_ZOOM, ZOOM_LONG)
389 this->mwindow = mwindow;
390 this->zoombar = zoombar;
392 int AmpZoomPanel::handle_event()
394 if( zoombar->shift_down() )
395 update(DEFAULT_ZOOM_TRACK);
396 mwindow->zoom_amp((int64_t)get_value());
400 ATrackZoomPanel::ATrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
401 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_atrack,
402 x, y, xS(64), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
404 this->mwindow = mwindow;
405 this->zoombar = zoombar;
407 int ATrackZoomPanel::handle_event()
409 if( zoombar->shift_down() )
410 update(DEFAULT_ZOOM_TRACK);
411 mwindow->zoom_atrack((int64_t)get_value());
412 zoombar->amp_zoom->update(mwindow->edl->local_session->zoom_y);
416 VTrackZoomPanel::VTrackZoomPanel(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
417 : ZoomPanel(mwindow, zoombar, mwindow->edl->local_session->zoom_vtrack,
418 x, y, xS(64), MIN_TRACK_ZOOM, MAX_TRACK_ZOOM, ZOOM_LONG)
420 this->mwindow = mwindow;
421 this->zoombar = zoombar;
423 int VTrackZoomPanel::handle_event()
425 if( zoombar->shift_down() )
426 update(DEFAULT_ZOOM_TRACK);
427 mwindow->zoom_vtrack((int64_t)get_value());
432 AutoZoom::AutoZoom(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int changemax)
433 : BC_Tumbler(x, y, mwindow->theme->get_image_set("zoombar_tumbler"))
435 this->mwindow = mwindow;
436 this->zoombar = zoombar;
437 this->changemax = changemax;
439 set_tooltip(_("Automation range maximum"));
441 set_tooltip(_("Automation range minimum"));
444 int AutoZoom::handle_up_event()
446 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,1,changemax);
448 mwindow->gui->zoombar->update_autozoom();
449 mwindow->gui->draw_overlays(0);
450 mwindow->gui->update_patchbay();
451 mwindow->gui->flash_canvas(1);
455 int AutoZoom::handle_down_event()
457 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype,0,changemax);
459 mwindow->gui->zoombar->update_autozoom();
460 mwindow->gui->draw_overlays(0);
461 mwindow->gui->update_patchbay();
462 mwindow->gui->flash_canvas(1);
468 AutoTypeMenu::AutoTypeMenu(MWindow *mwindow, ZoomBar *zoombar, int x, int y, int wid)
469 : BC_PopupMenu(x, y, wid + xS(24),
470 to_text(mwindow->edl->local_session->zoombar_showautotype), 1, 0, 12)
472 this->mwindow = mwindow;
473 this->zoombar = zoombar;
474 set_tooltip(_("Automation Type"));
477 void AutoTypeMenu::create_objects()
479 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_AUDIO_FADE)));
480 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_VIDEO_FADE)));
481 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_ZOOM)));
482 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_SPEED)));
483 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_X)));
484 add_item(new BC_MenuItem(to_text(AUTOGROUPTYPE_Y)));
487 const char* AutoTypeMenu::to_text(int mode)
490 case AUTOGROUPTYPE_AUDIO_FADE: return _("Audio Fade:");
491 case AUTOGROUPTYPE_VIDEO_FADE: return _("Video Fade:");
492 case AUTOGROUPTYPE_ZOOM: return _("Zoom:");
493 case AUTOGROUPTYPE_SPEED: return _("Speed:");
494 case AUTOGROUPTYPE_X: return "X:";
495 case AUTOGROUPTYPE_Y: return "Y:";
500 int AutoTypeMenu::from_text(char *text)
502 if(!strcmp(text, to_text(AUTOGROUPTYPE_AUDIO_FADE))) return AUTOGROUPTYPE_AUDIO_FADE;
503 if(!strcmp(text, to_text(AUTOGROUPTYPE_VIDEO_FADE))) return AUTOGROUPTYPE_VIDEO_FADE;
504 if(!strcmp(text, to_text(AUTOGROUPTYPE_ZOOM))) return AUTOGROUPTYPE_ZOOM;
505 if(!strcmp(text, to_text(AUTOGROUPTYPE_SPEED))) return AUTOGROUPTYPE_SPEED;
506 if(!strcmp(text, to_text(AUTOGROUPTYPE_X))) return AUTOGROUPTYPE_X;
507 if(!strcmp(text, to_text(AUTOGROUPTYPE_Y))) return AUTOGROUPTYPE_Y;
508 return AUTOGROUPTYPE_INT255;
511 int AutoTypeMenu::draw_face(int dx, int color)
513 BC_PopupMenu::draw_face(dx+xS(8), color);
514 color = mwindow->edl->local_session->zoombar_showautocolor;
517 int margin = get_margin();
518 int mx = margin+xS(8), my = 3*margin/8;
519 int bh = get_h() - 2*my;
520 draw_box(mx,my, bh,bh);
525 int AutoTypeMenu::handle_event()
527 mwindow->edl->local_session->zoombar_showautotype = from_text(this->get_text());
528 this->zoombar->update_autozoom();
533 ZoomTextBox::ZoomTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y, const char *text)
534 : BC_TextBox(x, y, xS(130), 1, text)
536 this->mwindow = mwindow;
537 this->zoombar = zoombar;
538 set_tooltip(_("Automation range"));
541 int ZoomTextBox::button_press_event()
543 if (!(get_buttonpress() == 4 || get_buttonpress() == 5)) {
544 BC_TextBox::button_press_event();
547 if (!is_event_win()) return 0;
550 if (get_relative_cursor_x() < get_w()/2)
554 if (get_buttonpress() == 4)
555 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 1, changemax);
558 if (get_buttonpress() == 5)
559 mwindow->change_currentautorange(mwindow->edl->local_session->zoombar_showautotype, 0, changemax);
561 mwindow->gui->zoombar->update_autozoom();
562 mwindow->gui->draw_overlays(0);
563 mwindow->gui->update_patchbay();
564 mwindow->gui->flash_canvas(1);
568 int ZoomTextBox::handle_event()
571 if (sscanf(this->get_text(),"%f to%f",&min, &max) == 2)
573 AUTOMATIONVIEWCLAMPS(min, mwindow->edl->local_session->zoombar_showautotype);
574 AUTOMATIONVIEWCLAMPS(max, mwindow->edl->local_session->zoombar_showautotype);
577 mwindow->edl->local_session->automation_mins[mwindow->edl->local_session->zoombar_showautotype] = min;
578 mwindow->edl->local_session->automation_maxs[mwindow->edl->local_session->zoombar_showautotype] = max;
579 mwindow->gui->zoombar->update_autozoom();
580 mwindow->gui->draw_overlays(0);
581 mwindow->gui->update_patchbay();
582 mwindow->gui->flash_canvas(1);
585 // TODO: Make the text turn red when it's a bad range..
593 FromTextBox::FromTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
594 : BC_TextBox(x, y, xS(90), 1, "")
596 this->mwindow = mwindow;
597 this->zoombar = zoombar;
598 set_tooltip(_("Selection start time"));
601 int FromTextBox::handle_event()
603 if(get_keypress() == NEWLINE)
605 zoombar->set_selection(SET_FROM);
611 int FromTextBox::update_position(double new_position)
613 Units::totext(string,
615 mwindow->edl->session->time_format,
616 mwindow->edl->session->sample_rate,
617 mwindow->edl->session->frame_rate,
618 mwindow->edl->session->frames_per_foot,
619 mwindow->get_timecode_offset());
620 //printf("FromTextBox::update_position %f %s\n", new_position, string);
630 LengthTextBox::LengthTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
631 : BC_TextBox(x, y, xS(90), 1, "")
633 this->mwindow = mwindow;
634 this->zoombar = zoombar;
635 set_tooltip(_("Selection length"));
638 int LengthTextBox::handle_event()
640 if(get_keypress() == NEWLINE)
642 zoombar->set_selection(SET_LENGTH);
648 int LengthTextBox::update_position(double new_position)
650 Units::totext(string,
652 mwindow->edl->session->time_format,
653 mwindow->edl->session->sample_rate,
654 mwindow->edl->session->frame_rate,
655 mwindow->edl->session->frames_per_foot);
664 ToTextBox::ToTextBox(MWindow *mwindow, ZoomBar *zoombar, int x, int y)
665 : BC_TextBox(x, y, xS(90), 1, "")
667 this->mwindow = mwindow;
668 this->zoombar = zoombar;
669 set_tooltip(_("Selection end time"));
672 int ToTextBox::handle_event()
674 if(get_keypress() == NEWLINE)
676 zoombar->set_selection(SET_TO);
682 int ToTextBox::update_position(double new_position)
684 Units::totext(string, new_position,
685 mwindow->edl->session->time_format,
686 mwindow->edl->session->sample_rate,
687 mwindow->edl->session->frame_rate,
688 mwindow->edl->session->frames_per_foot,
689 mwindow->get_timecode_offset());