Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / assetpopup.C
index 51e3f886a609b0e7c3f97db366045c37a26c1b90..66b3361a29b7ec22aad033fad9fe8e9236b23740 100644 (file)
@@ -99,19 +99,15 @@ void AssetPopup::create_objects()
 
 void AssetPopup::paste_assets()
 {
 
 void AssetPopup::paste_assets()
 {
-// Collect items into the drag vectors for temporary storage
-       gui->lock_window("AssetPopup::paste_assets");
-       mwindow->gui->lock_window("AssetPopup::paste_assets");
-       mwindow->cwindow->gui->lock_window("AssetPopup::paste_assets");
-
        int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
        gui->collect_assets(proxy);
        int proxy = mwindow->edl->session->awindow_folder == AW_PROXY_FOLDER ? 1 : 0;
        gui->collect_assets(proxy);
+// Collect items into the drag vectors for temporary storage
+       gui->unlock_window();
+       mwindow->gui->lock_window("AssetPopup::paste_assets");
        mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
                mwindow->edl->tracks->first, 0);   // do not overwrite
        mwindow->paste_assets(mwindow->edl->local_session->get_selectionstart(1),
                mwindow->edl->tracks->first, 0);   // do not overwrite
-
-       gui->unlock_window();
        mwindow->gui->unlock_window();
        mwindow->gui->unlock_window();
-       mwindow->cwindow->gui->unlock_window();
+       gui->lock_window("AssetPopup::paste_assets");
 }
 
 void AssetPopup::match_size()
 }
 
 void AssetPopup::match_size()
@@ -302,8 +298,10 @@ AssetPopupBuildIndex::~AssetPopupBuildIndex()
 
 int AssetPopupBuildIndex::handle_event()
 {
 
 int AssetPopupBuildIndex::handle_event()
 {
+       popup->unlock_window();
 //printf("AssetPopupBuildIndex::handle_event 1\n");
        mwindow->rebuild_indices();
 //printf("AssetPopupBuildIndex::handle_event 1\n");
        mwindow->rebuild_indices();
+       popup->lock_window("AssetPopupBuildIndex::handle_event");
        return 1;
 }
 
        return 1;
 }
 
@@ -394,9 +392,11 @@ AssetPopupOpenMixer::~AssetPopupOpenMixer()
 
 int AssetPopupOpenMixer::handle_event()
 {
 
 int AssetPopupOpenMixer::handle_event()
 {
+       popup->unlock_window();
        mwindow->gui->lock_window("AssetPopupOpenMixer::handle_event");
        mwindow->create_mixers();
        mwindow->gui->unlock_window();
        mwindow->gui->lock_window("AssetPopupOpenMixer::handle_event");
        mwindow->create_mixers();
        mwindow->gui->unlock_window();
+       popup->lock_window("AssetPopupOpenMixer::handle_event");
        return 1;
 }
 
        return 1;
 }
 
@@ -413,14 +413,16 @@ AssetPopupInsertMixer::~AssetPopupInsertMixer()
 
 int AssetPopupInsertMixer::handle_event()
 {
 
 int AssetPopupInsertMixer::handle_event()
 {
+       popup->unlock_window();
        mwindow->gui->lock_window("AssetPopupInsertMixer::handle_event");
        mwindow->create_mixers(-1);
        mwindow->gui->unlock_window();
        mwindow->gui->lock_window("AssetPopupInsertMixer::handle_event");
        mwindow->create_mixers(-1);
        mwindow->gui->unlock_window();
+       popup->lock_window("AssetPopupInsertMixer::handle_event");
        return 1;
 }
 
 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
        return 1;
 }
 
 AssetPopupPaste::AssetPopupPaste(MWindow *mwindow, AssetPopup *popup)
