X-Git-Url: https://git.cinelerra-gg.org/git/?p=goodguy%2Fcinelerra.git;a=blobdiff_plain;f=cinelerra-5.1%2Fcinelerra%2Fmwindow.C;h=2918e23e63e59e4035bb86e2b07059ea0536fd2e;hp=f245018ad465f1dd1d1b41c2c5a0c59a0a7e9467;hb=686c4d754c80b9865c0a5a7315c5fa4d0d39f4a7;hpb=e6b9eb867719075e4c4bb71a7bc08e11652e9062 diff --git a/cinelerra-5.1/cinelerra/mwindow.C b/cinelerra-5.1/cinelerra/mwindow.C index f245018a..2918e23e 100644 --- a/cinelerra-5.1/cinelerra/mwindow.C +++ b/cinelerra-5.1/cinelerra/mwindow.C @@ -296,6 +296,7 @@ MWindow::~MWindow() plugin_gui_lock->unlock(); hide_keyframe_guis(); clean_indexes(); + clean_backups(); save_defaults(); // Give up and go to a movie // cant run valgrind if this is used @@ -984,6 +985,58 @@ void MWindow::init_preferences() YUV::yuv.yuv_set_colors(preferences->yuv_color_space, preferences->yuv_color_range); } +void MWindow::clean_backups() +{ + FileSystem fs; + int total_excess; + long oldest = 0; + int oldest_item = -1; + char string[BCTEXTLEN]; + +// Delete extra backups + fs.set_filter("backup*.prev_*"); + fs.complete_path(preferences->index_directory); + fs.update(preferences->index_directory); + + // set to 50 for now + // total_excess = fs.dir_list.total - preferences->index_count; + total_excess = fs.dir_list.total - 50; + printf("Total excess of backups: %i \n", total_excess); + +//printf("MWindow::clean_backups 1 %d\n", fs.dir_list.total); + + while(total_excess > 0) + { +// Get oldest + for(int i = 0; i < fs.dir_list.total; i++) + { + fs.join_names(string, preferences->index_directory, fs.dir_list[i]->name); + + if(i == 0 || fs.get_date(string) <= oldest) + { + oldest = fs.get_date(string); + oldest_item = i; + } + } + + if(oldest_item >= 0) + { +// Remove backup file + fs.join_names(string, + preferences->index_directory, + fs.dir_list[oldest_item]->name); +//printf("MWindow::clean_backups 1 %s\n", string); + if(remove(string)) + perror("delete_backups"); + delete fs.dir_list[oldest_item]; + fs.dir_list.remove_number(oldest_item); + + } + + total_excess--; + } +} + void MWindow::clean_indexes() { FileSystem fs; @@ -2997,6 +3050,25 @@ void MWindow::show_vwindow(int raise) gui->mainmenu->show_vwindow->set_checked(1); } + +void MWindow::hide_vwindow(int raise) +{ + session->show_vwindow = 0; + int total_running = 0; + + for(int j = 0; j < vwindows.size(); j++) { + VWindow *vwindow = vwindows[j]; + if( !vwindow->is_running() ) continue; + total_running++; + if( !raise && !vwindow->gui->is_hidden() ) continue; + vwindow->gui->lock_window("MWindow::show_vwindow"); + vwindow->gui->hide_window(0); + vwindow->gui->unlock_window(); + } + gui->mainmenu->show_vwindow->set_checked(0); +} + + void MWindow::show_awindow() { session->show_awindow = 1; @@ -3008,6 +3080,17 @@ void MWindow::show_awindow() gui->mainmenu->show_awindow->set_checked(1); } +void MWindow::hide_awindow() +{ + session->show_awindow = 0; + + awindow->gui->lock_window("MWindow::show_awindow"); + awindow->gui->hide_window(); + awindow->gui->unlock_window(); + gui->mainmenu->show_awindow->set_checked(0); +} + + char *MWindow::get_cwindow_display() { char *x11_host = screens < 2 || session->window_config == 0 ? @@ -3023,6 +3106,18 @@ void MWindow::show_cwindow() gui->mainmenu->show_cwindow->set_checked(1); } + +void MWindow::hide_cwindow() +{ + session->show_cwindow = 0; + + cwindow->gui->lock_window("MWindow::show_cwindow"); + cwindow->gui->hide_window(); + cwindow->gui->unlock_window(); + gui->mainmenu->show_cwindow->set_checked(0); +} + + void MWindow::show_gwindow() { session->show_gwindow = 1; @@ -3035,6 +3130,7 @@ void MWindow::show_gwindow() gui->mainmenu->show_gwindow->set_checked(1); } + void MWindow::hide_gwindow() { session->show_gwindow = 0; @@ -3042,6 +3138,7 @@ void MWindow::hide_gwindow() gwindow->gui->lock_window("MWindow::show_gwindow"); gwindow->gui->hide_window(); gwindow->gui->unlock_window(); + gui->mainmenu->show_gwindow->set_checked(0); } void MWindow::show_lwindow() @@ -3055,6 +3152,17 @@ void MWindow::show_lwindow() gui->mainmenu->show_lwindow->set_checked(1); } +void MWindow::hide_lwindow() +{ + session->show_lwindow = 0; + + lwindow->gui->lock_window("MWindow::show_lwindow"); + lwindow->gui->hide_window(); + lwindow->gui->unlock_window(); + gui->mainmenu->show_lwindow->set_checked(0); +} + + void MWindow::restore_windows() { gui->unlock_window(); @@ -3084,7 +3192,7 @@ void MWindow::restore_windows() cwindow->gui->unlock_window(); } else if( session->show_cwindow && cwindow->gui->is_hidden() ) - cwindow->show_window(); + show_cwindow(); if( !session->show_gwindow && !gwindow->gui->is_hidden() ) { gwindow->gui->lock_window("MWindow::restore_windows"); @@ -4215,6 +4323,25 @@ void MWindow::get_backup_path(char *path, int len) cp += snprintf(cp, ep-cp, idx ? BACKUPn_FILE : BACKUP_FILE, idx); } +void MWindow::create_timestamped_copy_from_previous_backup(char *previouspath) +{ + if (previouspath == NULL) return; + char backup_path[BCTEXTLEN]; + backup_path[0] = 0; + time_t now = time(NULL); + struct tm* currenttime = localtime(&now); + snprintf(backup_path, sizeof(backup_path), + "%s/%s_%d%.2d%.2d_%.2d%.2d%.2d", + File::get_config_path(), BACKUP_FILE1, + currenttime->tm_year + 1900, + currenttime->tm_mon + 1, + currenttime->tm_mday, + currenttime->tm_hour, + currenttime->tm_min, + currenttime->tm_sec); + rename(previouspath, backup_path); +} + void MWindow::save_backup() { FileXML file; @@ -4225,6 +4352,8 @@ void MWindow::save_backup() snprintf(backup_path1, sizeof(backup_path1), "%s/%s", File::get_config_path(), BACKUP_FILE1); get_backup_path(backup_path, sizeof(backup_path)); + if( preferences->ongoing_backups ) + create_timestamped_copy_from_previous_backup(backup_path1); rename(backup_path, backup_path1); edl->save_xml(&file, backup_path); file.terminate_string(); @@ -4493,11 +4622,14 @@ static inline int gcd(int m, int n) int MWindow::create_aspect_ratio(float &w, float &h, int width, int height) { w = 1; h = 1; + double ar; + if(!width || !height) return 1; if( width == 720 && (height == 480 || height == 576) ) { w = 4; h = 3; return 0; // for NTSC and PAL } - double ar = (double)width / height; + + ar = (double)width / height; // square-ish pixels if( EQUIV(ar, 1.0000) ) return 0; if( EQUIV(ar, 1.3333) ) { w = 4; h = 3; return 0; } @@ -4505,6 +4637,8 @@ int MWindow::create_aspect_ratio(float &w, float &h, int width, int height) if( EQUIV(ar, 2.1111) ) { w = 19; h = 9; return 0; } if( EQUIV(ar, 2.2222) ) { w = 20; h = 9; return 0; } if( EQUIV(ar, 2.3333) ) { w = 21; h = 9; return 0; } + if( EQUIV(ar, 2.37037) ) { w = 64; h = 27; return 0; } + int ww = width, hh = height; // numerator, denominator must be under mx int mx = 255, n = gcd(ww, hh); @@ -5048,12 +5182,26 @@ int MWindow::select_asset(Asset *asset, int vstream, int astream, int delete_tra session->output_w = width; session->output_h = height; session->frame_rate = framerate; + session->interlace_mode = asset->interlace_mode; // not, asset->actual_width/actual_height asset->width = session->output_w; asset->height = session->output_h; asset->frame_rate = session->frame_rate; + create_aspect_ratio(session->aspect_w, session->aspect_h, session->output_w, session->output_h); + float ar = asset->aspect_ratio; + if (ar) { + //printf ("Aspect ratio from asset: %f \n", ar); + if( EQUIV(ar, 1.3333) ) { session->aspect_w = 4; session->aspect_h = 3; } + if( EQUIV(ar, 1.7777) ) { session->aspect_w = 16; session->aspect_h = 9; } + if( EQUIV(ar, 2.1111) ) { session->aspect_w = 19; session->aspect_h = 9; } + if( EQUIV(ar, 2.2222) ) { session->aspect_w = 20; session->aspect_h = 9; } + if( EQUIV(ar, 2.3333) ) { session->aspect_w = 21; session->aspect_h = 9; } + if( EQUIV(ar, 2.370370) ) { session->aspect_w = 64; session->aspect_h = 27; } + } + + Track *track = edl->tracks->first; for( Track *next_track=0; track; track=next_track ) { next_track = track->next;