Skip to content

Commit

Permalink
完成CodeArgumentsPanel的改造
Browse files Browse the repository at this point in the history
  • Loading branch information
autodotua committed May 5, 2024
1 parent 36957b1 commit a373699
Show file tree
Hide file tree
Showing 4 changed files with 219 additions and 241 deletions.
2 changes: 1 addition & 1 deletion SimpleFFmpegGUI.Core/Manager/PresetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public async Task SetDefaultPresetAsync(int id)
await db.SaveChangesAsync();
}

public Task<CodePreset> GetDefaultPreset(TaskType type)
public Task<CodePreset> GetDefaultPresetAsync(TaskType type)
{
return db.Presets.FirstOrDefaultAsync(p => p.Type == type && p.Default && !p.IsDeleted);
}
Expand Down
243 changes: 5 additions & 238 deletions SimpleFFmpegGUI.WPF/Panels/CodeArgumentsPanel.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
using FzLib;
using FzLib.Collection;
using FzLib.Collection;
using Mapster;
using Microsoft.DotNet.PlatformAbstractions;
using Microsoft.Extensions.DependencyInjection;
using SimpleFFmpegGUI.FFmpegLib;
using SimpleFFmpegGUI.Manager;
using SimpleFFmpegGUI.Model;
using SimpleFFmpegGUI.WPF.Model;
using SimpleFFmpegGUI.WPF.ViewModels;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
Expand Down Expand Up @@ -43,7 +41,6 @@ public enum ChannelOutputStrategy

public partial class CodeArgumentsPanel : UserControl
{
private bool canApplyDefaultPreset = true;

public CodeArgumentsPanel()
{
Expand All @@ -59,38 +56,12 @@ public OutputArguments GetOutputArguments()

public void SetAsClone()
{
canApplyDefaultPreset = false;
ViewModel.CanApplyDefaultPreset = false;
}

public async Task UpdateTypeAsync(TaskType type)
public Task UpdateTypeAsync(TaskType type)
{
bool updated = false;
if (canApplyDefaultPreset)//允许修改参数
{
if (Config.Instance.RememberLastArguments)//记住上次输出参数
{
if (Config.Instance.LastOutputArguments.GetOrDefault(type) is OutputArguments lastArguments)
{
ViewModel.Update(type, lastArguments);
//(await this.CreateMessageAsync()).QueueSuccess($"已加载上次任务的参数");
updated = true;
}
}
if (!updated)//记住上次输出参数为False,或不存在上次的参数
{
throw new NotImplementedException();
//if (PresetManager.GetDefaultPreset(type) is CodePreset defaultPreset)
//{
// ViewModel.Update(type, defaultPreset.Arguments);
// (await this.CreateMessageAsync()).QueueSuccess($"已加载默认预设“{defaultPreset.Name}”");
// updated = true;
//}
}
}
if (!updated)
{
ViewModel.Update(type);
}
return ViewModel.UpdateTypeAsync(type);
}

public void Update(TaskType type, OutputArguments arguments)
Expand Down Expand Up @@ -153,210 +124,6 @@ protected override async void OnDrop(DragEventArgs e)

}
}

