From aff8f05df1649db5cc66ec33a840fcab7f237e77 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 4 Sep 2021 01:17:23 +0900 Subject: [PATCH 1/2] update package and fix api changed. --- .../UserInterface/MicrophoneSoundVisualizer.cs | 5 +++-- .../KaraokeInputManager.cs | 18 ++++++++++-------- .../osu.Game.Rulesets.Karaoke.csproj | 2 +- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs index e90613155..a57904655 100644 --- a/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs +++ b/osu.Game.Rulesets.Karaoke/Graphics/UserInterface/MicrophoneSoundVisualizer.cs @@ -147,8 +147,9 @@ protected virtual bool OnMicrophoneEndSinging(MicrophoneEndPitchingEvent e) protected virtual bool OnMicrophoneSinging(MicrophonePitchingEvent e) { - var loudness = e.CurrentState.Microphone.Loudness; - var pitch = e.CurrentState.Microphone.Pitch; + var voice = e.CurrentState.Microphone.Voice; + var loudness = voice.Loudness; + var pitch = voice.Pitch; // todo : should convert to better value. loudnessVisualizer.Loudness = loudness; diff --git a/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs b/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs index 07a8ac1fe..624b35313 100644 --- a/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs +++ b/osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs @@ -102,18 +102,20 @@ public override void HandleInputStateChange(InputStateChangeEvent inputStateChan KeyBindingContainer.TriggerPressed(action); } } - else if (inputStateChange is MicrophoneSoundChangeEvent microphoneSoundChange) + else if (inputStateChange is MicrophoneVoiceChangeEvent microphoneSoundChange) { // Deal with realtime microphone event - var inputState = microphoneSoundChange.State as IMicrophoneInputState; - var lastState = microphoneSoundChange.LastState; - var state = inputState?.Microphone; + if (!(microphoneSoundChange.State is IMicrophoneInputState inputState)) + throw new NotMicrophoneInputStateException(); - if (state == null) - throw new ArgumentNullException($"{nameof(state)} cannot be null."); + var lastVoice = microphoneSoundChange.LastVoice; + var voice = inputState.Microphone.Voice; + + if (voice == null) + throw new ArgumentNullException($"{nameof(voice)} cannot be null."); // Convert beatmap's pitch to scale setting. - var scale = beatmap.PitchToScale(state.HasSound ? state.Pitch : lastState.Pitch); + var scale = beatmap.PitchToScale(voice.HasVoice ? voice.Pitch : lastVoice.Pitch); // TODO : adjust scale by scale += 5; @@ -123,7 +125,7 @@ public override void HandleInputStateChange(InputStateChangeEvent inputStateChan Scale = scale }; - if (lastState.HasSound && !state.HasSound) + if (lastVoice.HasVoice && !voice.HasVoice) KeyBindingContainer.TriggerReleased(action); else KeyBindingContainer.TriggerPressed(action); diff --git a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj index 22ac8c304..4833aa498 100644 --- a/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj +++ b/osu.Game.Rulesets.Karaoke/osu.Game.Rulesets.Karaoke.csproj @@ -11,7 +11,7 @@ - + From 08f551383d2d48b7625b41cfa2bee9ac8b12036b Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 4 Sep 2021 01:19:32 +0900 Subject: [PATCH 2/2] use body expression instead. --- .../Algorithms/NavigateCaretPositionAlgorithm.cs | 5 +---- .../CaretPosition/Algorithms/TypingCaretPositionAlgorithm.cs | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/NavigateCaretPositionAlgorithm.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/NavigateCaretPositionAlgorithm.cs index 9bff2b608..9baed75d1 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/NavigateCaretPositionAlgorithm.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/NavigateCaretPositionAlgorithm.cs @@ -65,9 +65,6 @@ public override NavigateCaretPosition MoveToLast() return new NavigateCaretPosition(lyric); } - public override NavigateCaretPosition MoveToTarget(Lyric lyric) - { - return new NavigateCaretPosition(lyric); - } + public override NavigateCaretPosition MoveToTarget(Lyric lyric) => new(lyric); } } diff --git a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TypingCaretPositionAlgorithm.cs b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TypingCaretPositionAlgorithm.cs index 6ce0efd10..4d1efc81a 100644 --- a/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TypingCaretPositionAlgorithm.cs +++ b/osu.Game.Rulesets.Karaoke/Edit/Lyrics/CaretPosition/Algorithms/TypingCaretPositionAlgorithm.cs @@ -84,10 +84,7 @@ public override TextCaretPosition MoveToLast() return new TextCaretPosition(lyric, GetMaxIndex(lyric.Text)); } - public override TextCaretPosition MoveToTarget(Lyric lyric) - { - return new TextCaretPosition(lyric, GetMinIndex(lyric.Text)); - } + public override TextCaretPosition MoveToTarget(Lyric lyric) => new(lyric, GetMinIndex(lyric.Text)); private bool lyricMovable(Lyric lyric) {