Add mkv default/forced flags to track chooser UI

Somewhat related to #4183
This commit is contained in:
nikolaj.olsson 2020-05-14 19:07:36 +02:00
parent d1231ec496
commit b4a562d977
5 changed files with 121 additions and 7 deletions

View File

@ -15,6 +15,9 @@
TrackEntry = 0xAE,
TrackNumber = 0xD7,
TrackType = 0x83,
FlagDefault = 0x88,
FlagForced = 0x55AA,
DefaultDuration = 0x23E383,
Name = 0x536E,
Language = 0x22B59C,

View File

@ -174,6 +174,8 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Matroska
bool isVideo = false;
bool isAudio = false;
bool isSubtitle = false;
bool isDefault = true;
bool isForced = false;
var trackNumber = 0;
string name = string.Empty;
string language = "eng"; // default value
@ -238,6 +240,14 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Matroska
ReadContentEncodingElement(element, ref contentCompressionAlgorithm, ref contentEncodingType, ref contentEncodingScope);
}
break;
case ElementId.FlagDefault:
var defaultValue = (int)ReadUInt((int)element.DataSize);
isDefault = defaultValue == 1;
break;
case ElementId.FlagForced:
var forcedValue = (int)ReadUInt((int)element.DataSize);
isForced = forcedValue == 1;
break;
}
_stream.Seek(element.EndPosition, SeekOrigin.Begin);
}
@ -254,7 +264,9 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Matroska
Name = name,
ContentEncodingType = contentEncodingType,
ContentCompressionAlgorithm = contentCompressionAlgorithm,
ContentEncodingScope = contentEncodingScope
ContentEncodingScope = contentEncodingScope,
IsDefault = isDefault,
IsForced = isForced,
});
if (isVideo)

View File

@ -14,6 +14,8 @@ namespace Nikse.SubtitleEdit.Core.ContainerFormats.Matroska
public bool IsVideo { get; set; }
public bool IsAudio { get; set; }
public bool IsSubtitle { get; set; }
public bool IsDefault { get; set; }
public bool IsForced { get; set; }
public string CodecId { get; set; }
internal byte[] CodecPrivateRaw { get; set; }
public int DefaultDuration { get; set; }

View File

@ -32,6 +32,13 @@
this.buttonOK = new System.Windows.Forms.Button();
this.listBox1 = new System.Windows.Forms.ListBox();
this.labelChoose = new System.Windows.Forms.Label();
this.listView1 = new System.Windows.Forms.ListView();
this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader2 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader3 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader4 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader5 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
this.SuspendLayout();
//
// buttonCancel
@ -39,7 +46,7 @@
this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonCancel.BackColor = System.Drawing.SystemColors.Control;
this.buttonCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.buttonCancel.Location = new System.Drawing.Point(362, 250);
this.buttonCancel.Location = new System.Drawing.Point(491, 302);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(75, 23);
this.buttonCancel.TabIndex = 46;
@ -49,7 +56,7 @@
// buttonOK
//
this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonOK.Location = new System.Drawing.Point(281, 250);
this.buttonOK.Location = new System.Drawing.Point(410, 302);
this.buttonOK.Name = "buttonOK";
this.buttonOK.Size = new System.Drawing.Size(75, 23);
this.buttonOK.TabIndex = 45;
@ -65,8 +72,9 @@
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(12, 43);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(425, 199);
this.listBox1.Size = new System.Drawing.Size(554, 251);
this.listBox1.TabIndex = 47;
this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
this.listBox1.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listBox1_MouseDoubleClick);
//
// labelChoose
@ -78,15 +86,66 @@
this.labelChoose.TabIndex = 48;
this.labelChoose.Text = "More than one subtitle found - please choose";
//
// listView1
//
this.listView1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnHeader1,
this.columnHeader2,
this.columnHeader3,
this.columnHeader4,
this.columnHeader5,
this.columnHeader6});
this.listView1.FullRowSelect = true;
this.listView1.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.listView1.HideSelection = false;
this.listView1.Location = new System.Drawing.Point(13, 43);
this.listView1.MultiSelect = false;
this.listView1.Name = "listView1";
this.listView1.Size = new System.Drawing.Size(553, 253);
this.listView1.TabIndex = 49;
this.listView1.UseCompatibleStateImageBehavior = false;
this.listView1.View = System.Windows.Forms.View.Details;
this.listView1.SelectedIndexChanged += new System.EventHandler(this.listView1_SelectedIndexChanged);
//
// columnHeader1
//
this.columnHeader1.Text = "Track#";
//
// columnHeader2
//
this.columnHeader2.Text = "Name";
this.columnHeader2.Width = 180;
//
// columnHeader3
//
this.columnHeader3.Text = "Language";
//
// columnHeader4
//
this.columnHeader4.Text = "Type";
this.columnHeader4.Width = 100;
//
// columnHeader5
//
this.columnHeader5.Text = "Default";
//
// columnHeader6
//
this.columnHeader6.Text = "Forced";
//
// MatroskaSubtitleChooser
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(450, 277);
this.ClientSize = new System.Drawing.Size(579, 329);
this.Controls.Add(this.labelChoose);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonOK);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.listView1);
this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.KeyPreview = true;
this.MaximizeBox = false;
@ -109,5 +168,12 @@
private System.Windows.Forms.Button buttonOK;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Label labelChoose;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.ColumnHeader columnHeader1;
private System.Windows.Forms.ColumnHeader columnHeader2;
private System.Windows.Forms.ColumnHeader columnHeader3;
private System.Windows.Forms.ColumnHeader columnHeader4;
private System.Windows.Forms.ColumnHeader columnHeader5;
private System.Windows.Forms.ColumnHeader columnHeader6;
}
}

