PKGBUILD fix libva/vdpau deps
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindow.C
index f62df89b82f2ea99718954b03de6636e5413b97f..e86eb4b8dfadeb9a9c1e23b3aec4659a1857470b 100644 (file)
@@ -80,6 +80,7 @@
 #include "mainsession.h"
 #include "mainundo.h"
 #include "mbuttons.h"
+#include "mixersalign.h"
 #include "mutex.h"
 #include "mwindowgui.h"
 #include "mwindow.h"
@@ -240,6 +241,7 @@ MWindow::MWindow()
        speed_edl = 0;
        proxy_beep = 0;
        shuttle = 0;
+       mixers_align = 0;
 }
 
 
@@ -249,6 +251,10 @@ MWindow::~MWindow()
        run_lock->lock("MWindow::~MWindow");
        in_destructor = 1;
 //printf("MWindow::~MWindow %d\n", __LINE__);
+       if( wwindow && wwindow->is_running() )
+               wwindow->close_window();
+       if( twindow && twindow->is_running() )
+               twindow->close_window();
        gui->remote_control->deactivate();
        gui->record->stop();
 #ifdef HAVE_DVB
@@ -260,6 +266,7 @@ MWindow::~MWindow()
        delete shuttle;         shuttle = 0;
        delete batch_render;    batch_render = 0;
        delete render;          render = 0;
+       delete mixers_align;    mixers_align = 0;
        commit_commercial();
        if( commercials && !commercials->remove_user() ) commercials = 0;
        close_mixers();
@@ -286,16 +293,12 @@ MWindow::~MWindow()
        if( cwindow && cwindow->gui ) cwindow->gui->close(0);
        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();
        zwindows.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
@@ -307,8 +310,6 @@ MWindow::~MWindow()
        close_gui(cwindow);
        close_gui(lwindow);
        close_gui(gwindow);
-       close_gui(twindow);
-       close_gui(wwindow);
        vwindows.remove_all_objects();
        zwindows.remove_all_objects();
        gui->close(0);
@@ -938,14 +939,7 @@ void MWindow::init_preferences()
 {
        preferences = new Preferences;
        preferences->load_defaults(defaults);
-       const char *lv2_path = getenv("LV2_PATH");
-       if( lv2_path && strcmp(lv2_path, preferences->lv2_path) ) {
-               strncpy(preferences->lv2_path, lv2_path, sizeof(preferences->lv2_path));
-               remove_plugin_index();
-       }
-       else if( !lv2_path && preferences->lv2_path[0] ) {
-               File::setenv_path("LV2_PATH",preferences->lv2_path, 0);
-       }
+       File::setenv_path("LV2_PATH",preferences->lv2_path, 1);
        session = new MainSession(this);
        session->load_defaults(defaults);
        // set x11_host, screens, window_config
@@ -1188,8 +1182,12 @@ ZWindow *MWindow::get_mixer(Mixer *&mixer)
        zwindows_lock->lock("MWindow::get_mixer");
        if( !mixer ) mixer = edl->mixers.new_mixer();
        ZWindow *zwindow = 0;
-       for( int i=0; !zwindow && i<zwindows.size(); ++i )
-               if( zwindows[i]->idx < 0 ) zwindow = zwindows[i];
+       for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
+               ZWindow *zwdw = zwindows[i];
+               if( zwdw->running() ) continue;
+               if( zwdw->idx >= 0 ) continue;
+               zwindow = zwindows[i];
+       }
        if( !zwindow )
                zwindows.append(zwindow = new ZWindow(this));
        zwindow->idx = mixer->idx;
@@ -1259,10 +1257,10 @@ void MWindow::update_mixer_tracks()
        zwindows_lock->unlock();
 }
 
-void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
-               int use_inout, int update_refresh, int toggle_audio, int loop_play)
+void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
+               int use_inout, int toggle_audio, int loop_play, float speed)
 {
-       zwindows_lock->lock("MWindow::queue_mixers");
+       zwindows_lock->lock("MWindow::handle_mixers");
        for( int vidx=0; vidx<zwindows.size(); ++vidx ) {
                ZWindow *zwindow = zwindows[vidx];
                if( zwindow->idx < 0 ) continue;
@@ -1291,8 +1289,8 @@ void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
                                track->record = track->play = 0;
                }
                zwindow->change_source(mixer_edl);
-               zwindow->issue_command(command,
-                       wait_tracking, use_inout, update_refresh, toggle_audio, loop_play);
+               zwindow->handle_mixer(command, 0,
+                               use_inout, toggle_audio, loop_play, speed);
        }
        zwindows_lock->unlock();
 }
