Skip to content

Commit

Permalink
Removed unnecessary includes, improved resizing efficiency, improved …
Browse files Browse the repository at this point in the history
…data copying functionality, added safety check to see if song folder exists, fixed bug where rest of list would be skipped if it couldn't find info.dat, added alternative mapper name in case they forgot to add it in the dat, but have it on beat saver, set the playback volume slightly lower
  • Loading branch information
40163650 committed Aug 20, 2023
1 parent 49cd692 commit 71010e5
Show file tree
Hide file tree
Showing 78 changed files with 230 additions and 130 deletions.
Binary file removed .vs/ProjectEvaluation/songanalyser.metadata.v5.1
Binary file not shown.
Binary file not shown.
Binary file removed .vs/ProjectEvaluation/songanalyser.projects.v5.1
Binary file not shown.
Binary file not shown.
Binary file modified .vs/SongAnalyser/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified .vs/SongAnalyser/v17/.futdcache.v2
Binary file not shown.
Binary file modified .vs/SongAnalyser/v17/.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion Properties/PublishProfiles/FolderProfile.pubxml.user
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project>
<PropertyGroup>
<History>True|2023-02-26T02:20:41.4518513Z;True|2023-02-26T02:08:54.4115132+00:00;True|2023-02-26T01:45:56.3187653+00:00;False|2023-02-26T01:45:47.6956226+00:00;True|2023-02-26T01:41:45.5062380+00:00;True|2023-02-26T01:39:30.6417546+00:00;True|2023-02-26T01:35:07.6457339+00:00;True|2022-06-28T11:48:15.1521704+01:00;True|2022-05-28T23:25:28.5880553+01:00;True|2022-05-20T15:39:16.7593643+01:00;True|2022-05-19T11:51:33.2028250+01:00;True|2022-05-18T23:25:52.5439790+01:00;True|2022-05-17T22:40:34.9974871+01:00;False|2022-05-17T22:40:07.0001215+01:00;True|2022-05-17T22:35:55.7124069+01:00;False|2022-05-17T22:35:40.7185512+01:00;True|2022-05-17T22:30:40.3887842+01:00;False|2022-05-17T22:29:42.4052652+01:00;True|2022-05-17T22:24:01.6030290+01:00;</History>
<History>True|2023-08-03T23:13:56.5164331Z;True|2023-02-26T02:20:41.4518513+00:00;True|2023-02-26T02:08:54.4115132+00:00;True|2023-02-26T01:45:56.3187653+00:00;False|2023-02-26T01:45:47.6956226+00:00;True|2023-02-26T01:41:45.5062380+00:00;True|2023-02-26T01:39:30.6417546+00:00;True|2023-02-26T01:35:07.6457339+00:00;True|2022-06-28T11:48:15.1521704+01:00;True|2022-05-28T23:25:28.5880553+01:00;True|2022-05-20T15:39:16.7593643+01:00;True|2022-05-19T11:51:33.2028250+01:00;True|2022-05-18T23:25:52.5439790+01:00;True|2022-05-17T22:40:34.9974871+01:00;False|2022-05-17T22:40:07.0001215+01:00;True|2022-05-17T22:35:55.7124069+01:00;False|2022-05-17T22:35:40.7185512+01:00;True|2022-05-17T22:30:40.3887842+01:00;False|2022-05-17T22:29:42.4052652+01:00;True|2022-05-17T22:24:01.6030290+01:00;</History>
<LastFailureDetails />
</PropertyGroup>
</Project>
153 changes: 76 additions & 77 deletions Results.Designer.cs

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

87 changes: 62 additions & 25 deletions Results.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using Newtonsoft.Json;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

using NVorbis;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
using NAudio.Vorbis;

namespace SongAnalyser
Expand Down Expand Up @@ -80,19 +77,44 @@ public partial class Results : Form

Form1 MyParentForm;

// Not sure how I feel about this more efficient resizing
bool currentlyResizing = false;
private const int WM_ENTERSIZEMOVE = 0x0231;
private const int WM_EXITSIZEMOVE = 0x0232;
protected override void WndProc(ref Message m)
{
switch (m.Msg)
{
case WM_ENTERSIZEMOVE:
currentlyResizing = true;
break;

case WM_EXITSIZEMOVE:
currentlyResizing = false;
Results_Resize(null, null);
break;
}
base.WndProc(ref m);
}


private void lv_Click(object sender, MouseEventArgs e)
{
if(lvResults == null || lvResults.SelectedItems == null || lvResults.SelectedItems[0] == null || e == null)
if (lvResults == null || lvResults.SelectedItems == null || lvResults.SelectedItems[0] == null || e == null)
{
return;
}

if (e.Button == MouseButtons.Right)
{
Clipboard.SetText(lvResults.SelectedItems[0].SubItems[4].Text);
string text = lvResults.SelectedItems[0].SubItems[0].Text + "\n" +
"Song By: " + lvResults.SelectedItems[0].SubItems[1].Text + "\n" +
"Map By: " + lvResults.SelectedItems[0].SubItems[2].Text + "\n" +
"Map Link: " + lvResults.SelectedItems[0].SubItems[4].Text;
Clipboard.SetText(text);
// https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox
uint uiFlags = 0x00000000 | 0x00040000 | 0x00001000 | 0x00000040;
MessageBoxTimeout(GetForegroundWindow(), $"Link Copied", $"", uiFlags, 0, 400);
MessageBoxTimeout(GetForegroundWindow(), $"Data Copied", $"", uiFlags, 0, 400);
}
}

