예제 #1
0
 void Tick()
 {
     time.Start();
     while (State != PlayerState.ShutDown)
     {
         if (State == PlayerState.Playing)
         {
             // Do Song Tick
             tempoStack += Tempo;
             int wait = Engine.GetTempoWait();
             while (tempoStack >= wait)
             {
                 tempoStack -= wait;
                 bool allDone = true;
                 for (int i = 0; i < NumTracks; i++)
                 {
                     Track track = tracks[i];
                     if (!track.Stopped || !SoundMixer.Instance.AllDead(i))
                     {
                         allDone = false;
                     }
                     track.Tick();
                     bool update = false;
                     while (track.Delay == 0 && !track.Stopped)
                     {
                         if (ExecuteNext(i))
                         {
                             update = true;
                         }
                     }
                     if (update || track.MODDepth > 0)
                     {
                         SoundMixer.Instance.UpdateChannels(i, track.GetVolume(), track.GetPan(), track.GetPitch());
                     }
                 }
                 position++;
                 if (allDone)
                 {
                     Stop();
                     SongEnded?.Invoke();
                 }
             }
         }
         // Do Instrument Tick
         if (State != PlayerState.Paused)
         {
             SoundMixer.Instance.Process();
         }
         // Wait for next frame
         time.Wait();
     }
     time.Stop();
 }
예제 #2
0
        void Tick()
        {
            time.Start();
            while (State != PlayerState.ShutDown)
            {
                if (State == PlayerState.Playing)
                {
                    tempoStack += tempo;
                    while (tempoStack >= 240)
                    {
                        tempoStack -= 240;
                        bool allDone = true;
                        for (int i = 0; i < 0x10; i++)
                        {
                            Track track = Tracks[i];
                            if (track.Enabled)
                            {
                                track.Tick();
                                while (track.Delay == 0 && !track.WaitingForNoteToFinishBeforeContinuingXD && !track.Stopped)
                                {
                                    ExecuteNext(track);
                                }
                                if (!track.Stopped || track.Channels.Count != 0)
                                {
                                    allDone = false;
                                }
                            }
                        }
                        if (allDone)
                        {
                            Stop();
                            SongEnded?.Invoke();
                        }
                    }

                    SoundMixer.Instance.ChannelTick();
                    SoundMixer.Instance.Process();
                }
                // Wait for next frame
                time.Wait();
            }
            time.Stop();
        }
예제 #3
0
        private void Tick()
        {
            _time.Start();
            while (true)
            {
                PlayerState state     = State;
                bool        playing   = state == PlayerState.Playing;
                bool        recording = state == PlayerState.Recording;
                if (!playing && !recording)
                {
                    goto stop;
                }

                void MixerProcess()
                {
                    _mixer.Process(_tracks, playing, recording);
                }

                while (_tempoStack >= 75)
                {
                    _tempoStack -= 75;
                    bool allDone = true;
                    for (int i = 0; i < 0x10; i++)
                    {
                        Track track = _tracks[i];
                        if (track.Enabled)
                        {
                            byte prevDuration = track.NoteDuration;
                            track.Tick();
                            bool update = false;
                            while (track.Rest == 0 && !track.Stopped)
                            {
                                ExecuteNext(i, ref update);
                            }
                            if (i == _longestTrack)
                            {
                                if (ElapsedTicks == MaxTicks)
                                {
                                    if (!track.Stopped)
                                    {
                                        ElapsedTicks = Events[i][track.CurEvent].Ticks[0] - track.Rest;
                                        _elapsedLoops++;
                                        if (ShouldFadeOut && !_mixer.IsFading() && _elapsedLoops > NumLoops)
                                        {
                                            _mixer.BeginFadeOut();
                                        }
                                    }
                                }
                                else
                                {
                                    ElapsedTicks++;
                                }
                            }
                            if (prevDuration == 1 && track.NoteDuration == 0) // Note was not renewed
                            {
                                track.Channel.State = EnvelopeState.Release;
                            }
                            if (!track.Stopped)
                            {
                                allDone = false;
                            }
                            if (track.NoteDuration != 0)
                            {
                                allDone = false;
                                if (update)
                                {
                                    track.Channel.SetVolume(track.Volume, track.Panpot);
                                    track.Channel.SetPitch(track.GetPitch());
                                }
                            }
                        }
                    }
                    if (_mixer.IsFadeDone())
                    {
                        allDone = true;
                    }
                    if (allDone)
                    {
                        MixerProcess();
                        State = PlayerState.Stopped;
                        SongEnded?.Invoke();
                    }
                }
                _tempoStack += _tempo;
                MixerProcess();
                if (playing)
                {
                    _time.Wait();
                }
            }
stop:
            _time.Stop();
        }
