Exemple #1
0
        public const int HResultFileAlreadyExists = -2147024816; // 0x80070050

        static void Main(string[] args)
        {
            string defaultInput = null;

            if (args.Length > 0 && !string.IsNullOrEmpty(args[0]))
            {
                defaultInput = args[0];
            }

            var midiPath = PromptForPath("Enter MIDI path", defaultInput);

            var fileDir             = midiPath.Directory.FullName;
            var inFileName          = Path.GetFileNameWithoutExtension(midiPath.Name);
            var outFilePath         = Path.Combine(fileDir, Path.ChangeExtension(inFileName, "txt"));
            var fixedOutFilePath    = Path.Combine(fileDir, Path.ChangeExtension(inFileName + "_clean", "mid"));
            var fixedOutFilePathTxt = Path.ChangeExtension(fixedOutFilePath, "txt");

            if (File.Exists(fixedOutFilePath))
            {
                if (!PromptConfirm($"'{fixedOutFilePath}' already exists, overwrite it?"))
                {
                    Console.WriteLine("Aborted");
                    Console.ReadKey();
                    return;
                }
            }

            TryDumpFile(outFilePath, midiPath.FullName);

            var fixer = new MidiFixer();

            fixer.AddMessage += (sender, handlerArgs) => Console.WriteLine($"{handlerArgs.Type}: {handlerArgs.Message}");;

            try
            {
                fixer.Fix(midiPath.FullName, fixedOutFilePath);
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to clean midi: " + e.Message);
                Console.Write("Done");
                Console.ReadKey();
                Environment.Exit(1);
            }

            Console.WriteLine("");

            TryDumpFile(fixedOutFilePathTxt, fixedOutFilePath);

            Console.WriteLine("Done!");
            Console.ReadKey();
        }
Exemple #2
0
        private async void ConvertButtonClick(object sender, EventArgs e)
        {
            var midiPath = new FileInfo(filePathBox.Text);

            var convert = Task.Run(() =>
            {
                var fileDir             = midiPath.Directory.FullName;
                var inFileName          = Path.GetFileNameWithoutExtension(midiPath.Name);
                var outFilePath         = Path.Combine(fileDir, Path.ChangeExtension(inFileName, "txt"));
                var fixedOutFilePath    = Path.Combine(fileDir, Path.ChangeExtension(inFileName + "_clean", "mid"));
                var fixedOutFilePathTxt = Path.ChangeExtension(fixedOutFilePath, "txt");

                var dumper = new Dumper();
                using (var fs = new FileStream(outFilePath, FileMode.Create))
                    dumper.Dump(midiPath.FullName, fs);

                var fixer = new MidiFixer();
                fixer.Fix(midiPath.FullName, fixedOutFilePath);

                using (var fs = new FileStream(fixedOutFilePathTxt, FileMode.Create))
                    dumper.Dump(fixedOutFilePath, fs);
            });

            try
            {
                await convert;
                MessageBox.Show("Done", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (IOException ioe)
            {
                MessageBox.Show(ioe.Message, "File Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (FormatException fe)
            {
                MessageBox.Show(fe.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }