repeat play, in/out <> shortcuts, append to proj wording, cleanup
[goodguy/history.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 9bab2c61df5bee55bcb4c4c58f973d6939bbcb56..53b5a1937b5bfca4ff1b8bc3b07264e509f26771 100644 (file)
@@ -872,6 +872,20 @@ PluginServer* MWindow::scan_plugindb(char *title,
        return 0;
 }
 
+// repair session files with xlated plugin titles
+void MWindow::fix_plugin_title(char *title)
+{
+       for(int i = 0; i < plugindb->total; i++) {
+               PluginServer *server = plugindb->get(i);
+               if( !server->title ) continue;
+               const char *server_title = server->title;
+               if( !bstrcasecmp(title, _(server_title)) ) {
+                       strcpy(title, server_title);
+                       return;
+               }
+       }
+}
+
 int MWindow::plugin_exists(const char *plugin_path, ArrayList<PluginServer*> &plugins)
 {
        for( int i=0; i<plugins.size(); ++i )
@@ -1034,7 +1048,7 @@ void MWindow::init_theme()
                fprintf(stderr, _("MWindow::init_theme: prefered theme %s not found.\n"),
                         preferences->theme);
 
-       const char *default_theme = _(DEFAULT_THEME);
+       const char *default_theme = DEFAULT_THEME;
        if( !theme_plugin && strcasecmp(preferences->theme, default_theme) ) {
                fprintf(stderr, _("MWindow::init_theme: trying default theme %s\n"),
                        default_theme);
@@ -1203,7 +1217,7 @@ void MWindow::update_mixer_tracks()
 }
 
 void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
-               int use_inout, int update_refresh, int toggle_audio)
+               int use_inout, int update_refresh, int toggle_audio, int loop_play)
 {
        zwindows_lock->lock("MWindow::queue_mixers");
        for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
@@ -1235,14 +1249,14 @@ void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
                }
                zwindow->change_source(mixer_edl);
                zwindow->issue_command(command,
-                       wait_tracking, use_inout, update_refresh, toggle_audio);
+                       wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
        }
        zwindows_lock->unlock();
 }
 
 void MWindow::refresh_mixers()
 {
-       queue_mixers(edl,CURRENT_FRAME,0,0,1,0);
+       queue_mixers(edl,CURRENT_FRAME,0,0,1,0,0);
 }
 
 void MWindow::stop_mixers()
@@ -1250,7 +1264,7 @@ void MWindow::stop_mixers()
        for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
                ZWindow *zwindow = zwindows[vidx];
                if( zwindow->idx < 0 ) continue;
-               zwindow->issue_command(STOP, 0, 0, 0, 0);
+               zwindow->issue_command(STOP, 0, 0, 0, 0, 0);
        }
 }
 
@@ -1273,6 +1287,50 @@ void MWindow::close_mixers()
        }
 }
 
