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
23 #include "bcdisplayinfo.h"
29 #include "edlsession.h"
31 #include "indexable.h"
33 #include "localsession.h"
34 #include "mainsession.h"
35 #include "meterpanel.h"
37 #include "mwindowgui.h"
40 MainSession::MainSession(MWindow *mwindow)
42 this->mwindow = mwindow;
45 // playback_cursor_visible = 0;
46 // is_playing_back = 0;
47 track_highlighted = 0;
48 plugin_highlighted = 0;
49 pluginset_highlighted = 0;
51 current_operation = NO_OPERATION;
52 drag_pluginservers = new ArrayList<PluginServer*>;
54 drag_assets = new ArrayList<Indexable*>;
55 drag_auto_gang = new ArrayList<Auto*>;
56 drag_clips = new ArrayList<EDL*>;
57 drag_edits = new ArrayList<Edit*>;
65 cwindow_fullscreen = 0;
66 rwindow_fullscreen = 0;
67 vwindow_fullscreen = 0;
68 zwindow_fullscreen = 0;
69 selected_zwindow = -1;
70 actual_frame_rate = 0;
82 drag_origin_x = drag_origin_y = 0;
83 drag_start_percentage = 0;
84 drag_start_position = 0;
85 cwindow_output_x = cwindow_output_y = 0;
86 batchrender_x = batchrender_y = batchrender_w = batchrender_h = 0;
87 lwindow_x = lwindow_y = lwindow_w = lwindow_h = 0;
88 mwindow_x = mwindow_y = mwindow_w = mwindow_h = 0;
89 vwindow_x = vwindow_y = vwindow_w = vwindow_h = 0;
90 cwindow_x = cwindow_y = cwindow_w = cwindow_h = 0;
91 ctool_x = ctool_y = 0;
92 awindow_x = awindow_y = awindow_w = awindow_h = 0;
93 bwindow_w = bwindow_h = 0;
94 rmonitor_x = rmonitor_y = rmonitor_w = rmonitor_h = 0;
95 rwindow_x = rwindow_y = rwindow_w = rwindow_h = 0;
96 gwindow_x = gwindow_y = 0;
97 cswindow_x = cswindow_y = cswindow_w = cswindow_h = 0;
98 swindow_x = swindow_y = swindow_w = swindow_h = 0;
99 ewindow_w = ewindow_h = 0;
100 channels_x = channels_y = 0;
101 picture_x = picture_y = 0;
102 scope_x = scope_y = scope_w = scope_h = 0;
103 histogram_x = histogram_y = histogram_w = histogram_h = 0;
110 show_vwindow = show_awindow = show_cwindow = show_gwindow = show_lwindow = 0;
111 plugindialog_w = plugindialog_h = 0;
112 // presetdialog_w = presetdialog_h = 0;
113 keyframedialog_w = keyframedialog_h = 0;
114 keyframedialog_column1 = 0;
115 keyframedialog_column2 = 0;
116 keyframedialog_all = 0;
117 menueffect_w = menueffect_h = 0;
118 transitiondialog_w = transitiondialog_h = 0;
121 MainSession::~MainSession()
123 delete drag_pluginservers;
125 delete drag_auto_gang;
130 void MainSession::boundaries()
132 lwindow_x = MAX(0, lwindow_x);
133 lwindow_y = MAX(0, lwindow_y);
134 mwindow_x = MAX(0, mwindow_x);
135 mwindow_y = MAX(0, mwindow_y);
136 cwindow_x = MAX(0, cwindow_x);
137 cwindow_y = MAX(0, cwindow_y);
138 vwindow_x = MAX(0, vwindow_x);
139 vwindow_y = MAX(0, vwindow_y);
140 awindow_x = MAX(0, awindow_x);
141 awindow_y = MAX(0, awindow_y);
142 gwindow_x = MAX(0, gwindow_x);
143 gwindow_y = MAX(0, gwindow_y);
144 rwindow_x = MAX(0, rwindow_x);
145 rwindow_y = MAX(0, rwindow_y);
146 rmonitor_x = MAX(0, rmonitor_x);
147 rmonitor_y = MAX(0, rmonitor_y);
148 CLAMP(cwindow_controls, 0, 1);
151 void MainSession::save_x11_host(int play_config, const char *x11_host)
153 strcpy(!play_config ? a_x11_host : b_x11_host, x11_host);
156 // set default x11 host, window_config, return screens
157 int MainSession::set_default_x11_host(int win_config)
159 if( win_config < 0 ) win_config = window_config;
160 const char *x11_host = win_config!=1 ? a_x11_host : b_x11_host;
161 BC_DisplayInfo display_info(x11_host,0);
162 int screen = display_info.get_screen();
163 if( screen < 0 && strcmp(a_x11_host, b_x11_host) ) {
164 win_config = win_config==1 ? 0 : 1;
165 x11_host = win_config!=1 ? a_x11_host : b_x11_host;
166 display_info.init_window(x11_host,0);
167 screen = display_info.get_screen();
171 display_info.init_window(x11_host,1);
174 if( display_info.get_screen_count() > 1 )
175 screens = strcmp(a_x11_host, b_x11_host) != 0 ? 2 : 1;
176 window_config = win_config;
177 BC_Window::set_default_x11_host(x11_host);
181 void MainSession::default_window_positions(int window_config)
183 // 0 - all windows on a, playback_config a
184 // 1 - all windows on b, playback_config b
185 // 2 - all windows on a, except composer on b, playback_config b
186 int screens = set_default_x11_host(window_config);
187 mwindow->set_screens(screens);
189 BC_DisplayInfo display_info(BC_Window::get_default_x11_host());
190 // Get defaults based on root window size
193 int root_w = display_info.get_root_w();
194 int root_h = display_info.get_root_h();
196 int border_left = display_info.get_left_border();
197 int border_right = display_info.get_right_border();
198 int border_top = display_info.get_top_border();
199 int border_bottom = display_info.get_bottom_border();
201 int dual_head = screens > 1 ? 1 : 0;
202 int right_w = root_w;
203 // Wider than 16:9, narrower than dual head
204 if( screens < 2 && (float)root_w / root_h > 1.8) {
207 case 600: right_w = 800; break;
208 case 720: right_w = 1280; break;
209 case 1024: right_w = 1280; break;
210 case 1200: right_w = 1600; break;
211 case 1080: right_w = 1920; break;
212 default: right_w = root_w/2; break;
214 if( window_config == 1 ) {
215 root_x = root_w - right_w;
219 // use same aspect ratio to compute left height
221 root_h = (root_w*root_h) / right_w;
227 vwindow_w = root_w / 2 - border_left - border_right;
228 vwindow_h = root_h * 6 / 10 - border_top - border_bottom;
230 int b_root_w = root_w;
231 int b_root_h = root_h;
232 if( !dual_head || window_config != 2 ) {
233 cwindow_x = root_x + root_w / 2;
235 cwindow_w = vwindow_w;
236 cwindow_h = vwindow_h;
239 // Get defaults based on root window size
240 BC_DisplayInfo b_display_info(b_x11_host);
241 b_root_w = b_display_info.get_root_w();
242 b_root_h = b_display_info.get_root_h();
245 cwindow_w = b_root_w-100;
246 cwindow_h = b_root_h-100;
249 ctool_x = cwindow_x + cwindow_w / 2;
250 ctool_y = cwindow_y + cwindow_h / 2;
253 mwindow_y = vwindow_y + vwindow_h + border_top + border_bottom;
254 mwindow_w = root_w * 2 / 3 - border_left - border_right;
255 mwindow_h = root_h - mwindow_y - border_top - border_bottom;
257 awindow_x = mwindow_x + border_left + border_right + mwindow_w;
258 awindow_y = mwindow_y;
259 awindow_w = root_x + root_w - awindow_x - border_left - border_right;
260 awindow_h = mwindow_h;
288 lwindow_w = MeterPanel::get_meters_width(mwindow->theme,
289 mwindow->edl->session->audio_channels,
295 lwindow_x = root_w - lwindow_w;
296 lwindow_h = mwindow_y;
308 if( !dual_head || window_config != 2 ) {
309 rmonitor_x = rwindow_x + rwindow_w + 10;
310 rmonitor_y = rwindow_y;
311 rmonitor_w = root_x + root_w - rmonitor_x;
312 rmonitor_h = rwindow_h;
315 rmonitor_x = cswindow_x = 50;
316 rmonitor_y = cswindow_y = 50;
317 rmonitor_w = b_root_w-100;
318 rmonitor_h = b_root_h-100;
319 if( cswindow_w < rmonitor_w ) cswindow_w = rmonitor_w;
320 if( cswindow_h < rmonitor_h ) cswindow_h = rmonitor_h;
330 batchrender_x = root_w / 2 - batchrender_w / 2;
331 batchrender_y = root_h / 2 - batchrender_h / 2;
334 int MainSession::load_defaults(BC_Hash *defaults)
336 // Setup main windows
337 strcpy(a_x11_host, defaults->get("A_X11_HOST", a_x11_host));
338 strcpy(b_x11_host, defaults->get("B_X11_HOST", b_x11_host));
339 window_config = defaults->get("WINDOW_CONFIG", window_config);
340 default_window_positions(window_config);
342 vwindow_x = defaults->get("VWINDOW_X", vwindow_x);
343 vwindow_y = defaults->get("VWINDOW_Y", vwindow_y);
344 vwindow_w = defaults->get("VWINDOW_W", vwindow_w);
345 vwindow_h = defaults->get("VWINDOW_H", vwindow_h);
348 cwindow_x = defaults->get("CWINDOW_X", cwindow_x);
349 cwindow_y = defaults->get("CWINDOW_Y", cwindow_y);
350 cwindow_w = defaults->get("CWINDOW_W", cwindow_w);
351 cwindow_h = defaults->get("CWINDOW_H", cwindow_h);
353 ctool_x = defaults->get("CTOOL_X", ctool_x);
354 ctool_y = defaults->get("CTOOL_Y", ctool_y);
356 gwindow_x = defaults->get("GWINDOW_X", gwindow_x);
357 gwindow_y = defaults->get("GWINDOW_Y", gwindow_y);
359 mwindow_x = defaults->get("MWINDOW_X", mwindow_x);
360 mwindow_y = defaults->get("MWINDOW_Y", mwindow_y);
361 mwindow_w = defaults->get("MWINDOW_W", mwindow_w);
362 mwindow_h = defaults->get("MWINDOW_H", mwindow_h);
364 lwindow_x = defaults->get("LWINDOW_X", lwindow_x);
365 lwindow_y = defaults->get("LWINDOW_Y", lwindow_y);
366 lwindow_w = defaults->get("LWINDOW_W", lwindow_w);
367 lwindow_h = defaults->get("LWINDOW_H", lwindow_h);
370 awindow_x = defaults->get("AWINDOW_X", awindow_x);
371 awindow_y = defaults->get("AWINDOW_Y", awindow_y);
372 awindow_w = defaults->get("AWINDOW_W", awindow_w);
373 awindow_h = defaults->get("AWINDOW_H", awindow_h);
375 ewindow_w = defaults->get("EWINDOW_W", ewindow_w);
376 ewindow_h = defaults->get("EWINDOW_H", ewindow_h);
378 channels_x = defaults->get("CHANNELS_X", channels_x);
379 channels_y = defaults->get("CHANNELS_Y", channels_y);
380 picture_x = defaults->get("PICTURE_X", picture_x);
381 picture_y = defaults->get("PICTURE_Y", picture_y);
382 scope_x = defaults->get("SCOPE_X", scope_x);
383 scope_y = defaults->get("SCOPE_Y", scope_y);
384 scope_w = defaults->get("SCOPE_W", scope_w);
385 scope_h = defaults->get("SCOPE_H", scope_h);
386 histogram_x = defaults->get("HISTOGRAM_X", histogram_x);
387 histogram_y = defaults->get("HISTOGRAM_Y", histogram_y);
388 histogram_w = defaults->get("HISTOGRAM_W", histogram_w);
389 histogram_h = defaults->get("HISTOGRAM_H", histogram_h);
390 record_scope = defaults->get("RECORD_SCOPE", record_scope);
391 use_hist = defaults->get("USE_HIST", use_hist);
392 use_wave = defaults->get("USE_WAVE", use_wave);
393 use_vector = defaults->get("USE_VECTOR", use_vector);
394 use_hist_parade = defaults->get("USE_HIST_PARADE", use_hist_parade);
395 use_wave_parade = defaults->get("USE_WAVE_PARADE", use_wave_parade);
397 //printf("MainSession::load_defaults 1\n");
400 afolders_w = defaults->get("ABINS_W", 200);
402 bwindow_w = defaults->get("BWINDOW_W", bwindow_w);
403 bwindow_h = defaults->get("BWINDOW_H", bwindow_h);
405 rwindow_x = defaults->get("RWINDOW_X", rwindow_x);
406 rwindow_y = defaults->get("RWINDOW_Y", rwindow_y);
407 rwindow_w = defaults->get("RWINDOW_W", rwindow_w);
408 rwindow_h = defaults->get("RWINDOW_H", rwindow_h);
410 cswindow_x = defaults->get("CSWINDOW_X", cswindow_x);
411 cswindow_y = defaults->get("CSWINDOW_Y", cswindow_y);
412 cswindow_w = defaults->get("CSWINDOW_W", cswindow_w);
413 cswindow_h = defaults->get("CSWINDOW_H", cswindow_h);
415 swindow_x = defaults->get("SWINDOW_X", swindow_x);
416 swindow_y = defaults->get("SWINDOW_Y", swindow_y);
417 swindow_w = defaults->get("SWINDOW_W", swindow_w);
418 swindow_h = defaults->get("SWINDOW_H", swindow_h);
420 rmonitor_x = defaults->get("RMONITOR_X", rmonitor_x);
421 rmonitor_y = defaults->get("RMONITOR_Y", rmonitor_y);
422 rmonitor_w = defaults->get("RMONITOR_W", rmonitor_w);
423 rmonitor_h = defaults->get("RMONITOR_H", rmonitor_h);
425 batchrender_x = defaults->get("BATCHRENDER_X", batchrender_x);
426 batchrender_y = defaults->get("BATCHRENDER_Y", batchrender_y);
427 batchrender_w = defaults->get("BATCHRENDER_W", batchrender_w);
428 batchrender_h = defaults->get("BATCHRENDER_H", batchrender_h);
430 show_vwindow = defaults->get("SHOW_VWINDOW", 1);
431 show_awindow = defaults->get("SHOW_AWINDOW", 1);
432 show_cwindow = defaults->get("SHOW_CWINDOW", 1);
433 show_lwindow = defaults->get("SHOW_LWINDOW", 0);
434 show_gwindow = defaults->get("SHOW_GWINDOW", 0);
436 cwindow_controls = defaults->get("CWINDOW_CONTROLS", cwindow_controls);
438 plugindialog_w = defaults->get("PLUGINDIALOG_W", 510);
439 plugindialog_h = defaults->get("PLUGINDIALOG_H", 415);
440 // presetdialog_w = defaults->get("PRESETDIALOG_W", 510);
441 // presetdialog_h = defaults->get("PRESETDIALOG_H", 415);
442 keyframedialog_w = defaults->get("KEYFRAMEDIALOG_W", 320);
443 keyframedialog_h = defaults->get("KEYFRAMEDIALOG_H", 415);
444 keyframedialog_column1 = defaults->get("KEYFRAMEDIALOG_COLUMN1", 150);
445 keyframedialog_column2 = defaults->get("KEYFRAMEDIALOG_COLUMN2", 100);
446 keyframedialog_all = defaults->get("KEYFRAMEDIALOG_ALL", 0);
447 menueffect_w = defaults->get("MENUEFFECT_W", 580);
448 menueffect_h = defaults->get("MENUEFFECT_H", 350);
449 transitiondialog_w = defaults->get("TRANSITIONDIALOG_W", 320);
450 transitiondialog_h = defaults->get("TRANSITIONDIALOG_H", 512);
452 current_tip = defaults->get("CURRENT_TIP", current_tip);
453 actual_frame_rate = defaults->get("ACTUAL_FRAME_RATE", (float)-1);
454 title_bar_alpha = defaults->get("TITLE_BAR_ALPHA", (float)0);
460 int MainSession::save_defaults(BC_Hash *defaults)
462 defaults->update("A_X11_HOST", a_x11_host);
463 defaults->update("B_X11_HOST", b_x11_host);
464 defaults->update("WINDOW_CONFIG", window_config);
466 defaults->update("MWINDOW_X", mwindow_x);
467 defaults->update("MWINDOW_Y", mwindow_y);
468 defaults->update("MWINDOW_W", mwindow_w);
469 defaults->update("MWINDOW_H", mwindow_h);
471 defaults->update("LWINDOW_X", lwindow_x);
472 defaults->update("LWINDOW_Y", lwindow_y);
473 defaults->update("LWINDOW_W", lwindow_w);
474 defaults->update("LWINDOW_H", lwindow_h);
476 defaults->update("VWINDOW_X", vwindow_x);
477 defaults->update("VWINDOW_Y", vwindow_y);
478 defaults->update("VWINDOW_W", vwindow_w);
479 defaults->update("VWINDOW_H", vwindow_h);
481 defaults->update("CWINDOW_X", cwindow_x);
482 defaults->update("CWINDOW_Y", cwindow_y);
483 defaults->update("CWINDOW_W", cwindow_w);
484 defaults->update("CWINDOW_H", cwindow_h);
486 defaults->update("CTOOL_X", ctool_x);
487 defaults->update("CTOOL_Y", ctool_y);
489 defaults->update("GWINDOW_X", gwindow_x);
490 defaults->update("GWINDOW_Y", gwindow_y);
492 defaults->update("AWINDOW_X", awindow_x);
493 defaults->update("AWINDOW_Y", awindow_y);
494 defaults->update("AWINDOW_W", awindow_w);
495 defaults->update("AWINDOW_H", awindow_h);
497 defaults->update("BWINDOW_W", bwindow_w);
498 defaults->update("BWINDOW_H", bwindow_h);
500 defaults->update("EWINDOW_W", ewindow_w);
501 defaults->update("EWINDOW_H", ewindow_h);
503 defaults->update("CHANNELS_X", channels_x);
504 defaults->update("CHANNELS_Y", channels_y);
505 defaults->update("PICTURE_X", picture_x);
506 defaults->update("PICTURE_Y", picture_y);
507 defaults->update("SCOPE_X", scope_x);
508 defaults->update("SCOPE_Y", scope_y);
509 defaults->update("SCOPE_W", scope_w);
510 defaults->update("SCOPE_H", scope_h);
511 defaults->update("HISTOGRAM_X", histogram_x);
512 defaults->update("HISTOGRAM_Y", histogram_y);
513 defaults->update("HISTOGRAM_W", histogram_w);
514 defaults->update("HISTOGRAM_H", histogram_h);
515 defaults->update("RECORD_SCOPE", record_scope);
516 defaults->update("USE_HIST", use_hist);
517 defaults->update("USE_WAVE", use_wave);
518 defaults->update("USE_VECTOR", use_vector);
519 defaults->update("USE_HIST_PARADE", use_hist_parade);
520 defaults->update("USE_WAVE_PARADE", use_wave_parade);
522 defaults->update("ABINS_W", afolders_w);
524 defaults->update("RMONITOR_X", rmonitor_x);
525 defaults->update("RMONITOR_Y", rmonitor_y);
526 defaults->update("RMONITOR_W", rmonitor_w);
527 defaults->update("RMONITOR_H", rmonitor_h);
529 defaults->update("RWINDOW_X", rwindow_x);
530 defaults->update("RWINDOW_Y", rwindow_y);
531 defaults->update("RWINDOW_W", rwindow_w);
532 defaults->update("RWINDOW_H", rwindow_h);
534 defaults->update("CSWINDOW_X", cswindow_x);
535 defaults->update("CSWINDOW_Y", cswindow_y);
536 defaults->update("CSWINDOW_W", cswindow_w);
537 defaults->update("CSWINDOW_H", cswindow_h);
539 defaults->update("SWINDOW_X", swindow_x);
540 defaults->update("SWINDOW_Y", swindow_y);
541 defaults->update("SWINDOW_W", swindow_w);
542 defaults->update("SWINDOW_H", swindow_h);
544 defaults->update("BATCHRENDER_X", batchrender_x);
545 defaults->update("BATCHRENDER_Y", batchrender_y);
546 defaults->update("BATCHRENDER_W", batchrender_w);
547 defaults->update("BATCHRENDER_H", batchrender_h);
549 defaults->update("SHOW_VWINDOW", show_vwindow);
550 defaults->update("SHOW_AWINDOW", show_awindow);
551 defaults->update("SHOW_CWINDOW", show_cwindow);
552 defaults->update("SHOW_LWINDOW", show_lwindow);
553 defaults->update("SHOW_GWINDOW", show_gwindow);
555 defaults->update("CWINDOW_CONTROLS", cwindow_controls);
557 defaults->update("PLUGINDIALOG_W", plugindialog_w);
558 defaults->update("PLUGINDIALOG_H", plugindialog_h);
559 // defaults->update("PRESETDIALOG_W", presetdialog_w);
560 // defaults->update("PRESETDIALOG_H", presetdialog_h);
561 defaults->update("KEYFRAMEDIALOG_W", keyframedialog_w);
562 defaults->update("KEYFRAMEDIALOG_H", keyframedialog_h);
563 defaults->update("KEYFRAMEDIALOG_COLUMN1", keyframedialog_column1);
564 defaults->update("KEYFRAMEDIALOG_COLUMN2", keyframedialog_column2);
565 defaults->update("KEYFRAMEDIALOG_ALL", keyframedialog_all);
567 defaults->update("MENUEFFECT_W", menueffect_w);
568 defaults->update("MENUEFFECT_H", menueffect_h);
570 defaults->update("TRANSITIONDIALOG_W", transitiondialog_w);
571 defaults->update("TRANSITIONDIALOG_H", transitiondialog_h);
573 defaults->update("ACTUAL_FRAME_RATE", actual_frame_rate);
574 defaults->update("TITLE_BAR_ALPHA", title_bar_alpha);
575 defaults->update("CURRENT_TIP", current_tip);
581 Track *MainSession::drag_handle_track()
584 switch( current_operation ) {
585 case DRAG_EDITHANDLE1:
586 case DRAG_EDITHANDLE2:
587 track = drag_edit->edits->track;
589 case DRAG_PLUGINHANDLE1:
590 case DRAG_PLUGINHANDLE2:
591 track = drag_plugin->edits->track;
597 void MainSession::update_clip_number()
600 for( int i=mwindow->edl->clips.size(); --i>=0; ) {
601 EDL *clip_edl = mwindow->edl->clips[i];
603 if( sscanf(clip_edl->local_session->clip_title,_("Clip %d"),&no) == 1 )
604 if( no > clip_no ) clip_no = no;
606 clip_number = clip_no+1;
609 int MainSession::load_file(const char *path)
612 FILE *fp = fopen(path,"r");
615 defaults.load_file(fp);
616 load_defaults(&defaults);
623 int MainSession::save_file(const char *path)
626 FILE *fp = fopen(path,"w");
629 save_defaults(&defaults);
630 defaults.save_file(fp);