Files
Futonizer/Models/TrackItem.cs
T

85 lines
2.8 KiB
C#

using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace Futonizer.Models;
/// <summary>
/// Represents one track of a queued MKV file, as shown in the track table.
/// The <see cref="Copy"/> property is user-editable and drives which tracks
/// are passed to mkvmerge when stripping.
/// </summary>
public class TrackItem : INotifyPropertyChanged
{
private bool _copy;
public int Id { get; init; }
public string Type { get; init; } = string.Empty;
public string Codec { get; init; } = string.Empty;
public string Language { get; init; } = string.Empty;
public string Name { get; init; } = string.Empty;
public bool ForcedDisplay { get; init; }
private bool _defaultTrack;
/// <summary>
/// Whether this track should be flagged as the default track of its type
/// when stripped. For subtitles this is kept in sync with <see cref="Copy"/>
/// (selecting a subtitle also makes it the default one).
/// </summary>
public bool DefaultTrack
{
get => _defaultTrack;
set
{
if (_defaultTrack == value) return;
_defaultTrack = value;
OnPropertyChanged();
}
}
/// <summary>
/// Text shown in the track table's Name column. Subtitle tracks are shown
/// as "Codec/Name" so tracks that share a display name but use a different
/// codec are easy to tell apart.
/// </summary>
public string DisplayName => Type == "subtitles" ? $"{Codec}/{Name}" : Name;
/// <summary>
/// Video is always kept, and chapters (a synthetic pseudo-track, not a
/// real mkvmerge track) are always kept too — neither is user-selectable,
/// so their Copy checkbox is shown checked but disabled.
/// </summary>
public bool IsEditable => Type is "audio" or "subtitles";
/// <summary>
/// Chapters aren't a real track and have no track ID; show a dash
/// instead of a meaningless number.
/// </summary>
public string IdDisplay => Type == "chapters" ? "—" : Id.ToString();
public bool Copy
{
get => _copy;
set
{
if (_copy == value) return;
_copy = value;
OnPropertyChanged();
}
}
/// <summary>
/// Key used to match subtitle tracks with the same identity across different
/// queued files when propagating a subtitle selection. Subtitles are matched
/// on "Codec/Name" so tracks with the same name but a different codec are
/// treated as distinct.
/// </summary>
public string PropagationKey => DisplayName;
public event PropertyChangedEventHandler? PropertyChanged;
private void OnPropertyChanged([CallerMemberName] string? name = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}