+void MWindow::create_mixers()
+{
+       if( !session->drag_assets->size() ) return;
+       undo->update_undo_before();
+
+       select_zwindow(0);
+       ArrayList<ZWindow *>new_mixers;
+
+       for( int i=0; i<session->drag_assets->total; ++i ) {
+               Indexable *indexable = session->drag_assets->values[i];
+               ArrayList<Indexable*> new_assets;
+               new_assets.append(indexable);
+               Track *track = edl->tracks->last;
+               load_assets(&new_assets, -1, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
+               track = !track ? edl->tracks->first : track->next;
+               Mixer *mixer = 0;
+               ZWindow *zwindow = get_mixer(mixer);
+               while( track ) {
+                       track->play = track->record = 0;
+                       if( track->data_type == TRACK_VIDEO ) {
+                               sprintf(track->title, _("Mixer %d"), zwindow->idx);
+                       }
+                       mixer->mixer_ids.append(track->get_mixer_id());
+                       track = track->next;
+               }
+               char *path = indexable->path;
+               char *tp = strrchr(path, '/');
+               if( !tp ) tp = path; else ++tp;
+               zwindow->set_title(tp);
+               new_mixers.append(zwindow);
+       }
+
+       tile_mixers();
+       for( int i=0; i<new_mixers.size(); ++i )
+               new_mixers[i]->start();
+
+       refresh_mixers();
+       save_backup();
+       undo->update_undo_after(_("create mixers"), LOAD_ALL);
+       restart_brender();
+       gui->update(1, 2, 1, 1, 1, 1, 0);
+       sync_parameters(CHANGE_ALL);
+}
+
 void MWindow::open_mixers()
 {
        for( int i=0; i<edl->mixers.size(); ++i ) {
@@ -1492,19 +1550,14 @@ void MWindow::restart_brender()
 //printf("MWindow::restart_brender 1\n");
        if( !brender_active || !preferences->use_brender ) return;
        if( !brender ) return;
-       int locked  = gui->get_window_lock();
-       if( locked ) gui->unlock_window();
        brender->restart(edl);
-       if( locked ) gui->lock_window("MWindow::restart_brender");
 }
 
 void MWindow::stop_brender()
 {
        if( !brender ) return;
-       int locked  = gui->get_window_lock();
-       if( locked ) gui->unlock_window();
+// cannot be holding mwindow->gui display lock
        brender->stop();
-       if( locked ) gui->lock_window("MWindow::stop_brender");
 }
 
 int MWindow::brender_available(int position)
@@ -1546,7 +1599,9 @@ void MWindow::set_brender_active(int v, int update)
        }
        else {
                edl->session->brender_start = edl->session->brender_end = 0;
+               gui->unlock_window();
                stop_brender();
+               gui->lock_window("MWindow::set_brender_active");
        }
        if( update ) {
                gui->update_timebar(0);
@@ -1668,6 +1723,11 @@ void MWindow::stop_playback(int wait)
        }
 }
 
+void MWindow::stop_transport()
+{
+       gui->stop_transport(gui->get_window_lock() ? "MWindow::stop_transport" : 0);
+}
+
 int MWindow::load_filenames(ArrayList<char*> *filenames,
        int load_mode,
        int update_filename)
