Пример #1
0
        // Merge button event function - Merges the WAV files together.
        private void MergeAudioButton_Click(object sender, EventArgs e)
        {
            // Get the user's home directory, and also create the temporary directory name.
            String userDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
            userDir = userDir.Substring(0, userDir.LastIndexOf('\\'));
            String tempDir = userDir + "\\AudioMergerTemp";

            try
            {
                // If there are less than 2 audio files, then there is nothing to do.
                if (FilenameGrid.Rows.Count < 2)
                {
                    String message = "Nothing to do.";
                    if ((FilenameGrid.Rows.Count == 1) && ((String)FilenameGrid.Rows[0].Cells[0].Value != null))
                        message += "  There is only 1 audio file.";
                    MessageBox.Show(this, message, "Message");
                    return;
                }

                // 2. Create the temporary directory in the user's home dir
                Directory.CreateDirectory(tempDir);
                if (!Directory.Exists(tempDir))
                    throw new SystemException("Unable to create temporary work directory: " + tempDir);

                // 3. Prompt the user for the output filename
                OpenFileDialog fileDlg = new OpenFileDialog();
                fileDlg.Filter = "WAV audio files (*.wav)|*.wav";
                fileDlg.Title = "Choose an output file";
                fileDlg.CheckFileExists = false;
                // Show the dialog, and if the user chooses to cancel, then
                // just return.
                if (fileDlg.ShowDialog() != DialogResult.OK)
                {
                    Directory.Delete(tempDir);
                    return;
                }
                String mixOutputFilename = fileDlg.FileName;

                StatusLabel1.Text = "Working...";

                // Create an array of filenames for the WAVFile class
                String[] audioFilenames = new String[FilenameGrid.Rows.Count];
                for (int row = 0; row < FilenameGrid.Rows.Count; ++row)
                    audioFilenames[row] = GetFullyPathedAudioFilename(row);

                // Perform the audio mix
                AudioMergeThread mergeThread = new AudioMergeThread(this, audioFilenames, fileDlg.FileName, tempDir);
                mergeThread.mThread.Start();
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                EnableAudioMergeGUIElements();
            }
        }
Пример #2
0
        // Merge button event function - Merges the WAV files together.
        private void MergeAudioButton_Click(object sender, EventArgs e)
        {
            // Get the user's home directory, and also create the temporary directory name.
            String userDir = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);

            userDir = userDir.Substring(0, userDir.LastIndexOf('\\'));
            String tempDir = userDir + "\\AudioMergerTemp";

            try
            {
                // If there are less than 2 audio files, then there is nothing to do.
                if (FilenameGrid.Rows.Count < 2)
                {
                    String message = "Nothing to do.";
                    if ((FilenameGrid.Rows.Count == 1) && ((String)FilenameGrid.Rows[0].Cells[0].Value != null))
                    {
                        message += "  There is only 1 audio file.";
                    }
                    MessageBox.Show(this, message, "Message");
                    return;
                }

                // 2. Create the temporary directory in the user's home dir
                Directory.CreateDirectory(tempDir);
                if (!Directory.Exists(tempDir))
                {
                    throw new SystemException("Unable to create temporary work directory: " + tempDir);
                }

                // 3. Prompt the user for the output filename
                OpenFileDialog fileDlg = new OpenFileDialog();
                fileDlg.Filter          = "WAV audio files (*.wav)|*.wav";
                fileDlg.Title           = "Choose an output file";
                fileDlg.CheckFileExists = false;
                // Show the dialog, and if the user chooses to cancel, then
                // just return.
                if (fileDlg.ShowDialog() != DialogResult.OK)
                {
                    Directory.Delete(tempDir);
                    return;
                }
                String mixOutputFilename = fileDlg.FileName;

                StatusLabel1.Text = "Working...";

                // Create an array of filenames for the WAVFile class
                String[] audioFilenames = new String[FilenameGrid.Rows.Count];
                for (int row = 0; row < FilenameGrid.Rows.Count; ++row)
                {
                    audioFilenames[row] = GetFullyPathedAudioFilename(row);
                }

                // Perform the audio mix
                AudioMergeThread mergeThread = new AudioMergeThread(this, audioFilenames, fileDlg.FileName, tempDir);
                mergeThread.mThread.Start();
            }
            catch (Exception exc)
            {
                MessageBox.Show(this, exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                EnableAudioMergeGUIElements();
            }
        }