diff --git a/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj b/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj index e86c3bd..81a8cff 100644 --- a/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj +++ b/GenshinLyreMidiPlayer.WPF/GenshinLyreMidiPlayer.WPF.csproj @@ -1,4 +1,4 @@ - + WinExe @@ -6,7 +6,7 @@ true GenshinLyreMidiPlayer.WPF.App app.manifest - 2.3.2 + 2.3.3 item_windsong_lyre.ico enable https://github.com/sabihoshi/GenshinLyreMidiPlayer diff --git a/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs b/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs index 1591142..30319b9 100644 --- a/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs +++ b/GenshinLyreMidiPlayer.WPF/ViewModels/LyrePlayerViewModel.cs @@ -16,7 +16,6 @@ using ModernWpf.Controls; using Stylet; using StyletIoC; -using static Windows.Media.MediaPlaybackAutoRepeatMode; using static GenshinLyreMidiPlayer.WPF.Core.LyrePlayer.Transpose; using MidiFile = GenshinLyreMidiPlayer.Data.Midi.MidiFile; @@ -91,7 +90,7 @@ public bool CanHitNext { get { - if (Playlist.Loop is List or Track) + if (Playlist.Loop is not PlaylistViewModel.LoopMode.Playlist) return true; var last = Playlist.GetPlaylist().LastOrDefault(); @@ -175,12 +174,17 @@ public async void Handle(PlayTimerNotification message) public void OnSongPositionChanged() { - if (!_ignoreSliderChange && Playback is { IsRunning: true }) + NotifyOfPropertyChange(() => CurrentTime); + + if (Playback is null) Next(); + + if (!_ignoreSliderChange && Playback is not null) { + var isRunning = Playback.IsRunning; Playback.Stop(); - Playback.MoveToTime(new MetricTimeSpan(CurrentTime)); + Playback.MoveToTime(new MetricTimeSpan(_songPosition)); - if (Settings.UseSpeakers) + if (Settings.UseSpeakers && isRunning) Playback.Start(); } @@ -191,12 +195,13 @@ public void OnSelectedMidiInputChanged() { _inputDevice?.Dispose(); - if (SelectedMidiInput?.DeviceName != null && SelectedMidiInput.DeviceName != "None") + if (SelectedMidiInput?.DeviceName is not null + && SelectedMidiInput.DeviceName != "None") { _inputDevice = InputDevice.GetByName(SelectedMidiInput.DeviceName); - _inputDevice.EventReceived += OnNoteEvent; - _inputDevice.StartEventsListening(); + _inputDevice!.EventReceived += OnNoteEvent; + _inputDevice!.StartEventsListening(); } } @@ -375,12 +380,18 @@ public async void Next() { var next = Playlist.Next(); if (next is null) + { + if (Playback is not null) + { + Playback.PlaybackStart = null; + Playback.MoveToStart(); + } + + MoveSlider(TimeSpan.Zero); return; + } - if (next == Playlist.OpenedFile && Playlist.Loop == Track) - Handle(next); - else if (next != Playlist.OpenedFile) - Handle(next); + Handle(next); if (Playback is not null) await PlayPause(); diff --git a/GenshinLyreMidiPlayer.WPF/ViewModels/PlaylistViewModel.cs b/GenshinLyreMidiPlayer.WPF/ViewModels/PlaylistViewModel.cs index 688278a..625ea0b 100644 --- a/GenshinLyreMidiPlayer.WPF/ViewModels/PlaylistViewModel.cs +++ b/GenshinLyreMidiPlayer.WPF/ViewModels/PlaylistViewModel.cs @@ -3,7 +3,6 @@ using System.Linq; using System.Threading.Tasks; using System.Windows.Media; -using Windows.Media; using GenshinLyreMidiPlayer.Data; using GenshinLyreMidiPlayer.Data.Entities; using GenshinLyreMidiPlayer.WPF.ModernWPF.Errors; @@ -13,13 +12,20 @@ using ModernWpf.Controls; using Stylet; using StyletIoC; -using static Windows.Media.MediaPlaybackAutoRepeatMode; using MidiFile = GenshinLyreMidiPlayer.Data.Midi.MidiFile; namespace GenshinLyreMidiPlayer.WPF.ViewModels { public class PlaylistViewModel : Screen { + public enum LoopMode + { + Once, + Track, + Playlist, + All + } + private readonly IEventAggregator _events; private readonly IContainer _ioc; @@ -39,7 +45,7 @@ public PlaylistViewModel(IContainer ioc, IEventAggregator events) public bool Shuffle { get; set; } - public MediaPlaybackAutoRepeatMode Loop { get; set; } + public LoopMode Loop { get; set; } public MidiFile? OpenedFile { get; set; } @@ -56,9 +62,10 @@ public PlaylistViewModel(IContainer ioc, IEventAggregator events) public string LoopStateString => Loop switch { - None => "\xF5E7", - Track => "\xE8ED", - List => "\xE8EE" + LoopMode.Once => "\xF5E7", + LoopMode.Track => "\xE8ED", + LoopMode.Playlist => "\xEBE7", + LoopMode.All => "\xE8EE" }; public void OnFilterTextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs e) @@ -79,32 +86,30 @@ public void ToggleShuffle() public void ToggleLoop() { var loopState = (int) Loop; - var loopStates = Enum.GetValues(typeof(MediaPlaybackAutoRepeatMode)).Length; + var loopStates = Enum.GetValues(typeof(LoopMode)).Length; var newState = (loopState + 1) % loopStates; - Loop = (MediaPlaybackAutoRepeatMode) newState; + Loop = (LoopMode) newState; } public MidiFile? Next() { var playlist = GetPlaylist().ToList(); + if (OpenedFile is null) return playlist.FirstOrDefault(); - if (Loop == Track) - return OpenedFile ?? playlist.FirstOrDefault(); - - var next = playlist.FirstOrDefault(); - - if (OpenedFile is not null) + switch (Loop) { - var current = playlist.IndexOf(OpenedFile) + 1; - - if (Loop is List) - current %= playlist.Count; - - next = playlist.ElementAtOrDefault(current); + case LoopMode.Once: + return null; + case LoopMode.Track: + return OpenedFile; } - return next; + var next = playlist.IndexOf(OpenedFile) + 1; + if (Loop is LoopMode.All) + next %= playlist.Count; + + return playlist.ElementAtOrDefault(next); } public BindableCollection GetPlaylist() => Shuffle ? ShuffledTracks : Tracks;