diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ee93ec5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# User-specific xcconfig files +Xcode-config/DEVELOPMENT_TEAM.xcconfig diff --git a/AudioWaveformGraph.xcodeproj/project.pbxproj b/AudioWaveformGraph.xcodeproj/project.pbxproj index 94a2796..3335b2e 100644 --- a/AudioWaveformGraph.xcodeproj/project.pbxproj +++ b/AudioWaveformGraph.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 3D29594227B2C7B300BA7C0A /* DEVELOPMENT_TEAM.template.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 3D29593F27B2C7B300BA7C0A /* DEVELOPMENT_TEAM.template.xcconfig */; }; + 3D29594327B2C7B300BA7C0A /* DEVELOPMENT_TEAM.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 3D29594027B2C7B300BA7C0A /* DEVELOPMENT_TEAM.xcconfig */; }; + 3D29594427B2C7B300BA7C0A /* Shared.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 3D29594127B2C7B300BA7C0A /* Shared.xcconfig */; }; EF1512EB258BDA8000F064A6 /* UIKitExtras.swift in Sources */ = {isa = PBXBuildFile; fileRef = EF1512EA258BDA8000F064A6 /* UIKitExtras.swift */; }; EFC5909725840B1500E5D4B4 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFC5909625840B1500E5D4B4 /* AppDelegate.swift */; }; EFC5909925840B1500E5D4B4 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = EFC5909825840B1500E5D4B4 /* SceneDelegate.swift */; }; @@ -29,6 +32,9 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 3D29593F27B2C7B300BA7C0A /* DEVELOPMENT_TEAM.template.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DEVELOPMENT_TEAM.template.xcconfig; sourceTree = ""; }; + 3D29594027B2C7B300BA7C0A /* DEVELOPMENT_TEAM.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = DEVELOPMENT_TEAM.xcconfig; sourceTree = ""; }; + 3D29594127B2C7B300BA7C0A /* Shared.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = Shared.xcconfig; sourceTree = ""; }; EF1512EA258BDA8000F064A6 /* UIKitExtras.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIKitExtras.swift; sourceTree = ""; }; EFC5909325840B1500E5D4B4 /* AudioWaveformGraph.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = AudioWaveformGraph.app; sourceTree = BUILT_PRODUCTS_DIR; }; EFC5909625840B1500E5D4B4 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; @@ -64,13 +70,25 @@ /* End PBXFrameworksBuildPhase section */ /* Begin PBXGroup section */ + 3D29593E27B2C7B300BA7C0A /* Xcode-config */ = { + isa = PBXGroup; + children = ( + 3D29593F27B2C7B300BA7C0A /* DEVELOPMENT_TEAM.template.xcconfig */, + 3D29594027B2C7B300BA7C0A /* DEVELOPMENT_TEAM.xcconfig */, + 3D29594127B2C7B300BA7C0A /* Shared.xcconfig */, + ); + path = "Xcode-config"; + sourceTree = ""; + }; EFC5908A25840B1500E5D4B4 = { isa = PBXGroup; children = ( + 3D29593E27B2C7B300BA7C0A /* Xcode-config */, EFC5909525840B1500E5D4B4 /* AudioWaveformGraph */, EFC5909425840B1500E5D4B4 /* Products */, ); sourceTree = ""; + usesTabs = 0; }; EFC5909425840B1500E5D4B4 /* Products */ = { isa = PBXGroup; @@ -191,7 +209,10 @@ files = ( EFC590A325840B1700E5D4B4 /* LaunchScreen.storyboard in Resources */, EFC590AC25840B7500E5D4B4 /* audio.mp3 in Resources */, + 3D29594227B2C7B300BA7C0A /* DEVELOPMENT_TEAM.template.xcconfig in Resources */, + 3D29594327B2C7B300BA7C0A /* DEVELOPMENT_TEAM.xcconfig in Resources */, EFC590A025840B1700E5D4B4 /* Assets.xcassets in Resources */, + 3D29594427B2C7B300BA7C0A /* Shared.xcconfig in Resources */, EFC5909E25840B1500E5D4B4 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; @@ -245,6 +266,7 @@ /* Begin XCBuildConfiguration section */ EFC590A525840B1700E5D4B4 /* Debug */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 3D29594127B2C7B300BA7C0A /* Shared.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -294,7 +316,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 14.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; MTL_FAST_MATH = YES; ONLY_ACTIVE_ARCH = YES; @@ -306,6 +328,7 @@ }; EFC590A625840B1700E5D4B4 /* Release */ = { isa = XCBuildConfiguration; + baseConfigurationReference = 3D29594127B2C7B300BA7C0A /* Shared.xcconfig */; buildSettings = { ALWAYS_SEARCH_USER_PATHS = NO; CLANG_ANALYZER_NONNULL = YES; @@ -349,7 +372,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 14.2; + IPHONEOS_DEPLOYMENT_TARGET = 12.0; MTL_ENABLE_DEBUG_INFO = NO; MTL_FAST_MATH = YES; SDKROOT = iphoneos; @@ -366,9 +389,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = AudioWaveformGraph/AudioWaveformGraph.entitlements; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 899AA7RGN5; INFOPLIST_FILE = AudioWaveformGraph/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", @@ -388,9 +409,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = AudioWaveformGraph/AudioWaveformGraph.entitlements; CODE_SIGN_STYLE = Automatic; - DEVELOPMENT_TEAM = 899AA7RGN5; INFOPLIST_FILE = AudioWaveformGraph/Info.plist; - IPHONEOS_DEPLOYMENT_TARGET = 13.0; LD_RUNPATH_SEARCH_PATHS = ( "$(inherited)", "@executable_path/Frameworks", diff --git a/AudioWaveformGraph/AppDelegate.swift b/AudioWaveformGraph/AppDelegate.swift index d42a4cb..1392725 100644 --- a/AudioWaveformGraph/AppDelegate.swift +++ b/AudioWaveformGraph/AppDelegate.swift @@ -10,21 +10,29 @@ import UIKit @main class AppDelegate: UIResponder, UIApplicationDelegate { - + var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + if #available(iOS 13, *) { + // Do nothing / do things that should only be done for iOS 13. + } else { + // Do iOS 12 specific window setup. + } + // Override point for customization after application launch. return true } // MARK: UISceneSession Lifecycle + @available(iOS 13, *) func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration { // Called when a new scene session is being created. // Use this method to select a configuration to create the new scene with. return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role) } + @available(iOS 13, *) func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set) { // Called when the user discards a scene session. // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions. diff --git a/AudioWaveformGraph/Graph/DataProvider.swift b/AudioWaveformGraph/Graph/DataProvider.swift index 3ee37bd..7434df9 100644 --- a/AudioWaveformGraph/Graph/DataProvider.swift +++ b/AudioWaveformGraph/Graph/DataProvider.swift @@ -53,8 +53,14 @@ class DataProvider { idx += hopSize } - summarySampleMax = vDSP.maximum(workingAvgSamples) - summarySampleMin = vDSP.minimum(workingAvgSamples) + if #available(iOS 13, *) { + summarySampleMax = vDSP.maximum(workingAvgSamples) + summarySampleMin = vDSP.minimum(workingAvgSamples) + } + else { + vDSP_maxv(workingAvgSamples, 1, &summarySampleMax, vDSP_Length(workingAvgSamples.count)) + vDSP_minv(workingAvgSamples, 1, &summarySampleMin, vDSP_Length(workingAvgSamples.count)) + } summarySamples = workingAvgSamples @@ -65,11 +71,11 @@ class DataProvider { } func sample(at time: Double) -> Float { - guard let summarySamples = summarySamples else { return 0 } - var summarySampleIdx = Int(time / duration * Double(summarySamples.count)) + // `time` can dip below 0 if rubber-banding to before the first or after the last sample while scrolling. + guard (0.0.. Float { var mean: Float = 0 - // todo: dangling pointer warning is safe in this case since it's never accessed outside of scope, but should be fixed - let ptr = UnsafePointer(a) - vDSP_meanv(ptr + startIdx, 1, &mean, UInt(endIdx - startIdx)) + + a.withUnsafeBufferPointer { bufferPointer in + let ptr = bufferPointer.baseAddress! + vDSP_meanv(ptr + startIdx, 1, &mean, UInt(endIdx - startIdx)) + } return mean } diff --git a/Xcode-config/DEVELOPMENT_TEAM.template.xcconfig b/Xcode-config/DEVELOPMENT_TEAM.template.xcconfig new file mode 100644 index 0000000..d6cf177 --- /dev/null +++ b/Xcode-config/DEVELOPMENT_TEAM.template.xcconfig @@ -0,0 +1 @@ +DEVELOPMENT_TEAM = AB1234C5DE diff --git a/Xcode-config/Shared.xcconfig b/Xcode-config/Shared.xcconfig new file mode 100644 index 0000000..f8a3edf --- /dev/null +++ b/Xcode-config/Shared.xcconfig @@ -0,0 +1,51 @@ +DEVELOPMENT_TEAM = 899AA7RGN5 + +#include? "DEVELOPMENT_TEAM.xcconfig" + +// Create the file DEVELOPMENT_TEAM.xcconfig +// in the "Xcode-config" directory within the project directory +// with the following build setting: +// DEVELOPMENT_TEAM = [Your TeamID] + +// One way to find your Team ID is to set the “Development Team” +// build setting (Xcode key: "DEVELOPMENT_TEAM") and have a look +// at the “Source Control” changes (menu item “Commit…”/⌥⌘C). +// Just make sure that this change doesn’t actually get commited. + +// You can also find your Team ID by logging into your Apple Developer account +// and going to +// https://developer.apple.com/account/#/membership +// It should be listed under “Team ID”. + +// To set this system up for your own project, +// copy the "Xcode-config" directory there, +// add it to your Xcode project, +// navigate to your project settings +// (root icon in the Xcode Project Navigator) +// click on the project icon there, +// click on the “Info” tab +// under “Configurations” +// open the “Debug”, “Release”, +// and any other build configurations you might have. +// There you can set the pull-down menus in the +// “Based on Configuration File” column to “Shared”. +// Your work in Xcode is done. + +// Don’t forget to add the DEVELOPMENT_TEAM.xcconfig file to your .gitignore: +// # User-specific xcconfig files +// Xcode-config/DEVELOPMENT_TEAM.xcconfig +// The two lines above are an example. +// Please don’t copy the comment slashes over though. + +// You can and should now replace the “DevelopmentTeam = AB1234C5DE;” entries in +// .xcodeproj/project.pbxproj +// with “DevelopmentTeam = "";” +// They would otherwise override the Team ID set via this config file and its include. +// Please note that .pbxproj files use straight quotes. + +// When you commit changes to the Xcode project file +// after changing settings in “Signing & Capabilities” +// Entries like these may appear in your file changes/commit diff preview: +// CODE_SIGN_IDENTITY = …; +// CODE_SIGN_STYLE = Manual/Automatic; +// Please make sure not to commit them to source control.