add timecode units/alignment/probe, add prefs auto_rotate,
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / mwindow.C
index 0fe6752f3598394b1fe16e6d1900e18a6c0631ba..7d0c140f17a90e1e986283c49f7822ac3041fd19 100644 (file)
@@ -243,6 +243,7 @@ MWindow::MWindow()
        in_destructor = 0;
        speed_edl = 0;
        beeper = 0;
+       redraw_tracks = 0;
        shuttle = 0;
        wintv = 0;
        x10tv = 0;
@@ -265,9 +266,10 @@ MWindow::~MWindow()
 #ifdef HAVE_DVB
        gui->channel_info->stop();
 #endif
-       delete beeper;
-       delete create_bd;       create_bd = 0;
-       delete create_dvd;      create_dvd = 0;
+       delete beeper;          beeper = 0;
+       delete redraw_tracks;   redraw_tracks = 0;
+       delete create_bd;       create_bd = 0;
+       delete create_dvd;      create_dvd = 0;
 #ifdef HAVE_SHUTTLE
        delete shuttle;         shuttle = 0;
 #endif
@@ -347,8 +349,9 @@ MWindow::~MWindow()
        delete gui;             gui = 0;
        delete mainindexes;     mainindexes = 0;
        delete mainprogress;    mainprogress = 0;
-       delete audio_cache;     audio_cache = 0;  // delete the cache after the assets
-       delete video_cache;     video_cache = 0;  // delete the cache after the assets
+ // delete the caches after the assets
+       if( audio_cache ) { audio_cache->remove_user();  audio_cache = 0; }
+       if( video_cache ) { video_cache->remove_user();  video_cache = 0; }
        delete frame_cache;     frame_cache = 0;
        delete wave_cache;      wave_cache = 0;
        delete plugin_guis;     plugin_guis = 0;
@@ -1210,6 +1213,20 @@ ZWindow *MWindow::get_mixer(Mixer *&mixer)
        return zwindow;
 }
 
