public static byte[] StringToBytes(string OutputBytesString, byte channel, byte velocity)
{
lastOutputString = "";
// Null string case - Return null
if (OutputBytesString == null) return null;
// Empty string case - Return null
if (OutputBytesString.Equals("")) return null;
// Limit channel
channel = (byte)(channel & 0x0F);
// Temporary array since BitConverter works on arrays.
byte[] temp = new byte[2];
temp[0] = channel;
temp[1] = velocity;
// Replace N with channel and VV with velocity (uppercase is forced by dialog box)
OutputBytesString = OutputBytesString.Replace( "N", System.BitConverter.ToString(temp, 0, 1).Substring(1,1) );
OutputBytesString = OutputBytesString.Replace( "VV", System.BitConverter.ToString(temp, 1, 1) );
// Store result for debugging
lastOutputString = OutputBytesString;
// Update byte representation
string[] array_hex = OutputBytesString.Split(' ');
byte[] array_bytes = new byte[array_hex.Length];
for (int i = 0; i < array_hex.Length; i++)
{
// This could potentially throw a parsing exception. Ignore here so it bubbles up to caller.
array_bytes[i] = System.Convert.ToByte(array_hex[i], 16);
}
return array_bytes;
}
}