Skip to content

Commit

Permalink
Final touchups
Browse files Browse the repository at this point in the history
Finish (not fix) C8 Eraser. It is good enough, I am eager to work on actually making music again.
  • Loading branch information
livvy94 committed Dec 1, 2021
1 parent 0259773 commit 7633e09
Show file tree
Hide file tree
Showing 10 changed files with 292 additions and 88 deletions.
7 changes: 0 additions & 7 deletions .appveyor.yml

This file was deleted.

4 changes: 0 additions & 4 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion PK Piano/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<configuration>
<startup>

<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.8"/></startup>
</configuration>
137 changes: 79 additions & 58 deletions PK Piano/Form1.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
using System;
using System.Windows.Forms;
using System.Media;
using System.Text;
using NAudio.Wave;
using NAudio.Wave;
using NAudio.Wave.SampleProviders;
using System;
using System.Collections.Generic;
using System.Media;
using System.Windows.Forms;

namespace PK_Piano
{
Expand Down Expand Up @@ -731,43 +730,44 @@ private void btnMPTconvert_Click(object sender, EventArgs e)
private void btnC8eraser_Click(object sender, EventArgs e)
{
//VALIDATION
//string clipboardContents = Clipboard.GetText();
//if (string.IsNullOrWhiteSpace(clipboardContents)) return; //only continue if there's something there
//if (clipboardContents.Contains("Not enough rows to process")) return;

//clipboardContents = clipboardContents.Replace("[", "").Replace("]", ""); //get rid of brackets
//var input = SongPiece.StringToBytes(clipboardContents);
var input = SongPiece.StringToBytes("0C 7F A7 C8 0C A7 C8");
var goodVersion = SongPiece.StringToBytes("18 7F A7 18 A7");
string clipboardContents = Clipboard.GetText();
if (string.IsNullOrWhiteSpace(clipboardContents)) return; //only continue if there's something there
if (clipboardContents.Contains("Not enough rows to process")) return;
clipboardContents = clipboardContents.Replace("[", "").Replace("]", ""); //get rid of brackets

List<byte> input;

try
{
input = SongPiece.StringToBytes(clipboardContents);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
return;
}

//var input = SongPiece.StringToBytes("0C A7 C8 C8"); //DIY Unit Test
//var goodVersion = SongPiece.StringToBytes("24 A7");
var optimizedBytes = ProcessBytes(input);
//RunTest(optimizedBytes, goodVersion);

RunTest(optimizedBytes, goodVersion);
//Clipboard.SetText(result.ToString());
Clipboard.SetText(optimizedBytes);
if (sfxEnabled) sfxEquipped.Play();
}

public static List<byte> ProcessBytes(List<byte> bytesInput)
public static string ProcessBytes(List<byte> bytesInput)
{
const string NO_NOTE_LENGTH_ERROR = "In order for the C8 Eraser function to work correctly, each note needs a note length in front of it.";
var result = new List<byte>();
var piece = new SongPiece();
bool lastByteWasANote = false;
bool lastByteWasANoteLength = false;
bool lastByteWasAnEffect = false;
int effectSkip = 0;
foreach (var b in bytesInput)
{
if (effectSkip > 0) //for effects with parameters, which shouldn't be processed
{
effectSkip--;
piece.tempNoteCollection.Add(b); //add the effect, byte by byte
continue;
}

if (lastByteWasAnEffect)
if (piece.tempNoteCollection.Count > 1)
{
result.AddRange(piece.ParseHex());
piece = new SongPiece(piece.noteLength, piece.noteLengthMultiplier); //keep the old note settings!
lastByteWasAnEffect = false;
throw new Exception(NO_NOTE_LENGTH_ERROR);
}

if (SongPiece.IsNoteLength(b))
Expand Down Expand Up @@ -805,61 +805,74 @@ public static List<byte> ProcessBytes(List<byte> bytesInput)
if (b == 0xC8)
{
piece.noteLengthMultiplier++; //keep track of how many C8s there have been
continue;
}
else
{
piece.tempNoteCollection.Add(b); //add the note to the collection
}
continue;
}

if (SongPiece.IsEffect(b))
{
effectSkip = SongPiece.GetNumberOfParameters(b);
piece.tempNoteCollection.Add(b);
lastByteWasAnEffect = true;
//I'm abandoning this functionality, but if anyone would like to try
//implementing it, I'd greatly appreciate it.
throw new Exception($"Effects such as {b:X2} are not supported yet.");
}
}

if (piece.noteLength == 0xFF)
{
throw new Exception(NO_NOTE_LENGTH_ERROR);
}

//Add any remaining notes to result
result.AddRange(piece.ParseHex());
return result;
}

