From c999bc845ddc673fe613f03e0a46877b514d0e2d Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 25 Jul 2020 11:10:37 +0900 Subject: [PATCH 1/6] add initial project --- osu-framework-microphone.sln | 14 +++++++ .../osu.Framework.Microphone.iOS.csproj | 38 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj diff --git a/osu-framework-microphone.sln b/osu-framework-microphone.sln index 0f9f672..af090a2 100644 --- a/osu-framework-microphone.sln +++ b/osu-framework-microphone.sln @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Framework.Microphone.Te EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Framework.Microphone.Tests.Android", "osu.Framework.Microphone.Tests.Android\osu.Framework.Microphone.Tests.Android.csproj", "{320089C6-A141-4D3E-BD5F-C4A6CE9E567B}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "osu.Framework.Microphone.iOS", "osu.Framework.Microphone.iOS\osu.Framework.Microphone.iOS.csproj", "{431614F4-D662-4CBD-B6C2-3E0D79CA968B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -85,6 +87,18 @@ Global {320089C6-A141-4D3E-BD5F-C4A6CE9E567B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU {320089C6-A141-4D3E-BD5F-C4A6CE9E567B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU {320089C6-A141-4D3E-BD5F-C4A6CE9E567B}.Release|iPhoneSimulator.Deploy.0 = Release|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Debug|iPhone.ActiveCfg = Debug|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Debug|iPhone.Build.0 = Debug|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Release|Any CPU.Build.0 = Release|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Release|iPhone.ActiveCfg = Release|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Release|iPhone.Build.0 = Release|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU + {431614F4-D662-4CBD-B6C2-3E0D79CA968B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj b/osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj new file mode 100644 index 0000000..487cbf1 --- /dev/null +++ b/osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj @@ -0,0 +1,38 @@ + + + xamarinios10 + Library + true + osu!framework iOS + osu.Framework.iOS + osu.Framework.iOS + Resources + A 2D application/game framework written with rhythm games in mind. + + + osu!framework iOS + ppy.osu.Framework.iOS + osu game framework + + + + + + + + + + + + + + + + + + true + true + PreserveNewest + + + From a34dfe892165a8f61a1a5a0f93f271b33155f5ca Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 25 Jul 2020 11:10:47 +0900 Subject: [PATCH 2/6] Modified project info --- .../osu.Framework.Microphone.iOS.csproj | 26 ++++++++++++------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj b/osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj index 487cbf1..bd7365b 100644 --- a/osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj +++ b/osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj @@ -3,16 +3,25 @@ xamarinios10 Library true - osu!framework iOS - osu.Framework.iOS + osu.Framework.Microphone.iOS osu.Framework.iOS Resources - A 2D application/game framework written with rhythm games in mind. + Unofficial osu!framework extension for using microphon as input device. - osu!framework iOS - ppy.osu.Framework.iOS - osu game framework + false + true + true + false + 1.0.10 + Git + osu-framework microphone andy840119 + andy840119 + osu!Karaoke + osu!Karaoke + + osu.Framework.Microphone.iOS + en @@ -21,11 +30,10 @@ - + - - + From a709d9a24c6050e91d44bd73744f78df10923743 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 25 Jul 2020 11:19:49 +0900 Subject: [PATCH 3/6] Add missing config. --- .config/dotnet-tools.json | 18 ++++++++++++++++++ Directory.Build.props | 4 ++-- global.json | 11 +++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 .config/dotnet-tools.json create mode 100644 global.json diff --git a/.config/dotnet-tools.json b/.config/dotnet-tools.json new file mode 100644 index 0000000..6ba6ae8 --- /dev/null +++ b/.config/dotnet-tools.json @@ -0,0 +1,18 @@ +{ + "version": 1, + "isRoot": true, + "tools": { + "cake.tool": { + "version": "0.35.0", + "commands": [ + "dotnet-cake" + ] + }, + "dotnet-format": { + "version": "3.1.37601", + "commands": [ + "dotnet-format" + ] + } + } +} \ No newline at end of file diff --git a/Directory.Build.props b/Directory.Build.props index 1026f42..e094946 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -19,9 +19,9 @@ - + - + $(MSBuildThisFileDirectory)CodeAnalysis\osu-framework-microphone.ruleset diff --git a/global.json b/global.json new file mode 100644 index 0000000..99c68cf --- /dev/null +++ b/global.json @@ -0,0 +1,11 @@ +{ + "sdk": { + "allowPrerelease": false, + "rollForward": "minor", + "version": "3.1.100" + }, + "msbuild-sdks": { + "MSBuild.Sdk.Extras": "2.0.54", + "Microsoft.Build.Traversal": "2.0.52" + } +} \ No newline at end of file From a0a422f463988605aec95b98103c5e0ac5bee963 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 25 Jul 2020 11:40:09 +0900 Subject: [PATCH 4/6] Add ios microphone handler to ask permission. --- .../Input/IOSMicrophoneHandler.cs | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs diff --git a/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs b/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs new file mode 100644 index 0000000..96de72b --- /dev/null +++ b/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs @@ -0,0 +1,59 @@ +using AVFoundation; +using Foundation; +using osu.Framework.Input.Handlers.Microphone; +using osu.Framework.Logging; +using osu.Framework.Platform; + +namespace osu.Framework.iOS.Input +{ + public class IOSMicrophoneHandler : OsuTKMicrophoneHandler + { + public override bool IsActive => throw new System.NotImplementedException(); + + public IOSMicrophoneHandler(int device) : base(device) + { + } + + public override bool Initialize(GameHost host) + { + var session = AVAudioSession.SharedInstance(); + var success = false; + + Logger.Log("Begin Recording", LoggingTarget.Information, LogLevel.Verbose); + + session.RequestRecordPermission((granted) => + { + Logger.Log($"Audio Permission: {granted}", LoggingTarget.Information, LogLevel.Verbose); + + if (granted) + { + session.SetCategory(AVAudioSession.CategoryRecord, out NSError error); + if (error == null) + { + session.SetActive(true, out error); + if (error != null) + { + Logger.Log(error.LocalizedDescription, LoggingTarget.Information, LogLevel.Error); + } + else + { + success = base.Initialize(host); + Logger.Log($"Microphone get permission status : {success}", LoggingTarget.Information, LogLevel.Verbose); + } + } + else + { + Logger.Log(error.LocalizedDescription, LoggingTarget.Information, LogLevel.Error); + } + } + else + { + Logger.Log("YOU MUST ENABLE MICROPHONE PERMISSION", LoggingTarget.Information, LogLevel.Error); + } + }); + + Logger.Log($"Checking : {success}", LoggingTarget.Information, LogLevel.Error); + return success; + } + } +} From 3dbaa6595c270d33718b718cb36e9f1592ea18e9 Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 25 Jul 2020 12:54:45 +0900 Subject: [PATCH 5/6] Inject OsuTKMicrophoneHandler on ios target. --- .../AppDelegate.cs | 15 ++++++++++++++- .../osu.Framework.Microphone.Tests.iOS.csproj | 4 ++++ .../Input/IOSMicrophoneHandler.cs | 2 +- .../Input/MicrophoneInputManager.cs | 18 +++++++++++++++--- 4 files changed, 34 insertions(+), 5 deletions(-) diff --git a/osu.Framework.Microphone.Tests.iOS/AppDelegate.cs b/osu.Framework.Microphone.Tests.iOS/AppDelegate.cs index 474d39c..43695a6 100644 --- a/osu.Framework.Microphone.Tests.iOS/AppDelegate.cs +++ b/osu.Framework.Microphone.Tests.iOS/AppDelegate.cs @@ -2,13 +2,26 @@ // See the LICENCE file in the repository root for full licence text. using Foundation; +using osu.Framework.Input.Handlers.Microphone; using osu.Framework.iOS; +using osu.Framework.iOS.Input; namespace osu.Framework.Tests { [Register("AppDelegate")] public class AppDelegate : GameAppDelegate { - protected override Game CreateGame() => new VisualTestGame(); + protected override Game CreateGame() => new TestingVisualTestGame(); + + internal class TestingVisualTestGame : VisualTestGame + { + protected override void LoadComplete() + { + base.LoadComplete(); + + // Need to cache IOSMicrophoneHandler in here to let MicrophoneInputManager knows. + Host.Dependencies.CacheAs(typeof(OsuTKMicrophoneHandler), new IOSMicrophoneHandler()); + } + } } } diff --git a/osu.Framework.Microphone.Tests.iOS/osu.Framework.Microphone.Tests.iOS.csproj b/osu.Framework.Microphone.Tests.iOS/osu.Framework.Microphone.Tests.iOS.csproj index 882d355..2d327f5 100644 --- a/osu.Framework.Microphone.Tests.iOS/osu.Framework.Microphone.Tests.iOS.csproj +++ b/osu.Framework.Microphone.Tests.iOS/osu.Framework.Microphone.Tests.iOS.csproj @@ -40,6 +40,10 @@ + + {431614f4-d662-4cbd-b6c2-3e0d79ca968b} + osu.Framework.Microphone.iOS + {D0F85C61-800A-4645-8633-AC59208FA732} osu.Framework.Microphone diff --git a/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs b/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs index 96de72b..41dd895 100644 --- a/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs +++ b/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs @@ -10,7 +10,7 @@ public class IOSMicrophoneHandler : OsuTKMicrophoneHandler { public override bool IsActive => throw new System.NotImplementedException(); - public IOSMicrophoneHandler(int device) : base(device) + public IOSMicrophoneHandler() : base(-1) { } diff --git a/osu.Framework.Microphone/Input/MicrophoneInputManager.cs b/osu.Framework.Microphone/Input/MicrophoneInputManager.cs index d97aed1..443f259 100644 --- a/osu.Framework.Microphone/Input/MicrophoneInputManager.cs +++ b/osu.Framework.Microphone/Input/MicrophoneInputManager.cs @@ -5,18 +5,30 @@ using osu.Framework.Input.Handlers.Microphone; using osu.Framework.Input.StateChanges.Events; using osu.Framework.Input.States; +using System; namespace osu.Framework.Input { public class MicrophoneInputManager : CustomInputManager { - private readonly OsuTKMicrophoneHandler handler; - protected override InputState CreateInitialState() => new MicrophoneInputState(new MicrophoneState()); + private readonly int deviceId; + public MicrophoneInputManager(int device = -1) { - AddHandler(handler = new OsuTKMicrophoneHandler(device)); + deviceId = device; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + // Use handler like iOS microphone handler if there's exist handler in dependencies. + if (Host.Dependencies.Get(typeof(OsuTKMicrophoneHandler)) is OsuTKMicrophoneHandler handler) + AddHandler(Activator.CreateInstance(handler.GetType()) as OsuTKMicrophoneHandler); + else + AddHandler(new OsuTKMicrophoneHandler(deviceId)); } public override void HandleInputStateChange(InputStateChangeEvent inputStateChange) From 2cdc8700ba3a418c52839021b80d4b8e0053c47a Mon Sep 17 00:00:00 2001 From: andy840119 Date: Sat, 25 Jul 2020 14:17:06 +0800 Subject: [PATCH 6/6] TODO : deal with Attempting to JIT compile method --- osu.Framework.Microphone.Tests.iOS/Info.plist | 18 ++++++++++-------- osu.Framework.Microphone.Tests.iOS/Linker.xml | 6 ++++++ .../Input/IOSMicrophoneHandler.cs | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/osu.Framework.Microphone.Tests.iOS/Info.plist b/osu.Framework.Microphone.Tests.iOS/Info.plist index c73d92a..d3603c7 100644 --- a/osu.Framework.Microphone.Tests.iOS/Info.plist +++ b/osu.Framework.Microphone.Tests.iOS/Info.plist @@ -2,10 +2,10 @@ + CFBundleIdentifier + ppy.osu-Framework-Microphone-Tests-iOS CFBundleName osu.Framework.Tests.iOS - CFBundleIdentifier - ppy.osu-Framework-Tests-iOS CFBundleShortVersionString 1.0 CFBundleVersion @@ -14,6 +14,10 @@ MinimumOSVersion 11.0 + NSMicrophoneUsageDescription + Ask for microphone permission + UIApplicationSupportsIndirectInputEvents + UIDeviceFamily 1 @@ -25,6 +29,10 @@ armv7 + UIRequiresFullScreen + + UIStatusBarHidden + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait @@ -34,11 +42,5 @@ XSAppIconAssets Assets.xcassets/AppIcon.appiconset - UIStatusBarHidden - - UIRequiresFullScreen - - UIApplicationSupportsIndirectInputEvents - diff --git a/osu.Framework.Microphone.Tests.iOS/Linker.xml b/osu.Framework.Microphone.Tests.iOS/Linker.xml index 51e6f60..be5441a 100644 --- a/osu.Framework.Microphone.Tests.iOS/Linker.xml +++ b/osu.Framework.Microphone.Tests.iOS/Linker.xml @@ -6,6 +6,12 @@ + + + + + + diff --git a/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs b/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs index 41dd895..fce5285 100644 --- a/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs +++ b/osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs @@ -23,7 +23,7 @@ public override bool Initialize(GameHost host) session.RequestRecordPermission((granted) => { - Logger.Log($"Audio Permission: {granted}", LoggingTarget.Information, LogLevel.Verbose); + Logger.Log($"Audio Permission: {granted}", LoggingTarget.Information); if (granted) { @@ -38,7 +38,7 @@ public override bool Initialize(GameHost host) else { success = base.Initialize(host); - Logger.Log($"Microphone get permission status : {success}", LoggingTarget.Information, LogLevel.Verbose); + Logger.Log($"Microphone get permission status : {success}", LoggingTarget.Information); } } else