public class CodeArgumentsPanelViewModel : INotifyPropertyChanged
{
private AudioArgumentsWithSwitch audio = new AudioArgumentsWithSwitch();

private ChannelOutputStrategy audioOutputStrategy = ChannelOutputStrategy.Code;

private bool canSetCombine;

private bool canSetConcat;

private bool canSetVideoAndAudio;

private bool canSpecifyFormat;

private CombineArguments combine = new CombineArguments();

private string extra;

private FormatArgumentWithSwitch format = new FormatArgumentWithSwitch();

private ProcessedOptions processedOptions = new ProcessedOptions();
private TaskType type;

private VideoArgumentsWithSwitch video = new VideoArgumentsWithSwitch();

private ChannelOutputStrategy videoOutputStrategy = ChannelOutputStrategy.Code;

public CodeArgumentsPanelViewModel()
{
}

public event PropertyChangedEventHandler PropertyChanged;

public OutputArguments Arguments { get; set; }
public IEnumerable AspectRatios { get; } = new[] { "16:9", "4:3", "1:1", "3:4", "16:9", "2.35" };

public AudioArgumentsWithSwitch Audio
{
get => audio;
set => this.SetValueAndNotify(ref audio, value, nameof(Audio));
}

public IEnumerable AudioBitrates { get; } = new[] { 32, 64, 96, 128, 192, 256, 320 };

public IEnumerable AudioCodecs { get; } = new[] { "自动", "AAC", "OPUS" };

public ChannelOutputStrategy AudioOutputStrategy
{
get => audioOutputStrategy;
set
{
this.SetValueAndNotify(ref audioOutputStrategy, value, nameof(AudioOutputStrategy));
if (value == ChannelOutputStrategy.Code && Audio == null)
{
Audio = new AudioArgumentsWithSwitch();
}
}
}

public IEnumerable AudioSamplingRates { get; } = new[] { 8000, 16000, 32000, 44100, 48000, 96000, 192000 };

public bool CanSetCombine
{
get => canSetCombine;
set => this.SetValueAndNotify(ref canSetCombine, value, nameof(CanSetCombine));
}

public bool CanSetConcat
{
get => canSetConcat;
set => this.SetValueAndNotify(ref canSetConcat, value, nameof(CanSetConcat));
}

public bool CanSetVideoAndAudio
{
get => canSetVideoAndAudio;
set
{
this.SetValueAndNotify(ref canSetVideoAndAudio, value, nameof(CanSetVideoAndAudio));
if (value)
{
VideoOutputStrategy = ChannelOutputStrategy.Code;
AudioOutputStrategy = ChannelOutputStrategy.Code;
}
else
{
VideoOutputStrategy = ChannelOutputStrategy.Disable;
AudioOutputStrategy = ChannelOutputStrategy.Disable;
}
}
}

public bool CanSpecifyFormat
{
get => canSpecifyFormat;
set => this.SetValueAndNotify(ref canSpecifyFormat, value, nameof(CanSpecifyFormat));
}

public IEnumerable ChannelOutputStrategies => Enum.GetValues(typeof(ChannelOutputStrategy));

public CombineArguments Combine
{
get => combine;
set => this.SetValueAndNotify(ref combine, value, nameof(Combine));
}

public string Extra
{
get => extra;
set => this.SetValueAndNotify(ref extra, value, nameof(Extra));
}

public FormatArgumentWithSwitch Format
{
get => format;
set => this.SetValueAndNotify(ref format, value, nameof(Format));
}

public IEnumerable Formats => VideoFormat.Formats;

public IEnumerable Fpses => new double[] { 10, 20, 23.976, 24, 25, 29.97, 30, 48, 59.94, 60, 120 };

public IEnumerable PixelFormats { get; } = new[] { "yuv420p", "yuvj420p", "yuv422p", "yuvj422p", "rgb24", "gray", "yuv420p10le" };

public ProcessedOptions ProcessedOptions
{
get => processedOptions;
set => this.SetValueAndNotify(ref processedOptions, value, nameof(ProcessedOptions));
}

public IEnumerable Sizes { get; } = new[] { "-1:2160", "-1:1440", "-1:1080", "-1:720", "-1:576", "-1:480" };
public VideoArgumentsWithSwitch Video
{
get => video;
set => this.SetValueAndNotify(ref video, value, nameof(Video));
}

public IEnumerable VideoCodecs { get; } = new[] { "自动" }.Concat(VideoCodec.VideoCodecs.Select(p => p.Name));

public ChannelOutputStrategy VideoOutputStrategy
{
get => videoOutputStrategy;
set
{
this.SetValueAndNotify(ref videoOutputStrategy, value, nameof(VideoOutputStrategy));
if (value == ChannelOutputStrategy.Code && Audio == null)
{
Video = new VideoArgumentsWithSwitch();
}
}
}

public OutputArguments GetArguments()
{
if (VideoOutputStrategy == ChannelOutputStrategy.Code)
{
Video.Apply();
}
if (AudioOutputStrategy == ChannelOutputStrategy.Code)
{
Audio.Apply();
}
Format.Apply();
return new OutputArguments()
{
Video = VideoOutputStrategy == ChannelOutputStrategy.Code ? Video.Adapt<VideoCodeArguments>() : null,
Audio = AudioOutputStrategy == ChannelOutputStrategy.Code ? Audio.Adapt<AudioCodeArguments>() : null,
Format = Format.Format,
Combine = Combine,
Extra = Extra,
ProcessedOptions = ProcessedOptions,
DisableVideo = VideoOutputStrategy == ChannelOutputStrategy.Disable,
DisableAudio = audioOutputStrategy == ChannelOutputStrategy.Disable,
};
}

public void Update(TaskType type, OutputArguments argument = null)
{
this.type = type;
CanSpecifyFormat = type is TaskType.Code or TaskType.Combine or TaskType.Concat;
CanSetVideoAndAudio = type is TaskType.Code;
CanSetCombine = type is TaskType.Combine;
CanSetConcat = type is TaskType.Concat;
if (argument != null)
{
Video = argument.Video.Adapt<VideoArgumentsWithSwitch>();
Video?.Update();
VideoOutputStrategy = argument.Video == null ?
(argument.DisableVideo ? ChannelOutputStrategy.Disable : ChannelOutputStrategy.Copy)
: ChannelOutputStrategy.Code;
Audio = argument.Audio.Adapt<AudioArgumentsWithSwitch>();
Audio?.Update();
AudioOutputStrategy = argument.Audio == null ?
(argument.DisableAudio ? ChannelOutputStrategy.Disable : ChannelOutputStrategy.Copy)
: ChannelOutputStrategy.Code;
Format = new FormatArgumentWithSwitch() { Format = argument.Format };
Format.Update();
Combine = argument.Combine;
ProcessedOptions = argument.ProcessedOptions ?? new ProcessedOptions();
Extra = argument.Extra;
}
}
}
public class Int2StringConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
Expand Down
Loading

0 comments on commit a373699

Please sign in to comment.