示例#1
0
        public void LoadFile(string path)
        {
            try {
                TmrUpdate.Stop();
                if (_file != null)
                {
                    _file.FourierProgress -= FourierProgress;
                    _file.FourierComplete -= FourierComplete;
                    _file.Dispose();
                }
                BtnPlay.Show();
                BtnSave.Show();
                BtnSynth.Show();
                BtnConvert.Show();
                LbTip.Text = "Loading audio file, please wait...";
                LbTip.Show();
                _curTime = TimeSpan.Zero;

                sheet.ClearNotes();
                sheet.StopSynthesize();

                sheet.Redraw();
                sheet.ScrollTop();

                _file = new AudioFile(path);

                _file.LoadComplete += (object sender, EventArgs e) =>
                {
                    LbTip.Invoke(new Action(delegate {
                        LbTip.Text = "Right click near the left end of a note to edit it.\nCtrl + N to add a note.";
                    }));
                    _file.Stopped         += PlaybackStopped;
                    _file.FourierProgress += FourierProgress;
                    _file.FourierComplete += FourierComplete;

                    _prevTime = TimeSpan.FromTicks(-1);
                    _curTime  = TimeSpan.Zero;

                    sheet.Invoke(new Action(() =>
                    {
                        sheet.Length = _file.TotalTime;
                        sheet.Time   = TimeSpan.Zero;

                        sheet.Redraw();
                        sheet.ScrollTop();
                        TmrRedraw.Start();
                    }));

                    _file.Analyze();
                };
                _maxLen = 0;

                this.Text = Path.GetFileName(path) + " - " + Application.ProductName;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                MessageBox.Show("Failed to load audio file! File may be corrupted or unsupported.", "Load failed", MessageBoxButtons.OK,
                                MessageBoxIcon.Exclamation);
            }
        }