コード例 #1
0
 private void Player_Finalfile(object sender, MplayerEvent e)
 {
     if (e.Message == " 1  ")
     {
         SongEnded?.Invoke(sender, e);
     }
 }
コード例 #2
0
ファイル: MutePlayer.cs プロジェクト: Viktor8/CRadio
        public void Play()
        {
            if (NowPlay)
            {
                return;
            }



            if (_endTimer == null)
            {
                TimerCallback callback = (o) =>
                {
                    _endTimer?.Change(int.MaxValue, int.MaxValue);
                    _endTimer?.Dispose();
                    _endTimer = null;

                    SongEnded?.Invoke(this, EventArgs.Empty);
                };

                _endTimer = new Timer(callback, null, (int)SongDuration.TotalMilliseconds, int.MaxValue);
            }

            int toEnd = (int)(SongDuration - SongProgress).TotalMilliseconds;

            _endTimer.Change(toEnd, int.MaxValue);

            NowPlay = true;
        }
コード例 #3
0
ファイル: ImmediateStreamer.cs プロジェクト: Viktor8/CRadio
        private void EndHandler(object sender, EventArgs arg)
        {
            _endFrameTimer?.Change(int.MaxValue, int.MaxValue);
            _endFrameTimer?.Dispose();
            _endFrameTimer = null;

            _frames             = null;
            _nextPartBeginIndex = -1;

            SongEnded?.Invoke(this, null);
        }
コード例 #4
0
ファイル: Player.cs プロジェクト: mkbiltek2019/VGMusicStudio
        public void SetCurrentPosition(long ticks)
        {
            if (Events == null)
            {
                SongEnded?.Invoke();
            }
            else if (State == PlayerState.Playing || State == PlayerState.Paused || State == PlayerState.Stopped)
            {
                if (State == PlayerState.Playing)
                {
                    Pause();
                }
                InitEmulation();
                bool u = false;
                while (true)
                {
                    if (ElapsedTicks == ticks)
                    {
                        goto finish;
                    }
                    else
                    {
                        while (_tempoStack >= 75)
                        {
                            _tempoStack -= 75;
                            for (int i = 0; i < 0x10; i++)
                            {
                                Track track = _tracks[i];
                                if (track.Enabled && !track.Stopped)
                                {
                                    track.Tick();
                                    while (track.Rest == 0 && !track.Stopped)
                                    {
                                        ExecuteNext(i, ref u);
                                    }
                                }
                            }
                            ElapsedTicks++;
                            if (ElapsedTicks == ticks)
                            {
                                goto finish;
                            }
                        }
                        _tempoStack += _tempo;
                    }
                }
finish:
                for (int i = 0; i < 0x10; i++)
                {
                    _tracks[i].NoteDuration = 0;
                }
                Pause();
            }
        }
コード例 #5
0
ファイル: SongPlayer.cs プロジェクト: Stich991/GBAMusicStudio
 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();
 }
コード例 #6
0
ファイル: Player.cs プロジェクト: ryanedgewurth/VGMusicStudio
        public void SetCurrentPosition(long ticks)
        {
            if (_tracks == null)
            {
                SongEnded?.Invoke();
            }
            else if (State == PlayerState.Playing || State == PlayerState.Paused || State == PlayerState.Stopped)
            {
                if (State == PlayerState.Playing)
                {
                    Pause();
                }
                InitEmulation();
                while (true)
                {
                    if (ElapsedTicks == ticks)
                    {
                        goto finish;
                    }
                    else
                    {
                        while (_tempoStack >= 240)
                        {
                            _tempoStack -= 240;
                            for (int trackIndex = 0; trackIndex < _tracks.Length; trackIndex++)
                            {
                                Track track = _tracks[trackIndex];
                                if (!track.Stopped)
                                {
                                    track.Tick();
                                    while (track.Rest == 0 && !track.Stopped)
                                    {
                                        ExecuteNext(track);
                                    }
                                }
                            }
                            ElapsedTicks++;
                            if (ElapsedTicks == ticks)
                            {
                                goto finish;
                            }
                        }
                        _tempoStack += _tempo;
                    }
                }
finish:
                for (int i = 0; i < _tracks.Length; i++)
                {
                    _tracks[i].StopAllChannels();
                }
                Pause();
            }
        }
コード例 #7
0
ファイル: Player.cs プロジェクト: mkbiltek2019/VGMusicStudio
 public void Play()
 {
     if (Events == null)
     {
         SongEnded?.Invoke();
     }
     else if (State == PlayerState.Playing || State == PlayerState.Paused || State == PlayerState.Stopped)
     {
         Stop();
         InitEmulation();
         State = PlayerState.Playing;
         CreateThread();
     }
 }
コード例 #8
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();
        }
