diff --git a/.github/workflows/build-ios.yml b/.github/workflows/build-ios.yml index 9f1d0605..e9e875d5 100644 --- a/.github/workflows/build-ios.yml +++ b/.github/workflows/build-ios.yml @@ -104,6 +104,34 @@ jobs: ls -lh "$IPA_PATH" + python - "$IPA_PATH" <<'PY' + import plistlib + import sys + from pathlib import PurePosixPath + from zipfile import ZipFile + + with ZipFile(sys.argv[1]) as ipa: + plist_path = next(name for name in ipa.namelist() + if PurePosixPath(name).match("Payload/*.app/Info.plist")) + info = plistlib.loads(ipa.read(plist_path)) + + minimum = tuple(int(part) for part in info.get("MinimumOSVersion", "0").split(".")) + if minimum[:2] < (15, 1): + raise SystemExit(f"MinimumOSVersion is {info.get('MinimumOSVersion')}, expected at least 15.1") + + project_uti = "pers.vocoder712.openutaumobile.ustx" + document_types = info.get("CFBundleDocumentTypes", []) + if not any(project_uti in item.get("LSItemContentTypes", []) for item in document_types): + raise SystemExit(f"IPA does not register the USTX document type {project_uti}") + + if "audio" not in info.get("UIBackgroundModes", []): + raise SystemExit("IPA does not declare the audio background mode") + + print(f"Minimum OS: {info['MinimumOSVersion']}") + print("USTX document type: registered") + print("Background audio: enabled") + PY + - name: Upload iOS Failure Diagnostics if: failure() uses: actions/upload-artifact@v4 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a57bf884..3ecc9650 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -196,7 +196,39 @@ dotnet build OpenUtauMobile.Android/OpenUtauMobile.Android.csproj -r $androidRid 菜单名称可能随 Rider 版本变化,参见 [Rider Android 调试说明](https://www.jetbrains.com/help/rider/Run_Debug_Configuration_Xamarin_Android.html)。 Debug 使用独立应用 ID 和本地调试签名,无需配置 CI 的发布签名密钥。 -### 6. 常见问题 +### 6. 构建 iOS(macOS) + +iOS 项目必须在 macOS 和 Xcode 上构建;Windows 本地构建不能替代 iOS SDK、模拟器或设备验证。 +当前 CI 固定使用 Xcode 27.0、.NET SDK 10.0.401 和 workload set 10.0.401.1。先在仓库根目录检查 +`xcodebuild -version` 与 `dotnet --version`,然后安装项目所需 workload: + +```bash +export AVALONIA_TELEMETRY_OPTOUT=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +dotnet workload restore OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj --version 10.0.401.1 +``` + +构建 ARM64 和 x64 模拟器宿主: + +```bash +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-arm64 -p:EnableCodeSigning=false +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-x64 -p:EnableCodeSigning=false +``` + +构建 ARM64 设备用的未签名 IPA: + +```bash +dotnet publish OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r ios-arm64 \ + -p:EnableCodeSigning=false -p:BuildIpa=true -p:PublishAot=false -p:UseMonoRuntime=true \ + -p:MtouchUseLlvm=false -p:TrimMode=partial -p:MtouchLink=SdkOnly \ + -p:EnableAssemblyILStripping=false -p:_IsDedupEnabled=false +``` + +未签名 IPA 可检查打包内容,但必须使用 Apple 开发证书和 provisioning profile 签名后才能安装到设备。 +在模拟器或设备上检查文档导入、音频路由变化和系统中断后的播放恢复、WORLDLINE 合成及 ONNX 推理; +构建成功只验证了编译和打包,不等同于运行时支持。 + +### 7. 常见问题 | 现象 | 检查与处理 | | --- | --- | diff --git a/OpenUtau.Core/Util/Onnx.cs b/OpenUtau.Core/Util/Onnx.cs index f19d0720..a7777fa1 100644 --- a/OpenUtau.Core/Util/Onnx.cs +++ b/OpenUtau.Core/Util/Onnx.cs @@ -46,7 +46,7 @@ public static List getRunnerOptions() { runners.Add("DirectML"); } return runners; - } else if (OS.IsMacOS()) { + } else if (OS.IsMacOS() || OS.IsIOS()) { return new List { "CPU", "CoreML" @@ -232,7 +232,7 @@ public static InferenceSession getInferenceSession(byte[] model, OnnxRunnerChoic return new InferenceSession(model); } else { // Try with CoreML subgraphs enabled first, fallback to default if it fails - if (OS.IsMacOS() && Preferences.Default.OnnxRunner == "CoreML") { + if ((OS.IsMacOS() || OS.IsIOS()) && Preferences.Default.OnnxRunner == "CoreML") { try { using var subgraphOptions = getOnnxSessionOptions(coremlEnableOnSubgraphs: true); return new InferenceSession(model, subgraphOptions); @@ -259,7 +259,7 @@ public static InferenceSession getInferenceSession(string modelPath, OnnxRunnerC return new InferenceSession(modelPath); } else { // Try with CoreML subgraphs enabled first, fallback to default if it fails - if (OS.IsMacOS() && Preferences.Default.OnnxRunner == "CoreML") { + if ((OS.IsMacOS() || OS.IsIOS()) && Preferences.Default.OnnxRunner == "CoreML") { try { using var subgraphOptions = getOnnxSessionOptions(coremlEnableOnSubgraphs: true); return new InferenceSession(modelPath, subgraphOptions); diff --git a/OpenUtauMobile.iOS/AppDelegate.cs b/OpenUtauMobile.iOS/AppDelegate.cs index 069d1881..fe7d0829 100644 --- a/OpenUtauMobile.iOS/AppDelegate.cs +++ b/OpenUtauMobile.iOS/AppDelegate.cs @@ -1,10 +1,13 @@ using System; using System.IO; +using System.Linq; using System.Text; using System.Threading.Tasks; using Foundation; using Avalonia; +using Avalonia.Controls.ApplicationLifetimes; using Avalonia.Media; +using Avalonia.Platform.Storage; using Avalonia.iOS; using ReactiveUI.Avalonia; using Microsoft.ML.OnnxRuntime; @@ -47,15 +50,83 @@ protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) ServiceHub.GraphicsBackendService = graphicsService; return base.CustomizeAppBuilder(builder) .With(IosGraphicsBackendProvider.CreatePlatformOptions(graphicsService.StartupFallbackOrder)) + .AfterApplicationSetup(static appBuilder => + { + if (appBuilder.Instance?.TryGetFeature() is { } lifetime) + { + lifetime.Activated += OnAppActivated; + } + }) .UseReactiveUI(_ => { }); } + /// + /// 接收 UIScene 在冷启动或运行期间交付的 USTX 工程。 + /// + private static async void OnAppActivated(object? sender, ActivatedEventArgs activation) + { + if (activation is not FileActivatedEventArgs files) + { + return; + } + + foreach (IStorageItem item in files.Files) + { + using (item) + { + if (item is IStorageFile file && + string.Equals(Path.GetExtension(file.Name), ".ustx", StringComparison.OrdinalIgnoreCase)) + { + await OpenProjectDocumentAsync(file); + } + } + } + } + + /// + /// 在安全作用域仍有效时复制外部工程,并交给共享导航队列打开。 + /// + private static async Task OpenProjectDocumentAsync(IStorageFile file) + { + string importDirectory = Path.Combine(PathManager.Inst.CachePath, "DocumentImports"); + string destinationPath = Path.Combine(importDirectory, $"{Guid.NewGuid():N}.ustx"); + try + { + Directory.CreateDirectory(importDirectory); + await using (Stream source = await file.OpenReadAsync()) + await using (FileStream destination = File.Create(destinationPath)) + { + await source.CopyToAsync(destination); + } + ExternalProjectOpenService.Enqueue(new ExternalProjectOpenRequest(destinationPath, DeleteSourceAfterRead: true)); + } + catch (Exception exception) + { + Log.Error(exception, "无法从 iOS 文件提供程序导入 USTX 工程"); + try + { + if (File.Exists(destinationPath)) + { + File.Delete(destinationPath); + } + } + catch (Exception cleanupException) when (cleanupException is IOException or UnauthorizedAccessException) + { + Log.Warning(cleanupException, "无法清理 iOS 导入缓存 {Path}", destinationPath); + } + ExternalProjectOpenService.ReportFailure(new IOException(L.S("Ios.Document.ImportFailed"), exception)); + } + } + private static void InitPathManager() { string dataPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal); - string cachePath = Path.Combine(dataPath, "Cache"); + string cachePath = NSFileManager.DefaultManager + .GetUrls(NSSearchPathDirectory.CachesDirectory, NSSearchPathDomain.User) + .FirstOrDefault()?.Path + ?? throw new InvalidOperationException("无法获取 iOS 缓存目录。"); PathManagerInitialization.Initialize( rootPath: dataPath, dataPath: dataPath, diff --git a/OpenUtauMobile.iOS/Info.plist b/OpenUtauMobile.iOS/Info.plist index a62bde20..7865fbec 100644 --- a/OpenUtauMobile.iOS/Info.plist +++ b/OpenUtauMobile.iOS/Info.plist @@ -4,10 +4,50 @@ CFBundleDisplayName OpenUtau Mobile 预览版 + UTExportedTypeDeclarations + + + UTTypeIdentifier + pers.vocoder712.openutaumobile.ustx + UTTypeDescription + OpenUtau Project + UTTypeConformsTo + + public.data + + UTTypeTagSpecification + + public.filename-extension + + ustx + + public.mime-type + application/x-openutau-project + + + + CFBundleDocumentTypes + + + CFBundleTypeName + OpenUtau Project + CFBundleTypeRole + Editor + LSHandlerRank + Owner + LSItemContentTypes + + pers.vocoder712.openutaumobile.ustx + + + LSRequiresIPhoneOS LSSupportsOpeningDocumentsInPlace + + UIApplicationSceneManifest + UIDeviceFamily 1 @@ -17,9 +57,9 @@ LaunchScreen UIFileSharingEnabled - UIRequiredDeviceCapabilities + UIBackgroundModes - armv7 + audio UISupportedInterfaceOrientations diff --git a/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj b/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj index 99b8bc53..e61531e8 100644 --- a/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj +++ b/OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj @@ -2,7 +2,7 @@ Exe net10.0-ios - 15.0 + 15.1 enable true diff --git a/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs b/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs index 77c232e9..0feb3e04 100644 --- a/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs +++ b/OpenUtauMobile.iOS/Services/Audio/IosAudioOutput.cs @@ -24,6 +24,8 @@ internal sealed class IosAudioOutput : IAudioOutput, IDisposable private readonly AVAudioEngine engine; private readonly AVAudioSourceNode sourceNode; private readonly AVAudioFormat outputFormat; + private readonly NSObject interruptionObserver; + private readonly NSObject routeChangeObserver; private readonly NSObject configurationChangeObserver; private ISampleProvider? sampleProvider; private PlaybackState playbackState = PlaybackState.Stopped; @@ -31,6 +33,8 @@ internal sealed class IosAudioOutput : IAudioOutput, IDisposable private float[] leftBuffer = Array.Empty(); private float[] rightBuffer = Array.Empty(); private long playedFrames; + private bool interruptionActive; + private bool resumeAfterInterruption; private bool disposed; public IosAudioOutput() @@ -44,8 +48,18 @@ public IosAudioOutput() engine.AttachNode(sourceNode); engine.Connect(sourceNode, engine.MainMixerNode, outputFormat); engine.Prepare(); + interruptionObserver = AVAudioSession.Notifications.ObserveInterruption((_, args) => + { + var type = (AVAudioSessionInterruptionType)GetNotificationNumber( + args.Notification, "AVAudioSessionInterruptionTypeKey"); + var options = (AVAudioSessionInterruptionOptions)GetNotificationNumber( + args.Notification, "AVAudioSessionInterruptionOptionKey"); + Dispatcher.UIThread.Post(() => OnAudioInterruption(type, options)); + }); + routeChangeObserver = AVAudioSession.Notifications.ObserveRouteChange( + (_, _) => Dispatcher.UIThread.Post(TryRestartAfterOutputChange)); configurationChangeObserver = AVAudioEngine.Notifications.ObserveConfigurationChange(engine, (_, _) => - Dispatcher.UIThread.Post(RestartAfterConfigurationChange)); + Dispatcher.UIThread.Post(TryRestartAfterOutputChange)); Log.Information("AVAudioEngine 音频后端初始化成功"); } @@ -110,44 +124,73 @@ public void Init(ISampleProvider provider) sampleProvider = preparedProvider; playedFrames = 0; playbackState = PlaybackState.Stopped; + resumeAfterInterruption = false; } } public void Play() { ThrowIfDisposed(); + PlaybackState previousState; + bool retryingInterruption; lock (syncRoot) { if (sampleProvider == null || (playbackState == PlaybackState.Playing && engine.Running)) { return; } + previousState = playbackState; + retryingInterruption = interruptionActive; playbackState = PlaybackState.Playing; } - if (!engine.Running) + try { - bool started = engine.StartAndReturnError(out NSError? error); - if (!started) + StartEngine(); + if (retryingInterruption) { lock (syncRoot) { - playbackState = PlaybackState.Stopped; + interruptionActive = false; + resumeAfterInterruption = false; } - throw new InvalidOperationException(error?.LocalizedDescription ?? "AVAudioEngine failed to start."); } } + catch (Exception exception) + { + lock (syncRoot) + { + playbackState = retryingInterruption ? previousState : PlaybackState.Stopped; + } + if (retryingInterruption && exception is InvalidOperationException) + { + Log.Warning(exception, "iOS 音频会话暂时无法恢复,保留中断前的播放请求"); + return; + } + throw; + } } public void Pause() { + bool pauseEngine = false; lock (syncRoot) { + if (interruptionActive) + { + resumeAfterInterruption = false; + return; + } if (playbackState == PlaybackState.Playing) { playbackState = PlaybackState.Paused; + pauseEngine = true; } } + if (pauseEngine) + { + engine.Pause(); + } } public void Stop() @@ -156,7 +199,9 @@ public void Stop() { playbackState = PlaybackState.Stopped; playedFrames = 0; + resumeAfterInterruption = false; } + engine.Pause(); } /// 仅接受当前路由;切换路由必须由用户操作系统选择器。 @@ -176,6 +221,8 @@ public void Dispose() return; } disposed = true; + interruptionObserver.Dispose(); + routeChangeObserver.Dispose(); configurationChangeObserver.Dispose(); engine.Stop(); engine.DetachNode(sourceNode); @@ -184,24 +231,6 @@ public void Dispose() engine.Dispose(); } - /// 设备格式变化会停止引擎,仅在仍需播放时恢复输出。 - private void RestartAfterConfigurationChange() - { - if (disposed || PlaybackState != PlaybackState.Playing) - { - return; - } - try - { - Play(); - } - catch (Exception exception) - { - Stop(); - Log.Error(exception, "切换音频路由后恢复 AVAudioEngine 失败"); - } - } - private int RenderAudio( ref bool isSilence, ref AudioTimeStamp timestamp, @@ -284,6 +313,119 @@ internal static void ConfigureAudioSession() } } + /// + /// 启动或恢复 AVAudioEngine,并在系统中断结束后重新激活音频会话。 + /// + private void StartEngine() + { + if (engine.Running) + { + return; + } + + ConfigureAudioSession(); + bool started = engine.StartAndReturnError(out NSError? error); + if (!started) + { + throw new InvalidOperationException(error?.LocalizedDescription ?? "AVAudioEngine failed to start."); + } + } + + /// + /// 在通话等系统中断期间暂停播放,并仅在系统允许时恢复。 + /// + private void OnAudioInterruption(AVAudioSessionInterruptionType type, AVAudioSessionInterruptionOptions options) + { + if (disposed) + { + return; + } + + if (type == AVAudioSessionInterruptionType.Began) + { + lock (syncRoot) + { + interruptionActive = true; + resumeAfterInterruption = playbackState == PlaybackState.Playing; + if (resumeAfterInterruption) + { + playbackState = PlaybackState.Paused; + } + } + engine.Pause(); + Log.Information("iOS 音频会话被中断,已暂停回放"); + return; + } + + if (type != AVAudioSessionInterruptionType.Ended) + { + return; + } + + bool resume; + lock (syncRoot) + { + interruptionActive = false; + resume = resumeAfterInterruption && (options & AVAudioSessionInterruptionOptions.ShouldResume) != 0; + resumeAfterInterruption = false; + } + + if (resume) + { + try + { + Play(); + } + catch (Exception exception) + { + lock (syncRoot) + { + playbackState = PlaybackState.Paused; + } + Log.Warning(exception, "iOS 音频中断结束后无法恢复回放"); + } + } + } + + /// + /// 输出路由或引擎配置变化后,仅在仍需播放时重启已停止的引擎。 + /// + private void TryRestartAfterOutputChange() + { + lock (syncRoot) + { + if (disposed || interruptionActive || playbackState != PlaybackState.Playing || engine.Running) + { + return; + } + } + + try + { + StartEngine(); + } + catch (Exception exception) + { + lock (syncRoot) + { + if (playbackState == PlaybackState.Playing) + { + playbackState = PlaybackState.Paused; + } + } + Log.Warning(exception, "iOS 音频输出变化后无法恢复 AVAudioEngine"); + } + } + + /// + /// 从系统音频通知中读取数值字段。 + /// + private static long GetNotificationNumber(NSNotification notification, string key) + { + using NSString nativeKey = new(key); + return (notification.UserInfo?.ObjectForKey(nativeKey) as NSNumber)?.Int64Value ?? 0; + } + private void ThrowIfDisposed() { ObjectDisposedException.ThrowIf(disposed, this); diff --git a/OpenUtauMobile/Assets/Lang/Strings.en.resx b/OpenUtauMobile/Assets/Lang/Strings.en.resx index 65ae62d3..01956d6d 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.en.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.en.resx @@ -529,6 +529,9 @@ Access to this folder is denied + + Couldn't open the selected project. + Go to parent folder diff --git a/OpenUtauMobile/Assets/Lang/Strings.ja.resx b/OpenUtauMobile/Assets/Lang/Strings.ja.resx index 00c7f952..3fe53108 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.ja.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.ja.resx @@ -529,6 +529,9 @@ このフォルダーへのアクセスが拒否されました + + 選択したプロジェクトを開けませんでした。 + 上のフォルダーへ移動 diff --git a/OpenUtauMobile/Assets/Lang/Strings.ru.resx b/OpenUtauMobile/Assets/Lang/Strings.ru.resx index 0847bc44..fc8e0567 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.ru.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.ru.resx @@ -458,6 +458,9 @@ Доступ к этой папке запрещён + + Не удалось открыть выбранный проект. + Перейти в родительскую папку diff --git a/OpenUtauMobile/Assets/Lang/Strings.uk.resx b/OpenUtauMobile/Assets/Lang/Strings.uk.resx index 1e358679..63b584dc 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.uk.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.uk.resx @@ -458,6 +458,9 @@ Доступ до цієї теки заборонено + + Не вдалося відкрити вибраний проєкт. + Перейти до батьківської теки diff --git a/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx b/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx index fc5190e2..a9a003cb 100644 --- a/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx +++ b/OpenUtauMobile/Assets/Lang/Strings.zh-Hans.resx @@ -529,6 +529,9 @@ 无权访问此目录 + + 无法打开所选工程。 + 返回上级目录 diff --git a/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs b/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs index 89d21967..fff820af 100644 --- a/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs +++ b/OpenUtauMobile/Services/NoteExtraction/GameBackendProvider.cs @@ -18,7 +18,9 @@ internal sealed record GameDependency(string PackageId, string? Path, GameConfig internal static class GameBackendProvider { - public static bool IsSupported => !OperatingSystem.IsBrowser() && !OperatingSystem.IsIOS(); + /// 按平台与运行库检查 GAME 后端是否可用。 + public static bool IsSupported(NoteExtractionBackend choice) => + !OperatingSystem.IsBrowser() && (choice == NoteExtractionBackend.Onnx || !OperatingSystem.IsIOS()); // 弹窗只读取模型文件与配置,不在 UI 线程创建推理会话。 public static GameDependency Inspect(NoteExtractionBackend choice) @@ -55,7 +57,7 @@ public static GameDependency Inspect(NoteExtractionBackend choice) public static IGameBackend Create(NoteExtractionBackend choice) { - if (!IsSupported) throw new PlatformNotSupportedException(L.S("NoteExtraction.Unsupported")); + if (!IsSupported(choice)) throw new PlatformNotSupportedException(L.S("NoteExtraction.Unsupported")); GameDependency dependency = Inspect(choice); if (!dependency.IsInstalled) { diff --git a/OpenUtauMobile/ViewLocator.cs b/OpenUtauMobile/ViewLocator.cs index 3bb67b02..28af6de3 100644 --- a/OpenUtauMobile/ViewLocator.cs +++ b/OpenUtauMobile/ViewLocator.cs @@ -1,13 +1,42 @@ using System; +using System.Collections.Generic; using Avalonia.Controls; using Avalonia.Controls.Templates; using OpenUtauMobile.ViewModels; +using OpenUtauMobile.Views; using Serilog; namespace OpenUtauMobile; public class ViewLocator : IDataTemplate { + // 显式视图工厂让 AOT 编译器看到每个页面构造函数,避免 iOS 运行时反射 JIT。 + private static readonly IReadOnlyDictionary> ViewFactories = new Dictionary> + { + [typeof(AboutViewModel)] = static () => new AboutView(), + [typeof(DependencyManagerViewModel)] = static () => new DependencyManagerView(), + [typeof(DiffSingerSetupViewModel)] = static () => new DiffSingerSetupView(), + [typeof(EditorViewModel)] = static () => new EditorView(), + [typeof(EnunuSingerSetupViewModel)] = static () => new EnunuSingerSetupView(), + [typeof(ExportLogsViewModel)] = static () => new ExportLogsView(), + [typeof(ExpressionGraphEditorViewModel)] = static () => new ExpressionGraphEditorView(), + [typeof(ExpressionGraphLibraryViewModel)] = static () => new ExpressionGraphLibraryView(), + [typeof(HomeViewModel)] = static () => new HomeView(), + [typeof(NeutrinoSingerSetupViewModel)] = static () => new NeutrinoSingerSetupView(), + [typeof(OptionsViewModel)] = static () => new OptionsView(), + [typeof(PluginDetailsViewModel)] = static () => new PluginDetailsView(), + [typeof(PluginManagerViewModel)] = static () => new PluginManagerView(), + [typeof(PluginSingerSetupViewModel)] = static () => new PluginSingerSetupView(), + [typeof(PluginWebSettingsViewModel)] = static () => new PluginWebSettingsView(), + [typeof(SandboxFileManagerViewModel)] = static () => new SandboxFileManagerView(), + [typeof(SettingsViewModel)] = static () => new SettingsView(), + [typeof(SingerDetailViewModel)] = static () => new SingerDetailView(), + [typeof(SingerManagementViewModel)] = static () => new SingerManagementView(), + [typeof(SingleFileSingerSetupViewModel)] = static () => new SingleFileSingerSetupView(), + [typeof(SplashScreenViewModel)] = static () => new SplashScreenView(), + [typeof(UtauSingerSetupViewModel)] = static () => new UtauSingerSetupView(), + }; + public Control? Build(object? data) { if (data is null) @@ -15,25 +44,24 @@ public class ViewLocator : IDataTemplate return null; } - string name = data.GetType().FullName!.Replace("ViewModel", "View"); - Type? type = Type.GetType(name); - if (type != null) + Type viewModelType = data.GetType(); + if (ViewFactories.TryGetValue(viewModelType, out Func? createView)) { try { - return (Control)Activator.CreateInstance(type)!; + return createView(); } catch (Exception exception) { - Log.Error(exception, "创建视图 {ViewType} 失败", name); + Log.Error(exception, "创建视图 {ViewModelType} 失败", viewModelType.FullName); return new TextBlock { - Text = $"Failed to create view: {name}\n{exception.GetBaseException().Message}" + Text = $"Failed to create view: {viewModelType.FullName}\n{exception.GetBaseException().Message}" }; } } - return new TextBlock { Text = "Not Found: " + name }; + return new TextBlock { Text = "Not Found: " + viewModelType.FullName }; } public bool Match(object? data) diff --git a/OpenUtauMobile/ViewModels/MainViewModel.cs b/OpenUtauMobile/ViewModels/MainViewModel.cs index 7283f50f..7620e42a 100644 --- a/OpenUtauMobile/ViewModels/MainViewModel.cs +++ b/OpenUtauMobile/ViewModels/MainViewModel.cs @@ -274,34 +274,26 @@ private async Task OpenExternalProjectAsync(ExternalProjectOpenRequest request) try { NavigateViewModelBase source = CurrentViewModel; - if (source is SandboxFileManagerViewModel sandbox && - (!await sandbox.ConfirmLeaveAsync() || CurrentViewModel != source)) return; if (ServiceHub.UseDesktopFileWorkflows) { + if (source is SandboxFileManagerViewModel sandbox && + (!await sandbox.ConfirmLeaveAsync() || CurrentViewModel != source)) return; ProjectOpenKind kind = request.DeleteSourceAfterRead || !Path.GetExtension(request.LocalPath).Equals(".ustx", StringComparison.OrdinalIgnoreCase) ? ProjectOpenKind.ExternalCopy : ProjectOpenKind.Normal; sourceTransferred = await OpenDesktopProjectAsync(new(request.LocalPath, kind, request.DeleteSourceAfterRead)); return; } - if (CurrentViewModel is EditorViewModel currentEditor) - { - bool canExit = await currentEditor.ConfirmExitAsync(); - if (!canExit || CurrentViewModel != currentEditor) - { - return; - } + ProjectOpenOptions options = new(request.LocalPath, ProjectOpenKind.ExternalCopy, request.DeleteSourceAfterRead); + EditorViewModel.PreparedProject prepared = await EditorViewModel.PrepareProjectAsync(options); + if (CurrentViewModel != source || !await ConfirmCloseAsync() || CurrentViewModel != source) return; - // 替换编辑器时不激活栈中页面,避免它在下一帧启动后台工作。 - if (!TryRemoveCurrentViewModel(currentEditor, notifyRevealedViewModel: false)) - { - return; - } + // 连同覆盖在编辑器上的工具页一起移除,避免两个编辑器共用同一工程。 + while (ActiveEditor != null || CurrentViewModel is ISingerInstallationPage) + { + if (!TryRemoveCurrentViewModel(CurrentViewModel, notifyRevealedViewModel: false)) return; } - EditorViewModel editor = new(this, new ProjectOpenOptions( - request.LocalPath, - ProjectOpenKind.ExternalCopy, - request.DeleteSourceAfterRead)); + EditorViewModel editor = new(this, options, prepared); OnNavigate(editor); sourceTransferred = true; await editor.ProjectLoadCompletion; @@ -356,18 +348,19 @@ public void OnBackRequested() } /// - /// 确认桌面窗口是否可以关闭。 + /// 确认当前页面和工程是否可以关闭或被替换。 /// /// 当前工程允许退出时返回 true。 public async Task ConfirmCloseAsync() { - if (CurrentViewModel is ISingerInstallationPage setup) + NavigateViewModelBase source = CurrentViewModel; + if (source is ISingerInstallationPage setup) { if (!setup.TryLeave()) return false; await setup.CloseSessionAsync(); + if (CurrentViewModel != source) return false; } if (HasActiveSingerInstallation) return false; - NavigateViewModelBase source = CurrentViewModel; if (source is SandboxFileManagerViewModel sandbox && (!await sandbox.ConfirmLeaveAsync() || CurrentViewModel != source)) return false; if (ActiveEditor is EditorViewModel editorViewModel) diff --git a/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs b/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs index fd94c4a7..929db7f4 100644 --- a/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs +++ b/OpenUtauMobile/ViewModels/NoteExtractionPopupViewModel.cs @@ -35,10 +35,10 @@ public sealed class NoteExtractionPopupViewModel : PopupViewModelBase && BatchSize is >= 1 and <= 32 && BatchSize == decimal.Truncate(BatchSize.Value) && MaxBatchDuration is >= 0 and <= 600 && (!ExtractPitch || RmvpeAvailable); public bool HasInvalidSettings => !Valid; - public bool CanUseOnnx => GameBackendProvider.IsSupported && Valid && onnx.IsInstalled && onnx.SupportsLanguage(Language?.Code); - public bool CanUseGgml => GameBackendProvider.IsSupported && Valid && ggml.IsInstalled && ggml.SupportsLanguage(Language?.Code); - public string OnnxStatus => Status("ONNX", onnx); - public string GgmlStatus => Status("GGML", ggml); + public bool CanUseOnnx => GameBackendProvider.IsSupported(NoteExtractionBackend.Onnx) && Valid && onnx.IsInstalled && onnx.SupportsLanguage(Language?.Code); + public bool CanUseGgml => GameBackendProvider.IsSupported(NoteExtractionBackend.Ggml) && Valid && ggml.IsInstalled && ggml.SupportsLanguage(Language?.Code); + public string OnnxStatus => Status("ONNX", onnx, NoteExtractionBackend.Onnx); + public string GgmlStatus => Status("GGML", ggml, NoteExtractionBackend.Ggml); public ReactiveCommand OnnxCommand { get; } public ReactiveCommand GgmlCommand { get; } public ReactiveCommand CancelCommand { get; } @@ -74,8 +74,8 @@ or nameof(BatchSize) or nameof(MaxBatchDuration)) }; } - private string Status(string name, GameDependency dependency) => string.Format(L.S("NoteExtraction.BackendStatus"), - name, dependency.PackageId, L.S(!GameBackendProvider.IsSupported ? "NoteExtraction.Unsupported" + private string Status(string name, GameDependency dependency, NoteExtractionBackend backend) => string.Format(L.S("NoteExtraction.BackendStatus"), + name, dependency.PackageId, L.S(!GameBackendProvider.IsSupported(backend) ? "NoteExtraction.Unsupported" : !dependency.IsInstalled ? "NoteExtraction.NotInstalled" : dependency.SupportsLanguage(Language?.Code) ? "Common.Installed" : "NoteExtraction.LanguageUnavailable")); diff --git a/README.md b/README.md index 6d00c9f6..c2b92a58 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ This is a developer preview. The tables describe the current source and packagin | Android | ARM64 (`arm64-v8a`), x64 (`x86_64`) | Minimum Android 7 / API 24; ARM64 and x64 local APK builds verified. | | Linux | x64, ARM64 | Desktop host and release jobs configured; use a matching Linux build host. | | macOS | x64, ARM64 | Desktop host and release jobs configured; build on macOS. | -| iOS | Simulator build configuration exists | Experimental host with AVAudioEngine audio and ONNX initialization; full feature parity is not established. Requires macOS/Xcode for development. | +| iOS | ARM64 device IPA; ARM64 and x64 simulator builds configured | .NET 10 host and unsigned IPA build are configured with iOS 15.1 minimum. Full runtime and device behavior still need validation. Requires macOS/Xcode for development. | | Browser / WebAssembly | Browser host exists | Experimental; Dummy audio output, no complete singing synthesis runtime integration. | Windows x86 and Android x86/ARM32 have some project/toolchain mappings but are not part of the current release matrix. @@ -50,20 +50,21 @@ is incomplete. **Unavailable** means the feature is not exposed or its required | Feature | Windows | Android | Linux | macOS | iOS | Browser | | --- | --- | --- | --- | --- | --- | --- | | Shared project / piano-roll editor | Integrated | Integrated | Integrated | Integrated | Experimental | Experimental | +| Built-in phonemizers | Integrated | Integrated | Integrated | Integrated | Experimental; reflection-based creation under Mono AOT needs device validation | Experimental | | Desktop workspace, persistent inspectors and tool manager | Integrated; local checks below | Uses mobile presentation | Integrated; host verification pending | Integrated; host verification pending | Uses mobile presentation | Uses mobile presentation | | Audio playback | Integrated | Integrated | Integrated | Integrated | Experimental (AVAudioEngine) | Unavailable (Dummy output) | -| Built-in worldline / WORLDLINE-R synthesis | Integrated | Integrated; page-size limitation below | Integrated | Integrated | Unavailable (worldline not bundled) | Unavailable | +| Built-in worldline / WORLDLINE-R synthesis | Integrated | Integrated; page-size limitation below | Integrated | Integrated | Integrated in the native build; on-device synthesis still needs validation | Unavailable | | External UTAU resampler / wavtool programs | Conditional: matching Windows tools | No desktop executable compatibility guarantee | Native resamplers conditional; Windows tools experimental through Wine; native external wavtools unavailable | Native resamplers conditional; Windows tools experimental through Wine; native external wavtools unavailable | Unavailable | Unavailable | -| ONNX Runtime CPU inference | Integrated | Integrated (Android AAR) | Integrated | Integrated | Experimental | Unavailable in the current host | -| ONNX hardware acceleration | Conditional: DirectML | Conditional: NNAPI | Conditional: CUDA + cuDNN | Conditional: CoreML | Not exposed as an iOS accelerator by the current selector | Unavailable | +| ONNX Runtime CPU inference | Integrated | Integrated (Android AAR) | Integrated | Integrated | iOS XCFramework is packaged; model inference still needs device validation | Unavailable in the current host | +| ONNX hardware acceleration | Conditional: DirectML | Conditional: NNAPI | Conditional: CUDA + cuDNN | Conditional: CoreML | Conditional: CoreML; device validation pending | Unavailable | | DiffSinger / Vogen model-based synthesis | Conditional | Conditional | Conditional | Conditional | Experimental | Unavailable | | HifiSampler renderer | Conditional | Conditional | Conditional | Conditional | Experimental | Unavailable | -| GAME note extraction: ONNX | Conditional | Conditional | Conditional | Conditional | Unavailable (entry hidden) | Unavailable (entry hidden) | -| RMVPE pitch curve after note extraction | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Unavailable | Unavailable | -| GAME note extraction: GGML | Conditional, CPU | Conditional, CPU | Conditional, CPU | Conditional, CPU | Unavailable | Unavailable | +| GAME note extraction: ONNX | Conditional | Conditional | Conditional | Conditional | Conditional, CPU/CoreML; device validation pending | Unavailable (entry hidden) | +| RMVPE pitch curve after note extraction | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`) | Conditional (`rmvpe`); device validation pending | Unavailable | +| GAME note extraction: GGML | Conditional, CPU | Conditional, CPU | Conditional, CPU | Conditional, CPU | Unavailable (native runtime not packaged) | Unavailable | | GGML Vulkan / CUDA / Metal acceleration | Not delivered by default | Not delivered by default | Not delivered by default | Not delivered by default | Unavailable | Unavailable | | Voicebank / `.oudep` dependency installation | Integrated | Integrated; storage permission required | Integrated | Integrated | Experimental | Experimental filesystem integration | -| Additional Core engines (ENUNU, VOICEVOX, NEUTRINO) | Conditional; external engine required, not verified here | Not verified | Conditional; external engine required, not verified here | Conditional; external engine required, not verified here | Not verified | Not integrated | +| Additional Core engines (ENUNU, VOICEVOX, NEUTRINO) | Conditional; external engine required, not verified here | Not verified | Conditional; external engine required, not verified here | Conditional; external engine required, not verified here | ENUNU/VOICEVOX unavailable (local server); NEUTRINO ONNX conditional, runtime validation pending | Not integrated | Model-based renderers require the appropriate voicebank and auxiliary models. HifiSampler additionally requires its vocoder dependency package. A renderer appearing in the registry does not certify an external engine's @@ -111,7 +112,7 @@ See [desktop architecture and verification](docs/DESKTOP_UI.md) for implementati ### Hardware acceleration - **ONNX:** the current [provider selector](OpenUtau.Core/Util/Onnx.cs) offers DirectML on Windows, - NNAPI on Android, CoreML on macOS, and CUDA on Linux when CUDA and cuDNN are detected. + NNAPI on Android, CoreML on macOS and iOS, and CUDA on Linux when CUDA and cuDNN are detected. Availability also depends on the packaged ONNX Runtime, device drivers and model operators. Selecting a provider does not establish that every operation executes on the GPU/NPU or that it is faster than CPU. - **GAME ONNX:** uses this ONNX configuration. Its encoder explicitly uses CPU when CoreML is selected; @@ -150,6 +151,10 @@ Windows directories were also tested. Android APK checks confirm the expected GA These checks do **not** establish Android device inference, debugger attachment, GPU performance, or successful execution of all GitHub-hosted jobs. Check the actual workflow runs for CI results. +The iOS build workflow publishes an unsigned ARM64 IPA and checks the minimum iOS version, USTX document +registration, and background-audio declaration in its `Info.plist`. Document import, audio routes, synthesis, +and ONNX/CoreML inference require device validation. + The new Android GAME libraries use 16 KB alignment. Existing dependencies can still emit `XA0141`: `libworldline.so` in the ARM64 build and `libSDL3.so` in the x64 build were observed with this warning. The whole APK is therefore not certified for 16 KB page-size devices. diff --git a/docs/CONTRIBUTING.en-US.md b/docs/CONTRIBUTING.en-US.md index 746197ec..91591847 100644 --- a/docs/CONTRIBUTING.en-US.md +++ b/docs/CONTRIBUTING.en-US.md @@ -153,6 +153,37 @@ If compilation fails, inspect the first error and resolved SDK/NDK/JDK paths. A from a missing model; do not copy binaries from another RID. Check the [known limitations](../README.md#verification-and-known-limits), including Android 16 KB alignment warnings in existing dependencies. See the Chinese guide for the full troubleshooting table. +### 6. Build iOS on macOS + +The iOS project must be built on macOS with Xcode; a Windows build cannot replace the iOS SDK, simulator or +device validation. CI currently pins Xcode 27.0, .NET SDK 10.0.401 and workload set 10.0.401.1. From the +repository root, check `xcodebuild -version` and `dotnet --version`, then install the project workloads: + +```bash +export AVALONIA_TELEMETRY_OPTOUT=1 +export DOTNET_CLI_TELEMETRY_OPTOUT=1 +dotnet workload restore OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj --version 10.0.401.1 +``` + +Build the ARM64 and x64 simulator hosts: + +```bash +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-arm64 -p:EnableCodeSigning=false +dotnet build OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r iossimulator-x64 -p:EnableCodeSigning=false +``` + +Publish an unsigned ARM64 device IPA: + +```bash +dotnet publish OpenUtauMobile.iOS/OpenUtauMobile.iOS.csproj -c Release -f net10.0-ios -r ios-arm64 \ + -p:EnableCodeSigning=false -p:BuildIpa=true +``` + +An unsigned IPA is useful for checking package contents, but it cannot be installed on a device until signed with +an Apple development identity and provisioning profile. Verify document import, playback through route changes +and interruptions, WORLDLINE synthesis and ONNX inference on a simulator or device before claiming runtime +support; a successful build only validates compilation and packaging. + --- ## Branches diff --git a/docs/PLATFORMS.md b/docs/PLATFORMS.md index 94eae970..ff702b36 100644 --- a/docs/PLATFORMS.md +++ b/docs/PLATFORMS.md @@ -45,14 +45,18 @@ Do not infer capability parity merely because hosts share App. RID-native files beside the executable for P/Invoke lookup. Preserve this during packaging changes; an assembly-only output is insufficient. - [iOS AppDelegate](../OpenUtauMobile.iOS/AppDelegate.cs) registers AVAudioEngine audio - initialization (with a Dummy fallback) and probes ONNX Runtime at startup. It does - not establish complete desktop/mobile feature parity. + initialization (with a Dummy fallback), probes ONNX Runtime at startup and receives + imported USTX documents. ONNX CPU and CoreML providers are available through the shared + runner selector and packaged iOS XCFramework; model execution still needs device validation. - iOS and Browser import the [Worldline native build](../native/worldline/README.md). Bazel produces static archives: iOS links them through `NativeReference` and resolves Core's `worldline` imports to explicitly retained main-program symbols; Browser uses - `NativeFileReference` with the .NET workload's Emscripten toolchain. This does not - provide GAME/ggml, ONNX support or a Browser audio output backend. iOS still requires - validation on macOS/Xcode and devices. + `NativeFileReference` with the .NET workload's Emscripten toolchain. Neither host + packages GAME/ggml; iOS GAME uses ONNX CPU, and Browser has no ONNX support or audio + output backend. iOS still requires validation on macOS/Xcode and devices. +- iOS excludes executable resamplers and wavtools that require `Process.Start`, and hides + ENUNU/VOICEVOX because they require a separate localhost server. In-process resamplers, + WORLDLINE and ONNX-based engines remain available subject to device validation. - [Browser Program](../OpenUtauMobile.Browser/Program.cs) uses silent Dummy audio and injects PathManager through private fields instead of its normal constructor. Core singleton/property changes therefore need browser