4 * Copyright (C) 2008 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 "bcdisplayinfo.h"
26 #include "edlsession.h"
28 #include "indexable.h"
29 #include "mainsession.h"
30 #include "meterpanel.h"
32 #include "mwindowgui.h"
35 MainSession::MainSession(MWindow *mwindow)
37 this->mwindow = mwindow;
40 // playback_cursor_visible = 0;
41 // is_playing_back = 0;
42 track_highlighted = 0;
43 plugin_highlighted = 0;
44 pluginset_highlighted = 0;
45 vcanvas_highlighted = 0;
46 ccanvas_highlighted = 0;
48 current_operation = NO_OPERATION;
49 drag_pluginservers = new ArrayList<PluginServer*>;
51 drag_assets = new ArrayList<Indexable*>;
52 drag_auto_gang = new ArrayList<Auto*>;
53 drag_clips = new ArrayList<EDL*>;
54 drag_edits = new ArrayList<Edit*>;
62 cwindow_fullscreen = 0;
63 rwindow_fullscreen = 0;
64 vwindow_fullscreen = 0;
65 actual_frame_rate = 0;
76 drag_origin_x = drag_origin_y = 0;
77 drag_start_percentage = 0;
78 drag_start_position = 0;
79 cwindow_output_x = cwindow_output_y = 0;
80 batchrender_x = batchrender_y = batchrender_w = batchrender_h = 0;
81 lwindow_x = lwindow_y = lwindow_w = lwindow_h = 0;
82 mwindow_x = mwindow_y = mwindow_w = mwindow_h = 0;
83 vwindow_x = vwindow_y = vwindow_w = vwindow_h = 0;
84 cwindow_x = cwindow_y = cwindow_w = cwindow_h = 0;
85 ctool_x = ctool_y = 0;
86 awindow_x = awindow_y = awindow_w = awindow_h = 0;
87 rmonitor_x = rmonitor_y = rmonitor_w = rmonitor_h = 0;
88 rwindow_x = rwindow_y = rwindow_w = rwindow_h = 0;
89 gwindow_x = gwindow_y = 0;
90 cswindow_x = cswindow_y = cswindow_w = cswindow_h = 0;
91 swindow_x = swindow_y = swindow_w = swindow_h = 0;
92 ewindow_w = ewindow_h = 0;
93 channels_x = channels_y = 0;
94 picture_x = picture_y = 0;
95 scope_x = scope_y = scope_w = scope_h = 0;
96 histogram_x = histogram_y = histogram_w = histogram_h = 0;
103 show_vwindow = show_awindow = show_cwindow = show_gwindow = show_lwindow = 0;
104 plugindialog_w = plugindialog_h = 0;
105 // presetdialog_w = presetdialog_h = 0;
106 keyframedialog_w = keyframedialog_h = 0;
107 keyframedialog_column1 = 0;
108 keyframedialog_column2 = 0;
109 keyframedialog_all = 0;
110 menueffect_w = menueffect_h = 0;
111 transitiondialog_w = transitiondialog_h = 0;
114 MainSession::~MainSession()
116 delete drag_pluginservers;
118 delete drag_auto_gang;
123 void MainSession::boundaries()
125 lwindow_x = MAX(0, lwindow_x);
126 lwindow_y = MAX(0, lwindow_y);
127 mwindow_x = MAX(0, mwindow_x);
128 mwindow_y = MAX(0, mwindow_y);
129 cwindow_x = MAX(0, cwindow_x);
130 cwindow_y = MAX(0, cwindow_y);
131 vwindow_x = MAX(0, vwindow_x);
132 vwindow_y = MAX(0, vwindow_y);
133 awindow_x = MAX(0, awindow_x);
134 awindow_y = MAX(0, awindow_y);
135 gwindow_x = MAX(0, gwindow_x);
136 gwindow_y = MAX(0, gwindow_y);
137 rwindow_x = MAX(0, rwindow_x);
138 rwindow_y = MAX(0, rwindow_y);
139 rmonitor_x = MAX(0, rmonitor_x);
140 rmonitor_y = MAX(0, rmonitor_y);
141 CLAMP(cwindow_controls, 0, 1);
144 void MainSession::save_x11_host(int play_config, const char *x11_host)
146 strcpy(!play_config ? a_x11_host : b_x11_host, x11_host);
149 // set default x11 host, window_config, return screens
150 int MainSession::set_default_x11_host(int win_config)
152 if( win_config < 0 ) win_config = window_config;
153 const char *x11_host = win_config!=1 ? a_x11_host : b_x11_host;
154 BC_DisplayInfo display_info(x11_host,0);
155 int screen = display_info.get_screen();
156 if( screen < 0 && strcmp(a_x11_host, b_x11_host) ) {
157 win_config = win_config==1 ? 0 : 1;
158 x11_host = win_config!=1 ? a_x11_host : b_x11_host;
159 display_info.init_window(x11_host,0);
160 screen = display_info.get_screen();
164 display_info.init_window(x11_host,1);
167 if( display_info.get_screen_count() > 1 )
168 screens = strcmp(a_x11_host, b_x11_host) != 0 ? 2 : 1;
169 window_config = win_config;
170 BC_Window::set_default_x11_host(x11_host);
174 void MainSession::default_window_positions(int window_config)
176 // 0 - all windows on a, playback_config a
177 // 1 - all windows on b, playback_config b
178 // 2 - all windows on a, except composer on b, playback_config b
179 int screens = set_default_x11_host(window_config);
180 mwindow->set_screens(screens);
182 BC_DisplayInfo display_info(BC_Window::get_default_x11_host());
183 // Get defaults based on root window size
186 int root_w = display_info.get_root_w();
187 int root_h = display_info.get_root_h();
189 int border_left = display_info.get_left_border();
190 int border_right = display_info.get_right_border();
191 int border_top = display_info.get_top_border();
192 int border_bottom = display_info.get_bottom_border();
194 int dual_head = screens > 1 ? 1 : 0;
195 int right_w = root_w;
196 // Wider than 16:9, narrower than dual head
197 if( screens < 2 && (float)root_w / root_h > 1.8) {
200 case 600: right_w = 800; break;
201 case 720: right_w = 1280; break;
202 case 1024: right_w = 1280; break;
203 case 1200: right_w = 1600; break;
204 case 1080: right_w = 1920; break;
205 default: right_w = root_w/2; break;
207 if( window_config == 1 ) {
208 root_x = root_w - right_w;
212 // use same aspect ratio to compute left height
214 root_h = (root_w*root_h) / right_w;
220 vwindow_w = root_w / 2 - border_left - border_right;
221 vwindow_h = root_h * 6 / 10 - border_top - border_bottom;
223 int b_root_w = root_w;
224 int b_root_h = root_h;
225 if( !dual_head || window_config != 2 ) {
226 cwindow_x = root_x + root_w / 2;
228 cwindow_w = vwindow_w;
229 cwindow_h = vwindow_h;
232 // Get defaults based on root window size
233 BC_DisplayInfo b_display_info(b_x11_host);
234 b_root_w = b_display_info.get_root_w();
235 b_root_h = b_display_info.get_root_h();
238 cwindow_w = b_root_w-100;
239 cwindow_h = b_root_h-100;
242 ctool_x = cwindow_x + cwindow_w / 2;
243 ctool_y = cwindow_y + cwindow_h / 2;
246 mwindow_y = vwindow_y + vwindow_h + border_top + border_bottom;
247 mwindow_w = root_w * 2 / 3 - border_left - border_right;
248 mwindow_h = root_h - mwindow_y - border_top - border_bottom;
250 awindow_x = mwindow_x + border_left + border_right + mwindow_w;
251 awindow_y = mwindow_y;
252 awindow_w = root_x + root_w - awindow_x - border_left - border_right;
253 awindow_h = mwindow_h;
278 lwindow_w = MeterPanel::get_meters_width(mwindow->theme,
279 mwindow->edl->session->audio_channels,
285 lwindow_x = root_w - lwindow_w;
286 lwindow_h = mwindow_y;
298 if( !dual_head || window_config != 2 ) {
299 rmonitor_x = rwindow_x + rwindow_w + 10;
300 rmonitor_y = rwindow_y;
301 rmonitor_w = root_x + root_w - rmonitor_x;
302 rmonitor_h = rwindow_h;
305 rmonitor_x = cswindow_x = 50;
306 rmonitor_y = cswindow_y = 50;
307 rmonitor_w = b_root_w-100;
308 rmonitor_h = b_root_h-100;
309 if( cswindow_w < rmonitor_w ) cswindow_w = rmonitor_w;
310 if( cswindow_h < rmonitor_h ) cswindow_h = rmonitor_h;
320 batchrender_x = root_w / 2 - batchrender_w / 2;
321 batchrender_y = root_h / 2 - batchrender_h / 2;
324 int MainSession::load_defaults(BC_Hash *defaults)
326 // Setup main windows
327 strcpy(a_x11_host, defaults->get("A_X11_HOST", a_x11_host));
328 strcpy(b_x11_host, defaults->get("B_X11_HOST", b_x11_host));
329 window_config = defaults->get("WINDOW_CONFIG", window_config);
330 default_window_positions(window_config);
332 vwindow_x = defaults->get("VWINDOW_X", vwindow_x);
333 vwindow_y = defaults->get("VWINDOW_Y", vwindow_y);
334 vwindow_w = defaults->get("VWINDOW_W", vwindow_w);
335 vwindow_h = defaults->get("VWINDOW_H", vwindow_h);
338 cwindow_x = defaults->get("CWINDOW_X", cwindow_x);
339 cwindow_y = defaults->get("CWINDOW_Y", cwindow_y);
340 cwindow_w = defaults->get("CWINDOW_W", cwindow_w);
341 cwindow_h = defaults->get("CWINDOW_H", cwindow_h);
343 ctool_x = defaults->get("CTOOL_X", ctool_x);
344 ctool_y = defaults->get("CTOOL_Y", ctool_y);
346 gwindow_x = defaults->get("GWINDOW_X", gwindow_x);
347 gwindow_y = defaults->get("GWINDOW_Y", gwindow_y);
349 mwindow_x = defaults->get("MWINDOW_X", mwindow_x);
350 mwindow_y = defaults->get("MWINDOW_Y", mwindow_y);
351 mwindow_w = defaults->get("MWINDOW_W", mwindow_w);
352 mwindow_h = defaults->get("MWINDOW_H", mwindow_h);
354 lwindow_x = defaults->get("LWINDOW_X", lwindow_x);
355 lwindow_y = defaults->get("LWINDOW_Y", lwindow_y);
356 lwindow_w = defaults->get("LWINDOW_W", lwindow_w);
357 lwindow_h = defaults->get("LWINDOW_H", lwindow_h);
360 awindow_x = defaults->get("AWINDOW_X", awindow_x);
361 awindow_y = defaults->get("AWINDOW_Y", awindow_y);
362 awindow_w = defaults->get("AWINDOW_W", awindow_w);
363 awindow_h = defaults->get("AWINDOW_H", awindow_h);
365 ewindow_w = defaults->get("EWINDOW_W", ewindow_w);
366 ewindow_h = defaults->get("EWINDOW_H", ewindow_h);
368 channels_x = defaults->get("CHANNELS_X", channels_x);
369 channels_y = defaults->get("CHANNELS_Y", channels_y);
370 picture_x = defaults->get("PICTURE_X", picture_x);
371 picture_y = defaults->get("PICTURE_Y", picture_y);
372 scope_x = defaults->get("SCOPE_X", scope_x);
373 scope_y = defaults->get("SCOPE_Y", scope_y);
374 scope_w = defaults->get("SCOPE_W", scope_w);
375 scope_h = defaults->get("SCOPE_H", scope_h);
376 histogram_x = defaults->get("HISTOGRAM_X", histogram_x);
377 histogram_y = defaults->get("HISTOGRAM_Y", histogram_y);
378 histogram_w = defaults->get("HISTOGRAM_W", histogram_w);
379 histogram_h = defaults->get("HISTOGRAM_H", histogram_h);
380 record_scope = defaults->get("RECORD_SCOPE", record_scope);
381 use_hist = defaults->get("USE_HIST", use_hist);
382 use_wave = defaults->get("USE_WAVE", use_wave);
383 use_vector = defaults->get("USE_VECTOR", use_vector);
384 use_hist_parade = defaults->get("USE_HIST_PARADE", use_hist_parade);
385 use_wave_parade = defaults->get("USE_WAVE_PARADE", use_wave_parade);
387 //printf("MainSession::load_defaults 1\n");
390 afolders_w = defaults->get("ABINS_W", 140);
391 rwindow_x = defaults->get("RWINDOW_X", rwindow_x);
392 rwindow_y = defaults->get("RWINDOW_Y", rwindow_y);
393 rwindow_w = defaults->get("RWINDOW_W", rwindow_w);
394 rwindow_h = defaults->get("RWINDOW_H", rwindow_h);
396 cswindow_x = defaults->get("CSWINDOW_X", cswindow_x);
397 cswindow_y = defaults->get("CSWINDOW_Y", cswindow_y);
398 cswindow_w = defaults->get("CSWINDOW_W", cswindow_w);
399 cswindow_h = defaults->get("CSWINDOW_H", cswindow_h);
401 swindow_x = defaults->get("SWINDOW_X", swindow_x);
402 swindow_y = defaults->get("SWINDOW_Y", swindow_y);
403 swindow_w = defaults->get("SWINDOW_W", swindow_w);
404 swindow_h = defaults->get("SWINDOW_H", swindow_h);
406 rmonitor_x = defaults->get("RMONITOR_X", rmonitor_x);
407 rmonitor_y = defaults->get("RMONITOR_Y", rmonitor_y);
408 rmonitor_w = defaults->get("RMONITOR_W", rmonitor_w);
409 rmonitor_h = defaults->get("RMONITOR_H", rmonitor_h);
411 batchrender_x = defaults->get("BATCHRENDER_X", batchrender_x);
412 batchrender_y = defaults->get("BATCHRENDER_Y", batchrender_y);
413 batchrender_w = defaults->get("BATCHRENDER_W", batchrender_w);
414 batchrender_h = defaults->get("BATCHRENDER_H", batchrender_h);
416 show_vwindow = defaults->get("SHOW_VWINDOW", 1);
417 show_awindow = defaults->get("SHOW_AWINDOW", 1);
418 show_cwindow = defaults->get("SHOW_CWINDOW", 1);
419 show_lwindow = defaults->get("SHOW_LWINDOW", 0);
420 show_gwindow = defaults->get("SHOW_GWINDOW", 0);
422 cwindow_controls = defaults->get("CWINDOW_CONTROLS", cwindow_controls);
424 plugindialog_w = defaults->get("PLUGINDIALOG_W", 510);
425 plugindialog_h = defaults->get("PLUGINDIALOG_H", 415);
426 // presetdialog_w = defaults->get("PRESETDIALOG_W", 510);
427 // presetdialog_h = defaults->get("PRESETDIALOG_H", 415);
428 keyframedialog_w = defaults->get("KEYFRAMEDIALOG_W", 320);
429 keyframedialog_h = defaults->get("KEYFRAMEDIALOG_H", 415);
430 keyframedialog_column1 = defaults->get("KEYFRAMEDIALOG_COLUMN1", 150);
431 keyframedialog_column2 = defaults->get("KEYFRAMEDIALOG_COLUMN2", 100);
432 keyframedialog_all = defaults->get("KEYFRAMEDIALOG_ALL", 0);
433 menueffect_w = defaults->get("MENUEFFECT_W", 580);
434 menueffect_h = defaults->get("MENUEFFECT_H", 350);
435 transitiondialog_w = defaults->get("TRANSITIONDIALOG_W", 320);
436 transitiondialog_h = defaults->get("TRANSITIONDIALOG_H", 512);
438 current_tip = defaults->get("CURRENT_TIP", current_tip);
439 actual_frame_rate = defaults->get("ACTUAL_FRAME_RATE", (float)-1);
445 int MainSession::save_defaults(BC_Hash *defaults)
447 defaults->update("A_X11_HOST", a_x11_host);
448 defaults->update("B_X11_HOST", b_x11_host);
449 defaults->update("WINDOW_CONFIG", window_config);
451 defaults->update("MWINDOW_X", mwindow_x);
452 defaults->update("MWINDOW_Y", mwindow_y);
453 defaults->update("MWINDOW_W", mwindow_w);
454 defaults->update("MWINDOW_H", mwindow_h);
456 defaults->update("LWINDOW_X", lwindow_x);
457 defaults->update("LWINDOW_Y", lwindow_y);
458 defaults->update("LWINDOW_W", lwindow_w);
459 defaults->update("LWINDOW_H", lwindow_h);
461 defaults->update("VWINDOW_X", vwindow_x);
462 defaults->update("VWINDOW_Y", vwindow_y);
463 defaults->update("VWINDOW_W", vwindow_w);
464 defaults->update("VWINDOW_H", vwindow_h);
466 defaults->update("CWINDOW_X", cwindow_x);
467 defaults->update("CWINDOW_Y", cwindow_y);
468 defaults->update("CWINDOW_W", cwindow_w);
469 defaults->update("CWINDOW_H", cwindow_h);
471 defaults->update("CTOOL_X", ctool_x);
472 defaults->update("CTOOL_Y", ctool_y);
474 defaults->update("GWINDOW_X", gwindow_x);
475 defaults->update("GWINDOW_Y", gwindow_y);
477 defaults->update("AWINDOW_X", awindow_x);
478 defaults->update("AWINDOW_Y", awindow_y);
479 defaults->update("AWINDOW_W", awindow_w);
480 defaults->update("AWINDOW_H", awindow_h);
482 defaults->update("EWINDOW_W", ewindow_w);
483 defaults->update("EWINDOW_H", ewindow_h);
485 defaults->update("CHANNELS_X", channels_x);
486 defaults->update("CHANNELS_Y", channels_y);
487 defaults->update("PICTURE_X", picture_x);
488 defaults->update("PICTURE_Y", picture_y);
489 defaults->update("SCOPE_X", scope_x);
490 defaults->update("SCOPE_Y", scope_y);
491 defaults->update("SCOPE_W", scope_w);
492 defaults->update("SCOPE_H", scope_h);
493 defaults->update("HISTOGRAM_X", histogram_x);
494 defaults->update("HISTOGRAM_Y", histogram_y);
495 defaults->update("HISTOGRAM_W", histogram_w);
496 defaults->update("HISTOGRAM_H", histogram_h);
497 defaults->update("RECORD_SCOPE", record_scope);
498 defaults->update("USE_HIST", use_hist);
499 defaults->update("USE_WAVE", use_wave);
500 defaults->update("USE_VECTOR", use_vector);
501 defaults->update("USE_HIST_PARADE", use_hist_parade);
502 defaults->update("USE_WAVE_PARADE", use_wave_parade);
504 defaults->update("ABINS_W", afolders_w);
506 defaults->update("RMONITOR_X", rmonitor_x);
507 defaults->update("RMONITOR_Y", rmonitor_y);
508 defaults->update("RMONITOR_W", rmonitor_w);
509 defaults->update("RMONITOR_H", rmonitor_h);
511 defaults->update("RWINDOW_X", rwindow_x);
512 defaults->update("RWINDOW_Y", rwindow_y);
513 defaults->update("RWINDOW_W", rwindow_w);
514 defaults->update("RWINDOW_H", rwindow_h);
516 defaults->update("CSWINDOW_X", cswindow_x);
517 defaults->update("CSWINDOW_Y", cswindow_y);
518 defaults->update("CSWINDOW_W", cswindow_w);
519 defaults->update("CSWINDOW_H", cswindow_h);
521 defaults->update("SWINDOW_X", swindow_x);
522 defaults->update("SWINDOW_Y", swindow_y);
523 defaults->update("SWINDOW_W", swindow_w);
524 defaults->update("SWINDOW_H", swindow_h);
526 defaults->update("BATCHRENDER_X", batchrender_x);
527 defaults->update("BATCHRENDER_Y", batchrender_y);
528 defaults->update("BATCHRENDER_W", batchrender_w);
529 defaults->update("BATCHRENDER_H", batchrender_h);
531 defaults->update("SHOW_VWINDOW", show_vwindow);
532 defaults->update("SHOW_AWINDOW", show_awindow);
533 defaults->update("SHOW_CWINDOW", show_cwindow);
534 defaults->update("SHOW_LWINDOW", show_lwindow);
535 defaults->update("SHOW_GWINDOW", show_gwindow);
537 defaults->update("CWINDOW_CONTROLS", cwindow_controls);
539 defaults->update("PLUGINDIALOG_W", plugindialog_w);
540 defaults->update("PLUGINDIALOG_H", plugindialog_h);
541 // defaults->update("PRESETDIALOG_W", presetdialog_w);
542 // defaults->update("PRESETDIALOG_H", presetdialog_h);
543 defaults->update("KEYFRAMEDIALOG_W", keyframedialog_w);
544 defaults->update("KEYFRAMEDIALOG_H", keyframedialog_h);
545 defaults->update("KEYFRAMEDIALOG_COLUMN1", keyframedialog_column1);
546 defaults->update("KEYFRAMEDIALOG_COLUMN2", keyframedialog_column2);
547 defaults->update("KEYFRAMEDIALOG_ALL", keyframedialog_all);
549 defaults->update("MENUEFFECT_W", menueffect_w);
550 defaults->update("MENUEFFECT_H", menueffect_h);
552 defaults->update("TRANSITIONDIALOG_W", transitiondialog_w);
553 defaults->update("TRANSITIONDIALOG_H", transitiondialog_h);
555 defaults->update("ACTUAL_FRAME_RATE", actual_frame_rate);
556 defaults->update("CURRENT_TIP", current_tip);