+ZWindow *MWindow::get_mixer(int idx)
+{
+       ZWindow *zwindow = 0;
+       zwindows_lock->lock("MWindow::get_mixer");
+       for( int i=0; !zwindow && i<zwindows.size(); ++i ) {
+               ZWindow *zwdw = zwindows[i];
+               if( !zwdw->running() ) continue;
+               if( zwdw->idx != idx ) continue;
+               zwindow = zwindows[i];
+       }
+       zwindows_lock->unlock();
+       return zwindow;
+}
+
 void MWindow::close_mixer(ZWindow *zwindow)
 {
        zwindows_lock->lock("MWindow::close_mixer 0");
@@ -1296,11 +1313,11 @@ void MWindow::handle_mixers(EDL *edl, int command, int wait_tracking,
                        k = mixer->mixer_ids.size();
                        while( --k >= 0 && track->get_mixer_id() != mixer->mixer_ids[k] );
                        if( k >= 0 ) {
-                               track->record = 1;
+                               track->armed = 1;
                                track->play = track->data_type == TRACK_VIDEO ? 1 : 0;
                        }
                        else
-                               track->record = track->play = 0;
+                               track->armed = track->play = 0;
                }
                zwindow->change_source(mixer_edl);
                zwindow->handle_mixer(command, 0,
@@ -1355,7 +1372,7 @@ ZWindow *MWindow::create_mixer(Indexable *indexable, double position)
        Mixer *mixer = 0;
        ZWindow *zwindow = get_mixer(mixer);
        while( track ) {
-               track->play = track->record = 0;
+               track->play = track->armed = 0;
                if( track->data_type == TRACK_VIDEO ) {
                        sprintf(track->title, _("Mixer %d"), zwindow->idx);
                }
@@ -1498,6 +1515,14 @@ void MWindow::tile_mixers()
        }
 }
 
+void MWindow::set_gang_tracks(int v)
+{
+       edl->session->gang_tracks = v;
+       gui->update(1, 1, 0, 0, 1, 0, 0);
+       gui->flush();
+}
+
+
 void MWindow::init_cache()
 {
        audio_cache = new CICache(preferences);
@@ -1768,7 +1793,7 @@ int MWindow::put_commercial()
        //check it
        for(Track *track=tracks->first; track && !errmsg; track=track->next) {
                if( track->data_type != TRACK_VIDEO ) continue;
-               if( !track->record ) continue;
+               if( !track->armed ) continue;
                if( count > 0 ) { errmsg = _("multiple video tracks"); break; }
                ++count;
                int64_t units_start = track->to_units(start,0);
@@ -1788,7 +1813,7 @@ int MWindow::put_commercial()
        //run it
        for(Track *track=tracks->first; track && !errmsg; track=track->next) {
                if( track->data_type != TRACK_VIDEO ) continue;
-               if( !track->record ) continue;
+               if( !track->armed ) continue;
                int64_t units_start = track->to_units(start,0);
                int64_t units_end = track->to_units(end,0);
                Edits *edits = track->edits;
@@ -2468,8 +2493,6 @@ int MWindow::to_proxy(Asset *asset, int new_scale, int new_use_scaler)
                for( int i=0,n=edl->nested_edls.size(); i<n; ++i ) {
                        EDL *orig_nested = edl->nested_edls[i];
                        char new_path[BCTEXTLEN];
-                       if( !ProxyRender::from_proxy_path(new_path, orig_nested, proxy_scale) )
-                               continue;
                        proxy_render.to_proxy_path(new_path, orig_nested, proxy_scale);
 // test if proxy asset was already added to proxy_assets
                        int got_it = 0;
@@ -2973,6 +2996,7 @@ void MWindow::show_lwindow()
 
 void MWindow::restore_windows()
 {
+       gui->unlock_window();
        if( !session->show_vwindow ) {
                for( int i=0, n=vwindows.size(); i<n; ++i ) {
                        VWindow *vwindow = vwindows[i];
@@ -3017,6 +3041,7 @@ void MWindow::restore_windows()
        else if( session->show_lwindow && lwindow->gui->is_hidden() )
                show_lwindow();
 
+       gui->lock_window("MWindow::restore_windows");
        gui->focus();
 }
 
@@ -3405,7 +3430,7 @@ int MWindow::get_hash_color(Edit *edit)
        char path[BCTEXTLEN];
        if( !edit->asset || edit->track->data_type != TRACK_VIDEO ||
            edl->session->proxy_scale == 1 ||
-           ProxyRender::from_proxy_path(path, idxbl, edl->session->proxy_scale) )
+           ProxyRender::from_proxy_path(path, (Asset*)idxbl, edl->session->proxy_scale) )
                strcpy(path, idxbl->path);
        char *cp = strrchr(path, '/');
        cp = !cp ? path : cp+1;
@@ -3706,6 +3731,7 @@ void MWindow::update_project(int load_mode)
 
        if( load_mode == LOADMODE_REPLACE ||
            load_mode == LOADMODE_REPLACE_CONCATENATE ) {
+               edl->session->timecode_offset = 0;
                delete gui->keyvalue_popup;
                gui->keyvalue_popup = 0;
                gui->load_panes();
@@ -3927,6 +3953,7 @@ int MWindow::save(int save_as)
        for( int i=stack.size(); --i>=0;  ) {
                StackItem &item = stack[i];
                Indexable *idxbl = item.idxbl;
+               if( !idxbl ) continue;
                if( idxbl->is_asset ) {
                        Asset *asset = (Asset *)idxbl;
                        if( asset->format == FILE_REF ) {
@@ -3934,8 +3961,8 @@ int MWindow::save(int save_as)
                                        return 1;
                        }
                }
-               else if( item.new_edl != item.idxbl )
-                       item.new_edl->overwrite_clip((EDL*)item.idxbl);
+               else if( item.new_edl != idxbl )
+                       item.new_edl->overwrite_clip((EDL*)idxbl);
        }
        EDL *new_edl = stack.size() ? stack[0].edl : edl;
        save(new_edl, path, 1);
@@ -3978,7 +4005,7 @@ void MWindow::clip_to_media()
                char *bp = strrchr(clip->local_session->clip_title, '/');
                bp = bp ? bp+1 : clip->local_session->clip_title;
                cp += snprintf(cp, ep-cp, "%s", bp);
-               EDL *nested = edl->new_nested_edl(clip, path);
+               EDL *nested = edl->new_nested_clip(clip, path);
                edl->clips.remove(clip);
                clip->remove_user();
                mainindexes->add_indexable(nested);
@@ -4441,7 +4468,9 @@ int MWindow::create_aspect_ratio(float &w, float &h, int width, int height)
 
 void MWindow::reset_caches()
 {
-       awindow->gui->stop_vicon_drawing();
+       int locked  = gui->get_window_lock();
+       if( locked ) gui->unlock_window();
+       awindow->gui->stop_vicon_drawing(1);
        frame_cache->remove_all();
        wave_cache->remove_all();
        audio_cache->remove_all();
@@ -4461,11 +4490,12 @@ void MWindow::reset_caches()
                if( vwindow->playback_engine->video_cache )
                        vwindow->playback_engine->video_cache->remove_all();
        }
+       if( locked ) gui->lock_window("MWindow::reset_caches");
 }
 
 void MWindow::remove_from_caches(Indexable *idxbl)
 {
-       awindow->gui->stop_vicon_drawing();
+       awindow->gui->stop_vicon_drawing(1);
        frame_cache->remove_item(idxbl);
        wave_cache->remove_item(idxbl);
        if( gui->render_engine &&
@@ -4505,7 +4535,7 @@ void MWindow::remove_from_caches(Indexable *idxbl)
 void MWindow::remove_assets_from_project(int push_undo, int redraw, int delete_indexes,
                ArrayList<Indexable*> *drag_assets, ArrayList<EDL*> *drag_clips)
 {
-       awindow->gui->stop_vicon_drawing();
+       awindow->gui->stop_vicon_drawing(1);
 
 // Remove from VWindow.
        if( drag_clips ) {
@@ -4751,31 +4781,30 @@ int MWindow::interrupt_indexes()
 
 void MWindow::next_time_format()
 {
-       switch(edl->session->time_format)
-       {
-               case TIME_HMS: edl->session->time_format = TIME_HMSF; break;
-               case TIME_HMSF: edl->session->time_format = TIME_SAMPLES; break;
-               case TIME_SAMPLES: edl->session->time_format = TIME_SAMPLES_HEX; break;
-               case TIME_SAMPLES_HEX: edl->session->time_format = TIME_FRAMES; break;
-               case TIME_FRAMES: edl->session->time_format = TIME_FEET_FRAMES; break;
-               case TIME_FEET_FRAMES: edl->session->time_format = TIME_SECONDS; break;
-               case TIME_SECONDS: edl->session->time_format = TIME_HMS; break;
+       switch( edl->session->time_format ) {
+       case TIME_HMS:          edl->session->time_format = TIME_HMSF;         break;
+       case TIME_HMSF:         edl->session->time_format = TIME_TIMECODE;     break;
+       case TIME_TIMECODE:     edl->session->time_format = TIME_FRAMES;       break;
+       case TIME_FRAMES:       edl->session->time_format = TIME_SAMPLES;      break;
+       case TIME_SAMPLES:      edl->session->time_format = TIME_SAMPLES_HEX;  break;
+       case TIME_SAMPLES_HEX:  edl->session->time_format = TIME_SECONDS;      break;
+       case TIME_SECONDS:      edl->session->time_format = TIME_FEET_FRAMES;  break;
+       case TIME_FEET_FRAMES:  edl->session->time_format = TIME_HMS;          break;
        }
-
        time_format_common();
 }
 
 void MWindow::prev_time_format()
 {
-       switch(edl->session->time_format)
-       {
-               case TIME_HMS: edl->session->time_format = TIME_SECONDS; break;
-               case TIME_SECONDS: edl->session->time_format = TIME_FEET_FRAMES; break;
-               case TIME_FEET_FRAMES: edl->session->time_format = TIME_FRAMES; break;
-               case TIME_FRAMES: edl->session->time_format = TIME_SAMPLES_HEX; break;
-               case TIME_SAMPLES_HEX: edl->session->time_format = TIME_SAMPLES; break;
-               case TIME_SAMPLES: edl->session->time_format = TIME_HMSF; break;
-               case TIME_HMSF: edl->session->time_format = TIME_HMS; break;
+       switch( edl->session->time_format ) {
+       case TIME_HMS:          edl->session->time_format = TIME_FEET_FRAMES;  break;
+       case TIME_HMSF:         edl->session->time_format = TIME_HMS;          break;
+       case TIME_TIMECODE:     edl->session->time_format = TIME_HMSF;         break;
+       case TIME_FRAMES:       edl->session->time_format = TIME_TIMECODE;     break;
+       case TIME_SAMPLES:      edl->session->time_format = TIME_FRAMES;       break;
+       case TIME_SAMPLES_HEX:  edl->session->time_format = TIME_SAMPLES;      break;
+       case TIME_SECONDS:      edl->session->time_format = TIME_SAMPLES_HEX;  break;
+       case TIME_FEET_FRAMES:  edl->session->time_format = TIME_SECONDS;      break;
        }
 
        time_format_common();
@@ -4989,7 +5018,7 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                                track->track_h = edl->session->output_h;
                        }
                        else if( delete_tracks )
-                               edl->tracks->delete_track(track);
+                               edl->tracks->delete_track(track, 0);
                }
                edl->retrack();
                edl->resample(old_framerate, session->frame_rate, TRACK_VIDEO);
@@ -5025,7 +5054,7 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra
                                                delete edit;
                                }
                                if( !track->edits->first )
-                                       edl->tracks->delete_track(track);
+                                       edl->tracks->delete_track(track, 0);
                        }
                }
                edl->rechannel();
@@ -5121,3 +5150,28 @@ int MWindow::get_cpus()
        return get_cpus(edl->session->output_w, edl->session->output_h);
 }
 
+void MWindow::draw_trackmovement()
+{
+       if( !redraw_tracks )
+               redraw_tracks = new DrawTrackMovement(this);
+       redraw_tracks->start();
+}
+
+DrawTrackMovement::DrawTrackMovement(MWindow *mwindow)
+ : Thread(1, 0, 0)
+{
+       this->mwindow = mwindow;
+}
+DrawTrackMovement::~DrawTrackMovement()
+{
+       join();
+}
+
+void DrawTrackMovement::run()
+{
+       mwindow->gui->lock_window("DrawTrackMovement::run");
+       mwindow->edl->tracks->update_y_pixels(mwindow->theme);
+       mwindow->gui->draw_trackmovement();
+       mwindow->gui->unlock_window();
+}
+