- : BC_MenuItem(_("Paste"))
+ : BC_MenuItem(C_("Paste"))
 {
        this->mwindow = mwindow;
        this->popup = popup;
 {
        this->mwindow = mwindow;
        this->popup = popup;
@@ -683,6 +685,8 @@ AssetCopyWindow::AssetCopyWindow(AssetCopyDialog *copy_dialog)
        ACW_W, ACW_H, ACW_W, ACW_H, 1, 0, 1)
 {
        this->copy_dialog = copy_dialog;
        ACW_W, ACW_H, ACW_W, ACW_H, 1, 0, 1)
 {
        this->copy_dialog = copy_dialog;
+// *** CONTEXT_HELP ***
+       context_help_set_keyword("Moving clips");
 }
 
 AssetCopyWindow::~AssetCopyWindow()
 }
 
 AssetCopyWindow::~AssetCopyWindow()
@@ -816,6 +820,8 @@ AssetPasteWindow::AssetPasteWindow(AssetPasteDialog *paste_dialog)
        APW_W, APW_H, APW_W, APW_H, 1, 0, 1)
 {
        this->paste_dialog = paste_dialog;
        APW_W, APW_H, APW_W, APW_H, 1, 0, 1)
 {
        this->paste_dialog = paste_dialog;
+// *** CONTEXT_HELP ***
+       context_help_set_keyword("Moving clips");
 }
 
 AssetPasteWindow::~AssetPasteWindow()
 }
 
 AssetPasteWindow::~AssetPasteWindow()
@@ -892,12 +898,13 @@ int SnapshotMenuItem::handle_event()
        if( !edl->have_video() ) return 1;
 
        Preferences *preferences = mwindow->preferences;
        if( !edl->have_video() ) return 1;
 
        Preferences *preferences = mwindow->preferences;
-       char filename[BCTEXTLEN];
+       char filename[BCTEXTLEN], snapshot_path[BCTEXTLEN];
        static const char *exts[] = { "png", "jpg", "tif", "ppm" };
        time_t tt;     time(&tt);
        struct tm tm;  localtime_r(&tt,&tm);
        static const char *exts[] = { "png", "jpg", "tif", "ppm" };
        time_t tt;     time(&tt);
        struct tm tm;  localtime_r(&tt,&tm);
+       File::getenv_path(snapshot_path, preferences->snapshot_path);
        snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
        snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
-               preferences->snapshot_path, _("snap"),
+               snapshot_path, _("snap"),
                1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
                tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
        char *asset_path = FileSystem::basepath(filename);
                1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
                tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
        char *asset_path = FileSystem::basepath(filename);
@@ -942,7 +949,7 @@ int SnapshotMenuItem::handle_event()
                        processors > 1 ? 2 : 1, 0);
                VFrame ***frames = file.get_video_buffer();
                VFrame *frame = frames[0][0];
                        processors > 1 ? 2 : 1, 0);
                VFrame ***frames = file.get_video_buffer();
                VFrame *frame = frames[0][0];
-               TransportCommand command;
+               TransportCommand command(preferences);
                //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
                command.command = CURRENT_FRAME;
                command.get_edl()->copy_all(edl);
                //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
                command.command = CURRENT_FRAME;
                command.get_edl()->copy_all(edl);
@@ -950,8 +957,8 @@ int SnapshotMenuItem::handle_event()
                command.realtime = 0;
 
                RenderEngine render_engine(0, preferences, 0, 0);
                command.realtime = 0;
 
                RenderEngine render_engine(0, preferences, 0, 0);
-               CICache video_cache(preferences);
-               render_engine.set_vcache(&video_cache);
+               CICache *video_cache = new CICache(preferences);
+               render_engine.set_vcache(video_cache);
                render_engine.arm_command(&command);
 
                double position = edl->local_session->get_selectionstart(1);
                render_engine.arm_command(&command);
 
                double position = edl->local_session->get_selectionstart(1);
@@ -961,6 +968,7 @@ int SnapshotMenuItem::handle_event()
                if( !ret )
                        ret = file.write_video_buffer(1);
                file.close_file();
                if( !ret )
                        ret = file.write_video_buffer(1);
                file.close_file();
