예제 #1
0
 private void Form1_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (validFile)
     {
         LibRemuxer.endProcessing();
     }
 }
예제 #2
0
        private async void Form1_Load(object sender, EventArgs e)
        {
            processInfo.Text       = "";
            processInfo.ScrollBars = RichTextBoxScrollBars.None;
            if (!LibRemuxer.beginProcessing(ref args))
            {
                if (!args.suppressErrors)
                {
                    Program.showError($"Couldn't parse input file \"{args.inputPath}\".");
                }
                Environment.Exit(1);
            }
            else
            {
                validFile = true;
                string text = "Extracting";
                if (args.midiPath != null)
                {
                    text += " notes";
                    if (args.audioPath != null)
                    {
                        text += " and audio";
                    }
                }
                else
                {
                    text += " audio";
                }
                text += $" from {Path.GetFileName(args.inputPath)}";

                if (args.numSubSongs > 1)
                {
                    text += $" ({args.subSong}/{args.numSubSongs}).";
                }
                processInfo.Text = text;

                await Task.Run(delegate
                {
                    float progress = 0;
                    while (progress >= 0)
                    {
                        progressBar1.Invoke(new Action(
                                                delegate
                        {
                            int percent = (int)(progress * 100);
                            if (progress > 0)
                            {
                                progressBar1.Value = percent;
                            }
                            Text = percent.ToString() + "%";
                        }));
                        progress = LibRemuxer.process();
                    }
                });
            }
            Close();
        }
예제 #3
0
        static void Main(string[] cmdLineArgs)
        {
            Args args = new Args();

            if (cmdLineArgs.Length == 0)
            {
                showUsage();
                return;
            }

            bool audioFlag = false, midiFlag = false;

            for (int i = 0; i < cmdLineArgs.Length; i++)
            {
                string arg = cmdLineArgs[i];
                if (arg.Length >= 2 && arg[0] == '-')
                {
                    char   flag    = arg[1];
                    string flagArg = null;

                    //Was an argument relating to this flag specified?
                    if (arg.Length > 2)
                    {
                        flagArg = arg.Substring(2);
                    }
                    if (flag == 'm')                     //Midi output
                    {
                        midiFlag      = true;
                        args.midiPath = flagArg;
                    }
                    else if (flag == 'a')                     //Audio output
                    {
                        audioFlag      = true;
                        args.audioPath = flagArg;
                    }
                    else if (flag == 's')                     //Sub song
                    {
                        if (flagArg != null)
                        {
                            if (!int.TryParse(flagArg, out args.subSong))
                            {
                                showUsage($"Invalid -s argument \"{flagArg}\".");
                                return;
                            }
                        }
                    }
                    else if (flag == 'l')                     //Song lenght
                    {
                        if (flagArg != null)
                        {
                            if (!float.TryParse(flagArg, out args.songLengthS))
                            {
                                showUsage($"Invalid -l argument \"{flagArg}\".");
                                return;
                            }
                        }
                    }
                    else if (flag == 'i')                     //Input note file
                    {
                        args.modInsTrack = true;
                    }
                    else if (flag == 'e')                     //Suppress conversion errors
                    {
                        args.suppressErrors = true;
                    }
                    else
                    {
                        showUsage($"Invalid flag -{flag}.");
                        return;
                    }
                }
                else
                {
                    args.inputPath = cmdLineArgs[i];
                    if (string.IsNullOrWhiteSpace(args.inputPath))
                    {
                        showUsage("No input file specified.");
                        return;
                    }
                }
            }

            //Check if input file exests
            if (!File.Exists(args.inputPath))
            {
                showError($"Couldn't find input file \"{args.inputPath}\".");
                return;
            }

            //Derive output paths from input path if output path is not specified or if no output flags are specified
            bool noOutputFlags = !midiFlag && !audioFlag;

            if (noOutputFlags || midiFlag && args.midiPath == null)
            {
                args.midiPath = Path.ChangeExtension(args.inputPath, "mid");
            }
            if (noOutputFlags || audioFlag && args.audioPath == null)
            {
                args.audioPath = Path.ChangeExtension(args.inputPath, "wav");
            }

            //Check validity of output paths
            try
            {
                if (midiFlag)
                {
                    checkPath(args.midiPath, "-m");
                }
                if (audioFlag)
                {
                    checkPath(args.audioPath, "-a");
                }
            }
            catch (Exception e)
            {
                showError(e.Message);
                return;
            }

            try
            {
                LibRemuxer.initLib();
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new Form1(args));
            }
            finally
            {
                LibRemuxer.closeLib();
            }
        }