2014-05-22 01:23:28 +02:00
// Copyright (c) 2014, Thomas Goyne <plorkyeran@aegisub.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
//
// Aegisub Project http://www.aegisub.org/
# include "project.h"
2014-06-02 19:04:25 +02:00
# include "ass_dialogue.h"
2014-05-22 01:23:28 +02:00
# include "ass_file.h"
# include "async_video_provider.h"
# include "audio_controller.h"
2014-07-09 16:22:49 +02:00
# include "audio_provider_factory.h"
2014-06-02 19:04:25 +02:00
# include "base_grid.h"
2014-05-22 01:23:28 +02:00
# include "charset_detect.h"
# include "compat.h"
# include "dialog_progress.h"
2014-05-22 21:07:15 +02:00
# include "dialogs.h"
2014-05-29 17:28:37 +02:00
# include "format.h"
2014-05-22 01:23:28 +02:00
# include "include/aegisub/context.h"
# include "include/aegisub/video_provider.h"
# include "mkv_wrap.h"
# include "options.h"
2014-06-02 19:04:25 +02:00
# include "selection_controller.h"
2014-05-22 01:23:28 +02:00
# include "subs_controller.h"
2014-06-02 19:04:25 +02:00
# include "utils.h"
2014-05-22 01:23:28 +02:00
# include "video_controller.h"
# include "video_display.h"
2014-07-09 16:22:49 +02:00
# include <libaegisub/audio/provider.h>
2014-05-29 17:28:37 +02:00
# include <libaegisub/format_path.h>
2014-05-22 01:23:28 +02:00
# include <libaegisub/fs.h>
# include <libaegisub/keyframe.h>
# include <libaegisub/log.h>
# include <libaegisub/make_unique.h>
# include <libaegisub/path.h>
# include <boost/algorithm/string/case_conv.hpp>
# include <boost/filesystem/operations.hpp>
# include <wx/msgdlg.h>
Project : : Project ( agi : : Context * c ) : context ( c ) {
OPT_SUB ( " Audio/Cache/Type " , & Project : : ReloadAudio , this ) ;
OPT_SUB ( " Audio/Provider " , & Project : : ReloadAudio , this ) ;
OPT_SUB ( " Provider/Audio/FFmpegSource/Decode Error Handling " , & Project : : ReloadAudio , this ) ;
OPT_SUB ( " Provider/Avisynth/Allow Ancient " , & Project : : ReloadVideo , this ) ;
OPT_SUB ( " Provider/Avisynth/Memory Max " , & Project : : ReloadVideo , this ) ;
OPT_SUB ( " Provider/Video/FFmpegSource/Decoding Threads " , & Project : : ReloadVideo , this ) ;
OPT_SUB ( " Provider/Video/FFmpegSource/Unsafe Seeking " , & Project : : ReloadVideo , this ) ;
OPT_SUB ( " Subtitle/Provider " , & Project : : ReloadVideo , this ) ;
OPT_SUB ( " Video/Force BT.601 " , & Project : : ReloadVideo , this ) ;
OPT_SUB ( " Video/Provider " , & Project : : ReloadVideo , this ) ;
}
Project : : ~ Project ( ) { }
2014-05-22 03:32:42 +02:00
void Project : : UpdateRelativePaths ( ) {
2015-08-22 03:17:48 +02:00
context - > ass - > Properties . audio_file = context - > path - > MakeRelative ( audio_file , " ?script " ) . generic_string ( ) ;
context - > ass - > Properties . video_file = context - > path - > MakeRelative ( video_file , " ?script " ) . generic_string ( ) ;
context - > ass - > Properties . timecodes_file = context - > path - > MakeRelative ( timecodes_file , " ?script " ) . generic_string ( ) ;
context - > ass - > Properties . keyframes_file = context - > path - > MakeRelative ( keyframes_file , " ?script " ) . generic_string ( ) ;
2014-05-22 01:23:28 +02:00
}
void Project : : ReloadAudio ( ) {
if ( audio_provider )
LoadAudio ( audio_file ) ;
}
void Project : : ReloadVideo ( ) {
2014-05-24 15:44:45 +02:00
if ( video_provider ) {
DoLoadVideo ( video_file ) ;
context - > videoController - > JumpToFrame ( context - > videoController - > GetFrameN ( ) ) ;
}
2014-05-22 01:23:28 +02:00
}
void Project : : ShowError ( wxString const & message ) {
wxMessageBox ( message , " Error loading file " , wxOK | wxICON_ERROR | wxCENTER , context - > parent ) ;
}
void Project : : ShowError ( std : : string const & message ) {
ShowError ( to_wx ( message ) ) ;
}
2014-05-22 03:32:42 +02:00
void Project : : SetPath ( agi : : fs : : path & var , const char * token , const char * mru , agi : : fs : : path const & value ) {
var = value ;
if ( * token )
2015-08-22 03:17:48 +02:00
context - > path - > SetToken ( token , value ) ;
2014-05-22 03:32:42 +02:00
if ( * mru )
config : : mru - > Add ( mru , value ) ;
UpdateRelativePaths ( ) ;
}
2014-06-02 19:04:25 +02:00
bool Project : : DoLoadSubtitles ( agi : : fs : : path const & path , std : : string encoding , ProjectProperties & properties ) {
2014-05-22 01:23:28 +02:00
try {
if ( encoding . empty ( ) )
encoding = CharSetDetect : : GetEncoding ( path ) ;
}
catch ( agi : : UserCancelException const & ) {
2014-06-02 19:04:25 +02:00
return false ;
2014-05-22 01:23:28 +02:00
}
2014-05-26 18:34:01 +02:00
catch ( agi : : fs : : FileNotFound const & ) {
config : : mru - > Remove ( " Subtitle " , path ) ;
2014-06-02 19:04:25 +02:00
ShowError ( path . string ( ) + " not found. " ) ;
return false ;
2014-05-26 18:34:01 +02:00
}
2014-05-22 01:23:28 +02:00
if ( encoding ! = " binary " ) {
// Try loading as timecodes and keyframes first since we can't
// distinguish them based on filename alone, and just ignore failures
// rather than trying to differentiate between malformed timecodes
// files and things that aren't timecodes files at all
2014-06-02 19:04:25 +02:00
try { DoLoadTimecodes ( path ) ; return false ; } catch ( . . . ) { }
try { DoLoadKeyframes ( path ) ; return false ; } catch ( . . . ) { }
2014-05-22 01:23:28 +02:00
}
try {
2014-06-02 19:04:25 +02:00
properties = context - > subsController - > Load ( path , encoding ) ;
2014-05-22 01:23:28 +02:00
}
2014-06-02 19:04:25 +02:00
catch ( agi : : UserCancelException const & ) { return false ; }
2014-05-22 01:23:28 +02:00
catch ( agi : : fs : : FileNotFound const & ) {
config : : mru - > Remove ( " Subtitle " , path ) ;
2014-06-02 19:04:25 +02:00
ShowError ( path . string ( ) + " not found. " ) ;
return false ;
2014-05-22 01:23:28 +02:00
}
catch ( agi : : Exception const & e ) {
2014-06-02 19:04:25 +02:00
ShowError ( e . GetMessage ( ) ) ;
return false ;
2014-05-22 01:23:28 +02:00
}
catch ( std : : exception const & e ) {
2014-06-02 19:04:25 +02:00
ShowError ( std : : string ( e . what ( ) ) ) ;
return false ;
2014-05-22 01:23:28 +02:00
}
catch ( . . . ) {
2014-06-02 19:04:25 +02:00
ShowError ( wxString ( " Unknown error " ) ) ;
return false ;
}
Selection sel ;
AssDialogue * active_line = nullptr ;
if ( ! context - > ass - > Events . empty ( ) ) {
int row = mid < int > ( 0 , properties . active_row , context - > ass - > Events . size ( ) - 1 ) ;
active_line = & * std : : next ( context - > ass - > Events . begin ( ) , row ) ;
sel . insert ( active_line ) ;
2014-05-22 01:23:28 +02:00
}
2014-06-02 19:04:25 +02:00
context - > selectionController - > SetSelectionAndActive ( std : : move ( sel ) , active_line ) ;
context - > subsGrid - > ScrollTo ( properties . scroll_position ) ;
return true ;
2014-05-22 01:23:28 +02:00
}
2014-11-16 22:25:17 +01:00
void Project : : LoadSubtitles ( agi : : fs : : path path , std : : string encoding , bool load_linked ) {
2014-06-02 19:04:25 +02:00
ProjectProperties properties ;
2014-11-16 22:25:17 +01:00
if ( DoLoadSubtitles ( path , encoding , properties ) & & load_linked )
2014-06-02 19:04:25 +02:00
LoadUnloadFiles ( properties ) ;
2014-05-22 01:23:28 +02:00
}
void Project : : CloseSubtitles ( ) {
context - > subsController - > Close ( ) ;
2015-08-22 03:17:48 +02:00
context - > path - > SetToken ( " ?script " , " " ) ;
2014-06-02 19:04:25 +02:00
LoadUnloadFiles ( context - > ass - > Properties ) ;
auto line = & * context - > ass - > Events . begin ( ) ;
context - > selectionController - > SetSelectionAndActive ( { line } , line ) ;
2014-05-22 01:23:28 +02:00
}
2014-06-02 19:04:25 +02:00
void Project : : LoadUnloadFiles ( ProjectProperties properties ) {
2014-05-22 01:23:28 +02:00
auto load_linked = OPT_GET ( " App/Auto/Load Linked Files " ) - > GetInt ( ) ;
if ( ! load_linked ) return ;
2015-08-22 03:17:48 +02:00
auto audio = context - > path - > MakeAbsolute ( properties . audio_file , " ?script " ) ;
auto video = context - > path - > MakeAbsolute ( properties . video_file , " ?script " ) ;
auto timecodes = context - > path - > MakeAbsolute ( properties . timecodes_file , " ?script " ) ;
auto keyframes = context - > path - > MakeAbsolute ( properties . keyframes_file , " ?script " ) ;
2014-05-22 01:23:28 +02:00
if ( video = = video_file & & audio = = audio_file & & keyframes = = keyframes_file & & timecodes = = timecodes_file )
return ;
if ( load_linked = = 2 ) {
2014-05-22 17:06:33 +02:00
wxString str = _ ( " Do you want to load/unload the associated files? " ) ;
str + = " \n " ;
auto append_file = [ & ] ( agi : : fs : : path const & p , wxString const & unload , wxString const & load ) {
if ( p . empty ( ) )
str + = " \n " + unload ;
else
2014-05-29 17:28:37 +02:00
str + = " \n " + agi : : wxformat ( load , p ) ;
2014-05-22 17:06:33 +02:00
} ;
if ( audio ! = audio_file )
append_file ( audio , _ ( " Unload audio " ) , _ ( " Load audio file: %s " ) ) ;
if ( video ! = video_file )
append_file ( video , _ ( " Unload video " ) , _ ( " Load video file: %s " ) ) ;
if ( timecodes ! = timecodes_file )
append_file ( timecodes , _ ( " Unload timecodes " ) , _ ( " Load timecodes file: %s " ) ) ;
if ( keyframes ! = keyframes_file )
append_file ( keyframes , _ ( " Unload keyframes " ) , _ ( " Load keyframes file: %s " ) ) ;
if ( wxMessageBox ( str , _ ( " (Un)Load files? " ) , wxYES_NO | wxCENTRE , context - > parent ) ! = wxYES )
2014-05-22 01:23:28 +02:00
return ;
}
bool loaded_video = false ;
if ( video ! = video_file ) {
if ( video . empty ( ) )
CloseVideo ( ) ;
else if ( ( loaded_video = DoLoadVideo ( video ) ) ) {
auto vc = context - > videoController . get ( ) ;
2014-06-02 19:04:25 +02:00
vc - > JumpToFrame ( properties . video_position ) ;
2014-05-22 03:32:42 +02:00
2014-06-02 19:04:25 +02:00
auto ar_mode = static_cast < AspectRatio > ( properties . ar_mode ) ;
2014-05-22 03:32:42 +02:00
if ( ar_mode = = AspectRatio : : Custom )
2014-06-02 19:04:25 +02:00
vc - > SetAspectRatio ( properties . ar_value ) ;
2014-05-22 03:32:42 +02:00
else
vc - > SetAspectRatio ( ar_mode ) ;
2014-06-02 19:04:25 +02:00
context - > videoDisplay - > SetZoom ( properties . video_zoom ) ;
2014-05-22 01:23:28 +02:00
}
}
if ( ! timecodes . empty ( ) ) LoadTimecodes ( timecodes ) ;
if ( ! keyframes . empty ( ) ) LoadKeyframes ( keyframes ) ;
if ( audio ! = audio_file ) {
if ( audio . empty ( ) )
CloseAudio ( ) ;
else
DoLoadAudio ( audio , false ) ;
}
2014-05-23 21:40:06 +02:00
else if ( loaded_video & & OPT_GET ( " Video/Open Audio " ) - > GetBool ( ) & & audio_file ! = video_file & & video_provider - > HasAudio ( ) )
2014-05-22 01:23:28 +02:00
DoLoadAudio ( video , true ) ;
}
void Project : : DoLoadAudio ( agi : : fs : : path const & path , bool quiet ) {
if ( ! progress )
progress = new DialogProgress ( context - > parent ) ;
try {
try {
2015-08-22 03:17:48 +02:00
audio_provider = GetAudioProvider ( path , * context - > path , progress ) ;
2014-05-22 01:23:28 +02:00
}
catch ( agi : : UserCancelException const & ) { return ; }
catch ( . . . ) {
config : : mru - > Remove ( " Audio " , path ) ;
throw ;
}
}
catch ( agi : : fs : : FileNotFound const & e ) {
2014-05-29 14:57:27 +02:00
return ShowError ( _ ( " The audio file was not found: " ) + to_wx ( e . GetMessage ( ) ) ) ;
2014-05-22 01:23:28 +02:00
}
2014-07-09 16:22:49 +02:00
catch ( agi : : AudioDataNotFound const & e ) {
2014-05-22 01:23:28 +02:00
if ( quiet ) {
2014-05-29 14:57:27 +02:00
LOG_D ( " video/open/audio " ) < < " File " < < video_file < < " has no audio data: " < < e . GetMessage ( ) ;
2014-05-22 01:23:28 +02:00
return ;
}
else
2014-05-29 14:57:27 +02:00
return ShowError ( _ ( " None of the available audio providers recognised the selected file as containing audio data. \n \n The following providers were tried: \n " ) + to_wx ( e . GetMessage ( ) ) ) ;
2014-05-22 01:23:28 +02:00
}
2014-07-09 16:22:49 +02:00
catch ( agi : : AudioProviderError const & e ) {
2014-05-29 14:57:27 +02:00
return ShowError ( _ ( " None of the available audio providers have a codec available to handle the selected file. \n \n The following providers were tried: \n " ) + to_wx ( e . GetMessage ( ) ) ) ;
2014-05-22 01:23:28 +02:00
}
catch ( agi : : Exception const & e ) {
2014-05-29 14:57:27 +02:00
return ShowError ( e . GetMessage ( ) ) ;
2014-05-22 01:23:28 +02:00
}
2014-05-22 03:32:42 +02:00
SetPath ( audio_file , " ?audio " , " Audio " , path ) ;
2014-05-22 01:23:28 +02:00
AnnounceAudioProviderModified ( audio_provider . get ( ) ) ;
}
2014-06-24 01:29:46 +02:00
void Project : : LoadAudio ( agi : : fs : : path path ) {
2014-05-22 01:23:28 +02:00
DoLoadAudio ( path , false ) ;
}
void Project : : CloseAudio ( ) {
AnnounceAudioProviderModified ( nullptr ) ;
audio_provider . reset ( ) ;
2014-05-22 03:32:42 +02:00
SetPath ( audio_file , " ?audio " , " " , " " ) ;
2014-05-22 01:23:28 +02:00
}
bool Project : : DoLoadVideo ( agi : : fs : : path const & path ) {
if ( ! progress )
progress = new DialogProgress ( context - > parent ) ;
try {
auto old_matrix = context - > ass - > GetScriptInfo ( " YCbCr Matrix " ) ;
video_provider = agi : : make_unique < AsyncVideoProvider > ( path , old_matrix , context - > videoController . get ( ) , progress ) ;
}
catch ( agi : : UserCancelException const & ) { return false ; }
catch ( agi : : fs : : FileSystemError const & err ) {
config : : mru - > Remove ( " Video " , path ) ;
ShowError ( to_wx ( err . GetMessage ( ) ) ) ;
return false ;
}
catch ( VideoProviderError const & err ) {
ShowError ( to_wx ( err . GetMessage ( ) ) ) ;
return false ;
}
2014-05-23 15:58:46 +02:00
AnnounceVideoProviderModified ( video_provider . get ( ) ) ;
2014-05-22 01:23:28 +02:00
UpdateVideoProperties ( context - > ass . get ( ) , video_provider . get ( ) , context - > parent ) ;
video_provider - > LoadSubtitles ( context - > ass . get ( ) ) ;
timecodes = video_provider - > GetFPS ( ) ;
keyframes = video_provider - > GetKeyFrames ( ) ;
2014-05-22 03:32:42 +02:00
2014-05-22 01:23:28 +02:00
timecodes_file . clear ( ) ;
keyframes_file . clear ( ) ;
2014-05-22 03:32:42 +02:00
SetPath ( video_file , " ?video " , " Video " , path ) ;
2014-05-22 01:23:28 +02:00
std : : string warning = video_provider - > GetWarning ( ) ;
if ( ! warning . empty ( ) )
wxMessageBox ( to_wx ( warning ) , " Warning " , wxICON_WARNING | wxOK ) ;
video_has_subtitles = false ;
if ( agi : : fs : : HasExtension ( path , " mkv " ) )
video_has_subtitles = MatroskaWrapper : : HasSubtitles ( path ) ;
AnnounceKeyframesModified ( keyframes ) ;
AnnounceTimecodesModified ( timecodes ) ;
return true ;
}
2014-06-24 01:29:46 +02:00
void Project : : LoadVideo ( agi : : fs : : path path ) {
2014-05-23 15:34:52 +02:00
if ( path . empty ( ) ) return ;
2014-05-22 01:23:28 +02:00
if ( ! DoLoadVideo ( path ) ) return ;
2014-05-23 15:34:52 +02:00
if ( OPT_GET ( " Video/Open Audio " ) - > GetBool ( ) & & audio_file ! = video_file & & video_provider - > HasAudio ( ) )
2014-05-22 01:23:28 +02:00
DoLoadAudio ( video_file , true ) ;
2014-05-23 21:36:28 +02:00
double dar = video_provider - > GetDAR ( ) ;
if ( dar > 0 )
context - > videoController - > SetAspectRatio ( dar ) ;
else
context - > videoController - > SetAspectRatio ( AspectRatio : : Default ) ;
context - > videoController - > JumpToFrame ( 0 ) ;
2014-05-22 01:23:28 +02:00
}
void Project : : CloseVideo ( ) {
AnnounceVideoProviderModified ( nullptr ) ;
video_provider . reset ( ) ;
2014-05-22 03:32:42 +02:00
SetPath ( video_file , " ?video " , " " , " " ) ;
2014-05-22 01:23:28 +02:00
video_has_subtitles = false ;
2014-05-23 21:36:28 +02:00
context - > ass - > Properties . ar_mode = 0 ;
context - > ass - > Properties . ar_value = 0.0 ;
context - > ass - > Properties . video_position = 0 ;
2014-05-22 01:23:28 +02:00
}
void Project : : DoLoadTimecodes ( agi : : fs : : path const & path ) {
timecodes = agi : : vfr : : Framerate ( path ) ;
2014-05-22 03:32:42 +02:00
SetPath ( timecodes_file , " " , " Timecodes " , path ) ;
2014-05-22 01:23:28 +02:00
AnnounceTimecodesModified ( timecodes ) ;
}
2014-06-24 01:29:46 +02:00
void Project : : LoadTimecodes ( agi : : fs : : path path ) {
2014-05-22 01:23:28 +02:00
try {
DoLoadTimecodes ( path ) ;
}
catch ( agi : : fs : : FileSystemError const & e ) {
2014-05-29 14:57:27 +02:00
ShowError ( e . GetMessage ( ) ) ;
2014-05-22 01:23:28 +02:00
config : : mru - > Remove ( " Timecodes " , path ) ;
}
catch ( agi : : vfr : : Error const & e ) {
2014-05-29 14:57:27 +02:00
ShowError ( " Failed to parse timecodes file: " + e . GetMessage ( ) ) ;
2014-05-22 01:23:28 +02:00
config : : mru - > Remove ( " Timecodes " , path ) ;
}
}
void Project : : CloseTimecodes ( ) {
timecodes = video_provider ? video_provider - > GetFPS ( ) : agi : : vfr : : Framerate { } ;
2014-05-22 03:32:42 +02:00
SetPath ( timecodes_file , " " , " " , " " ) ;
2014-05-22 01:23:28 +02:00
AnnounceTimecodesModified ( timecodes ) ;
}
void Project : : DoLoadKeyframes ( agi : : fs : : path const & path ) {
keyframes = agi : : keyframe : : Load ( path ) ;
2014-05-22 03:32:42 +02:00
SetPath ( keyframes_file , " " , " Keyframes " , path ) ;
2014-05-22 01:23:28 +02:00
AnnounceKeyframesModified ( keyframes ) ;
}
2014-06-24 01:29:46 +02:00
void Project : : LoadKeyframes ( agi : : fs : : path path ) {
2014-05-22 01:23:28 +02:00
try {
DoLoadKeyframes ( path ) ;
}
catch ( agi : : fs : : FileSystemError const & e ) {
2014-05-29 14:57:27 +02:00
ShowError ( e . GetMessage ( ) ) ;
2014-05-22 01:23:28 +02:00
config : : mru - > Remove ( " Keyframes " , path ) ;
}
catch ( agi : : keyframe : : Error const & e ) {
2014-05-29 14:57:27 +02:00
ShowError ( " Failed to parse keyframes file: " + e . GetMessage ( ) ) ;
2014-05-22 01:23:28 +02:00
config : : mru - > Remove ( " Keyframes " , path ) ;
}
}
void Project : : CloseKeyframes ( ) {
keyframes = video_provider ? video_provider - > GetKeyFrames ( ) : std : : vector < int > { } ;
2014-05-22 03:32:42 +02:00
SetPath ( keyframes_file , " " , " " , " " ) ;
2014-05-22 01:23:28 +02:00
AnnounceKeyframesModified ( keyframes ) ;
}
void Project : : LoadList ( std : : vector < agi : : fs : : path > const & files ) {
// Keep these lists sorted
// Video formats
const char * videoList [ ] = {
" .asf " ,
" .avi " ,
" .avs " ,
" .d2v " ,
" .m2ts " ,
" .m4v " ,
" .mkv " ,
" .mov " ,
" .mp4 " ,
" .mpeg " ,
" .mpg " ,
" .ogm " ,
" .rm " ,
" .rmvb " ,
" .ts " ,
" .webm "
" .wmv " ,
" .y4m " ,
" .yuv "
} ;
// Subtitle formats
const char * subsList [ ] = {
" .ass " ,
" .srt " ,
" .ssa " ,
" .sub " ,
2014-05-22 18:13:34 +02:00
" .ttxt "
2014-05-22 01:23:28 +02:00
} ;
// Audio formats
const char * audioList [ ] = {
" .aac " ,
" .ac3 " ,
" .ape " ,
" .dts " ,
" .flac " ,
" .m4a " ,
" .mka " ,
" .mp3 " ,
" .ogg " ,
" .w64 " ,
" .wav " ,
" .wma "
} ;
auto search = [ ] ( const char * * begin , const char * * end , std : : string const & str ) {
return std : : binary_search ( begin , end , str . c_str ( ) , [ ] ( const char * a , const char * b ) {
return strcmp ( a , b ) < 0 ;
} ) ;
} ;
2014-05-22 18:13:34 +02:00
agi : : fs : : path audio , video , subs , timecodes , keyframes ;
2014-05-22 01:23:28 +02:00
for ( auto file : files ) {
if ( file . is_relative ( ) ) file = absolute ( file ) ;
if ( ! agi : : fs : : FileExists ( file ) ) continue ;
auto ext = file . extension ( ) . string ( ) ;
boost : : to_lower ( ext ) ;
2014-05-22 18:13:34 +02:00
// Could be subtitles, keyframes or timecodes, so try loading as each
if ( ext = = " .txt " | | ext = = " .log " ) {
if ( timecodes . empty ( ) ) {
try {
DoLoadTimecodes ( file ) ;
timecodes = file ;
continue ;
} catch ( . . . ) { }
}
if ( keyframes . empty ( ) ) {
try {
DoLoadKeyframes ( file ) ;
keyframes = file ;
continue ;
} catch ( . . . ) { }
}
if ( subs . empty ( ) & & ext ! = " .log " )
subs = file ;
continue ;
}
2014-05-22 01:23:28 +02:00
if ( subs . empty ( ) & & search ( std : : begin ( subsList ) , std : : end ( subsList ) , ext ) )
subs = file ;
if ( video . empty ( ) & & search ( std : : begin ( videoList ) , std : : end ( videoList ) , ext ) )
video = file ;
if ( audio . empty ( ) & & search ( std : : begin ( audioList ) , std : : end ( audioList ) , ext ) )
audio = file ;
}
2014-06-02 19:04:25 +02:00
ProjectProperties properties ;
if ( ! subs . empty ( ) ) {
if ( ! DoLoadSubtitles ( subs , " " , properties ) )
subs . clear ( ) ;
}
2014-05-22 18:13:34 +02:00
2014-06-29 20:23:37 +02:00
if ( ! video . empty ( ) & & DoLoadVideo ( video ) ) {
2014-05-26 17:58:43 +02:00
double dar = video_provider - > GetDAR ( ) ;
if ( dar > 0 )
context - > videoController - > SetAspectRatio ( dar ) ;
else
context - > videoController - > SetAspectRatio ( AspectRatio : : Default ) ;
context - > videoController - > JumpToFrame ( 0 ) ;
2014-05-22 18:13:34 +02:00
// We loaded these earlier, but loading video unloaded them
// Non-Do version of Load in case they've vanished or changed between
// then and now
if ( ! timecodes . empty ( ) )
LoadTimecodes ( timecodes ) ;
if ( ! keyframes . empty ( ) )
LoadKeyframes ( keyframes ) ;
2014-05-22 03:32:42 +02:00
}
2014-05-22 18:13:34 +02:00
2014-05-22 01:23:28 +02:00
if ( ! audio . empty ( ) )
DoLoadAudio ( audio , false ) ;
else if ( OPT_GET ( " Video/Open Audio " ) - > GetBool ( ) & & audio_file ! = video_file )
DoLoadAudio ( video_file , true ) ;
if ( ! subs . empty ( ) )
2014-06-02 19:04:25 +02:00
LoadUnloadFiles ( properties ) ;
2014-05-22 01:23:28 +02:00
}