コード例 #1
0
ファイル: video_context.cpp プロジェクト: Azpidatziak/Aegisub
void VideoContext::OnSubtitlesSave() {
	context->ass->SetScriptInfo("VFR File", MakeRelativePath(GetTimecodesName(), context->ass->filename));
	context->ass->SetScriptInfo("Keyframes File", MakeRelativePath(GetKeyFramesName(), context->ass->filename));

	if (!IsLoaded()) {
		context->ass->SetScriptInfo("Video File", "");
		context->ass->SetScriptInfo("Video Aspect Ratio", "");
		context->ass->SetScriptInfo("Video Position", "");
		return;
	}

	wxString ar;
	if (arType == 4)
		ar = wxString::Format("c%g", arValue);
	else
		ar = wxString::Format("%d", arType);

	context->ass->SetScriptInfo("Video File", MakeRelativePath(videoFile, context->ass->filename));
	context->ass->SetScriptInfo("YCbCr Matrix", videoProvider->GetColorSpace());
	context->ass->SetScriptInfo("Video Aspect Ratio", ar);
	context->ass->SetScriptInfo("Video Position", wxString::Format("%d", frame_n));
}
コード例 #2
0
ファイル: frame_main.cpp プロジェクト: Leinad4Mind/Aegisub
void FrameMain::OnSubtitlesOpen() {
	UpdateTitle();
	auto vc = context->videoController;

	/// @todo figure out how to move this to the relevant controllers without
	///       prompting for each file loaded/unloaded

	// Load stuff from the new script
	auto video     = config::path->MakeAbsolute(context->ass->GetScriptInfo("Video File"), "?script");
	auto vfr       = config::path->MakeAbsolute(context->ass->GetScriptInfo("VFR File"), "?script");
	auto keyframes = config::path->MakeAbsolute(context->ass->GetScriptInfo("Keyframes File"), "?script");
	auto audio     = config::path->MakeAbsolute(context->ass->GetScriptInfo("Audio URI"), "?script");

	bool videoChanged     = !blockVideoLoad && video != vc->GetVideoName();
	bool timecodesChanged = vfr != vc->GetTimecodesName();
	bool keyframesChanged = keyframes != vc->GetKeyFramesName();
	bool audioChanged     = !blockAudioLoad && audio != context->audioController->GetAudioURL();

	// Check if there is anything to change
	int autoLoadMode = OPT_GET("App/Auto/Load Linked Files")->GetInt();
	if (autoLoadMode == 0 || (!videoChanged && !timecodesChanged && !keyframesChanged && !audioChanged)) {
		SetDisplayMode(1, 1);
		return;
	}

	if (autoLoadMode == 2) {
		if (wxMessageBox(_("Do you want to load/unload the associated files?"), _("(Un)Load files?"), wxYES_NO | wxCENTRE, this) != wxYES) {
			SetDisplayMode(1, 1);
			if (vc->IsLoaded() && vc->GetProvider()->GetColorSpace() != context->ass->GetScriptInfo("YCbCr Matrix"))
				vc->Reload();
			return;
		}
	}

	if (audioChanged)
		blockAudioLoad = true;

	// Video
	if (videoChanged) {
		vc->SetVideo(video);
		if (vc->IsLoaded()) {
			vc->JumpToFrame(context->ass->GetUIStateAsInt("Video Position"));

			std::string arString = context->ass->GetUIState("Video Aspect Ratio");
			if (boost::starts_with(arString, "c")) {
				double ar = 0.;
				agi::util::try_parse(arString.substr(1), &ar);
				vc->SetAspectRatio(ar);
			}
			else {
				int ar = 0;
				if (agi::util::try_parse(arString, &ar) && ar >= 0 && ar < 4)
					vc->SetAspectRatio((AspectRatio)ar);
			}

			double videoZoom = 0.;
			if (agi::util::try_parse(context->ass->GetUIState("Video Zoom Percent"), &videoZoom))
				context->videoDisplay->SetZoom(videoZoom);
		}
	}
	else if (vc->IsLoaded() && vc->GetProvider()->GetColorSpace() != context->ass->GetScriptInfo("YCbCr Matrix"))
		vc->Reload();

	vc->LoadTimecodes(vfr);
	vc->LoadKeyframes(keyframes);

	// Audio
	if (audioChanged) {
		blockAudioLoad = false;
		try {
			if (audio.empty())
				context->audioController->CloseAudio();
			else
				context->audioController->OpenAudio(audio);
		}
		catch (agi::UserCancelException const&) { }
		catch (agi::fs::FileSystemError const& err) {
			wxMessageBox(to_wx(err.GetMessage()), "Error opening audio", wxOK | wxICON_ERROR | wxCENTER, this);
		}
	}

	SetDisplayMode(1, 1);
}