diff --git a/MusicOrganizer/MainForm.Designer.cs b/MusicOrganizer/MainForm.Designer.cs index ebb5a64..39a3909 100644 --- a/MusicOrganizer/MainForm.Designer.cs +++ b/MusicOrganizer/MainForm.Designer.cs @@ -32,6 +32,10 @@ this.button2 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button(); 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(); ((System.ComponentModel.ISupportInitialize)(this.objectListView1)).BeginInit(); this.SuspendLayout(); @@ -64,17 +68,49 @@ this.button1.TabIndex = 0; this.button1.Text = "Select music folder"; this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.button1_Click); // // 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.Location = new System.Drawing.Point(0, 61); this.objectListView1.Name = "objectListView1"; this.objectListView1.Size = new System.Drawing.Size(629, 773); this.objectListView1.TabIndex = 1; this.objectListView1.UseCompatibleStateImageBehavior = false; + this.objectListView1.UseOverlays = false; 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 // this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F); @@ -96,5 +132,9 @@ private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button1; private BrightIdeasSoftware.ObjectListView objectListView1; + private BrightIdeasSoftware.OLVColumn columnFilename; + private BrightIdeasSoftware.OLVColumn columnArtist; + private BrightIdeasSoftware.OLVColumn columnTitle; + private BrightIdeasSoftware.OLVColumn columnBpm; } } \ No newline at end of file diff --git a/MusicOrganizer/MainForm.cs b/MusicOrganizer/MainForm.cs index 8e22b12..3c3e454 100644 --- a/MusicOrganizer/MainForm.cs +++ b/MusicOrganizer/MainForm.cs @@ -1,11 +1,6 @@ using System; using System.Collections.Generic; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; using System.Windows.Forms; namespace MusicOrganizer @@ -15,6 +10,63 @@ namespace MusicOrganizer public MainForm() { 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(); + + 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); + } } } -} +} \ No newline at end of file