public static void RunTest(List<byte> resultBytes, List<byte> goodVersionBytes)
{
//DIY unit test
string result = "";
foreach (var b in resultBytes)
//Convert the byte array to a string
var resultString = "";
foreach (var num in result)
{
result += b.ToString("X2") + " "; //convert the list back into a string
resultString += num.ToString("X2") + ' ';
}

string goodVersion = "";
foreach (var b in goodVersionBytes)
{
goodVersion += b.ToString("X2") + " "; //convert the list back into a string
}
return resultString.TrimEnd(' ');
}

result = result.Trim();
goodVersion = goodVersion.Trim();
//public static void RunTest(List<byte> resultBytes, List<byte> goodVersionBytes)
//{
// //DIY Unit Test
// string result = "";
// foreach (var b in resultBytes)
// {
// result += b.ToString("X2") + " "; //convert the list back into a string
// }

var message = "";
if (result == goodVersion)
message += "*** PASS ***\r\n";
else
message += "*** FAIL ***\r\n";
message += "Result:\r\n" + result + "\r\nDesired output:\r\n" + goodVersion;
MessageBox.Show(message);
}
// string goodVersion = "";
// foreach (var b in goodVersionBytes)
// {
// goodVersion += b.ToString("X2") + " "; //convert the list back into a string
// }

// result = result.Trim();
// goodVersion = goodVersion.Trim();

// var message = "";
// if (result == goodVersion)
// message += "*** PASS ***\r\n";
// else
// message += "*** FAIL ***\r\n";
// message += "Result:\r\n" + result + "\r\nDesired output:\r\n" + goodVersion;
// MessageBox.Show(message);
//}


//Text blip stuff
//If the sfxEnabled boolean value is set to true, then various parts of the UI will give audio feedback.
//I'm getting kind of tired of it, though, so I'm going to make it toggleable in the future.
byte numberOfLettersBeforeSound;
SoundPlayer sfxTextBlip = new SoundPlayer(Properties.Resources.ExtraAudio_Text_Blip); //adding these so it doesn't make a new instance of SoundPlayer *every* time
SoundPlayer sfxEquipped = new SoundPlayer(Properties.Resources.ExtraAudio_Equipped_);
readonly SoundPlayer sfxTextBlip = new SoundPlayer(Properties.Resources.ExtraAudio_Text_Blip); //adding these so it doesn't make a new instance of SoundPlayer *every* time
readonly SoundPlayer sfxEquipped = new SoundPlayer(Properties.Resources.ExtraAudio_Equipped_);

private void PlayTextTypeSound(string type)
{
Expand Down Expand Up @@ -958,6 +971,14 @@ private void Form1_Load(object sender, EventArgs e)
toolTip1.SetToolTip(btnCopySlidingPan, "[E2 length panning]");
toolTip1.SetToolTip(btnCopySlidingVolume, "[EE length volume]");

toolTip1.SetToolTip(btnTremolo, "[EB start speed range]");
toolTip1.SetToolTip(btnChannelTranspose, "Transpose a channel by a number of semitones.");
toolTip1.SetToolTip(btnMPTconvert, "Convert a single channel of notes copied from an OpenMPT module.");
toolTip1.SetToolTip(btnC8eraser, "Take a bunch of notes in the clipboard and attempt to optimize them.");

toolTip1.SetToolTip(btnTempo, "[E7 tempo]");
toolTip1.SetToolTip(btnGlobalVolume, "[E5 volume]");

//toolTip1.SetToolTip(ANYTHING, "");
//toolTip1.SetToolTip(ANYTHING, "");
//toolTip1.SetToolTip(ANYTHING, "");
Expand Down
Loading

0 comments on commit 7633e09

Please sign in to comment.