clipedit remove vs delete
[goodguy/history.git] / cinelerra-5.0 / cinelerra / mwindow.C
index 7ad079b382fba0341bb98dd34ed51c8aad5fca49..f29b98e61fb2d4d57d5c726d5d6ffd7c52b2d1c2 100644 (file)
 #include "vwindowgui.h"
 #include "vwindow.h"
 #include "wavecache.h"
+#include "wwindow.h"
 #include "zoombar.h"
 
 #include <string.h>
@@ -200,6 +201,7 @@ MWindow::MWindow()
        awindow = 0;
        gwindow = 0;
        twindow = 0;
+       wwindow = 0;
        lwindow = 0;
        sighandler = 0;
        reload_status = 0;
@@ -235,7 +237,6 @@ MWindow::~MWindow()
        hide_keyframe_guis();
        clean_indexes();
        save_defaults();
-
 // Give up and go to a movie
 //  cant run valgrind if this is used
 //     if( !reload_status ) exit(0);
@@ -250,12 +251,14 @@ MWindow::~MWindow()
        if( lwindow && lwindow->gui ) lwindow->gui->close(0);
        if( gwindow && gwindow->gui ) gwindow->gui->close(0);
        if( twindow && twindow->is_running() ) twindow->close_window();
+       if( wwindow && wwindow->is_running() ) wwindow->close_window();
        vwindows.remove_all_objects();
        gui->close(0);
        if( awindow ) awindow->join();
        if( cwindow ) cwindow->join();
        if( lwindow ) lwindow->join();
        if( twindow ) twindow->join();
+       if( wwindow ) wwindow->join();
        if( gwindow ) gwindow->join();
        join();
 #else
@@ -268,6 +271,7 @@ MWindow::~MWindow()
        close_gui(lwindow);
        close_gui(gwindow);
        close_gui(twindow);
+       close_gui(wwindow);
        vwindows.remove_all_objects();
        gui->close(0);
        join();
@@ -284,6 +288,7 @@ MWindow::~MWindow()
        delete awindow;         awindow = 0;
        delete lwindow;         lwindow = 0;
        delete twindow;         twindow = 0;
+       delete wwindow;         wwindow = 0;
        delete gwindow;         gwindow = 0;
        // must be last or nouveau chokes
        delete cwindow;         cwindow = 0;
@@ -330,8 +335,7 @@ void MWindow::quit(int unlock)
        interrupt_indexes();
        clean_indexes();
        save_defaults();
-// This is the last thread to exit
-       playback_3d->quit();
+       gui->set_done(0);
        if(unlock) gui->lock_window("MWindow::quit");
 }
 
@@ -658,10 +662,19 @@ void MWindow::init_gwindow()
 
 void MWindow::init_tipwindow()
 {
-       twindow = new TipWindow(this);
+       if( !twindow )
+               twindow = new TipWindow(this);
        twindow->start();
 }
 
+void MWindow::show_warning(int *do_warning, const char *text)
+{
+       if( do_warning && !*do_warning ) return;
+       if( !wwindow )
+               wwindow = new WWindow(this);
+       wwindow->show_warning(do_warning, text);
+}
+
 void MWindow::init_theme()
 {
        Timer timer;
@@ -671,27 +684,44 @@ void MWindow::init_theme()
        if(!strcasecmp(preferences->theme, "Blond"))
                strcpy(preferences->theme, DEFAULT_THEME);
 
-       for(int i = 0; i < plugindb->total; i++)
-       {
-               if(plugindb->values[i]->theme &&
-                       !strcasecmp(preferences->theme, plugindb->values[i]->title))
-               {
-                       PluginServer plugin = *plugindb->values[i];
-                       plugin.open_plugin(0, preferences, 0, 0);
-                       theme = plugin.new_theme();
-                       theme->mwindow = this;
-                       strcpy(theme->path, plugin.path);
-                       plugin.close_plugin();
-                       break;
+       PluginServer *theme_plugin = 0;
+       for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
+               if( plugindb->values[i]->theme &&
+                   !strcasecmp(preferences->theme, plugindb->values[i]->title) )
+                       theme_plugin = plugindb->values[i];
+       }
+
+       if( !theme_plugin )
+               fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
+                        preferences->theme);
+
+       if( !theme_plugin && strcasecmp(preferences->theme, DEFAULT_THEME) ) {
+               fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
+                       DEFAULT_THEME);
+               for(int i = 0; i < plugindb->total && !theme_plugin; i++) {
+                       if( plugindb->values[i]->theme &&
+                           !strcasecmp(DEFAULT_THEME, plugindb->values[i]->title) )
+                               theme_plugin = plugindb->values[i];
                }
        }
 
