Skip to content

Commit

Permalink
Merge pull request #154 from andy840119/slave/micrphone-status
Browse files Browse the repository at this point in the history
Implement microphone status preview.
  • Loading branch information
andy840119 authored Aug 2, 2020
2 parents ea1b1a2 + 577ce61 commit f50bae7
Show file tree
Hide file tree
Showing 13 changed files with 307 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ protected KaraokeSkinnableColumnTestScene()
[BackgroundDependencyLoader]
private void load(RulesetConfigCache configCache)
{
// Cache ruleset config manager because karaoke input manager need it.
// Cache ruleset config manager and session because karaoke input manager need it.
var config = (KaraokeRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance());
var session = new KaraokeSessionStatics(config, null);

Dependencies.Cache(config);
Dependencies.Cache(session);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.

using osu.Framework.Allocation;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.UI;

namespace osu.Game.Rulesets.Karaoke.Tests.Skinning
Expand All @@ -12,9 +11,6 @@ public class TestSceneNotePlayfield : KaraokeSkinnableColumnTestScene
[BackgroundDependencyLoader]
private void load(RulesetConfigCache configCache)
{
var config = (KaraokeRulesetConfigManager)configCache.GetConfigFor(Ruleset.Value.CreateInstance());
Dependencies.Cache(new KaraokeSessionStatics(config, null));

SetContents(() => new KaraokeInputManager(new KaraokeRuleset().RulesetInfo)
{
Child = new NotePlayfield(COLUMN_NUMBER)
Expand Down
39 changes: 39 additions & 0 deletions osu.Game.Rulesets.Karaoke.Tests/UI/TestCaseSaitenStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright (c) andy840119 <[email protected]>. Licensed under the GPL Licence.
// See the LICENCE file in the repository root for full licence text.

using NUnit.Framework;
using osu.Framework.Graphics;
using osu.Game.Rulesets.Karaoke.UI.Components;
using osu.Game.Tests.Visual;

namespace osu.Game.Rulesets.Karaoke.Tests.UI
{
[TestFixture]
public class TestCaseSaitenStatus : OsuTestScene
{
[TestCase(SaitenStatusMode.AndroidMicrophonePermissionDeclined)]
[TestCase(SaitenStatusMode.AndroidDoesNotSupported)]
[TestCase(SaitenStatusMode.IOSMicrophonePermissionDeclined)]
[TestCase(SaitenStatusMode.IOSDoesNotSupported)]
[TestCase(SaitenStatusMode.OSXMicrophonePermissionDeclined)]
[TestCase(SaitenStatusMode.OSXDoesNotSupported)]
[TestCase(SaitenStatusMode.WindowsMicrophonePermissionDeclined)]
[TestCase(SaitenStatusMode.NoMicrophoneDevice)]
[TestCase(SaitenStatusMode.NotSaitening)]
[TestCase(SaitenStatusMode.AutoPlay)]
[TestCase(SaitenStatusMode.Edit)]
[TestCase(SaitenStatusMode.Saitening)]
[TestCase(SaitenStatusMode.NotInitialized)]
public void TestMode(SaitenStatusMode mode)
{
AddStep("create mod display", () =>
{
Child = new SaitenStatus(mode)
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre
};
});
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osu.Game.Configuration;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.UI.Components;

namespace osu.Game.Rulesets.Karaoke.Configuration
{
Expand Down Expand Up @@ -50,6 +51,9 @@ public KaraokeSessionStatics(KaraokeRulesetConfigManager config, IBeatmap beatma

// Practice
Set<LyricLine>(KaraokeRulesetSession.NowLyric, null);

// Saiten stsus
Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.NotInitialized);
}

private T getValue<T>(KaraokeRulesetSetting setting) => rulesetConfigManager.GetBindable<T>(setting).Value;
Expand All @@ -75,5 +79,8 @@ public enum KaraokeRulesetSession

// Practice
NowLyric,

// Saiten status
SaitenStatus,
}
}
36 changes: 30 additions & 6 deletions osu.Game.Rulesets.Karaoke/KaraokeInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
using osu.Framework.Input.Handlers.Microphone;
using osu.Framework.Input.StateChanges.Events;
using osu.Framework.Input.States;
using osu.Framework.Logging;
using osu.Game.Beatmaps;
using osu.Game.Input.Handlers;
using osu.Game.Rulesets.Karaoke.Beatmaps;
using osu.Game.Rulesets.Karaoke.Configuration;
using osu.Game.Rulesets.Karaoke.Mods;
using osu.Game.Rulesets.Karaoke.UI.Components;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Edit;
Expand All @@ -34,27 +36,49 @@ public KaraokeInputManager(RulesetInfo ruleset)
private IBeatmap beatmap;

[BackgroundDependencyLoader(true)]
private void load(KaraokeRulesetConfigManager config, IBindable<IReadOnlyList<Mod>> mods, IBindable<WorkingBeatmap> beatmap, EditorBeatmap editorBeatmap)
private void load(KaraokeRulesetConfigManager config, IBindable<IReadOnlyList<Mod>> mods, IBindable<WorkingBeatmap> beatmap, KaraokeSessionStatics session, EditorBeatmap editorBeatmap)
{
if (editorBeatmap != null)
{
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.Edit);
return;
}

this.beatmap = beatmap.Value.Beatmap;

var disableMicrophoneDeviceByMod = mods.Value.OfType<IApplicableToMicrophone>().Any(x => !x.MicrophoneEnabled);

if (disableMicrophoneDeviceByMod)
{
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.AutoPlay);
return;
}

var beatmapSaitenable = beatmap.Value.Beatmap.IsScorable();

if (!beatmapSaitenable)
{
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.NotSaitening);
return;
}

try
{
var selectedDevice = config.GetBindable<string>(KaraokeRulesetSetting.MicrophoneDevice).Value;
var microphoneList = new MicrophoneManager().MicrophoneDeviceNames.ToList();

var selectedDevice = config.GetBindable<string>(KaraokeRulesetSetting.MicrophoneDevice).Value;
var microphoneList = new MicrophoneManager().MicrophoneDeviceNames.ToList();
// Find index by selection id
var deviceIndex = microphoneList.IndexOf(selectedDevice);
AddHandler(new OsuTKMicrophoneHandler(deviceIndex));

// Find index by selection id
var deviceIndex = microphoneList.IndexOf(selectedDevice);
AddHandler(new OsuTKMicrophoneHandler(deviceIndex));
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.Saitening);
}
catch (Exception ex)
{
Logger.Error(ex, "Microphone initialize error.");
// todo : set real error by exception
session.Set(KaraokeRulesetSession.SaitenStatus, SaitenStatusMode.WindowsMicrophonePermissionDeclined);
}
}

