From 6766356f6636d7b94137a1fa3f572e773270ec5c Mon Sep 17 00:00:00 2001 From: Achim Winkler Date: Fri, 12 Jul 2024 15:30:24 +0200 Subject: [PATCH 1/3] two different sort methods for TrackSortDialog added (track = old, filename = new) --- TeddyBench/TrackSortDialog.Designer.cs | 17 +++++++++++++++ TeddyBench/TrackSortDialog.cs | 30 ++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/TeddyBench/TrackSortDialog.Designer.cs b/TeddyBench/TrackSortDialog.Designer.cs index 2985057..f54805b 100644 --- a/TeddyBench/TrackSortDialog.Designer.cs +++ b/TeddyBench/TrackSortDialog.Designer.cs @@ -47,6 +47,7 @@ private void InitializeComponent() this.splitContainer2 = new System.Windows.Forms.SplitContainer(); this.btnDown = new System.Windows.Forms.Button(); this.btnUp = new System.Windows.Forms.Button(); + this.cmbSorting = new System.Windows.Forms.ComboBox(); this.lstTracks = 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())); @@ -114,6 +115,7 @@ private void InitializeComponent() // this.splitContainer2.Panel1.Controls.Add(this.btnDown); this.splitContainer2.Panel1.Controls.Add(this.btnUp); + this.splitContainer2.Panel1.Controls.Add(this.cmbSorting); // // splitContainer2.Panel2 // @@ -144,6 +146,20 @@ private void InitializeComponent() this.btnUp.UseVisualStyleBackColor = true; this.btnUp.Click += new System.EventHandler(this.btnUp_Click); // + // cmbSorting + // + this.cmbSorting.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.cmbSorting.FormattingEnabled = true; + this.cmbSorting.Items.AddRange(new object[] { + "Track", + "Filename"}); + this.cmbSorting.Location = new System.Drawing.Point(0, 46); + this.cmbSorting.Name = "cmbSorting"; + this.cmbSorting.Size = new System.Drawing.Size(85, 23); + this.cmbSorting.TabIndex = 0; + this.cmbSorting.SelectedIndex = 0; + this.cmbSorting.SelectedIndexChanged += new System.EventHandler(this.cmbSorting_SelectedIndexChanged); + // // lstTracks // this.lstTracks.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { @@ -212,6 +228,7 @@ private void InitializeComponent() private System.Windows.Forms.SplitContainer splitContainer2; private System.Windows.Forms.Button btnUp; private System.Windows.Forms.Button btnDown; + private System.Windows.Forms.ComboBox cmbSorting; private System.Windows.Forms.ListView lstTracks; private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; diff --git a/TeddyBench/TrackSortDialog.cs b/TeddyBench/TrackSortDialog.cs index 7c35377..d06c154 100644 --- a/TeddyBench/TrackSortDialog.cs +++ b/TeddyBench/TrackSortDialog.cs @@ -186,6 +186,36 @@ private void btnDown_Click(object sender, EventArgs e) lstTracks.Select(); } + private void cmbSorting_SelectedIndexChanged(object sender, EventArgs e) + { + UpdateSorting(); + } + + private void UpdateSorting() + { + FileList = new List>(); + + var fileTuples = FileNames.Select(f => new Tuple(f, GetTag(f))); + + if (cmbSorting.SelectedIndex == 0) + { + foreach (Tuple item in fileTuples.OrderBy(i => (i.Item2 == null) ? int.MaxValue : i.Item2.Track.Value)) + { + FileList.Add(item); + } + } + else + { + foreach (Tuple item in fileTuples.OrderBy(i => i.Item1)) + { + FileList.Add(item); + } + } + + UpdateView(); + } + + private void RebuildFileList() { FileList = new List>(); From 1813b74df905fe11acbe7e5012e49bbfa86a7db7 Mon Sep 17 00:00:00 2001 From: Achim Winkler Date: Mon, 15 Jul 2024 00:42:22 +0200 Subject: [PATCH 2/3] date sort fixed --- TeddyBench/TeddyMain.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/TeddyBench/TeddyMain.cs b/TeddyBench/TeddyMain.cs index 7b594e4..7a26cdf 100644 --- a/TeddyBench/TeddyMain.cs +++ b/TeddyBench/TeddyMain.cs @@ -131,7 +131,17 @@ public int Compare(object a, object b) return 1; } - int returnVal = String.Compare(s1, s2); + int returnVal = 0; + + if (Characteristic != 2) + { + returnVal = String.Compare(s1, s2); + } + else + { + // do not use the string representation to avoid wrong sort results + returnVal = DateTime.Compare(t1.FileInfo.CreationTime, t2.FileInfo.CreationTime); + } return (Order ? 1 : -1) * returnVal; } From 2814ece8c0a9956c8932a5fa538f691ec0214912 Mon Sep 17 00:00:00 2001 From: Achim Winkler Date: Wed, 18 Dec 2024 10:03:25 +0100 Subject: [PATCH 3/3] TAF limitation warnings added --- TeddyBench/TrackSortDialog.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/TeddyBench/TrackSortDialog.cs b/TeddyBench/TrackSortDialog.cs index d06c154..db38f1b 100644 --- a/TeddyBench/TrackSortDialog.cs +++ b/TeddyBench/TrackSortDialog.cs @@ -1,4 +1,5 @@ using Id3; +using NAudio.Wave; using System; using System.Collections.Generic; using System.ComponentModel; @@ -31,13 +32,32 @@ protected override void OnLoad(EventArgs e) base.OnLoad(e); var fileTuples = FileNames.Select(f => new Tuple(f, GetTag(f))); + TimeSpan totalTime = new TimeSpan(0L); foreach (Tuple item in fileTuples.OrderBy(i => (i.Item2 == null) ? int.MaxValue : i.Item2.Track.Value)) { FileList.Add(item); + + /* Calculate total length of MP3 file */ + TimeSpan time = new MediaFoundationReader(item.Item1).TotalTime; + totalTime += time; } + + var h = (int)(totalTime.TotalMinutes / 60); + var m = (int)(totalTime.TotalMinutes % 60); + var s = (int)(totalTime.TotalSeconds % 60); + this.Text += " (Number of files: " + FileList.Count + ", Duration: " + $"{h:D2}:{m:D2}:{s:D2}" + ")"; - UpdateView(); + UpdateView(); + + if (FileList.Count > 99) + { + MessageBox.Show("A TAF file can not handle more than 99 tracks!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } + else if (totalTime.TotalSeconds > 43200) /* 12h = 43200 = 60 * 60 * 12 */ + { + MessageBox.Show("A TAF file can not handle more than 12h total playtime!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); + } } private Id3Tag GetTag(string f) @@ -185,7 +205,7 @@ private void btnDown_Click(object sender, EventArgs e) RebuildFileList(); lstTracks.Select(); } - + private void cmbSorting_SelectedIndexChanged(object sender, EventArgs e) { UpdateSorting();