add new boxblur plugin, mods to videoscope, fix segv for menu btns kfrm-tweak/kfrm...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mainsession.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "auto.h"
23 #include "bcdisplayinfo.h"
24 #include "clip.h"
25 #include "bchash.h"
26 #include "edit.h"
27 #include "edits.h"
28 #include "edl.h"
29 #include "edlsession.h"
30 #include "guicast.h"
31 #include "indexable.h"
32 #include "language.h"
33 #include "localsession.h"
34 #include "mainsession.h"
35 #include "meterpanel.h"
36 #include "mwindow.h"
37 #include "mwindowgui.h"
38 #include "plugin.h"
39
40 MainSession::MainSession(MWindow *mwindow)
41 {
42         this->mwindow = mwindow;
43         changes_made = 0;
44         filename[0] = 0;
45 //      playback_cursor_visible = 0;
46 //      is_playing_back = 0;
47         track_highlighted = 0;
48         plugin_highlighted = 0;
49         pluginset_highlighted = 0;
50         edit_highlighted = 0;
51         current_operation = NO_OPERATION;
52         drag_pluginservers = new ArrayList<PluginServer*>;
53         drag_plugin = 0;
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*>;
58         drag_edit = 0;
59         drag_group = 0;
60         drag_group_edit = 0;
61         drag_group_position = 0;
62         drag_group_first_track = 0;
63         group_number = 1;
64         clip_number = 1;
65         brender_end = 0;
66         cwindow_controls = 1;
67         trim_edits = 0;
68         current_tip = -1;
69         selected_zwindow = -1;
70         actual_frame_rate = 0;
71         title_bar_alpha = 0;
72         window_config = 0;
73         a_x11_host[0] = 0;
74         b_x11_host[0] = 0;
75         record_scope = 0;
76
77         drag_auto = 0;
78         drag_button = 0;
79         drag_handle = 0;
80         drag_position = 0;
81         drag_start = 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;
104         use_hist = 0;
105         use_wave = 0;
106         use_vector = 0;
107         use_hist_parade = 0;
108         use_wave_parade = 0;
109         use_wave_gain = 5;
110         use_vect_gain = 5;
111         use_smooth = 0;
112         afolders_w = 0;
113         show_vwindow = show_awindow = show_cwindow = show_gwindow = show_lwindow = 0;
114         plugindialog_w = plugindialog_h = 0;
115 //      presetdialog_w = presetdialog_h = 0;
116         keyframedialog_w = keyframedialog_h = 0;
117         keyframedialog_column1 = 0;
118         keyframedialog_column2 = 0;
119         keyframedialog_all = 0;
120         menueffect_w = menueffect_h = 0;
121         transitiondialog_w = transitiondialog_h = 0;
122 }
123
124 MainSession::~MainSession()
125 {
126         delete drag_pluginservers;
127         delete drag_assets;
128         delete drag_auto_gang;
129         delete drag_clips;
130         delete drag_edits;
131         if( drag_group )
132                 drag_group->remove_user();
133 }
134
135 void MainSession::boundaries()
136 {
137         lwindow_x = MAX(0, lwindow_x);
138         lwindow_y = MAX(0, lwindow_y);
139         mwindow_x = MAX(0, mwindow_x);
140         mwindow_y = MAX(0, mwindow_y);
141         cwindow_x = MAX(0, cwindow_x);
142         cwindow_y = MAX(0, cwindow_y);
143         vwindow_x = MAX(0, vwindow_x);
144         vwindow_y = MAX(0, vwindow_y);
145         awindow_x = MAX(0, awindow_x);
146         awindow_y = MAX(0, awindow_y);
147         gwindow_x = MAX(0, gwindow_x);
148         gwindow_y = MAX(0, gwindow_y);
149         rwindow_x = MAX(0, rwindow_x);
150         rwindow_y = MAX(0, rwindow_y);
151         rmonitor_x = MAX(0, rmonitor_x);
152         rmonitor_y = MAX(0, rmonitor_y);
153         CLAMP(cwindow_controls, 0, 1);
154 }
155
156 void MainSession::save_x11_host(int play_config, const char *x11_host)
157 {
158         strcpy(!play_config ? a_x11_host : b_x11_host, x11_host);
159 }
160
161 // set default x11 host, window_config, return screens
162 int MainSession::set_default_x11_host(int win_config)
163 {
164         if( win_config < 0 ) win_config = window_config;
165         const char *x11_host = win_config!=1 ? a_x11_host : b_x11_host;
166         BC_DisplayInfo display_info(x11_host,0);
167         int screen = display_info.get_screen();
168         if( screen < 0 && strcmp(a_x11_host, b_x11_host) ) {
169                 win_config = win_config==1 ? 0 : 1;
170                 x11_host = win_config!=1 ? a_x11_host : b_x11_host;
171                 display_info.init_window(x11_host,0);
172                 screen = display_info.get_screen();
173         }
174         if( screen < 0 ) {
175                 x11_host = "";
176                 display_info.init_window(x11_host,1);
177         }
178         int screens = 1;
179         if( display_info.get_screen_count() > 1 )
180                 screens = strcmp(a_x11_host, b_x11_host) != 0 ? 2 : 1;
181         window_config = win_config;
182         BC_Window::set_default_x11_host(x11_host);
183         return screens;
184 }
185
186 void MainSession::default_window_positions(int window_config)
187 {
188 // 0 - all windows on a, playback_config a
189 // 1 - all windows on b, playback_config b
190 // 2 - all windows on a, except composer on b, playback_config b
191         int screens = set_default_x11_host(window_config);
192         mwindow->set_screens(screens);
193
194         BC_DisplayInfo display_info(BC_Window::get_default_x11_host());
195 // Get defaults based on root window size
196         int root_x = 0;
197         int root_y = 0;
198         int root_w = display_info.get_root_w();
199         int root_h = display_info.get_root_h();
200
201         int border_left = display_info.get_left_border();
202         int border_right = display_info.get_right_border();
203         int border_top = display_info.get_top_border();
204         int border_bottom = display_info.get_bottom_border();
205
206         int dual_head = screens > 1 ? 1 : 0;
207         int left_w = 0, left_h = 0, right_w = 0;
208         int xin_screens = display_info.get_xinerama_screens();
209         if( xin_screens > 1 ) {
210                 dual_head = 1;
211                 int x, y, w, h;
212                 for( int s=0; s<xin_screens; ++s ) {
213                         if( display_info.xinerama_geometry(s, x, y, w, h) )
214                                 continue;
215                         if( !y && !x ) {
216                                 left_w = w;  left_h = h;
217                                 break;
218                         }
219                 }
220                 if( left_w > 0 ) {
221                         for( int s=0; s<xin_screens; ++s ) {
222                                 if( display_info.xinerama_geometry(s, x, y, w, h) )
223                                         continue;
224                                 if( !y && x == left_w ) {
225                                         right_w = w;
226                                         screens = 2;
227                                         break;
228                                 }
229                         }
230                         if( window_config == 1 ) {
231                                 root_x = left_w;
232                                 root_w = right_w;
233                         }
234                         else {
235                                 root_w = left_w;
236                                 root_h = left_h;
237                         }
238                 }
239         }
240 // Wider than 16:9, narrower than dual head
241         else if( screens < 2 && (float)root_w / root_h > 1.8 ) {
242                 dual_head = 1;
243                 switch( root_h ) {
244                 case 600:  right_w = 800;   break;
245                 case 720:  right_w = 1280;  break;
246                 case 1024: right_w = 1280;  break;
247                 case 1200: right_w = 1600;  break;
248                 case 1080: right_w = 1920;  break;
249                 default:
250                         dual_head = 0;
251                         break;
252                 }
253                 if( dual_head ) {
254                         if( window_config == 1 ) {
255                                 root_x = root_w - right_w;
256                                 root_w = right_w;
257                         }
258                         else {
259                                 // use same aspect ratio to compute left height
260                                 root_w -= right_w;
261                                 root_h = (root_w*root_h) / right_w;
262                         }
263                 }
264         }
265
266         vwindow_x = root_x;
267         vwindow_y = root_y;
268         vwindow_w = root_w / 2 - border_left - border_right;
269         vwindow_h = root_h * 6 / 10 - border_top - border_bottom;
270
271         int b_root_w = root_w;
272         int b_root_h = root_h;
273         if( !dual_head || window_config != 2 ) {
274                 cwindow_x = root_x + root_w / 2;
275                 cwindow_y = root_y;
276                 cwindow_w = vwindow_w;
277                 cwindow_h = vwindow_h;
278         }
279         else {
280 // Get defaults based on root window size
281                 BC_DisplayInfo b_display_info(b_x11_host);
282                 b_root_w = b_display_info.get_root_w();
283                 b_root_h = b_display_info.get_root_h();
284                 cwindow_x = xS(50);
285                 cwindow_y = yS(50);
286                 cwindow_w = b_root_w-xS(100);
287                 cwindow_h = b_root_h-yS(100);
288         }
289
290         ctool_x = cwindow_x + cwindow_w / 2;
291         ctool_y = cwindow_y + cwindow_h / 2;
292
293         mwindow_x = root_x;
294         mwindow_y = vwindow_y + vwindow_h + border_top + border_bottom;
295         mwindow_w = root_w * 2 / 3 - border_left - border_right;
296         mwindow_h = root_h - mwindow_y - border_top - border_bottom;
297
298         awindow_x = mwindow_x + border_left + border_right + mwindow_w;
299         awindow_y = mwindow_y;
300         awindow_w = root_x + root_w - awindow_x - border_left - border_right;
301         awindow_h = mwindow_h;
302
303         bwindow_w = xS(600);
304         bwindow_h = yS(360);
305
306         ewindow_w = xS(640);
307         ewindow_h = yS(240);
308
309         channels_x = 0;
310         channels_y = 0;
311         picture_x = 0;
312         picture_y = 0;
313         scope_x = 0;
314         scope_y = 0;
315         scope_w = xS(640);
316         scope_h = yS(320);
317         histogram_x = 0;
318         histogram_y = 0;
319         histogram_w = xS(320);
320         histogram_h = yS(480);
321         record_scope = 0;
322         use_hist = 1;
323         use_wave = 1;
324         use_vector = 1;
325         use_hist_parade = 1;
326         use_wave_parade = 1;
327         use_wave_gain = 5;
328         use_vect_gain = 5;
329         use_smooth = 1;
330
331         if(mwindow->edl)
332                 lwindow_w = MeterPanel::get_meters_width(mwindow->theme,
333                         mwindow->edl->session->audio_channels,
334                         1);
335         else
336                 lwindow_w = xS(100);
337
338         lwindow_y = 0;
339         lwindow_x = root_w - lwindow_w;
340         lwindow_h = mwindow_y;
341
342         rwindow_x = root_x;
343         rwindow_y = root_y;
344         rwindow_h = yS(500);
345         rwindow_w = xS(650);
346
347         cswindow_x = root_x;
348         cswindow_y = root_y;
349         cswindow_w = xS(1280);
350         cswindow_h = yS(600);
351
352         if( !dual_head || window_config != 2 ) {
353                 rmonitor_x = rwindow_x + rwindow_w + xS(10);
354                 rmonitor_y = rwindow_y;
355                 rmonitor_w = root_x + root_w - rmonitor_x;
356                 rmonitor_h = rwindow_h;
357         }
358         else {
359                 rmonitor_x = cswindow_x = xS(50);
360                 rmonitor_y = cswindow_y = yS(50);
361                 rmonitor_w = b_root_w-xS(100);
362                 rmonitor_h = b_root_h-yS(100);
363                 if( cswindow_w < rmonitor_w ) cswindow_w = rmonitor_w;
364                 if( cswindow_h < rmonitor_h ) cswindow_h = rmonitor_h;
365         }
366
367         swindow_x = root_x;
368         swindow_y = root_y;
369         swindow_w = xS(600);
370         swindow_h = yS(400);
371
372         batchrender_w = xS(750);
373         batchrender_h = yS(400);
374         batchrender_x = root_w / 2 - batchrender_w / 2;
375         batchrender_y = root_h / 2 - batchrender_h / 2;
376 }
377
378 int MainSession::load_defaults(BC_Hash *defaults)
379 {
380 // Setup main windows
381         char *a_host = defaults->get("A_X11_HOST", a_x11_host);
382         if( a_host != a_x11_host )
383                 strcpy(a_x11_host, defaults->get("A_X11_HOST", a_x11_host));
384         char *b_host = defaults->get("B_X11_HOST", b_x11_host);
385         if( b_host != b_x11_host )
386                 strcpy(b_x11_host, defaults->get("B_X11_HOST", b_x11_host));
387         window_config = defaults->get("WINDOW_CONFIG", window_config);
388         default_window_positions(window_config);
389
390         vwindow_x = defaults->get("VWINDOW_X", vwindow_x);
391         vwindow_y = defaults->get("VWINDOW_Y", vwindow_y);
392         vwindow_w = defaults->get("VWINDOW_W", vwindow_w);
393         vwindow_h = defaults->get("VWINDOW_H", vwindow_h);
394
395
396         cwindow_x = defaults->get("CWINDOW_X", cwindow_x);
397         cwindow_y = defaults->get("CWINDOW_Y", cwindow_y);
398         cwindow_w = defaults->get("CWINDOW_W", cwindow_w);
399         cwindow_h = defaults->get("CWINDOW_H", cwindow_h);
400
401         ctool_x = defaults->get("CTOOL_X", ctool_x);
402         ctool_y = defaults->get("CTOOL_Y", ctool_y);
403
404         gwindow_x = defaults->get("GWINDOW_X", gwindow_x);
405         gwindow_y = defaults->get("GWINDOW_Y", gwindow_y);
406
407         mwindow_x = defaults->get("MWINDOW_X", mwindow_x);
408         mwindow_y = defaults->get("MWINDOW_Y", mwindow_y);
409         mwindow_w = defaults->get("MWINDOW_W", mwindow_w);
410         mwindow_h = defaults->get("MWINDOW_H", mwindow_h);
411
412         lwindow_x = defaults->get("LWINDOW_X", lwindow_x);
413         lwindow_y = defaults->get("LWINDOW_Y", lwindow_y);
414         lwindow_w = defaults->get("LWINDOW_W", lwindow_w);
415         lwindow_h = defaults->get("LWINDOW_H", lwindow_h);
416
417
418         awindow_x = defaults->get("AWINDOW_X", awindow_x);
419         awindow_y = defaults->get("AWINDOW_Y", awindow_y);
420         awindow_w = defaults->get("AWINDOW_W", awindow_w);
421         awindow_h = defaults->get("AWINDOW_H", awindow_h);
422
423         ewindow_w = defaults->get("EWINDOW_W", ewindow_w);
424         ewindow_h = defaults->get("EWINDOW_H", ewindow_h);
425
426         channels_x = defaults->get("CHANNELS_X", channels_x);
427         channels_y = defaults->get("CHANNELS_Y", channels_y);
428         picture_x = defaults->get("PICTURE_X", picture_x);
429         picture_y = defaults->get("PICTURE_Y", picture_y);
430         scope_x = defaults->get("SCOPE_X", scope_x);
431         scope_y = defaults->get("SCOPE_Y", scope_y);
432         scope_w = defaults->get("SCOPE_W", scope_w);
433         scope_h = defaults->get("SCOPE_H", scope_h);
434         histogram_x = defaults->get("HISTOGRAM_X", histogram_x);
435         histogram_y = defaults->get("HISTOGRAM_Y", histogram_y);
436         histogram_w = defaults->get("HISTOGRAM_W", histogram_w);
437         histogram_h = defaults->get("HISTOGRAM_H", histogram_h);
438         record_scope = defaults->get("RECORD_SCOPE", record_scope);
439         use_hist = defaults->get("USE_HIST", use_hist);
440         use_wave = defaults->get("USE_WAVE", use_wave);
441         use_vector = defaults->get("USE_VECTOR", use_vector);
442         use_hist_parade = defaults->get("USE_HIST_PARADE", use_hist_parade);
443         use_wave_parade = defaults->get("USE_WAVE_PARADE", use_wave_parade);
444         use_wave_gain = defaults->get("USE_WAVE_GAIN", use_wave_gain);
445         use_vect_gain = defaults->get("USE_VECT_GAIN", use_vect_gain);
446         use_smooth = defaults->get("USE_SMOOTH", use_smooth);
447
448 //printf("MainSession::load_defaults 1\n");
449
450 // Other windows
451         afolders_w = defaults->get("ABINS_W", xS(200));
452
453         bwindow_w = defaults->get("BWINDOW_W", bwindow_w);
454         bwindow_h = defaults->get("BWINDOW_H", bwindow_h);
455
456         rwindow_x = defaults->get("RWINDOW_X", rwindow_x);
457         rwindow_y = defaults->get("RWINDOW_Y", rwindow_y);
458         rwindow_w = defaults->get("RWINDOW_W", rwindow_w);
459         rwindow_h = defaults->get("RWINDOW_H", rwindow_h);
460
461         cswindow_x = defaults->get("CSWINDOW_X", cswindow_x);
462         cswindow_y = defaults->get("CSWINDOW_Y", cswindow_y);
463         cswindow_w = defaults->get("CSWINDOW_W", cswindow_w);
464         cswindow_h = defaults->get("CSWINDOW_H", cswindow_h);
465
466         swindow_x = defaults->get("SWINDOW_X", swindow_x);
467         swindow_y = defaults->get("SWINDOW_Y", swindow_y);
468         swindow_w = defaults->get("SWINDOW_W", swindow_w);
469         swindow_h = defaults->get("SWINDOW_H", swindow_h);
470
471         rmonitor_x = defaults->get("RMONITOR_X", rmonitor_x);
472         rmonitor_y = defaults->get("RMONITOR_Y", rmonitor_y);
473         rmonitor_w = defaults->get("RMONITOR_W", rmonitor_w);
474         rmonitor_h = defaults->get("RMONITOR_H", rmonitor_h);
475
476         batchrender_x = defaults->get("BATCHRENDER_X", batchrender_x);
477         batchrender_y = defaults->get("BATCHRENDER_Y", batchrender_y);
478         batchrender_w = defaults->get("BATCHRENDER_W", batchrender_w);
479         batchrender_h = defaults->get("BATCHRENDER_H", batchrender_h);
480
481         show_vwindow = defaults->get("SHOW_VWINDOW", 1);
482         show_awindow = defaults->get("SHOW_AWINDOW", 1);
483         show_cwindow = defaults->get("SHOW_CWINDOW", 1);
484         show_lwindow = defaults->get("SHOW_LWINDOW", 0);
485         show_gwindow = defaults->get("SHOW_GWINDOW", 0);
486
487         cwindow_controls = defaults->get("CWINDOW_CONTROLS", cwindow_controls);
488
489         plugindialog_w = defaults->get("PLUGINDIALOG_W", xS(510));
490         plugindialog_h = defaults->get("PLUGINDIALOG_H", yS(415));
491 //      presetdialog_w = defaults->get("PRESETDIALOG_W", xS(510));
492 //      presetdialog_h = defaults->get("PRESETDIALOG_H", yS(415));
493         keyframedialog_w = defaults->get("KEYFRAMEDIALOG_W", xS(320));
494         keyframedialog_h = defaults->get("KEYFRAMEDIALOG_H", yS(415));
495         keyframedialog_column1 = defaults->get("KEYFRAMEDIALOG_COLUMN1", xS(150));
496         keyframedialog_column2 = defaults->get("KEYFRAMEDIALOG_COLUMN2", xS(100));
497         keyframedialog_all = defaults->get("KEYFRAMEDIALOG_ALL", 0);
498         menueffect_w = defaults->get("MENUEFFECT_W", xS(580));
499         menueffect_h = defaults->get("MENUEFFECT_H", yS(350));
500         transitiondialog_w = defaults->get("TRANSITIONDIALOG_W", xS(320));
501         transitiondialog_h = defaults->get("TRANSITIONDIALOG_H", yS(512));
502
503         current_tip = defaults->get("CURRENT_TIP", current_tip);
504         actual_frame_rate = defaults->get("ACTUAL_FRAME_RATE", (float)-1);
505         title_bar_alpha = defaults->get("TITLE_BAR_ALPHA", (float)1);
506
507         boundaries();
508         return 0;
509 }
510
511 int MainSession::save_defaults(BC_Hash *defaults)
512 {
513         defaults->update("A_X11_HOST", a_x11_host);
514         defaults->update("B_X11_HOST", b_x11_host);
515         defaults->update("WINDOW_CONFIG", window_config);
516 // Window positions
517         defaults->update("MWINDOW_X", mwindow_x);
518         defaults->update("MWINDOW_Y", mwindow_y);
519         defaults->update("MWINDOW_W", mwindow_w);
520         defaults->update("MWINDOW_H", mwindow_h);
521
522         defaults->update("LWINDOW_X", lwindow_x);
523         defaults->update("LWINDOW_Y", lwindow_y);
524         defaults->update("LWINDOW_W", lwindow_w);
525         defaults->update("LWINDOW_H", lwindow_h);
526
527         defaults->update("VWINDOW_X", vwindow_x);
528         defaults->update("VWINDOW_Y", vwindow_y);
529         defaults->update("VWINDOW_W", vwindow_w);
530         defaults->update("VWINDOW_H", vwindow_h);
531
532         defaults->update("CWINDOW_X", cwindow_x);
533         defaults->update("CWINDOW_Y", cwindow_y);
534         defaults->update("CWINDOW_W", cwindow_w);
535         defaults->update("CWINDOW_H", cwindow_h);
536
537         defaults->update("CTOOL_X", ctool_x);
538         defaults->update("CTOOL_Y", ctool_y);
539
540         defaults->update("GWINDOW_X", gwindow_x);
541         defaults->update("GWINDOW_Y", gwindow_y);
542
543         defaults->update("AWINDOW_X", awindow_x);
544         defaults->update("AWINDOW_Y", awindow_y);
545         defaults->update("AWINDOW_W", awindow_w);
546         defaults->update("AWINDOW_H", awindow_h);
547
548         defaults->update("BWINDOW_W", bwindow_w);
549         defaults->update("BWINDOW_H", bwindow_h);
550
551         defaults->update("EWINDOW_W", ewindow_w);
552         defaults->update("EWINDOW_H", ewindow_h);
553
554         defaults->update("CHANNELS_X", channels_x);
555         defaults->update("CHANNELS_Y", channels_y);
556         defaults->update("PICTURE_X", picture_x);
557         defaults->update("PICTURE_Y", picture_y);
558         defaults->update("SCOPE_X", scope_x);
559         defaults->update("SCOPE_Y", scope_y);
560         defaults->update("SCOPE_W", scope_w);
561         defaults->update("SCOPE_H", scope_h);
562         defaults->update("HISTOGRAM_X", histogram_x);
563         defaults->update("HISTOGRAM_Y", histogram_y);
564         defaults->update("HISTOGRAM_W", histogram_w);
565         defaults->update("HISTOGRAM_H", histogram_h);
566         defaults->update("RECORD_SCOPE", record_scope);
567         defaults->update("USE_HIST", use_hist);
568         defaults->update("USE_WAVE", use_wave);
569         defaults->update("USE_VECTOR", use_vector);
570         defaults->update("USE_HIST_PARADE", use_hist_parade);
571         defaults->update("USE_WAVE_PARADE", use_wave_parade);
572         defaults->update("USE_WAVE_GAIN", use_wave_gain);
573         defaults->update("USE_VECT_GAIN", use_vect_gain);
574         defaults->update("USE_SMOOTH", use_smooth);
575
576         defaults->update("ABINS_W", afolders_w);
577
578         defaults->update("RMONITOR_X", rmonitor_x);
579         defaults->update("RMONITOR_Y", rmonitor_y);
580         defaults->update("RMONITOR_W", rmonitor_w);
581         defaults->update("RMONITOR_H", rmonitor_h);
582
583         defaults->update("RWINDOW_X", rwindow_x);
584         defaults->update("RWINDOW_Y", rwindow_y);
585         defaults->update("RWINDOW_W", rwindow_w);
586         defaults->update("RWINDOW_H", rwindow_h);
587
588         defaults->update("CSWINDOW_X", cswindow_x);
589         defaults->update("CSWINDOW_Y", cswindow_y);
590         defaults->update("CSWINDOW_W", cswindow_w);
591         defaults->update("CSWINDOW_H", cswindow_h);
592
593         defaults->update("SWINDOW_X", swindow_x);
594         defaults->update("SWINDOW_Y", swindow_y);
595         defaults->update("SWINDOW_W", swindow_w);
596         defaults->update("SWINDOW_H", swindow_h);
597
598         defaults->update("BATCHRENDER_X", batchrender_x);
599         defaults->update("BATCHRENDER_Y", batchrender_y);
600         defaults->update("BATCHRENDER_W", batchrender_w);
601         defaults->update("BATCHRENDER_H", batchrender_h);
602
603         defaults->update("SHOW_VWINDOW", show_vwindow);
604         defaults->update("SHOW_AWINDOW", show_awindow);
605         defaults->update("SHOW_CWINDOW", show_cwindow);
606         defaults->update("SHOW_LWINDOW", show_lwindow);
607         defaults->update("SHOW_GWINDOW", show_gwindow);
608
609         defaults->update("CWINDOW_CONTROLS", cwindow_controls);
610
611         defaults->update("PLUGINDIALOG_W", plugindialog_w);
612         defaults->update("PLUGINDIALOG_H", plugindialog_h);
613 //      defaults->update("PRESETDIALOG_W", presetdialog_w);
614 //      defaults->update("PRESETDIALOG_H", presetdialog_h);
615         defaults->update("KEYFRAMEDIALOG_W", keyframedialog_w);
616         defaults->update("KEYFRAMEDIALOG_H", keyframedialog_h);
617         defaults->update("KEYFRAMEDIALOG_COLUMN1", keyframedialog_column1);
618         defaults->update("KEYFRAMEDIALOG_COLUMN2", keyframedialog_column2);
619         defaults->update("KEYFRAMEDIALOG_ALL", keyframedialog_all);
620
621         defaults->update("MENUEFFECT_W", menueffect_w);
622         defaults->update("MENUEFFECT_H", menueffect_h);
623
624         defaults->update("TRANSITIONDIALOG_W", transitiondialog_w);
625         defaults->update("TRANSITIONDIALOG_H", transitiondialog_h);
626
627         defaults->update("ACTUAL_FRAME_RATE", actual_frame_rate);
628         defaults->update("TITLE_BAR_ALPHA", title_bar_alpha);
629         defaults->update("CURRENT_TIP", current_tip);
630
631
632         return 0;
633 }
634
635 Track *MainSession::drag_handle_track()
636 {
637         Track *track = 0;
638         switch( current_operation ) {
639         case DRAG_EDITHANDLE1:
640         case DRAG_EDITHANDLE2:
641                 track = drag_edit->edits->track;
642                 break;
643         case DRAG_PLUGINHANDLE1:
644         case DRAG_PLUGINHANDLE2:
645                 track = drag_plugin->edits->track;
646                 break;
647         }
648         return track;
649 }
650
651 void MainSession::update_clip_number()
652 {
653         int clip_no = 0;
654         for( int i=mwindow->edl->clips.size(); --i>=0; ) {
655                 EDL *clip_edl = mwindow->edl->clips[i];
656                 int no = 0;
657                 if( sscanf(clip_edl->local_session->clip_title,_("Clip %d"),&no) == 1 )
658                         if( no > clip_no ) clip_no = no;
659         }
660         clip_number = clip_no+1;
661 }
662
663 int MainSession::load_file(const char *path)
664 {
665         int ret = 1;
666         FILE *fp = fopen(path,"r");
667         if( fp ) {
668                 BC_Hash defaults;
669                 defaults.load_file(fp);
670                 load_defaults(&defaults);
671                 fclose(fp);
672                 ret = 0;
673         }
674         return ret;
675 }
676
677 int MainSession::save_file(const char *path)
678 {
679         int ret = 1;
680         FILE *fp = fopen(path,"w");
681         if( fp ) {
682                 BC_Hash defaults;
683                 save_defaults(&defaults);
684                 defaults.save_file(fp);
685                 fclose(fp);
686                 ret = 0;
687         }
688         return ret;
689 }
690