Skip to content

Commit

Permalink
Merge pull request #36 from andy840119/ios-support
Browse files Browse the repository at this point in the history
iOS support
  • Loading branch information
andy840119 authored Jan 1, 2021
2 parents d271197 + 2cdc870 commit 2aa38be
Show file tree
Hide file tree
Showing 11 changed files with 199 additions and 14 deletions.
18 changes: 18 additions & 0 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
}
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
</None>
</ItemGroup>
<ItemGroup Label="Code Analysis">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="2.9.8" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.0.0" PrivateAssets="All" />
<AdditionalFiles Include="$(MSBuildThisFileDirectory)CodeAnalysis\BannedSymbols.txt" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="2.9.8" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="All" />
</ItemGroup>
<PropertyGroup Label="Code Analysis">
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodeAnalysis\osu-framework-microphone.ruleset</CodeAnalysisRuleSet>
Expand Down
11 changes: 11 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
14 changes: 14 additions & 0 deletions osu-framework-microphone.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 14 additions & 1 deletion osu.Framework.Microphone.Tests.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}
}
18 changes: 10 additions & 8 deletions osu.Framework.Microphone.Tests.iOS/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleIdentifier</key>
<string>ppy.osu-Framework-Microphone-Tests-iOS</string>
<key>CFBundleName</key>
<string>osu.Framework.Tests.iOS</string>
<key>CFBundleIdentifier</key>
<string>ppy.osu-Framework-Tests-iOS</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleVersion</key>
Expand All @@ -14,6 +14,10 @@
<true/>
<key>MinimumOSVersion</key>
<string>11.0</string>
<key>NSMicrophoneUsageDescription</key>
<string>Ask for microphone permission</string>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
Expand All @@ -25,6 +29,10 @@
<array>
<string>armv7</string>
</array>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIStatusBarHidden</key>
<true/>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
Expand All @@ -34,11 +42,5 @@
</array>
<key>XSAppIconAssets</key>
<string>Assets.xcassets/AppIcon.appiconset</string>
<key>UIStatusBarHidden</key>
<true/>
<key>UIRequiresFullScreen</key>
<true/>
<key>UIApplicationSupportsIndirectInputEvents</key>
<true/>
</dict>
</plist>
6 changes: 6 additions & 0 deletions osu.Framework.Microphone.Tests.iOS/Linker.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
<assembly fullname="osu.Framework.iOS">
<type fullname="*" />
</assembly>
<assembly fullname="osu.Framework.Microphone">
<type fullname="*" />
</assembly>
<assembly fullname="osu.Framework.Microphone.iOS">
<type fullname="*" />
</assembly>
<assembly fullname="osu.Framework.Microphone.Tests">
<type fullname="*" />
</assembly>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu.Framework.Microphone.iOS\osu.Framework.Microphone.iOS.csproj">
<Project>{431614f4-d662-4cbd-b6c2-3e0d79ca968b}</Project>
<Name>osu.Framework.Microphone.iOS</Name>
</ProjectReference>
<ProjectReference Include="..\osu.Framework.Microphone\osu.Framework.Microphone.csproj">
<Project>{D0F85C61-800A-4645-8633-AC59208FA732}</Project>
<Name>osu.Framework.Microphone</Name>
Expand Down
59 changes: 59 additions & 0 deletions osu.Framework.Microphone.iOS/Input/IOSMicrophoneHandler.cs
Original file line number Diff line number Diff line change
@@ -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() : base(-1)
{
}

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);

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);
}
}
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;
}
}
}
46 changes: 46 additions & 0 deletions osu.Framework.Microphone.iOS/osu.Framework.Microphone.iOS.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<Project Sdk="MSBuild.Sdk.Extras">
<PropertyGroup Label="Project">
<TargetFramework>xamarinios10</TargetFramework>
<OutputType>Library</OutputType>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AssemblyName>osu.Framework.Microphone.iOS</AssemblyName>
<RootNamespace>osu.Framework.iOS</RootNamespace>
<IPhoneResourcePrefix>Resources</IPhoneResourcePrefix>
<Description>Unofficial osu!framework extension for using microphon as input device.</Description>
</PropertyGroup>
<PropertyGroup Label="Nuget">
<GenerateProgramFile>false</GenerateProgramFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<IsPackable>true</IsPackable>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Version>1.0.10</Version>
<RepositoryType>Git</RepositoryType>
<PackageTags>osu-framework microphone andy840119</PackageTags>
<Authors>andy840119</Authors>
<Company>osu!Karaoke</Company>
<Product>osu!Karaoke</Product>
<PackageReleaseNotes>喵</PackageReleaseNotes>
<PackageId>osu.Framework.Microphone.iOS</PackageId>
<NeutralLanguage>en</NeutralLanguage>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="Xamarin.iOS" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\osu.Framework.Microphone\osu.Framework.Microphone.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Framework.iOS" Version="2020.722.0" />
</ItemGroup>
<ItemGroup>
<NativeLibs Include="$(MSBuildThisFileDirectory)\*.a" />
<None Include="@(NativeLibs)">
<Pack>true</Pack>
<PackageCopyToOutput>true</PackageCopyToOutput>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
18 changes: 15 additions & 3 deletions osu.Framework.Microphone/Input/MicrophoneInputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2aa38be

Please sign in to comment.