change to id based refs for plugins, save plugin on/off in edit drag/drop, fix transi...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindow.C
index c63c25bee2c8815e68d24684ef61758701388667..63522d6872690e155ccc96e351a6e4dc02eb53db 100644 (file)
@@ -268,7 +268,9 @@ MWindow::~MWindow()
        delete beeper;
        delete create_bd;       create_bd = 0;
        delete create_dvd;      create_dvd = 0;
+#ifdef HAVE_SHUTTLE
        delete shuttle;         shuttle = 0;
+#endif
 #ifdef HAVE_WINTV
        delete wintv;           wintv = 0;
 #endif
@@ -675,6 +677,7 @@ int MWindow::init_plugins(MWindow *mwindow, Preferences *preferences)
 
 int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
 {
+#ifdef HAVE_LADSPA
        char *path = getenv("LADSPA_PATH");
        char ladspa_path[BCTEXTLEN];
        if( !path ) {
@@ -719,6 +722,7 @@ int MWindow::init_ladspa_plugins(MWindow *mwindow, Preferences *preferences)
                }
                fclose(fp);
        }
+#endif
        return 1;
 }
 
@@ -742,7 +746,7 @@ void MWindow::scan_plugin_index(MWindow *mwindow, Preferences *preferences, FILE
        char plugin_path[BCTEXTLEN];
        sprintf(plugin_path, "%s/%s", plug_dir, plug_path);
        FileSystem fs;
-       fs.set_filter( "[*.plugin][*.so]" );
+       fs.set_filter( "[*.plugin][*.so][*.dll]" );
        int result = fs.update(plugin_path);
        if( result || !fs.dir_list.total ) return;
        int vis_id = idx++;
@@ -3254,10 +3258,9 @@ void MWindow::show_keyframe_gui(Plugin *plugin)
 {
        keyframe_gui_lock->lock("MWindow::show_keyframe_gui");
 // Find existing thread
-       for(int i = 0; i < keyframe_threads->size(); i++)
-       {
-               if(keyframe_threads->get(i)->plugin == plugin)
-               {
+       for( int i=0; i<keyframe_threads->size(); ++i ) {
+               int plugin_id = keyframe_threads->get(i)->plugin_id;
+               if( plugin_id == plugin->orig_id ) {
                        keyframe_threads->get(i)->start_window(plugin, 0);
                        keyframe_gui_lock->unlock();
                        return;
@@ -3265,10 +3268,8 @@ void MWindow::show_keyframe_gui(Plugin *plugin)
        }
 
 // Find unused thread
-       for(int i = 0; i < keyframe_threads->size(); i++)
-       {
-               if(!keyframe_threads->get(i)->plugin)
-               {
+       for( int i=0; i<keyframe_threads->size(); ++i ) {
+               if( keyframe_threads->get(i)->plugin_id < 0 ) {
                        keyframe_threads->get(i)->start_window(plugin, 0);
                        keyframe_gui_lock->unlock();
                        return;
@@ -3279,7 +3280,6 @@ void MWindow::show_keyframe_gui(Plugin *plugin)
        KeyFrameThread *thread = new KeyFrameThread(this);
        keyframe_threads->append(thread);
        thread->start_window(plugin, 0);
-
        keyframe_gui_lock->unlock();
 }
 
@@ -3297,14 +3297,12 @@ SET_TRACE
 //printf("MWindow::show_plugin %d\n", __LINE__);
 SET_TRACE
 
-
        plugin_gui_lock->lock("MWindow::show_plugin");
-       for(int i = 0; i < plugin_guis->total; i++)
-       {
-// Pointer comparison
-               if(plugin_guis->get(i)->plugin == plugin)
-               {
-                       plugin_guis->get(i)->raise_window();
+       for( int i=0; i<plugin_guis->total; ++i ) {
+// Pointer/id comparison
+               PluginServer *plugin_gui = plugin_guis->get(i);
+               if( plugin_gui->plugin_id == plugin->orig_id ) {
+                       plugin_gui->raise_window();
                        done = 1;
                        break;
                }
@@ -3344,23 +3342,26 @@ SET_TRACE
 void MWindow::hide_plugin(Plugin *plugin, int lock)
 {
        plugin->show = 0;
+       return hide_plugin(plugin->orig_id, lock);
+}
+
+void MWindow::hide_plugin(int plugin_id, int lock)
+{
 // Update the toggle
        gui->lock_window("MWindow::hide_plugin");
        gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
        gui->unlock_window();
 
        if(lock) plugin_gui_lock->lock("MWindow::hide_plugin");
-       for(int i = 0; i < plugin_guis->total; i++)
-       {
-               if(plugin_guis->get(i)->plugin == plugin)
-               {
-                       PluginServer *ptr = plugin_guis->get(i);
-                       plugin_guis->remove(ptr);
+       for( int i=0; i<plugin_guis->total; ++i ) {
+               PluginServer *plugin_gui = plugin_guis->get(i);
+               if( plugin_gui->plugin_id == plugin_id ) {
+                       plugin_guis->remove(plugin_gui);
                        if(lock) plugin_gui_lock->unlock();
 // Last command executed in client side close
 // Schedule for deletion
-                       ptr->hide_gui();
-                       delete_plugin(ptr);
+                       plugin_gui->hide_gui();
+                       delete_plugin(plugin_gui);
 //sleep(1);
                        return;
                }
@@ -3409,11 +3410,10 @@ void MWindow::hide_keyframe_guis()
 void MWindow::hide_keyframe_gui(Plugin *plugin)
 {
        keyframe_gui_lock->lock("MWindow::hide_keyframe_gui");
-       for(int i = 0; i < keyframe_threads->size(); i++)
-       {
-               if(keyframe_threads->get(i)->plugin == plugin)
-               {
-                       keyframe_threads->get(i)->close_window();
+       for( int i = 0; i < keyframe_threads->size(); i++) {
+               KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
+               if( keyframe_gui->plugin_id == plugin->orig_id ) {
+                       keyframe_gui->close_window();
                        break;
                }
        }
@@ -3487,15 +3487,13 @@ void MWindow::update_keyframe_guis()
 {
 // Send new configuration to keyframe GUI's
        keyframe_gui_lock->lock("MWindow::update_keyframe_guis");
-       for(int i = 0; i < keyframe_threads->size(); i++)
-       {
-               KeyFrameThread *ptr = keyframe_threads->get(i);
-               if(edl->tracks->plugin_exists(ptr->plugin))
-                       ptr->update_gui(1);
+       for( int i=0; i<keyframe_threads->size(); ++i ) {
+               KeyFrameThread *keyframe_gui = keyframe_threads->get(i);
+               Plugin *plugin = edl->tracks->plugin_exists(keyframe_gui->plugin_id);
+               if( plugin )
+                       keyframe_gui->update_gui(1);
                else
-               {
-                       ptr->close_window();
-               }
+                       keyframe_gui->close_window();
        }
        keyframe_gui_lock->unlock();
 }
@@ -3505,55 +3503,42 @@ void MWindow::update_plugin_guis(int do_keyframe_guis)
 // Send new configuration to plugin GUI's
        plugin_gui_lock->lock("MWindow::update_plugin_guis");
 
-       for(int i = 0; i < plugin_guis->size(); i++)
-       {
-               PluginServer *ptr = plugin_guis->get(i);
-               if(edl->tracks->plugin_exists(ptr->plugin))
-                       ptr->update_gui();
-               else
-               {
-// Schedule for deletion if no plugin
-                       plugin_guis->remove_number(i);
-                       i--;
-
-                       ptr->hide_gui();
-                       delete_plugin(ptr);
+       for( int i=0; i<plugin_guis->size(); ++i ) {
+               PluginServer *plugin_gui = plugin_guis->get(i);
+               Plugin *plugin = edl->tracks->plugin_exists(plugin_gui->plugin_id);
+               if( plugin && plugin->show )
+                       plugin_gui->update_gui();
+               else {
+// Schedule for deletion if no plugin or not shown
+                       plugin_guis->remove_number(i--);
+                       plugin_gui->hide_gui();
+                       delete_plugin(plugin_gui);
                }
        }
 
 
 // Change plugin variable if not visible
        Track *track = edl->tracks->first;
-       while(track)
-       {
-               for(int i = 0; i < track->plugin_set.size(); i++)
-               {
+       for( ; track; track=track->next ) {
+               for( int i=0; i < track->plugin_set.size(); ++i ) {
                        Plugin *plugin = (Plugin*)track->plugin_set[i]->first;
-                       while(plugin)
-                       {
+                       for( ; plugin; plugin = (Plugin*)plugin->next ) {
                                int got_it = 0;
-                               for(int i = 0; i < plugin_guis->size(); i++)
-                               {
+                               for( int i=0; i<plugin_guis->size(); ++i ) {
                                        PluginServer *server = plugin_guis->get(i);
-                                       if(server->plugin == plugin)
-                                       {
+                                       if( server->plugin_id == plugin->orig_id ) {
                                                got_it = 1;
                                                break;
                                        }
                                }
-
-                               if(!got_it) plugin->show = 0;
-                               plugin = (Plugin*)plugin->next;
+                               if( !got_it ) plugin->show = 0;
                        }
                }
-
-               track = track->next;
        }
 
        plugin_gui_lock->unlock();
-
-
-       if(do_keyframe_guis) update_keyframe_guis();
+       if( do_keyframe_guis )
+               update_keyframe_guis();
 }
 
 void MWindow::stop_plugin_guis()
@@ -3562,10 +3547,8 @@ void MWindow::stop_plugin_guis()
        plugin_gui_lock->lock("MWindow::stop_plugin_guis");
 
        for( int i=0; i<plugin_guis->size(); ++i ) {
-               PluginServer *ptr = plugin_guis->get(i);
-               if( edl->tracks->plugin_exists(ptr->plugin) ) {
-                       ptr->render_stop();
-               }
+               PluginServer *plugin_gui = plugin_guis->get(i);
+               plugin_gui->render_stop();
        }
        plugin_gui_lock->unlock(); 
 }
@@ -3639,39 +3622,15 @@ int MWindow::get_tracking_direction()
 void MWindow::update_plugin_states()
 {
        plugin_gui_lock->lock("MWindow::update_plugin_states");
-       for(int i = 0; i < plugin_guis->total; i++)
-       {
-               int result = 0;
+       for( int i=0; i<plugin_guis->total; ++i ) {
 // Get a plugin GUI
-               Plugin *src_plugin = plugin_guis->get(i)->plugin;
                PluginServer *src_plugingui = plugin_guis->get(i);
-
-// Search for plugin in EDL.  Only the master EDL shows plugin GUIs.
-               for(Track *track = edl->tracks->first;
-                       track && !result;
-                       track = track->next)
-               {
-                       for(int j = 0;
-                               j < track->plugin_set.total && !result;
-                               j++)
-                       {
-                               PluginSet *plugin_set = track->plugin_set[j];
-                               for(Plugin *plugin = (Plugin*)plugin_set->first;
-                                       plugin && !result;
-                                       plugin = (Plugin*)plugin->next)
-                               {
-                                       if(plugin == src_plugin &&
-                                               !strcmp(plugin->title, src_plugingui->title)) result = 1;
-                               }
-                       }
-               }
-
-
+               int plugin_id = src_plugingui->plugin_id;
+               Plugin *src_plugin = edl->tracks->plugin_exists(plugin_id);
 // Doesn't exist anymore
-               if(!result)
-               {
-                       hide_plugin(src_plugin, 0);
-                       i--;
+               if( !src_plugin ) {
+                       hide_plugin(plugin_id, 0);
+                       --i;
                }
        }
        plugin_gui_lock->unlock();
@@ -3680,10 +3639,8 @@ void MWindow::update_plugin_states()
 
 void MWindow::update_plugin_titles()
 {
-       for(int i = 0; i < plugin_guis->total; i++)
-       {
+       for( int i=0; i<plugin_guis->total; ++i )
                plugin_guis->get(i)->update_title();
-       }
 }
 
 int MWindow::asset_to_edl(EDL *new_edl,
@@ -4287,7 +4244,10 @@ void MWindow::save_project(const char *dir, int save_mode, int overwrite, int re
        char progress_title[BCTEXTLEN];
        sprintf(progress_title, _("Saving to %s:\n"), dir);
        int total_assets = save_edl->assets->total();
+       gui->lock_window("MWindow::save_project");
        MainProgressBar *progress = mainprogress->start_progress(progress_title, total_assets);
+       gui->unlock_window();
+
        int ret = 0;
        Asset *current = save_edl->assets->first;
        for( int i=0; !ret && current; ++i, current=NEXT ) {