protected override InputState CreateInitialState()
Expand Down
1 change: 0 additions & 1 deletion osu.Game.Rulesets.Karaoke/KaraokeRuleset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
using osu.Game.Rulesets.Karaoke.Mods;
using osu.Game.Rulesets.Karaoke.Objects;
using osu.Game.Rulesets.Karaoke.Replays;
using osu.Game.Rulesets.Karaoke.Resources.Fonts;
using osu.Game.Rulesets.Karaoke.Scoring;
using osu.Game.Rulesets.Karaoke.Skinning;
using osu.Game.Rulesets.Karaoke.UI;
Expand Down
4 changes: 1 addition & 3 deletions osu.Game.Rulesets.Karaoke/Mods/KaraokeModDisableNote.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@

namespace osu.Game.Rulesets.Karaoke.Mods
{
public class KaraokeModDisableNote : Mod, IApplicableToHitObject, IApplicableToMicrophone
public class KaraokeModDisableNote : Mod, IApplicableToHitObject
{
public override string Name => "Disable note";
public override string Acronym => "DN";
public override double ScoreMultiplier => 0;
public override IconUsage? Icon => KaraokeIcon.ModDisableNote;
public override ModType Type => ModType.Fun;

public bool MicrophoneEnabled => false;

public void ApplyToHitObject(HitObject hitObject)
{
if (hitObject is Note note)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ private void computeImageSize()
}
}

private IDictionary<string, string> githubUrls = new Dictionary<string, string>
private readonly IDictionary<string, string> githubUrls = new Dictionary<string, string>
{
{ "karaoke", "https://github.com/karaoke-dev/karaoke/" },
{ "edge", "https://github.com/karaoke-dev/karaoke" },
Expand All @@ -193,13 +193,14 @@ protected override void AddLinkText(string text, LinkInline linkInline)
var baseUri = new Uri(githubUrls[text]);

// Get hash tag with number
var pattern = @"(\#[0-9]+\b)(?!;)";
const string pattern = @"(\#[0-9]+\b)(?!;)";
var issueOrRequests = Regex.Matches(linkInline.Url, pattern, RegexOptions.IgnoreCase);

if (!issueOrRequests.Any())
return;

AddText("(");

foreach (var issue in issueOrRequests.Select(x=>x.Value))
{
AddDrawable(new MarkdownLinkText($"{text}{issue}", new LinkInline
Expand All @@ -210,10 +211,12 @@ protected override void AddLinkText(string text, LinkInline linkInline)
if(issue != issueOrRequests.LastOrDefault()?.Value)
AddText(", ");
}

AddText(")");

// add use name if has user
var user = linkInline.Url.Split('@').LastOrDefault();

if (!string.IsNullOrEmpty(user))
{
var textScale = new Vector2(0.7f);
Expand Down
2 changes: 1 addition & 1 deletion osu.Game.Rulesets.Karaoke/Skinning/KaraokeInternalSkin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class KaraokeInternalSkin : ISkin

protected abstract string ResourceName { get; }

public KaraokeInternalSkin()
protected KaraokeInternalSkin()
{
// TODO : need a better way to load resource
var assembly = Assembly.GetExecutingAssembly();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.IO;
using osu.Game.Rulesets.Karaoke.Beatmaps.Formats;
using osu.Game.Rulesets.Karaoke.Skinning.Components;
Expand Down
Loading

0 comments on commit f50bae7

Please sign in to comment.