示例#1
0
        private void btnStartConversion(object sender, EventArgs e)
        {
            OsuFileConverter converter = new OsuFileConverter();

            btnStart.Text    = "Loading...";
            btnStart.Enabled = false;

            if (ValidateInputs())
            {
                // For every file
                for (int i = 0; i < osuFilePaths.Length; i++)
                {
                    // For every convert
                    foreach (var rate in rates)
                    {
                        string audioFilePath;

                        // Convert the .osu file
                        string audioFileName = converter.Start(osuFilePaths[i], osuFileNames[i], tbxAudio.Text, rate, cbxOffset.Checked);

                        // Reset start button
                        btnStart.Text    = "Start Conversion";
                        btnStart.Enabled = true;

                        if (audioFileName == "error")
                        {
                            MessageBox.Show("Could not read the .osu file correctly.", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else if (audioFileName == "fileError")
                        {
                            return;
                        }
                        else
                        {
                            DirectoryInfo songDir = Directory.GetParent(osuFilePaths[i]);
                            audioFilePath = Path.Combine(songDir.FullName, audioFileName);
                            audioFilePath = audioFilePath.Substring(0, audioFilePath.Length - 4);
                        }

                        if (cbxAudio.Checked == true)
                        {
                            if (!File.Exists(audioFilePath + ".mp3"))
                            {
                                MessageBox.Show("Could not find the audio file.", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                return;
                            }

                            // Convert .mp3 file to .wav
                            Codec.MP3ToWave(audioFilePath + ".mp3", audioFilePath + ".wav");

                            // Change the tempo of the .wav
                            string[] args = new string[] { audioFilePath + ".wav", audioFilePath + rate * 100 + ".wav" };
                            float    rateDeltaInProcent = ((float)rate * 100) - 100;
                            bool     keepPitch          = cbxPitch.Checked;
                            AudioStrech.Start(args, rateDeltaInProcent, keepPitch);

                            // Convert .wav file to .mp3
                            Codec.WaveToMP3(audioFilePath + rate * 100 + ".wav", audioFilePath + rate * 100 + ".mp3");

                            // Remove the .wav files
                            File.Delete(audioFilePath + ".wav");
                            File.Delete(audioFilePath + rate * 100 + ".wav");
                        }
                    }
                }

                DialogResult exit = MessageBox.Show("Convertions successful! Do you want to exit the application?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                if (exit == DialogResult.Yes)
                {
                    Application.Exit();
                }
            }

            // Reset start button
            btnStart.Text    = "Start Conversion";
            btnStart.Enabled = true;
        }
示例#2
0
        private void btnStartConversion(object sender, EventArgs e)
        {
            OsuFileConverter converter = new OsuFileConverter();
            bool             success   = false;

            // Visual
            btnStart.Text    = "Loading...";
            btnStart.Enabled = false;

            if (ValidateInputs())
            {
                // For every file
                for (int i = 0; i < osuFilePaths.Length; i++)
                {
                    // For every convert
                    foreach (var rate in rates)
                    {
                        string audioFilePath;
                        string audioFileName = converter.getAudioName(osuFilePaths[i], rate);

                        if (audioFileName == "error")
                        {
                            MessageBox.Show("Could not read the .osu file correctly.", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else if (audioFileName == "fileError")
                        {
                            return;
                        }
                        else
                        {
                            DirectoryInfo songDir = Directory.GetParent(osuFilePaths[i]);
                            audioFilePath = Path.Combine(songDir.FullName, audioFileName);
                            audioFilePath = audioFilePath.Substring(0, audioFilePath.Length - 4);
                        }

                        // Convert the .mp3 file
                        if (cbxAudio.Checked == true)
                        {
                            if (!File.Exists(audioFilePath + ".mp3"))
                            {
                                MessageBox.Show("Could not find the .mp3 file for the .osu file you selected. Make sure they are in the same folder!", "Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                // Reset start button
                                btnStart.Text    = "Start Conversion";
                                btnStart.Enabled = true;

                                return;
                            }
                            else if (File.Exists(audioFilePath + rate * 100 + ".mp3"))
                            {
                                DialogResult answer = MessageBox.Show("There already excists an audio file called " + (audioFileName.Remove(audioFileName.Length - 4) + rate * 100 + ".mp3") + " here. Do you want to OVERWRITE the file?", "Warning", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);

                                if (answer == DialogResult.Yes)
                                {
                                    ConvertAudio(audioFilePath, rate);
                                }
                                else if (answer == DialogResult.No)
                                {
                                    // No nothing
                                }
                                else if (answer == DialogResult.Cancel)
                                {
                                    // Stop converting

                                    // Reset start button
                                    btnStart.Text    = "Start Conversion";
                                    btnStart.Enabled = true;

                                    return;
                                }
                            }
                            else
                            {
                                ConvertAudio(audioFilePath, rate);
                            }
                        }

                        // Convert the .osu file
                        success = converter.Start(osuFilePaths[i], osuFileNames[i], rate, cbxAudio.Checked);
                    }
                }

                if (success)
                {
                    DialogResult exit = MessageBox.Show("Convertions successful! Do you want to exit the application?", "Success", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
                    if (exit == DialogResult.Yes)
                    {
                        Application.Exit();
                    }
                }
            }

            // Reset start button
            btnStart.Text    = "Start Conversion";
            btnStart.Enabled = true;
        }