@@ -2155,74 +2215,37 @@ void MWindow::test_plugins(EDL *new_edl, char *path)
 {
        char string[BCTEXTLEN];
 
-// Do a check weather plugins exist
-       for(Track *track = new_edl->tracks->first; track; track = track->next)
-       {
-               for(int k = 0; k < track->plugin_set.total; k++)
-               {
+// Do a check whether plugins exist
+       for( Track *track=new_edl->tracks->first; track; track=track->next ) {
+               for( int k=0; k<track->plugin_set.total; ++k ) {
                        PluginSet *plugin_set = track->plugin_set[k];
-                       for(Plugin *plugin = (Plugin*)plugin_set->first;
-                               plugin;
-                               plugin = (Plugin*)plugin->next)
-                       {
-                               if(plugin->plugin_type == PLUGIN_STANDALONE)
-                               {
+                       for( Plugin *plugin = (Plugin*)plugin_set->first;
+                                       plugin; plugin = (Plugin*)plugin->next ) {
+                               if( plugin->plugin_type != PLUGIN_STANDALONE ) continue;
 // ok we need to find it in plugindb
-                                       int plugin_found = 0;
-
-                                       for(int j = 0; j < plugindb->size(); j++)
-                                       {
-                                               PluginServer *server = plugindb->get(j);
-                                               if(server->title &&
-                                                       !strcasecmp(server->title, plugin->title) &&
-                                                       ((track->data_type == TRACK_AUDIO && server->audio) ||
-                                                       (track->data_type == TRACK_VIDEO && server->video)) &&
-                                                       (!server->transition))
-                                                       plugin_found = 1;
-                                       }
-
-                                       if (!plugin_found)
-                                       {
-                                               sprintf(string,
+                               PluginServer *server =
+                                       scan_plugindb(plugin->title, track->data_type);
+                               if( !server || server->transition ) {
+                                       sprintf(string,
        _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
          "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
-                                                       "effect", plugin->title,
-                                                       path);
-                                               MainError::show_error(string);
-                                       }
+                                               "effect", _(plugin->title), path);
+                                       MainError::show_error(string);
                                }
                        }
                }
 
-               for(Edit *edit = (Edit*)track->edits->first;
-                       edit;
-                       edit = (Edit*)edit->next)
-               {
-                       if (edit->transition)
-                       {
+               for( Edit *edit=track->edits->first; edit; edit=edit->next ) {
+                       if( !edit->transition ) continue;
 // ok we need to find transition in plugindb
-
-                               int transition_found = 0;
-                               for(int j = 0; j < plugindb->size(); j++)
-                               {
-                                       PluginServer *server = plugindb->get(j);
-                                       if(server->title &&
-                                               !strcasecmp(server->title, edit->transition->title) &&
-                                               ((track->data_type == TRACK_AUDIO && server->audio) ||
-                                               (track->data_type == TRACK_VIDEO && server->video)) &&
-                                               (server->transition))
-                                               transition_found = 1;
-                               }
-
-                               if (!transition_found)
-                               {
-                                       sprintf(string,
+                       PluginServer *server =
+                               scan_plugindb(edit->transition->title, track->data_type);
+                       if( !server || !server->transition ) {
+                               sprintf(string,
        _("The %s '%s' in file '%s' is not part of your installation of Cinelerra.\n"
          "The project won't be rendered as it was meant and Cinelerra might crash.\n"),
-                                               "transition", edit->transition->title,
-                                               path);
-                                       MainError::show_error(string);
-                               }
+                                       "transition", _(edit->transition->title), path);
+                               MainError::show_error(string);
                        }
                }
        }
@@ -3222,7 +3245,6 @@ void MWindow::update_project(int load_mode)
        const int debug = 0;
 
        if(debug) PRINT_TRACE
-       init_brender();
        edl->tracks->update_y_pixels(theme);
 
        if(debug) PRINT_TRACE
@@ -3236,6 +3258,7 @@ void MWindow::update_project(int load_mode)
        gui->update(1, 1, 1, 1, 1, 1, 1);
        if(debug) PRINT_TRACE
        gui->unlock_window();
+       init_brender();
 
        cwindow->gui->lock_window("MWindow::update_project 1");
        cwindow->update(0, 0, 1, 1, 1);
@@ -3262,6 +3285,10 @@ void MWindow::update_project(int load_mode)
                        if( !vwindow->is_running() ) continue;
                        vwindow->close_window();
                }
+               for( int i=0; i<edl->vwindow_edls.size(); ++i ) {
+                       VWindow *vwindow = get_viewer(1, -1);
+                       vwindow->change_source(i);
+               }
                if(debug) PRINT_TRACE
                select_zwindow(0);
                close_mixers();
@@ -3966,29 +3993,9 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                if( channels < 1 ) channels = 1;
                if( channels > 6 ) channels = 6;
                session->audio_tracks = session->audio_channels = channels;
-               switch( channels ) {
-               case 6:
-                       session->achannel_positions[0] = 90;
-                       session->achannel_positions[1] = 150;
-                       session->achannel_positions[2] = 30;
-                       session->achannel_positions[3] = 210;
-                       session->achannel_positions[4] = 330;
-                       session->achannel_positions[5] = 270;
-                       break;
-               case 2:
-                       session->achannel_positions[0] = 180;
-                       session->achannel_positions[1] = 0;
-                       break;
-               case 1:
-                       session->achannel_positions[1] = 90;
-                       break;
-               default: {
-                       if( !channels ) break;
-                       double t = 0, dt = 360./channels;
-                       for( int i=channels; --i>=0; t+=dt )
-                               session->achannel_positions[i] = int(t+0.5);
-                       break; }
-               }
+
+               int *achannel_positions = preferences->channel_positions[session->audio_channels-1];
+               memcpy(&session->achannel_positions, achannel_positions, sizeof(session->achannel_positions));
                remap_audio(MWindow::AUDIO_1_TO_1);
 
                if( delete_tracks ) {