View File

@ -4,6 +4,7 @@ using Nikse.SubtitleEdit.Core.ContainerFormats.Mp4.Boxes;
using Nikse.SubtitleEdit.Logic;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Windows.Forms;
namespace Nikse.SubtitleEdit.Forms
@ -23,21 +24,39 @@ namespace Nikse.SubtitleEdit.Forms
UiUtil.FixLargeFonts(this, buttonOK);
}
public int SelectedIndex => listBox1.SelectedIndex;
public int SelectedIndex { get; private set; }
internal void Initialize(List<MatroskaTrackInfo> subtitleInfoList)
{
listBox1.Visible = false;
listView1.Visible = true;
var format = Configuration.Settings.Language.MatroskaSubtitleChooser.TrackXLanguageYTypeZ;
foreach (var info in subtitleInfoList)
{
var track = string.Format((!string.IsNullOrWhiteSpace(info.Name) ? "{0} - {1}" : "{0}"), info.TrackNumber, info.Name);
listBox1.Items.Add(string.Format(format, track, info.Language, info.CodecId));
AddListViewItem(info);
}
listBox1.SelectedIndex = 0;
listView1.Items[0].Selected = true;
listView1.FocusedItem = listView1.Items[0];
}
private void AddListViewItem(MatroskaTrackInfo info)
{
var item = new ListViewItem(info.TrackNumber.ToString());
item.SubItems.Add(info.Name);
item.SubItems.Add(info.Language);
item.SubItems.Add(info.CodecId);
item.SubItems.Add(info.IsDefault.ToString(CultureInfo.InvariantCulture));
item.SubItems.Add(info.IsForced.ToString(CultureInfo.InvariantCulture));
listView1.Items.Add(item);
}
internal void Initialize(List<Trak> mp4SubtitleTracks)
{
listBox1.Visible = true;
listView1.Visible = false;
int i = 0;
foreach (var track in mp4SubtitleTracks)
{
@ -72,5 +91,17 @@ namespace Nikse.SubtitleEdit.Forms
DialogResult = DialogResult.OK;
}
private void listView1_SelectedIndexChanged(object sender, EventArgs e)
{
if (listView1.SelectedItems.Count > 0)
{
SelectedIndex = listView1.SelectedItems[0].Index;
}
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
SelectedIndex = listBox1.SelectedIndex;
}
}
}