Implemented ListView showing songs grouped by BPM

This commit is contained in:
Daniel Brunner
2017-07-09 15:04:06 +02:00
parent 480ef82dcf
commit 5bc5649beb
2 changed files with 99 additions and 7 deletions

View File

@@ -32,6 +32,10 @@
this.button2 = new System.Windows.Forms.Button(); this.button2 = new System.Windows.Forms.Button();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.objectListView1 = new BrightIdeasSoftware.ObjectListView(); this.objectListView1 = new BrightIdeasSoftware.ObjectListView();
this.columnFilename = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
this.columnArtist = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
this.columnTitle = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
this.columnBpm = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.objectListView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.objectListView1)).BeginInit();
this.SuspendLayout(); this.SuspendLayout();
@@ -64,17 +68,49 @@
this.button1.TabIndex = 0; this.button1.TabIndex = 0;
this.button1.Text = "Select music folder"; this.button1.Text = "Select music folder";
this.button1.UseVisualStyleBackColor = true; this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
// //
// objectListView1 // objectListView1
// //
this.objectListView1.AllColumns.Add(this.columnFilename);
this.objectListView1.AllColumns.Add(this.columnArtist);
this.objectListView1.AllColumns.Add(this.columnTitle);
this.objectListView1.AllColumns.Add(this.columnBpm);
this.objectListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
this.columnFilename,
this.columnArtist,
this.columnTitle});
this.objectListView1.Dock = System.Windows.Forms.DockStyle.Fill; this.objectListView1.Dock = System.Windows.Forms.DockStyle.Fill;
this.objectListView1.Location = new System.Drawing.Point(0, 61); this.objectListView1.Location = new System.Drawing.Point(0, 61);
this.objectListView1.Name = "objectListView1"; this.objectListView1.Name = "objectListView1";
this.objectListView1.Size = new System.Drawing.Size(629, 773); this.objectListView1.Size = new System.Drawing.Size(629, 773);
this.objectListView1.TabIndex = 1; this.objectListView1.TabIndex = 1;
this.objectListView1.UseCompatibleStateImageBehavior = false; this.objectListView1.UseCompatibleStateImageBehavior = false;
this.objectListView1.UseOverlays = false;
this.objectListView1.View = System.Windows.Forms.View.Details; this.objectListView1.View = System.Windows.Forms.View.Details;
// //
// columnFilename
//
this.columnFilename.AspectName = "filename";
this.columnFilename.Text = "Filename";
//
// columnArtist
//
this.columnArtist.AspectName = "artist";
this.columnArtist.Text = "Artist";
//
// columnTitle
//
this.columnTitle.AspectName = "title";
this.columnTitle.Text = "Title";
//
// columnBpm
//
this.columnBpm.AspectName = "bpm";
this.columnBpm.DisplayIndex = 3;
this.columnBpm.IsVisible = false;
this.columnBpm.Text = "Bpm";
//
// MainForm // MainForm
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
@@ -96,5 +132,9 @@
private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button1;
private BrightIdeasSoftware.ObjectListView objectListView1; private BrightIdeasSoftware.ObjectListView objectListView1;
private BrightIdeasSoftware.OLVColumn columnFilename;
private BrightIdeasSoftware.OLVColumn columnArtist;
private BrightIdeasSoftware.OLVColumn columnTitle;
private BrightIdeasSoftware.OLVColumn columnBpm;
} }
} }

View File

@@ -1,11 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.IO;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace MusicOrganizer namespace MusicOrganizer
@@ -15,6 +10,63 @@ namespace MusicOrganizer
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
objectListView1.AlwaysGroupByColumn = columnBpm;
}
private void button1_Click(object sender, EventArgs e)
{
try
{
string musicFolder;
using (var dialog = new FolderBrowserDialog())
{
var result = dialog.ShowDialog();
if (result != DialogResult.OK)
return;
if (string.IsNullOrWhiteSpace(dialog.SelectedPath))
return;
musicFolder = dialog.SelectedPath;
}
if (!musicFolder.EndsWith("\\") && !musicFolder.EndsWith("/"))
musicFolder += Path.DirectorySeparatorChar;
var paths = Directory.GetFileSystemEntries(musicFolder, "*.mp3", SearchOption.AllDirectories);
var objects = new List<object>();
foreach (var path in paths)
{
var file = TagLib.File.Create(path);
string relativePath;
if (path.StartsWith(musicFolder))
relativePath = path.Remove(0, musicFolder.Length);
else
relativePath = path;
objects.Add(new {
filename = relativePath,
artist = file.Tag.FirstPerformer,
title = file.Tag.Title,
bpm = string.Format("{0}BPM", file.Tag.BeatsPerMinute)
});
}
objectListView1.SetObjects(objects);
objectListView1.AutoResizeColumns();
button2.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
} }
} }
} }