From 870f3dd6d95800651376fe000aaaec1f9aa2ef1d Mon Sep 17 00:00:00 2001 From: Brad Howes Date: Sun, 22 Dec 2024 15:18:44 +0100 Subject: [PATCH] Pin to specifiic SF2Lib that works on iOS < 17 --- .../project.pbxproj | 18 +++++------ .../SoundFontsApp/App/AppDelegate.swift | 30 ++++++++++------- .../App/MainViewController.swift | 15 +++++---- .../App/UIApplication+Extensions.swift | 7 +--- .../Audio/AudioEngine.swift | 32 ++++++++++--------- .../ConsolidatedConfigProvider.swift | 1 + 6 files changed, 55 insertions(+), 48 deletions(-) diff --git a/SoundFontInfoLib/SoundFontInfoLib.xcodeproj/project.pbxproj b/SoundFontInfoLib/SoundFontInfoLib.xcodeproj/project.pbxproj index 374488e5..61c38c94 100644 --- a/SoundFontInfoLib/SoundFontInfoLib.xcodeproj/project.pbxproj +++ b/SoundFontInfoLib/SoundFontInfoLib.xcodeproj/project.pbxproj @@ -10,7 +10,7 @@ BD2398A32BBB65D5009265E4 /* SF2Files.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD9C8A272A8AC2DC0055A95C /* SF2Files.framework */; }; BD6791622973622C0055BB38 /* FourCharCode.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD6791612973622C0055BB38 /* FourCharCode.swift */; }; BD74D17123CDB1D200204ED4 /* SoundFontInfoLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = BD74D16723CDB1D200204ED4 /* SoundFontInfoLib.framework */; }; - BD9C8A262A8A68C20055A95C /* SF2Lib in Frameworks */ = {isa = PBXBuildFile; productRef = BD9C8A252A8A68C20055A95C /* SF2Lib */; }; + BD7779472D18548C004AA250 /* SF2Lib in Frameworks */ = {isa = PBXBuildFile; productRef = BD7779462D18548C004AA250 /* SF2Lib */; }; BDB1BF9E265DB1F0002AD159 /* SoundFontInfoLib.h in Headers */ = {isa = PBXBuildFile; fileRef = BDB1BF40265DB1F0002AD159 /* SoundFontInfoLib.h */; settings = {ATTRIBUTES = (Public, ); }; }; BDB1BFF0265DB1F1002AD159 /* SoundFontInfo.mm in Sources */ = {isa = PBXBuildFile; fileRef = BDB1BF9C265DB1F0002AD159 /* SoundFontInfo.mm */; }; BDB1BFF1265DB788002AD159 /* SoundFontInfo.h in Headers */ = {isa = PBXBuildFile; fileRef = BDB1BF95265DB1F0002AD159 /* SoundFontInfo.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -57,8 +57,8 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + BD7779472D18548C004AA250 /* SF2Lib in Frameworks */, BD2398A32BBB65D5009265E4 /* SF2Files.framework in Frameworks */, - BD9C8A262A8A68C20055A95C /* SF2Lib in Frameworks */, BDFA98F3280C73280069A46F /* AudioToolbox.framework in Frameworks */, BDD2D6AB261C8854000557A3 /* Accelerate.framework in Frameworks */, ); @@ -154,7 +154,7 @@ ); name = SoundFontInfoLib; packageProductDependencies = ( - BD9C8A252A8A68C20055A95C /* SF2Lib */, + BD7779462D18548C004AA250 /* SF2Lib */, ); productName = SoundFontInfoLib; productReference = BD74D16723CDB1D200204ED4 /* SoundFontInfoLib.framework */; @@ -214,7 +214,7 @@ ); mainGroup = BD74D15D23CDB1D200204ED4; packageReferences = ( - BD9C8A242A8A68C20055A95C /* XCRemoteSwiftPackageReference "SF2Lib" */, + BD7779452D18548C004AA250 /* XCRemoteSwiftPackageReference "SF2Lib" */, ); productRefGroup = BD74D16823CDB1D200204ED4 /* Products */; projectDirPath = ""; @@ -681,20 +681,20 @@ /* End XCConfigurationList section */ /* Begin XCRemoteSwiftPackageReference section */ - BD9C8A242A8A68C20055A95C /* XCRemoteSwiftPackageReference "SF2Lib" */ = { + BD7779452D18548C004AA250 /* XCRemoteSwiftPackageReference "SF2Lib" */ = { isa = XCRemoteSwiftPackageReference; repositoryURL = "https://github.com/bradhowes/SF2Lib"; requirement = { - branch = main; - kind = branch; + kind = exactVersion; + version = 6.1.0; }; }; /* End XCRemoteSwiftPackageReference section */ /* Begin XCSwiftPackageProductDependency section */ - BD9C8A252A8A68C20055A95C /* SF2Lib */ = { + BD7779462D18548C004AA250 /* SF2Lib */ = { isa = XCSwiftPackageProductDependency; - package = BD9C8A242A8A68C20055A95C /* XCRemoteSwiftPackageReference "SF2Lib" */; + package = BD7779452D18548C004AA250 /* XCRemoteSwiftPackageReference "SF2Lib" */; productName = SF2Lib; }; /* End XCSwiftPackageProductDependency section */ diff --git a/SoundFontsApp/SoundFontsApp/App/AppDelegate.swift b/SoundFontsApp/SoundFontsApp/App/AppDelegate.swift index 2978ff2b..4b934463 100644 --- a/SoundFontsApp/SoundFontsApp/App/AppDelegate.swift +++ b/SoundFontsApp/SoundFontsApp/App/AppDelegate.swift @@ -48,15 +48,21 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { } /** - Notification handler for when the application starts. + Notification handler for when the application starts. Handles requests to visit the AppStore and view the SoundFonts + page there. - parameter application: the application that is running - parameter launchOptions: the options used to start the application */ - func application(_ application: UIApplication, - didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - observer = NotificationCenter.default.addObserver(forName: .visitAppStore, object: nil, - queue: nil) { [weak self] _ in + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? + ) -> Bool { + observer = NotificationCenter.default.addObserver( + forName: .visitAppStore, + object: nil, + queue: nil + ) { [weak self] _ in self?.visitAppStore() } return true @@ -69,8 +75,11 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { - parameter url: the URL of the file to open - parameter options: dictionary of options that may affect the opening (unused) */ - func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool { - // DispatchQueue.main.async { self.components.fontsViewManager.addSoundFonts(urls: [url]) } + func application( + _ app: UIApplication, + open url: URL, + options: [UIApplication.OpenURLOptionsKey: Any] = [:] + ) -> Bool { pendingAddition = url return true } @@ -130,10 +139,9 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { false } - @objc private func visitAppStore() { - guard let writeReviewURL = URL(string: "https://itunes.apple.com/app/id1453325077?action=write-review") else { - fatalError("Expected a valid URL") + private func visitAppStore() { + if let writeReviewURL = URL(string: "https://itunes.apple.com/app/id1453325077?action=write-review") { + UIApplication.shared.open(writeReviewURL, options: [:], completionHandler: nil) } - UIApplication.shared.open(writeReviewURL, options: [:], completionHandler: nil) } } diff --git a/SoundFontsApp/SoundFontsApp/App/MainViewController.swift b/SoundFontsApp/SoundFontsApp/App/MainViewController.swift index 1bbdc5e8..2d2a6f85 100644 --- a/SoundFontsApp/SoundFontsApp/App/MainViewController.swift +++ b/SoundFontsApp/SoundFontsApp/App/MainViewController.swift @@ -15,9 +15,9 @@ import ProgressHUD final class MainViewController: UIViewController { private lazy var log: Logger = Logging.logger("MainViewController") - private var activePresetManager: ActivePresetManager! + private var activePresetManager: ActivePresetManager? private var audioEngine: AudioEngine? - private var settings: Settings! + private var settings: Settings? private var askForReview: AskForReview? private var startRequested = false @@ -40,7 +40,7 @@ final class MainViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() - UIApplication.shared.appDelegate.setMainViewController(self) + UIApplication.shared.appDelegate?.setMainViewController(self) setNeedsUpdateOfScreenEdgesDeferringSystemGestures() observers.append(NotificationCenter.default.addObserver(forName: .showChanges, object: nil, queue: nil) { [weak self] _ in @@ -58,7 +58,7 @@ final class MainViewController: UIViewController { override func viewDidAppear(_ animated: Bool) { super.viewDidAppear(animated) - + guard let settings else { return } if !skipTutorial { if !settings.showedTutorial { showTutorial() @@ -103,8 +103,9 @@ extension MainViewController { Show the changes screen if there are changes to be shown. */ func showChanges(_ force: Bool = false) { + guard let settings else { return } let currentVersion = alwaysShowChanges ? "" : Bundle.main.releaseVersionNumber - + if settings.showedChanges != currentVersion || alwaysShowChanges || force { let changes = ChangesCompiler.compile() settings.showedChanges = currentVersion @@ -288,7 +289,7 @@ extension MainViewController: ControllerConfiguration { } if let audioEngine = router.audioEngine { - activePresetManager.runOnNotifyQueue { + router.activePresetManager.runOnNotifyQueue { audioEngine.attachKeyboard(keyboard) self.setAudioEngineInBackground(audioEngine) } @@ -303,7 +304,7 @@ extension MainViewController: ControllerConfiguration { } } - activePresetManager.restoreActive(settings.lastActivePreset) + router.activePresetManager.restoreActive(router.settings.lastActivePreset) log.debug("establishConnections END") } diff --git a/SoundFontsApp/SoundFontsApp/App/UIApplication+Extensions.swift b/SoundFontsApp/SoundFontsApp/App/UIApplication+Extensions.swift index c833d127..c8e51386 100644 --- a/SoundFontsApp/SoundFontsApp/App/UIApplication+Extensions.swift +++ b/SoundFontsApp/SoundFontsApp/App/UIApplication+Extensions.swift @@ -5,10 +5,5 @@ import UIKit extension UIApplication { /// Obtain the AppDelegate instance for the application - var appDelegate: AppDelegate { - guard let del = self.delegate as? AppDelegate else { - fatalError("unexpected nil or type for appDelegate") - } - return del - } + var appDelegate: AppDelegate? { self.delegate as? AppDelegate } } diff --git a/SoundFontsFramework/SoundFontsFramework/Audio/AudioEngine.swift b/SoundFontsFramework/SoundFontsFramework/Audio/AudioEngine.swift index 7ea1cc98..37beeec1 100644 --- a/SoundFontsFramework/SoundFontsFramework/Audio/AudioEngine.swift +++ b/SoundFontsFramework/SoundFontsFramework/Audio/AudioEngine.swift @@ -76,6 +76,8 @@ public final class AudioEngine: SynthProvider { - parameter mode: determines how the sampler is hosted. - parameter activePresetManager: the manager of the active preset - parameter settings: user-adjustable settings + - parameter midi: the provider of MIDI events + - parameter midiControllerActionStateManager: manager for mapping of MIDI controller events to internal actions */ init(mode: Mode, activePresetManager: ActivePresetManager, settings: Settings, midi: MIDI?, midiControllerActionStateManager: MIDIControllerActionStateManager?) { @@ -122,9 +124,9 @@ public final class AudioEngine: SynthProvider { // MARK: - Control -public extension AudioEngine { +extension AudioEngine { - func attachKeyboard(_ keyboard: AnyKeyboard) { + public func attachKeyboard(_ keyboard: AnyKeyboard) { guard let midi = self.midi, let midiConnectionMonitor = self.midiConnectionMonitor, let midiControllerActionStateManager = self.midiControllerActionStateManager @@ -144,7 +146,7 @@ public extension AudioEngine { - returns: Result value indicating success or failure */ - func start() -> StartResult { + public func start() -> StartResult { log.debug("start BEGIN") let synth = makeSynth() self._synth = synth @@ -174,7 +176,7 @@ public extension AudioEngine { /** Stop the existing audio engine. NOTE: this only applies to the standalone case. */ - func stop() { + public func stop() { log.debug("stop BEGIN") guard mode == .standalone else { fatalError("unexpected `stop` called on audioUnit") } @@ -212,19 +214,19 @@ public extension AudioEngine { /** Command the synth to stop playing active notes. */ - func stopAllNotes() { synth?.stopAllNotes() } + public func stopAllNotes() { synth?.stopAllNotes() } } // MARK: - Configuration Changes -private extension AudioEngine { +extension AudioEngine { /** Change the synth to use the given preset configuration values. - parameter presetConfig: the configuration to use */ - func applyPresetConfig(_ presetConfig: PresetConfig) { + private func applyPresetConfig(_ presetConfig: PresetConfig) { log.debug("applyPresetConfig BEGIN") if presetConfig.presetTuning != 0.0 { @@ -275,7 +277,7 @@ private extension AudioEngine { - parameter value: the value to set in cents (+/- 2400) */ - func setTuning(_ value: Float) { + private func setTuning(_ value: Float) { log.debug("setTuning BEGIN - \(value)") synth?.synthGlobalTuning = value log.debug("setTuning END") @@ -286,7 +288,7 @@ private extension AudioEngine { - parameter value: the value to set */ - func setGain(_ value: Float) { + private func setGain(_ value: Float) { log.debug("setGain BEGIN - \(value)") synth?.synthGain = value log.debug("setGain END") @@ -297,7 +299,7 @@ private extension AudioEngine { - parameter value: the value to set */ - func setPan(_ value: Float) { + private func setPan(_ value: Float) { log.debug("setPan BEGIN - \(value)") synth?.synthStereoPan = value log.debug("setPan END") @@ -308,13 +310,13 @@ private extension AudioEngine { - parameter value: range in semitones */ - func setPitchBendRange(value: UInt8) { + private func setPitchBendRange(value: UInt8) { log.debug("setPitchBendRange BEGIN - \(value)") synth?.setPitchBendRange(value: value) log.debug("setPitchBendRange END") } - func pendingPresetLoad() { + private func pendingPresetLoad() { // We delay changing preset in case there is another change coming over due to UI/MIDI controls. When another one // comes in we cancel the running timer and restart it, setting a new preset only after the time finishes and fires. DispatchQueue.main.async { [weak self] in @@ -333,7 +335,7 @@ private extension AudioEngine { - returns: StartResult indicating success or failure */ - func loadActivePreset(_ afterLoadBlock: (() -> Void)? = nil) -> StartResult { + private func loadActivePreset(_ afterLoadBlock: (() -> Void)? = nil) -> StartResult { log.debug("loadActivePreset BEGIN - \(self.activePresetManager.active.description, privacy: .public)") // Ok if the sampler is not yet available. We will apply the preset when it is @@ -378,9 +380,9 @@ private extension AudioEngine { return .success(synth) } - func makeSynth() -> AnyMIDISynth { AVAudioUnitSampler() } + private func makeSynth() -> AnyMIDISynth { AVAudioUnitSampler() } - func startEngine(_ synth: AnyMIDISynth) -> StartResult { + private func startEngine(_ synth: AnyMIDISynth) -> StartResult { log.debug("creating AVAudioEngine") let engine = AVAudioEngine() self.engine = engine diff --git a/SoundFontsFramework/SoundFontsFramework/Audio/Configuration File/ConsolidatedConfigProvider.swift b/SoundFontsFramework/SoundFontsFramework/Audio/Configuration File/ConsolidatedConfigProvider.swift index 99950bd4..cfd8403a 100644 --- a/SoundFontsFramework/SoundFontsFramework/Audio/Configuration File/ConsolidatedConfigProvider.swift +++ b/SoundFontsFramework/SoundFontsFramework/Audio/Configuration File/ConsolidatedConfigProvider.swift @@ -41,6 +41,7 @@ public final class ConsolidatedConfigProvider: NSObject { - parameter inApp: `true` if running as an app, `false` if as an AUv3 app extension - parameter fileURL: the location for the document + - parameter identity: the unique tag assigned to this instance */ public init(inApp: Bool, fileURL: URL, identity: String) { self.log = Logging.logger("ConsolidatedConfigProvider[\(identity)]")