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; } 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..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,6 +205,36 @@ private void btnDown_Click(object sender, EventArgs e) RebuildFileList(); 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() {