1 #include "awindowgui.h"
4 #include "cwindowgui.h"
9 #include "edlsession.h"
10 #include "filesystem.h"
11 #include "keyframepopup.h"
14 #include "localsession.h"
15 #include "mainclock.h"
16 #include "maincursor.h"
18 #include "mainsession.h"
22 #include "mwindowgui.h"
25 #include "pluginpopup.h"
26 #include "samplescroll.h"
27 #include "statusbar.h"
29 #include "trackcanvas.h"
30 #include "trackscroll.h"
32 #include "transitionpopup.h"
33 #include "vwindowgui.h"
37 // the main window uses its own private colormap for video
38 MWindowGUI::MWindowGUI(MWindow *mwindow)
39 : BC_Window(PROGRAM_NAME ": Program",
40 mwindow->session->mwindow_x,
41 mwindow->session->mwindow_y,
42 mwindow->session->mwindow_w,
43 mwindow->session->mwindow_h,
50 this->mwindow = mwindow;
58 MWindowGUI::~MWindowGUI()
63 if(samplescroll) delete samplescroll;
64 if(trackscroll) delete trackscroll;
72 delete transition_menu;
75 void MWindowGUI::get_scrollbars()
77 //printf("MWindowGUI::get_scrollbars 1\n");
78 int64_t h_needed = mwindow->edl->get_tracks_height(mwindow->theme);
79 int64_t w_needed = mwindow->edl->get_tracks_width();
82 view_w = mwindow->theme->mcanvas_w;
83 view_h = mwindow->theme->mcanvas_h;
84 //printf("MWindowGUI::get_scrollbars 1\n");
86 // Scrollbars are constitutive
87 need_xscroll = need_yscroll = 1;
88 view_h = mwindow->theme->mcanvas_h;
89 view_w = mwindow->theme->mcanvas_w;
91 // for(int i = 0; i < 2; i++)
93 // if(w_needed > view_w)
96 // view_h = mwindow->theme->mcanvas_h - SCROLL_SPAN;
101 // if(h_needed > view_h)
104 // view_w = mwindow->theme->mcanvas_w - SCROLL_SPAN;
109 //printf("MWindowGUI::get_scrollbars 1\n");
111 if(canvas && (view_w != canvas->get_w() || view_h != canvas->get_h()))
113 canvas->reposition_window(mwindow->theme->mcanvas_x,
114 mwindow->theme->mcanvas_y,
118 //printf("MWindowGUI::get_scrollbars 1\n");
123 add_subwindow(samplescroll = new SampleScroll(mwindow,
125 mwindow->theme->mhscroll_x,
126 mwindow->theme->mhscroll_y,
127 mwindow->theme->mhscroll_w));
129 samplescroll->resize_event();
131 samplescroll->set_position();
135 if(samplescroll) delete samplescroll;
137 mwindow->edl->local_session->view_start = 0;
139 //printf("MWindowGUI::get_scrollbars 1\n");
143 //printf("MWindowGUI::get_scrollbars 1.1 %p %p\n", this, canvas);
145 add_subwindow(trackscroll = new TrackScroll(mwindow,
147 mwindow->theme->mvscroll_x,
148 mwindow->theme->mvscroll_y,
149 mwindow->theme->mvscroll_h));
151 trackscroll->resize_event();
154 //printf("MWindowGUI::get_scrollbars 1.2\n");
155 trackscroll->update_length(mwindow->edl->get_tracks_height(mwindow->theme),
156 mwindow->edl->local_session->track_start,
158 //printf("MWindowGUI::get_scrollbars 1.3\n");
162 if(trackscroll) delete trackscroll;
164 mwindow->edl->local_session->track_start = 0;
166 //printf("get_scrollbars 2 %d %d\n", need_xscroll, w_needed);
169 int MWindowGUI::create_objects()
172 set_icon(mwindow->theme->get_image("mwindow_icon"));
177 add_subwindow(mainmenu = new MainMenu(mwindow, this));
180 mwindow->theme->get_mwindow_sizes(this, get_w(), get_h());
182 mwindow->theme->draw_mwindow_bg(this);
184 mainmenu->create_objects();
187 add_subwindow(mbuttons = new MButtons(mwindow, this));
188 mbuttons->create_objects();
191 add_subwindow(timebar = new MTimeBar(mwindow,
193 mwindow->theme->mtimebar_x,
194 mwindow->theme->mtimebar_y,
195 mwindow->theme->mtimebar_w,
196 mwindow->theme->mtimebar_h));
197 timebar->create_objects();
200 add_subwindow(patchbay = new PatchBay(mwindow, this));
201 patchbay->create_objects();
207 mwindow->gui->add_subwindow(canvas = new TrackCanvas(mwindow, this));
208 canvas->create_objects();
211 add_subwindow(zoombar = new ZoomBar(mwindow, this));
212 zoombar->create_objects();
215 add_subwindow(statusbar = new StatusBar(mwindow, this));
216 statusbar->create_objects();
219 add_subwindow(mainclock = new MainClock(mwindow,
220 mwindow->theme->mclock_x,
221 mwindow->theme->mclock_y,
222 mwindow->theme->mclock_w));
223 mainclock->set_frame_offset( (double)
224 (mwindow->edl->session->get_frame_offset() /
225 mwindow->edl->session->frame_rate));
226 mainclock->update(0);
230 cursor = new MainCursor(mwindow, this);
231 cursor->create_objects();
234 add_subwindow(edit_menu = new EditPopup(mwindow, this));
235 edit_menu->create_objects();
238 add_subwindow(plugin_menu = new PluginPopup(mwindow, this));
239 plugin_menu->create_objects();
242 add_subwindow(keyframe_menu = new KeyframePopup(mwindow, this));
243 keyframe_menu->create_objects();
245 add_subwindow(transition_menu = new TransitionPopup(mwindow, this));
246 transition_menu->create_objects();
254 void MWindowGUI::update_title(char *path)
257 char filename[BCTEXTLEN], string[BCTEXTLEN];
258 fs.extract_name(filename, path);
259 sprintf(string, PROGRAM_NAME ": %s", filename);
261 //printf("MWindowGUI::update_title %s\n", string);
265 void MWindowGUI::redraw_time_dependancies()
267 zoombar->redraw_time_dependancies();
269 mainclock->update(mwindow->edl->local_session->get_selectionstart(1));
272 int MWindowGUI::focus_in_event()
274 cursor->focus_in_event();
278 int MWindowGUI::focus_out_event()
280 cursor->focus_out_event();
285 int MWindowGUI::resize_event(int w, int h)
287 mwindow->session->mwindow_w = w;
288 mwindow->session->mwindow_h = h;
289 mwindow->theme->get_mwindow_sizes(this, w, h);
290 mwindow->theme->draw_mwindow_bg(this);
292 mainmenu->reposition_window(0, 0, w, mainmenu->get_h());
293 mbuttons->resize_event();
294 statusbar->resize_event();
295 timebar->resize_event();
296 patchbay->resize_event();
297 zoombar->resize_event();
299 canvas->resize_event();
304 void MWindowGUI::update(int scrollbars,
312 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
313 if(scrollbars) this->get_scrollbars();
314 if(timebar) this->timebar->update();
315 if(zoombar) this->zoombar->update();
316 if(patchbay) this->patchbay->update();
317 if(clock) this->mainclock->update(
318 mwindow->edl->local_session->get_selectionstart(1));
321 this->canvas->draw(canvas);
322 this->cursor->show();
323 this->canvas->flash();
324 // Activate causes the menubar to deactivate. Don't want this for
326 if(canvas != 3) this->canvas->activate();
328 if(buttonbar) mbuttons->update();
330 // Can't age if the cache called this to draw missing picons
331 if(canvas != 2 && canvas != 3)
332 mwindow->age_caches();
335 int MWindowGUI::visible(int64_t x1, int64_t x2, int64_t view_x1, int64_t view_x2)
337 return (x1 >= view_x1 && x1 < view_x2) ||
338 (x2 > view_x1 && x2 <= view_x2) ||
339 (x1 <= view_x1 && x2 >= view_x2);
343 int MWindowGUI::show_message(char *message, int color)
345 //printf("MWindowGUI::show_message %s %d\n", message, color);
346 if(color < 0) color = mwindow->theme->message_normal;
347 statusbar->status_text->set_color(color);
348 statusbar->status_text->update(message);
352 // Drag motion called from other window
353 int MWindowGUI::drag_motion()
355 if(get_hidden()) return 0;
357 canvas->drag_motion();
361 int MWindowGUI::drag_stop()
363 if(get_hidden()) return 0;
365 int result = canvas->drag_stop();
369 void MWindowGUI::default_positions()
371 //printf("MWindowGUI::default_positions 1\n");
372 mwindow->vwindow->gui->lock_window("MWindowGUI::default_positions");
373 mwindow->cwindow->gui->lock_window("MWindowGUI::default_positions");
374 mwindow->awindow->gui->lock_window("MWindowGUI::default_positions");
376 // printf("MWindowGUI::default_positions 1 %d %d %d %d\n", mwindow->session->vwindow_x,
377 // mwindow->session->vwindow_y,
378 // mwindow->session->vwindow_w,
379 // mwindow->session->vwindow_h);
380 reposition_window(mwindow->session->mwindow_x,
381 mwindow->session->mwindow_y,
382 mwindow->session->mwindow_w,
383 mwindow->session->mwindow_h);
384 mwindow->vwindow->gui->reposition_window(mwindow->session->vwindow_x,
385 mwindow->session->vwindow_y,
386 mwindow->session->vwindow_w,
387 mwindow->session->vwindow_h);
388 mwindow->cwindow->gui->reposition_window(mwindow->session->cwindow_x,
389 mwindow->session->cwindow_y,
390 mwindow->session->cwindow_w,
391 mwindow->session->cwindow_h);
392 mwindow->awindow->gui->reposition_window(mwindow->session->awindow_x,
393 mwindow->session->awindow_y,
394 mwindow->session->awindow_w,
395 mwindow->session->awindow_h);
396 //printf("MWindowGUI::default_positions 1\n");
398 resize_event(mwindow->session->mwindow_w,
399 mwindow->session->mwindow_h);
400 //printf("MWindowGUI::default_positions 1\n");
401 mwindow->vwindow->gui->resize_event(mwindow->session->vwindow_w,
402 mwindow->session->vwindow_h);
403 //printf("MWindowGUI::default_positions 1\n");
404 mwindow->cwindow->gui->resize_event(mwindow->session->cwindow_w,
405 mwindow->session->cwindow_h);
406 //printf("MWindowGUI::default_positions 1\n");
407 mwindow->awindow->gui->resize_event(mwindow->session->awindow_w,
408 mwindow->session->awindow_h);
410 //printf("MWindowGUI::default_positions 1\n");
413 mwindow->vwindow->gui->flush();
414 mwindow->cwindow->gui->flush();
415 mwindow->awindow->gui->flush();
417 mwindow->vwindow->gui->unlock_window();
418 mwindow->cwindow->gui->unlock_window();
419 mwindow->awindow->gui->unlock_window();
420 //printf("MWindowGUI::default_positions 2\n");
439 int MWindowGUI::repeat_event(int64_t duration)
441 // if(duration == 100)
442 // mwindow->sync_parameters(CHANGE_ALL);
443 return cursor->repeat_event(duration);
447 int MWindowGUI::translation_event()
449 //printf("MWindowGUI::translation_event 1 %d %d\n", get_x(), get_y());
450 mwindow->session->mwindow_x = get_x();
451 mwindow->session->mwindow_y = get_y();
456 int MWindowGUI::save_defaults(BC_Hash *defaults)
458 defaults->update("MWINDOWWIDTH", get_w());
459 defaults->update("MWINDOWHEIGHT", get_h());
460 mainmenu->save_defaults(defaults);
461 BC_WindowBase::save_defaults(defaults);
464 int MWindowGUI::keypress_event()
466 //printf("MWindowGUI::keypress_event 1 %d\n", get_keypress());
468 result = mbuttons->keypress_event();
472 switch(get_keypress())
480 mbuttons->transport->handle_transport(STOP, 1, 0, 0);
481 lock_window("MWindowGUI::keypress_event 1");
482 mwindow->prev_edit_handle(shift_down());
485 mwindow->move_left();
495 mbuttons->transport->handle_transport(STOP, 1, 0, 0);
496 lock_window("MWindowGUI::keypress_event 2");
497 mwindow->next_edit_handle(shift_down());
500 mwindow->move_right();
506 if(ctrl_down() && !alt_down())
512 if(!ctrl_down() && alt_down())
514 mwindow->expand_autos(0,1,1);
518 if(ctrl_down() && alt_down())
520 mwindow->expand_autos(1,1,1);
525 mwindow->expand_sample();
531 if(ctrl_down() && !alt_down())
533 mwindow->zoom_in_y();
537 if(!ctrl_down() && alt_down())
539 mwindow->shrink_autos(0,1,1);
543 if(ctrl_down() && alt_down())
545 mwindow->shrink_autos(1,1,1);
550 mwindow->zoom_in_sample();
571 mwindow->move_down();
576 mwindow->zoom_in_t();
583 int cursor_x = canvas->get_relative_cursor_x();
584 int cursor_y = canvas->get_relative_cursor_y();
586 if(get_keypress() == TAB)
588 // Switch the record button
589 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
591 int64_t track_x, track_y, track_w, track_h;
592 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
594 if(cursor_y >= track_y &&
595 cursor_y < track_y + track_h)
608 Track *this_track = 0;
609 for(Track *track = mwindow->edl->tracks->first; track; track = track->next)
611 int64_t track_x, track_y, track_w, track_h;
612 canvas->track_dimensions(track, track_x, track_y, track_w, track_h);
614 if(cursor_y >= track_y &&
615 cursor_y < track_y + track_h)
623 int total_selected = mwindow->edl->tracks->total_of(Tracks::RECORD);
625 // nothing previously selected
626 if(total_selected == 0)
628 mwindow->edl->tracks->select_all(Tracks::RECORD,
632 if(total_selected == 1)
634 // this patch was previously the only one on
635 if(this_track && this_track->record)
637 mwindow->edl->tracks->select_all(Tracks::RECORD,
640 // another patch was previously the only one on
643 mwindow->edl->tracks->select_all(Tracks::RECORD,
646 this_track->record = 1;
651 if(total_selected > 1)
653 mwindow->edl->tracks->select_all(Tracks::RECORD,
656 this_track->record = 1;
669 mwindow->cwindow->update(0, 1, 1);
670 lock_window("TrackCanvas::keypress_event 3");
676 // since things under cursor have changed...
678 cursor_motion_event();
685 int MWindowGUI::close_event()
690 int MWindowGUI::menu_h()
692 return mainmenu->get_h();