@@ -1300,7 +1298,7 @@ void MWindow::queue_mixers(EDL *edl, int command, int wait_tracking,
 void MWindow::refresh_mixers(int dir)
 {
        int command = dir >= 0 ? CURRENT_FRAME : LAST_FRAME;
-       queue_mixers(edl,command,0,0,1,0,0);
+       handle_mixers(edl, command, 0, 0, 0, 0, 0);
 }
 
 void MWindow::stop_mixers()
@@ -1308,7 +1306,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, 0);
+               zwindow->handle_mixer(STOP, 0, 0, 0, 0, 0);
        }
 }
 
@@ -1319,6 +1317,7 @@ void MWindow::close_mixers(int destroy)
        for( int i=zwindows.size(); --i>=0; ) {
                ZWindow *zwindow = zwindows[i];
                if( zwindow->idx < 0 ) continue;
+               zwindow->idx = -1;
                zwindow->destroy = destroy;
                ZWindowGUI *zgui = zwindow->zgui;
                zgui->lock_window("MWindow::select_zwindow 0");
@@ -1333,12 +1332,12 @@ void MWindow::close_mixers(int destroy)
        }
 }
 
-ZWindow *MWindow::create_mixer(Indexable *indexable)
+ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
 {
        ArrayList<Indexable*> new_assets;
        new_assets.append(indexable);
        Track *track = edl->tracks->last;
-       load_assets(&new_assets, 0, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
+       load_assets(&new_assets, position, LOADMODE_NEW_TRACKS, 0, 0, 0, 0, 0, 0);
        track = !track ? edl->tracks->first : track->next;
        Mixer *mixer = 0;
        ZWindow *zwindow = get_mixer(mixer);
@@ -1363,7 +1362,7 @@ ZWindow *MWindow::create_mixer(Indexable *indexable)
        return zwindow;
 }
 
-void MWindow::create_mixers()
+void MWindow::create_mixers(double position)
 {
        if( !session->drag_assets->size() &&
            !session->drag_clips->size() ) return;
@@ -1375,13 +1374,13 @@ void MWindow::create_mixers()
        for( int i=0; i<session->drag_assets->size(); ++i ) {
                Indexable *indexable = session->drag_assets->get(i);
                if( !indexable->have_video() ) continue;
-               ZWindow *zwindow = create_mixer(indexable);
+               ZWindow *zwindow = create_mixer(indexable, position);
                new_mixers.append(zwindow);
        }
        for( int i=0; i<session->drag_clips->size(); ++i ) {
                Indexable *indexable = (Indexable*)session->drag_clips->get(i);
                if( !indexable->have_video() ) continue;
-               ZWindow *zwindow = create_mixer(indexable);
+               ZWindow *zwindow = create_mixer(indexable, position);
                new_mixers.append(zwindow);
        }
 
@@ -1551,6 +1550,8 @@ void MWindow::init_menus()
        ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_NONE);
        ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_UPONE);
        ILACEFIXMETHODLISTADD(ILACE_FIXMETHOD_DOWNONE);
+
+       mixers_align = new MixersAlign(this);
 }
 
 void MWindow::init_indexes()