-       if(!theme)
-       {
-               fprintf(stderr, _("MWindow::init_theme: theme %s not found.\n"), preferences->theme);
+       if(!theme_plugin) {
+               fprintf(stderr, _("MWindow::init_theme: theme_plugin not found.\n"));
                exit(1);
        }
 
+       PluginServer plugin = *theme_plugin;
+       if( plugin.open_plugin(0, preferences, 0, 0) ) {
+               fprintf(stderr, _("MWindow::init_theme: unable to load theme %s\n"),
+                       theme_plugin->title);
+               exit(1);
+       }
+
+       theme = plugin.new_theme();
+       theme->mwindow = this;
+       strcpy(theme->path, plugin.path);
+       plugin.close_plugin();
+
 // Load default images & settings
        theme->Theme::initialize();
 // Load user images & settings
@@ -1407,6 +1437,7 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                select_asset(0, 0);
                edl->local_session->preview_start = 0;
                edl->local_session->preview_end = edl->tracks->total_playable_length();
+               edl->local_session->loop_playback = 0;
                edl->local_session->set_selectionstart(0);
                edl->local_session->set_selectionend(0);
                fit_selection();
@@ -1593,7 +1624,6 @@ void MWindow::create_objects(int want_gui,
        if(debug) PRINT_TRACE
 //     show_splash();
 
-       init_error();
        if(debug) PRINT_TRACE
        init_defaults(defaults, config_path);
        init_preferences();
@@ -1603,6 +1633,7 @@ void MWindow::create_objects(int want_gui,
        if(debug) PRINT_TRACE
        init_theme();
        if(debug) PRINT_TRACE
+       init_error();
 
        char string[BCTEXTLEN];
        strcpy(string, preferences->plugin_dir);
@@ -1790,7 +1821,7 @@ ENABLE_BUFFER
 //PRINT_TRACE
        gwindow->start();
 //PRINT_TRACE
-       Thread::start();
+//     Thread::start();
 //PRINT_TRACE
        playback_3d->start();
 //PRINT_TRACE
@@ -2646,8 +2677,16 @@ static inline int gcd(int m, int n)
 
 int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
 {
+       w = 1;  h = 1;
        if(!width || !height) return 1;
        double ar = (double)width / height;
+// square-ish pixels
+       if( EQUIV(ar, 1.0000) ) return 0;
+       if( EQUIV(ar, 1.3333) ) { w = 4;  h = 3;  return 0; }
+       if( EQUIV(ar, 1.7777) ) { w = 16; h = 9;  return 0; }
+       if( EQUIV(ar, 2.1111) ) { w = 19; h = 9;  return 0; }
+       if( EQUIV(ar, 2.2222) ) { w = 20; h = 9;  return 0; }
+       if( EQUIV(ar, 2.3333) ) { w = 21; h = 9;  return 0; }
        int ww = width, hh = height;
        // numerator, denominator must be under mx
        int mx = 255, n = gcd(ww, hh);
@@ -2763,6 +2802,13 @@ void MWindow::remove_assets_from_project(int push_undo)
                }
        }
        
+       for(int i = 0; i < session->drag_assets->size(); i++)
+       {
+               Indexable *indexable = session->drag_assets->values[i];
+               remove_indexfile(indexable);
+       }
+
+//printf("MWindow::rebuild_indices 1 %s\n", indexable->path);
        if(push_undo) undo->update_undo_before();
        edl->remove_from_project(session->drag_assets);
        edl->remove_from_project(session->drag_clips);