Exemplo n.º 1
0
        internal void StartSync()
        {
            long startpos;

            if (IsPaused())
            {
                startpos = -1;
            }
            else if (!clsAudioSync.StaticAudioSyncEna)
            {
                startpos = 0;
            }
            else
            {
                startpos = (P.F.CurrentBBT.Beats < Elapsed.Play.Count &&
                            Elapsed.Play[P.F.CurrentBBT.Beats] > 0) ?
                           Elapsed.Play[P.F.CurrentBBT.Beats] :
                           Elapsed.GetPrevActivePos(P.F.CurrentBBT.Beats);
            }

            int?nextbeat = null;
            //long? playsigbytes = (!P.frmStart.chkNoAudioSync.Checked && AutoSync.Cmd != clsAutoSync.eCmd.Record) ?
            long?playsigbytes = (clsAudioSync.StaticAudioSyncEna && clsAudioSync.Cmd != clsAudioSync.eCmd.Record) ?
                                Elapsed.GetNextActive(CurrentBBT.Beats, out nextbeat) : null;

            try {
                if (P.F.frmAutoSync != null && !IsPaused() &&
                    P.F.frmAutoSync.trkPos.Enabled && P.F.frmAutoSync.chkStartRecPos.Checked)
                {
                    long pos   = GetSeconds2Units(P.F.frmAutoSync.trkPos.Value);
                    int  index = Elapsed.GetPlayIndex(pos) + 1; //one after next
                    //if (!P.frmStart.chkNoAudioSync.Checked) {
                    if (clsAudioSync.StaticAudioSyncEna)
                    {
                        playsigbytes = (index < Elapsed.Play.Count) ? Elapsed.Play[index] : (long?)null;
                    }
                    PlayFile((double)P.F.frmAutoSync.trkPos.Value, playsigbytes);
                }
                else
                {
                    PlayFile(startpos, playsigbytes); //play and wait for switchkey
                }
                P.F.frmAutoSync?.StartPlay();
            }
            catch (AudioIOException) {
                return;
            }

            MidiPlay.Sync.RefreshBBTTimer.Stop();
            MidiPlay.Sync.BBTQueue.Clear();

            //* refreshBBT on next OnMP3Timer call
            if (nextbeat.HasValue)
            {
                CurrentBBT = new clsMTime.clsBBT(nextbeat.Value, true);
            }

            if (P.F.frmAutoSync != null)
            {
                P.F.frmAutoSync.UpdateCurrentPos();
            }
            P.frmStart.StreamPlayOnAll();      //enable/disable StartPlay/StopPlay etc.
            P.frmStart.FormsStreamOnOff(true); //enable/disable controls (not StartPlay/StopPlay etc.)
        }