103 lines
2.3 KiB
C#
103 lines
2.3 KiB
C#
using System;
|
|
using System.Reflection;
|
|
using System.Globalization;
|
|
|
|
using Melanchall.DryWetMidi.Common;
|
|
|
|
using SBRL.Utilities;
|
|
|
|
namespace MusicBoxConverter
|
|
{
|
|
class MainClass
|
|
{
|
|
public static int Main(string[] args)
|
|
{
|
|
CultureInfo.CurrentCulture = new CultureInfo("en-GB", false);
|
|
string inputFilename = "";
|
|
string outputFilename = "";
|
|
bool debug = false;
|
|
MusicBox targetMusicBox = MusicBox.Note30Corrected;
|
|
float scaleFactorX = -1f;
|
|
float scaleFactorY = -1f;
|
|
|
|
for(int i = 0; i < args.Length; i++)
|
|
{
|
|
switch(args[i])
|
|
{
|
|
case "-i":
|
|
case "--input":
|
|
inputFilename = args[++i];
|
|
break;
|
|
|
|
case "-o":
|
|
case "--output":
|
|
outputFilename = args[++i];
|
|
break;
|
|
|
|
case "--auto-dev":
|
|
inputFilename = "/home/sbrl/Music/Sheets/HappyBirthday.midi";
|
|
//inputFilename = "/tmp/Scale.midi";
|
|
|
|
outputFilename = "/tmp/test.svg";
|
|
break;
|
|
|
|
case "--debug":
|
|
debug = true;
|
|
break;
|
|
|
|
case "--box":
|
|
targetMusicBox = (MusicBox)typeof(MusicBox).GetField(
|
|
args[++i],
|
|
BindingFlags.GetField |
|
|
BindingFlags.Static |
|
|
BindingFlags.Public
|
|
).GetValue(null);
|
|
break;
|
|
|
|
case "-sx":
|
|
case "--scale-factor-x":
|
|
scaleFactorX = float.Parse(args[++i], CultureInfo.InvariantCulture);
|
|
break;
|
|
|
|
case "-sy":
|
|
case "--scale-factor-y":
|
|
scaleFactorY = float.Parse(args[++i], CultureInfo.InvariantCulture);
|
|
break;
|
|
|
|
case "-h":
|
|
case "--help":
|
|
Console.Error.WriteLine(EmbeddedFiles.ReadAllText("MusicBoxConverter.Help.txt"));
|
|
return 0;
|
|
|
|
default:
|
|
Console.Error.WriteLine("Error: Unknown option {0}.", args[i]);
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if(inputFilename == string.Empty) {
|
|
Console.Error.WriteLine("Error: No input file specified.");
|
|
return 1;
|
|
}
|
|
if(outputFilename == string.Empty) {
|
|
Console.Error.WriteLine("Error: No output file specified.");
|
|
return 1;
|
|
}
|
|
|
|
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
|
|
inputFilename,
|
|
targetMusicBox
|
|
) {
|
|
Debug = debug
|
|
};
|
|
|
|
if(scaleFactorX > 0)
|
|
converter.SetScaleFactorX(scaleFactorX);
|
|
if(scaleFactorY > 0)
|
|
converter.SetScaleFactorY(scaleFactorY);
|
|
converter.Output(outputFilename);
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
}
|