Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

two different sort methods for TrackSortDialog added + TAF limitation warnings added (99 files and 12h) #82

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion TeddyBench/TeddyMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
17 changes: 17 additions & 0 deletions TeddyBench/TrackSortDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

52 changes: 51 additions & 1 deletion TeddyBench/TrackSortDialog.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Id3;
using NAudio.Wave;
using System;
using System.Collections.Generic;
using System.ComponentModel;
Expand Down Expand Up @@ -31,13 +32,32 @@ protected override void OnLoad(EventArgs e)
base.OnLoad(e);

var fileTuples = FileNames.Select(f => new Tuple<string, Id3Tag>(f, GetTag(f)));
TimeSpan totalTime = new TimeSpan(0L);

foreach (Tuple<string, Id3Tag> 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)
Expand Down Expand Up @@ -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<Tuple<string, Id3Tag>>();

var fileTuples = FileNames.Select(f => new Tuple<string, Id3Tag>(f, GetTag(f)));

if (cmbSorting.SelectedIndex == 0)
{
foreach (Tuple<string, Id3Tag> item in fileTuples.OrderBy(i => (i.Item2 == null) ? int.MaxValue : i.Item2.Track.Value))
{
FileList.Add(item);
}
}
else
{
foreach (Tuple<string, Id3Tag> item in fileTuples.OrderBy(i => i.Item1))
{
FileList.Add(item);
}
}

UpdateView();
}


private void RebuildFileList()
{
Expand Down