+               video_cache->remove_user();
        }
        if( !ret ) {
                asset->folder_no = AW_MEDIA_FOLDER;
        }
        if( !ret ) {
                asset->folder_no = AW_MEDIA_FOLDER;
@@ -1018,111 +1026,34 @@ int GrabshotMenuItem::handle_event()
 }
 
 GrabshotThread::GrabshotThread(MWindow *mwindow)
 }
 
 GrabshotThread::GrabshotThread(MWindow *mwindow)
- : Thread(1, 0, 0)
+ : BC_DragBox(mwindow->gui)
 {
        this->mwindow = mwindow;
 {
        this->mwindow = mwindow;
-       popup = 0;
-       done = -1;
 }
 }
+
 GrabshotThread::~GrabshotThread()
 {
 GrabshotThread::~GrabshotThread()
 {
-       delete popup;
 }
 
 void GrabshotThread::start(GrabshotMenuItem *menu_item)
 {
 }
 
 void GrabshotThread::start(GrabshotMenuItem *menu_item)
 {
-       popup = new GrabshotPopup(this, menu_item->mode);
-       popup->lock_window("GrabshotThread::start");
-       for( int i=0; i<4; ++i )
-               edge[i] = new BC_Popup(mwindow->gui, 0,0, 1,1, ORANGE, 1);
-       mwindow->gui->grab_buttons();
-       mwindow->gui->grab_cursor();
-       popup->grab(mwindow->gui);
-       popup->create_objects();
-       popup->show_window();
-       popup->unlock_window();
-       done = 0;
-       Thread::start();
+       mode = menu_item->mode;
+       start_drag();
 }
 
 }
 
-void GrabshotThread::run()
+int GrabshotThread::handle_done_event(int x0, int y0, int x1, int y1)
 {
 {
-       popup->lock_window("GrabshotThread::run 0");
-       while( !done ) {
-               popup->update();
-               popup->unlock_window();
-               enable_cancel();
-               Timer::delay(200);
-               disable_cancel();
-               popup->lock_window("GrabshotThread::run 1");
-       }
-       mwindow->gui->ungrab_cursor();
-       mwindow->gui->ungrab_buttons();
-       popup->ungrab(mwindow->gui);
-       for( int i=0; i<4; ++i ) delete edge[i];
-       popup->unlock_window();
-       delete popup;  popup = 0;
-}
+       int cx = x0,    cy = y0;
+       int cw = x1-x0, ch = y1-y0;
 
 
-GrabshotPopup::GrabshotPopup(GrabshotThread *grab_thread, int mode)
- : BC_Popup(grab_thread->mwindow->gui, 0,0, 16,16, -1,1)
-{
-       this->grab_thread = grab_thread;
-       this->mode = mode;
-       dragging = -1;
-       grab_color = ORANGE;
-       x0 = y0 = x1 = y1 = -1;
-       lx0 = ly0 = lx1 = ly1 = -1;
-}
-GrabshotPopup::~GrabshotPopup()
-{
-}
-
-int GrabshotPopup::grab_event(XEvent *event)
-{
-       int cur_drag = dragging;
-       switch( event->type ) {
-       case ButtonPress:
-               if( cur_drag > 0 ) return 1;
-               x0 = event->xbutton.x_root;
-               y0 = event->xbutton.y_root;
-               if( !cur_drag ) {
-                       draw_selection(-1);
-                       if( event->xbutton.button == RIGHT_BUTTON ) break;
-                       if( x0>=get_x() && x0<get_x()+get_w() &&
-                           y0>=get_y() && y0<get_y()+get_h() ) break;
-               }
-               x1 = x0;  y1 = y0;
-               draw_selection(1);
-               dragging = 1;
-               return 1;
-       case ButtonRelease:
-               dragging = 0;
-       case MotionNotify:
-               if( cur_drag > 0 ) {
-                       x1 = event->xbutton.x_root;
-                       y1 = event->xbutton.y_root;
-                       draw_selection(0);
-               }
-               return 1;
-       default:
-               return 0;
-       }
-
-       int cx = lx0,     cy = ly0;
-       int cw = lx1-lx0, ch = ly1-ly0;
-       hide_window();
-       sync_display();
-       grab_thread->done = 1;
-
-       MWindow *mwindow = grab_thread->mwindow;
        Preferences *preferences = mwindow->preferences;
        Preferences *preferences = mwindow->preferences;
-       char filename[BCTEXTLEN];
+       char filename[BCTEXTLEN], snapshot_path[BCTEXTLEN];
        static const char *exts[] = { "png", "jpg", "tif", "ppm" };
        time_t tt;     time(&tt);
        struct tm tm;  localtime_r(&tt,&tm);
        static const char *exts[] = { "png", "jpg", "tif", "ppm" };
        time_t tt;     time(&tt);
        struct tm tm;  localtime_r(&tt,&tm);
+       File::getenv_path(snapshot_path, preferences->snapshot_path);
        snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
        snprintf(filename,sizeof(filename),"%s/%s_%04d%02d%02d-%02d%02d%02d.%s",
-               preferences->snapshot_path, _("grab"),
+               snapshot_path, _("grab"),
                1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
                tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
        char *asset_path = FileSystem::basepath(filename);
                1900+tm.tm_year,1+tm.tm_mon,tm.tm_mday,
                tm.tm_hour,tm.tm_min,tm.tm_sec, exts[mode]);
        char *asset_path = FileSystem::basepath(filename);
@@ -1148,12 +1079,13 @@ int GrabshotPopup::grab_event(XEvent *event)
        }
 
 // no odd dimensions
        }
 
 // no odd dimensions