Expand Down Expand Up @@ -122,7 +144,7 @@ public void SetupColumns()
lvResults.Columns.Add("Artist", -2, HorizontalAlignment.Left);
lvResults.Columns.Add("Mapper", -2, HorizontalAlignment.Left);
lvResults.Columns.Add("Folder Name", -2, HorizontalAlignment.Left);
lvResults.Columns.Add("Link (Right Click Entry to Copy)", -2, HorizontalAlignment.Left);
lvResults.Columns.Add("Link", -2, HorizontalAlignment.Left);

lvResults.View = View.Details;
lvResults.LabelEdit = false;
Expand All @@ -148,15 +170,20 @@ private void Results_Load(object sender, EventArgs e)

string path = Form1.path;

foreach(string folder in Directory.GetDirectories(path))
if (!Directory.Exists(path))
{
return;
}

foreach (string folder in Directory.GetDirectories(path))
{
string datfile = folder + "/info.dat";
if(!File.Exists(datfile))
if (!File.Exists(datfile))
{
datfile = folder + "/Info.dat";
if (!File.Exists(datfile))
{
break;
continue;
}
}

Expand All @@ -173,10 +200,19 @@ private void Results_Load(object sender, EventArgs e)
link = "https://beatsaver.com/maps/" + rx.Match(shortFolder);
}

// 273e5 (Bury The Light - Chained.Trap)
int hyphenIndex = shortFolder.IndexOf("-") + 2;
int bracketIndex = shortFolder.IndexOf(")");
string mapperAlt = "";
if (bracketIndex != -1 && hyphenIndex != -1)
{
mapperAlt = " (" + shortFolder.Substring(hyphenIndex, bracketIndex - hyphenIndex) + ")";
}

ListViewItem lvItem = new(song._songName);
// lvItem.SubItems.Add(song?._songSubName);
// lvItem.SubItems.Add(song?._songSubName);
lvItem.SubItems.Add(song._songAuthorName);
lvItem.SubItems.Add(song._levelAuthorName);
lvItem.SubItems.Add(song._levelAuthorName + mapperAlt);
lvItem.SubItems.Add(shortFolder);
lvItem.SubItems.Add(link);

Expand All @@ -200,13 +236,14 @@ private void Results_FormClosing(object sender, FormClosingEventArgs e)

// Called twice when resizing both width and height
// Even occurs for file explorer, I wouldn't worry about it
Point buttonRefreshLoc = new(25, 815); // Allocate once
Point buttonOpenLoc = new(106, 815);
Point buttonPlayLoc = new(216, 815);
Point buttonBackLoc = new(324, 815);
Point labelTracksLoc = new(405, 819);
Point buttonRefreshLoc = new(25, 815); // Allocate once
Point buttonOpenLoc = new(106, 815);
Point buttonPlayLoc = new(216, 815);
Point buttonBackLoc = new(324, 815);
Point labelTracksLoc = new(405, 819);
private void Results_Resize(object sender, EventArgs e)
{
if (currentlyResizing) return;
lvResults.Width = Width - 75;
tbFilter.Width = lvResults.Width - 42;
lvResults.Height = Height - 120;
Expand All @@ -233,8 +270,8 @@ public void btnRefresh_Click(object sender, EventArgs e)
private void btOpen_Click(object sender, EventArgs e)
{
string path = Form1.path;
string folder = "";
if(lvResults.SelectedItems.Count > 0)
string folder = "";
if (lvResults.SelectedItems.Count > 0)
{
folder = lvResults.SelectedItems[0].SubItems[3].Text;
}
Expand Down Expand Up @@ -268,7 +305,7 @@ private void tbFilter_TextChanged(object sender, EventArgs e)

private void btn_Back_Click(object sender, EventArgs e)
{
if(waveOut != null)
if (waveOut != null)
{
waveOut.Stop();
}
Expand All @@ -287,7 +324,7 @@ private void OnPlaybackStopped(object sender, StoppedEventArgs args)

private void btnPlay_Click(object sender, EventArgs e)
{
if(playing)
if (playing)
{
waveOut.Stop();
return;
Expand All @@ -308,16 +345,16 @@ private void btnPlay_Click(object sender, EventArgs e)
return;
}
List<string> fileList = Directory.GetFiles(dir).ToList();

// No need for complicated regex, this will be small
foreach(string file in fileList)
foreach (string file in fileList)
{
if(file.EndsWith("ogg") || file.EndsWith("egg"))
if (file.EndsWith("ogg") || file.EndsWith("egg"))
{
waveReader = new VorbisWaveReader(file);
waveOut = new WaveOut();
waveOut.Init(waveReader);
waveOut.Volume = 0.33f; // Actually sets the volume of the application
waveOut.Volume = 0.25f; // Actually sets the volume of the application
waveOut.Play();
waveOut.PlaybackStopped += OnPlaybackStopped;
playing = true;
Expand Down
Loading

0 comments on commit 71010e5

Please sign in to comment.