コード例 #9
0
ファイル: SongPlayer.cs プロジェクト: Stich991/GBAMusicStudio
        public void Play()
        {
            Stop();

            if (NumTracks == 0)
            {
                SongEnded?.Invoke();
                return;
            }

            for (int i = 0; i < NumTracks; i++)
            {
                tracks[i].Init();
            }
            DetermineLongestTrack();

            position = 0; tempoStack = 0;
            Tempo    = Engine.GetDefaultTempo();

            State = PlayerState.Playing;
        }
コード例 #10
0
 void player_PlaybackStopped(object sender, StoppedEventArgs e)
 {
     SongEnded?.Invoke(this, new EventArgs());
 }
コード例 #11
0
ファイル: Player.cs プロジェクト: CaspervdB/musicPlayer
 private void MusicPlayer_PlaybackStopped(object sender, EventArgs e)
 {
     SongEnded?.Invoke(this, e);
 }
コード例 #12
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();
 }
コード例 #13
0
 /// <summary>
 /// Raises the <see cref="SongEnded"/> event.
 /// </summary>
 protected void OnSongEnded() =>
 SongEnded?.Invoke(this);
コード例 #14
0
ファイル: Player.cs プロジェクト: mkbiltek2019/VGMusicStudio
        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();
        }
コード例 #15
0
ファイル: Player.cs プロジェクト: ryanedgewurth/VGMusicStudio
        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();
        }
コード例 #16
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();
 }
コード例 #17
0
ファイル: Playroutine.cs プロジェクト: stefl0n/turrican2tools
        /// <summary>
        /// performs a single song-position-advance
        /// </summary>
        void TrackStepExecute()
        {
            trackstepWait = 0;

            if (trackstepPosition > tfx.SongEndPositions[songNo] || trackstepPosition >= tfx.Tracksteps.Length)
            {
                Paula.Reset();

                if (trackstepPosition < tfx.Tracksteps.Length)
                {
                    TrackstepPositionChanged?.Invoke(this, EventArgs.Empty);
                }
                SongEnded?.Invoke(this, EventArgs.Empty);
                trackstepWait = 1;
                stopped       = true;
                return;
            }

            if (tfx.Tracksteps[trackstepPosition][0] == 0xEFFE)
            {
                var line = tfx.Tracksteps[trackstepPosition];

                switch (line[1])
                {
                case 0:     // stop the player
                    stopped = true;
                    break;

                case 1:     // Play a section starting at position and ending here times
                            // times.  If times is 0000 then section will repeat forever.
                            // line+4=position, line+6=times
                    int position = line[2];
                    int times    = line[3];

                    trackstepPosition = position;     // TD: error-check, count loops

                    break;

                case 2:     // set the tempo
                            // TD
                    break;

                case 3:     // start a master volume slide (?)
                    if (line[3] == 0xEE)
                    {
                        --tempoNumber;
                        //Frequency = 14;
                        TempoChanged?.Invoke(this, EventArgs.Empty);
                    }
                    else if (line[3] == 0x10)
                    {
                        //Frequency = 30;
                        TempoChanged?.Invoke(this, EventArgs.Empty);
                    }
                    break;

                case 4:
                    break;

                default:
                    break;
                }
            }
            else
            {
                for (int i = 0; i < 8; ++i)
                {
                    var track         = tracks[i];
                    var d             = tfx.Tracksteps[trackstepPosition][i];
                    int stepPattern   = d >> 8;
                    int stepTranspose = (sbyte)(d & 0xFF);

                    // init pattern
                    track.PatternPC      = 0;
                    track.NumWait        = 0;
                    track.NumPatternLoop = 0;

                    // TD: handle 0xFE correctly!
                    if (stepPattern >= 0x80)
                    {
                        if (stepPattern != 0x80)
                        {
                            track.PatternNo = -1;
                        }
                    }
                    else
                    {
                        Log("starting pattern " + track.PatternNo + " in tick " + tickCounter);

                        track.PatternNo = stepPattern;
                        track.Transpose = stepTranspose;
                    }
                }

                trackstepWait = 1;
            }

            TrackstepPositionChanged?.Invoke(this, EventArgs.Empty);

            ++trackstepPosition;
        }
コード例 #18
0
 async void OnMediaEnded(object sender, RoutedEventArgs e) => await SongEnded?.Invoke(this, true);
コード例 #19
0
ファイル: ViewModel.cs プロジェクト: Craftingman/AngelMP3
 public MediaController()
 {
     mediaPlayer             = new MediaPlayer();
     mediaPlayer.MediaEnded += (object s, EventArgs e) => SongEnded?.Invoke(this, e);
     updatePosTimer.Elapsed += (object s, ElapsedEventArgs e) => App.Current.Dispatcher.Invoke(new Action(() => HandleUpdatePosTimer()));
 }