-       int rw = get_root_w(0), rh = get_root_h(0);
+       int rw = mwindow->gui->get_root_w(0);
+       int rh = mwindow->gui->get_root_h(0);
        if( cx < 0 ) { cw += cx;  cx = 0; }
        if( cy < 0 ) { ch += cy;  cy = 0; }
        if( cx+cw > rw ) cw = rw-cx;
        if( cy+ch > rh ) ch = rh-cy;
        if( cx < 0 ) { cw += cx;  cx = 0; }
        if( cy < 0 ) { ch += cy;  cy = 0; }
        if( cx+cw > rw ) cw = rw-cx;
        if( cy+ch > rh ) ch = rh-cy;
-       if( !cw || !ch ) return 1;
+       if( !cw || !ch ) return 0;
 
        VFrame vframe(cw,ch, BC_RGB888);
        if( cx+cw < rw ) ++cw;
 
        VFrame vframe(cw,ch, BC_RGB888);
        if( cx+cw < rw ) ++cw;
@@ -1196,37 +1128,3 @@ int GrabshotPopup::grab_event(XEvent *event)
        return 1;
 }
 
        return 1;
 }
 
-void GrabshotPopup::update()
-{
-       set_color(grab_color ^= GREEN);
-       draw_box(0,0, get_w(),get_h());
-       flash(1);
-}
-
-void GrabshotPopup::draw_selection(int show)
-{
-       if( show < 0 ) {
-               for( int i=0; i<4; ++i ) hide_window(0);
-               flush();
-               return;
-       }
-
-       int nx0 = x0 < x1 ? x0 : x1;
-       int nx1 = x0 < x1 ? x1 : x0;
-       int ny0 = y0 < y1 ? y0 : y1;
-       int ny1 = y0 < y1 ? y1 : y0;
-       lx0 = nx0;  lx1 = nx1;  ly0 = ny0;  ly1 = ny1;
-
-       --nx0;  --ny0;
-       BC_Popup **edge = grab_thread->edge;
-       edge[0]->reposition_window(nx0,ny0, nx1-nx0, 1);
-       edge[1]->reposition_window(nx1,ny0, 1, ny1-ny0);
-       edge[2]->reposition_window(nx0,ny1, nx1-nx0, 1);
-       edge[3]->reposition_window(nx0,ny0, 1, ny1-ny0);
-
-       if( show > 0 ) {
-               for( int i=0; i<4; ++i ) edge[i]->show_window(0);
-       }
-       flush();
-}
-