@@ -1589,10 +1590,15 @@ void MWindow::init_exportedl()
 void MWindow::init_shuttle()
 {
 #ifdef HAVE_SHUTTLE
-       const char *dev_name = Shuttle::probe();
-       if( dev_name ) {
+       int ret = Shuttle::probe();
+       if( ret >= 0 ) {
                shuttle = new Shuttle(this);
-               shuttle->start(dev_name);
+               if( shuttle->read_config_file() > 0 ) {
+                       printf("shuttle: bad config file\n");
+                       delete shuttle;  shuttle = 0;
+                       return;
+               }
+               shuttle->start(ret);
        }
 #endif
 }
@@ -1817,23 +1823,11 @@ void MWindow::stop_transport()
 
 void MWindow::undo_before(const char *description, void *creator)
 {
-       if( cwindow->playback_engine->is_playing_back ) {
-               undo_command = cwindow->playback_engine->command->command;
-               cwindow->playback_engine->que->send_command(STOP, CHANGE_NONE, 0, 0);
-               gui->unlock_window();
-               cwindow->playback_engine->interrupt_playback(1);
-               gui->lock_window(description);
-       }
        undo->update_undo_before(description, creator);
 }
 
 void MWindow::undo_after(const char *description, uint32_t load_flags, int changes_made)
 {
-       if( undo_command != COMMAND_NONE ) {
-               cwindow->playback_engine->que->send_command(undo_command, CHANGE_NONE, edl, 1, 0);
-               undo_command = COMMAND_NONE;
-       }
-
        undo->update_undo_after(description, load_flags, changes_made);
 }
 
@@ -1884,10 +1878,8 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
                sprintf(string, _("Loading %s"), new_asset->path);
                gui->show_message(string);
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
                ftype = new_file->open_file(preferences, new_asset, 1, 0);
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
                result = 1;
                switch( ftype ) {
@@ -1897,7 +1889,8 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                        if( new_asset->video_data &&
                            ((new_asset->width % 2) || (new_asset->height % 2)) ) {
                                char string[BCTEXTLEN];
-                               sprintf(string, _("%s's resolution is %dx%d.\nImages with odd dimensions may not decode properly."),
+                               sprintf(string, _("%s's resolution is %dx%d.\n"
+                                       "Images with odd dimensions may not decode properly."),
                                        new_asset->path, new_asset->width, new_asset->height);
                                MainError::show_error(string);
                        }
@@ -2025,9 +2018,7 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
                case FILE_IS_XML: {
                        FileXML xml_file;
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                        xml_file.read_from_file(filenames->get(i));
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                        const char *cin_version = 0;
                        while( !xml_file.read_tag() ) {
                                if( xml_file.tag.title_is("EDL") ) {
@@ -2060,7 +2051,6 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                                nested_edl->load_xml(&xml_file, LOAD_ALL);
                                int groups = nested_edl->regroup(session->group_number);
                                session->group_number += groups;
-//printf("MWindow::load_filenames %p %s\n", nested_edl, nested_edl->project_path);
                                new_edl->create_nested(nested_edl);
                                new_edl->set_path(filenames->get(i));
                                nested_edl->Garbage::remove_user();
@@ -2070,9 +2060,7 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                                new_edl->load_xml(&xml_file, LOAD_ALL);
                                int groups = new_edl->regroup(session->group_number);
                                session->group_number += groups;
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                                test_plugins(new_edl, filenames->get(i));
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
                                if( load_mode == LOADMODE_REPLACE ||
                                    load_mode == LOADMODE_REPLACE_CONCATENATE ) {
@@ -2118,34 +2106,28 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
 // Paste them.
 // Don't back up here.
-       if(new_edls.size())
-       {
+       if( new_edls.size() ) {
 // For pasting, clear the active region
-               if(load_mode == LOADMODE_PASTE ||
-                       load_mode == LOADMODE_NESTED)
-               {
+               if( load_mode == LOADMODE_PASTE ||
+                   load_mode == LOADMODE_NESTED ) {
                        double start = edl->local_session->get_selectionstart();
                        double end = edl->local_session->get_selectionend();
                        if(!EQUIV(start, end))
-                               edl->clear(start,
-                                       end,
+                               edl->clear(start, end,
                                        edl->session->labels_follow_edits,
                                        edl->session->plugins_follow_edits,
                                        edl->session->autos_follow_edits);
-               }
 
-               paste_edls(&new_edls, load_mode, 0, -1,
-                       edl->session->labels_follow_edits,
-                       edl->session->plugins_follow_edits,
-                       edl->session->autos_follow_edits,
-                       0); // overwrite
+                       paste_edls(&new_edls, load_mode, 0, -1,
+                               edl->session->labels_follow_edits,
+                               edl->session->plugins_follow_edits,
+                               edl->session->autos_follow_edits,
+                               0); // overwrite
+               }
+               else
+                       paste_edls(&new_edls, load_mode, 0, -1, 1, 1, 1, 0);
        }
 
-
-
-
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
-
 // Add new assets to EDL and schedule assets for index building.
        int got_indexes = 0;
        for( int i=0; i<new_edls.size(); ++i ) {
@@ -2158,7 +2140,6 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
        }
 
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
        for( int i=0; i<new_assets.size(); ++i ) {
                Asset *new_asset = new_assets[i];
 
@@ -2176,29 +2157,22 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                edl->assets->update(new_asset);
                got_indexes = 1;
        }
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
 // Start examining next batch of index files
        if(got_indexes) mainindexes->start_build();
-if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
 
 // Open plugin GUIs
        Track *track = edl->tracks->first;
-       while(track)
-       {
-               for(int j = 0; j < track->plugin_set.size(); j++)
-               {
+       while( track ) {
+               for( int j = 0; j < track->plugin_set.size(); j++ ) {
                        PluginSet *plugins = track->plugin_set[j];
                        Plugin *plugin = plugins->get_first_plugin();
 
-                       while(plugin)
-                       {
-                               if(load_mode == LOADMODE_REPLACE ||
-                                       load_mode == LOADMODE_REPLACE_CONCATENATE)
-                               {
-                                       if(plugin->plugin_type == PLUGIN_STANDALONE &&
-                                               plugin->show)
-                                       {
+                       while(plugin) {
+                               if( load_mode == LOADMODE_REPLACE ||
+                                   load_mode == LOADMODE_REPLACE_CONCATENATE ) {
+                                       if( plugin->plugin_type == PLUGIN_STANDALONE &&
+                                           plugin->show ) {
                                                show_plugin(plugin);
                                        }
                                }
@@ -2225,6 +2199,8 @@ if(debug) printf("MWindow::load_filenames %d\n", __LINE__);
                edl->local_session->loop_playback = 0;
                edl->local_session->set_selectionstart(0);
                edl->local_session->set_selectionend(0);
+               edl->local_session->unset_inpoint();
+               edl->local_session-> unset_outpoint();
                set_brender_active(0, 0);
                fit_selection();
                goto_start();
@@ -2761,6 +2737,12 @@ void MWindow::create_objects(int want_gui,
        BC_WindowBase::get_resources()->vframe_shm = 1;
 }
 
+int MWindow::uses_opengl()
+{
+       if( !playback_3d || !playback_3d->running() ) return 0;
+       PlaybackConfig *playback_config = edl->session->playback_config;
+       return playback_config->vconfig->driver == PLAYBACK_X11_GL ? 1 : 0;
+}
 
 void MWindow::show_splash()
 {
@@ -2949,25 +2931,30 @@ void MWindow::restore_windows()
        gui->focus();
 }
 
-void MWindow::save_layout(int no)
-{
-       char layout_path[BCTEXTLEN];
-       snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
-               File::get_config_path(), no);
-       session->save_file(layout_path);
-}
-
-void MWindow::load_layout(int no)
+void MWindow::load_layout(const char *layout)
 {
-       char layout_path[BCTEXTLEN];
-       snprintf(layout_path, sizeof(layout_path), "%s/" LAYOUT_FILE,
-               File::get_config_path(), no);
-       session->load_file(layout_path);
+       char path[BCTEXTLEN];
+       snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
+       session->load_file(path);
        restore_windows();
        gui->default_positions();
        save_defaults();
 }
 
+void MWindow::save_layout(const char *layout)
+{
+       char path[BCTEXTLEN];
+       snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
+       session->save_file(path);
+}
+
+void MWindow::delete_layout(const char *layout)
+{
+       char path[BCTEXTLEN];
+       snprintf(path, sizeof(path), "%s/%s", File::get_config_path(), layout);
+       unlink(path);
+}
+
 int MWindow::tile_windows(int window_config)
 {
        int need_reload = 0;
@@ -3083,35 +3070,24 @@ void MWindow::sync_parameters(int change_type)
        if( in_destructor ) return;
 
 // Sync engines which are playing back
-       if(cwindow->playback_engine->is_playing_back)
-       {
-               if(change_type == CHANGE_PARAMS)
-               {
+       if( cwindow->playback_engine->is_playing_back ) {
+               if( change_type == CHANGE_PARAMS ) {
 // TODO: block keyframes until synchronization is done
                        cwindow->playback_engine->sync_parameters(edl);
                }
-               else
+               else {
 // Stop and restart
-               {
                        int command = cwindow->playback_engine->command->command;
-                       cwindow->playback_engine->que->send_command(STOP,
-                               CHANGE_NONE,
-                               0,
-                               0);
 // Waiting for tracking to finish would make the restart position more
 // accurate but it can't lock the window to stop tracking for some reason.
 // Not waiting for tracking gives a faster response but restart position is
 // only as accurate as the last tracking update.
-                       cwindow->playback_engine->interrupt_playback(0);
-                       cwindow->playback_engine->que->send_command(command,
-                                       change_type,
-                                       edl,
-                                       1,
-                                       0);
+                       cwindow->playback_engine->transport_stop(0);
+                       cwindow->playback_engine->next_command->realtime = 1;
+                       cwindow->playback_engine->transport_command(command, change_type, edl, 0);
                }
        }
-       else
-       {
+       else {
                cwindow->refresh_frame(change_type);
        }
 }