コード例 #1
0
        private void runFadeEffectProcess()
        {
            if (isRunning)
            {
                return;
            }
            try
            {
                if (fadeInPresetComboBox.Items.Count <= 0)
                {
                    MessageBox.Show("Fade in Preset is empty.",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    fadeInPresetComboBox.Focus();
                    return;
                }
                if (fadeOutPresetComboBox.Items.Count <= 0)
                {
                    MessageBox.Show("Fade in Preset is empty.",
                                    "Warning",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Warning);
                    fadeOutPresetComboBox.Focus();
                    return;
                }
                isRunning = true;

                List <string> files = new List <string>();
                foreach (DataGridViewRow row in fileList.Rows)
                {
                    files.Add(Path.Combine((string)row.Cells[1].Value,
                                           (string)row.Cells[0].Value));
                }
                if (files.Count <= 0)
                {
                    return;
                }

                progressBar.Maximum = files.Count;
                int count = 0;
                foreach (string file in files)
                {
                    fileList.Rows[count].ErrorText = string.Empty;
                    if (cancelRequest)
                    {
                        break;
                    }

                    ISfFileHost filehost = null;
                    int         undo     = 0;
                    try
                    {
                        filehost = forgeApp.FindFile(file);
                        if (filehost == null)
                        {
                            filehost = forgeApp.OpenFile(file,
                                                         false,
                                                         false);
                        }
                        if (filehost.WaitForDoneOrCancel() == SfStatus.Fail)
                        {
                            fileList.Rows[count].ErrorText = string.Format("{0} can not be opened.",
                                                                           file);
                            continue;
                        }
                        undo = filehost.BeginUndo("Fade In and Out");
                        SfStatus status   = SfStatus.NotAvailable;
                        Int64    fadetime = filehost.SecondsToPosition((double)fadeInTimeNumericUpDown.Value);
                        if (fadetime <= filehost.Length)
                        {
                            filehost.DoEffect(EffectName,
                                              fadeInPresetComboBox.Text,
                                              new SfAudioSelection(0,
                                                                   fadetime),
                                              EffectOptions.EffectOnly);
                            status = filehost.WaitForDoneOrCancel();
                            if (status == SfStatus.Success)
                            {
                                fadetime = filehost.SecondsToPosition((double)fadeOutTimeNumericUpDown.Value);
                                if (fadetime <= filehost.Length)
                                {
                                    filehost.DoEffect(EffectName,
                                                      fadeOutPresetComboBox.Text,
                                                      new SfAudioSelection(filehost.Length - fadetime,
                                                                           fadetime),
                                                      EffectOptions.EffectOnly);
                                    status = filehost.WaitForDoneOrCancel();
                                }
                                else
                                {
                                    fileList.Rows[count].ErrorText = string.Format("The fade out time({0}) is longer than total time({1}).",
                                                                                   fadetime,
                                                                                   filehost.Length);
                                    status = SfStatus.Fail;
                                }
                            }
                        }
                        else
                        {
                            fileList.Rows[count].ErrorText = string.Format("The fade in time({0}) is longer than total time({1}).",
                                                                           fadetime,
                                                                           filehost.Length);
                            status = SfStatus.Fail;
                        }
                        filehost.WaitForDoneOrCancel();
                        if (status != SfStatus.Success)
                        {
                            if (fileList.Rows[count].ErrorText == string.Empty)
                            {
                                fileList.Rows[count].ErrorText = string.Format("error code({0}).",
                                                                               status);
                            }
                        }
                        filehost.EndUndo(undo,
                                         (status != SfStatus.Success));
                        filehost.WaitForDoneOrCancel();
                        filehost.Save(SaveOptions.WaitForDoneOrCancel);
                        filehost.WaitForDoneOrCancel();
                        filehost.Close(CloseOptions.SaveChanges);
                        filehost.WaitForDoneOrCancel();
                    }
                    catch (Exception e)
                    {
                        forgeApp.SetStatusText(e.ToString());
                        filehost.EndUndo(undo,
                                         true);
                        filehost.Close(CloseOptions.DiscardChanges);
                        fileList.Rows[count].ErrorText = e.ToString();
                    }
                    finally
                    {
                        count++;
                        progressBar.Value++;
                        progressBar.Refresh();
                    }
                }
            }
            finally
            {
                isRunning     = false;
                cancelRequest = false;
            }
        }