예제 #4
0
        private void Tick()
        {
            _time.Start();
            while (true)
            {
                PlayerState state     = State;
                bool        playing   = state == PlayerState.Playing;
                bool        recording = state == PlayerState.Recording;
                if (!playing && !recording)
                {
                    goto stop;
                }

                void MixerProcess()
                {
                    _mixer.ChannelTick();
                    _mixer.Process(playing, recording);
                }

                while (_tempoStack >= 240)
                {
                    _tempoStack -= 240;
                    bool allDone = true;
                    for (int trackIndex = 0; trackIndex < _tracks.Length; trackIndex++)
                    {
                        Track track = _tracks[trackIndex];
                        track.Tick();
                        while (track.Rest == 0 && !track.Stopped)
                        {
                            ExecuteNext(track);
                        }
                        if (trackIndex == _longestTrack)
                        {
                            if (ElapsedTicks == MaxTicks)
                            {
                                if (!track.Stopped)
                                {
                                    List <SongEvent> evs = Events[trackIndex];
                                    for (int i = 0; i < evs.Count; i++)
                                    {
                                        SongEvent ev = evs[i];
                                        if (ev.Offset == track.CurOffset)
                                        {
                                            ElapsedTicks = ev.Ticks[0] - track.Rest;
                                            break;
                                        }
                                    }
                                    _elapsedLoops++;
                                    if (ShouldFadeOut && !_mixer.IsFading() && _elapsedLoops > NumLoops)
                                    {
                                        _mixer.BeginFadeOut();
                                    }
                                }
                            }
                            else
                            {
                                ElapsedTicks++;
                            }
                        }
                        if (!track.Stopped || track.Channels.Count != 0)
                        {
                            allDone = false;
                        }
                    }
                    if (_mixer.IsFadeDone())
                    {
                        allDone = true;
                    }
                    if (allDone)
                    {
                        MixerProcess();
                        State = PlayerState.Stopped;
                        SongEnded?.Invoke();
                    }
                }
                _tempoStack += _tempo;
                MixerProcess();
                if (playing)
                {
                    _time.Wait();
                }
            }
stop:
            _time.Stop();
        }
예제 #5
0
 private void Tick()
 {
     time.Start();
     while (State == PlayerState.Playing || State == PlayerState.Recording)
     {
         while (tempoStack >= 240)
         {
             tempoStack -= 240;
             bool allDone = true;
             for (int i = 0; i < tracks.Length; i++)
             {
                 Track track = tracks[i];
                 track.Tick();
                 while (track.Rest == 0 && !track.Stopped)
                 {
                     ExecuteNext(i);
                 }
                 if (i == longestTrack)
                 {
                     if (ElapsedTicks == MaxTicks)
                     {
                         if (!track.Stopped)
                         {
                             ElapsedTicks = Events[i][track.CurEvent].Ticks[0] - track.Rest;
                             elapsedLoops++;
                             if (ShouldFadeOut && !fadeOutBegan && elapsedLoops > NumLoops)
                             {
                                 fadeOutBegan = true;
                                 mixer.BeginFadeOut();
                             }
                         }
                     }
                     else
                     {
                         ElapsedTicks++;
                     }
                 }
                 if (!track.Stopped || track.Channels.Count != 0)
                 {
                     allDone = false;
                 }
             }
             if (fadeOutBegan && mixer.IsFadeDone())
             {
                 allDone = true;
             }
             if (allDone)
             {
                 State = PlayerState.Stopped;
                 SongEnded?.Invoke();
             }
         }
         tempoStack += tempo;
         mixer.ChannelTick();
         mixer.Process(State == PlayerState.Playing, State == PlayerState.Recording);
         if (State == PlayerState.Playing)
         {
             time.Wait();
         }
     }
     time.Stop();
 }
예제 #6
0
 private void Tick()
 {
     time.Start();
     while (State == PlayerState.Playing || State == PlayerState.Recording)
     {
         while (tempoStack >= 75)
         {
             tempoStack -= 75;
             bool allDone = true;
             for (int i = 0; i < 0x10; i++)
             {
                 Track track = tracks[i];
                 if (track.Enabled)
                 {
                     byte prevDuration = track.NoteDuration;
                     track.Tick();
                     bool update = false;
                     while (track.Rest == 0 && !track.Stopped)
                     {
                         ExecuteNext(i, ref update);
                     }
                     if (i == longestTrack)
                     {
                         if (ElapsedTicks == MaxTicks)
                         {
                             if (!track.Stopped)
                             {
                                 ElapsedTicks = Events[i][track.CurEvent].Ticks[0] - track.Rest;
                                 elapsedLoops++;
                                 if (ShouldFadeOut && !fadeOutBegan && elapsedLoops > NumLoops)
                                 {
                                     fadeOutBegan = true;
                                     mixer.BeginFadeOut();
                                 }
                             }
                         }
                         else
                         {
                             ElapsedTicks++;
                         }
                     }
                     if (prevDuration == 1 && track.NoteDuration == 0) // Note was not renewed
                     {
                         track.Channel.State = EnvelopeState.Release;
                     }
                     if (!track.Stopped)
                     {
                         allDone = false;
                     }
                     if (track.NoteDuration != 0)
                     {
                         allDone = false;
                         if (update)
                         {
                             track.Channel.SetVolume(track.Volume, track.Panpot);
                             track.Channel.SetPitch(track.GetPitch());
                         }
                     }
                 }
             }
             if (fadeOutBegan && mixer.IsFadeDone())
             {
                 allDone = true;
             }
             if (allDone)
             {
                 State = PlayerState.Stopped;
                 SongEnded?.Invoke();
             }
         }
         tempoStack += tempo;
         mixer.Process(tracks, State == PlayerState.Playing, State == PlayerState.Recording);
         if (State == PlayerState.Playing)
         {
             time.Wait();
         }
     }
     time.Stop();
 }