From fda91fdcc33c4eef1eea19774429a89445e507e9 Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Tue, 19 Mar 2024 19:59:40 +0100 Subject: [PATCH 1/2] Made SpectrogramFlatView unavailable to macOS as it relies on some iOS only stuff. --- .../SpectrogramFlatView/SpectrogramFlatView.swift | 4 ++++ .../Visualizations/SpectrogramFlatView/SpectrogramModel.swift | 4 ++++ .../Visualizations/SpectrogramFlatView/SpectrogramSlice.swift | 4 ++++ .../SpectrogramFlatView/UIColor+intermediate.swift | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift index 2a2da28..5bdab8d 100644 --- a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift +++ b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift @@ -66,6 +66,8 @@ Steps involved: import AudioKit import SwiftUI +#if !os(macOS) || targetEnvironment(macCatalyst) + /// Displays a rolling plot of the frequency spectrum. /// /// Each slice represents a point in time with the frequencies shown from bottom to top @@ -145,3 +147,5 @@ struct SpectrogramFlatView_Previews: PreviewProvider { return SpectrogramFlatView(node: Mixer()) } } + +#endif diff --git a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramModel.swift b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramModel.swift index 59ba7de..8e9c7e5 100644 --- a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramModel.swift +++ b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramModel.swift @@ -1,6 +1,8 @@ // Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKitUI/ // +#if !os(macOS) || targetEnvironment(macCatalyst) + import AudioKit import SwiftUI @@ -168,3 +170,5 @@ class SpectrogramFlatModel: ObservableObject { } } + +#endif diff --git a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramSlice.swift b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramSlice.swift index 58c2269..ad93873 100644 --- a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramSlice.swift +++ b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramSlice.swift @@ -1,5 +1,7 @@ // Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKitUI/ +#if !os(macOS) || targetEnvironment(macCatalyst) + import SwiftUI /// One slice with frequencies from low frequencies at the bottom up to high frequences. @@ -286,3 +288,5 @@ struct SpectrogramSlice_Previews: PreviewProvider { ).scaleEffect(x: 1, y: -1) } } + +#endif diff --git a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/UIColor+intermediate.swift b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/UIColor+intermediate.swift index dae71f0..fb41b54 100644 --- a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/UIColor+intermediate.swift +++ b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/UIColor+intermediate.swift @@ -1,5 +1,7 @@ // Copyright AudioKit. All Rights Reserved. Revision History at http://github.com/AudioKit/AudioKitUI/ +#if !os(macOS) || targetEnvironment(macCatalyst) + import Foundation import UIKit @@ -38,3 +40,5 @@ extension Array where Element: UIColor { } } } + +#endif From 4f3f2462c0d67deec62d3f1838423ba1d6333db3 Mon Sep 17 00:00:00 2001 From: mahal raskin Date: Tue, 19 Mar 2024 20:00:11 +0100 Subject: [PATCH 2/2] Added comment on what to to next and how to make class available on macOS --- .../SpectrogramFlatView/SpectrogramFlatView.swift | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift index 5bdab8d..646da37 100644 --- a/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift +++ b/Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift @@ -35,6 +35,19 @@ Steps involved: this implementation caches the resulting image. + Suggested next steps on development: + * Layout and draw the slices directly on a Canvas (instead of HStack) and independently move the Canvas left. + * Make class compatible with macOS + - Drawing with Canvas instead of UIGraphicsImageRenderer + (caching of UIImage no longer needed if callback can draw directly on one Canvas) + - CrossPlatformColor from Waveform.swift or Color.Resolved instead of UIColor for gradient lookup + * Add some parameters that can be changed while the spectrogram is running + - Pause so user can have a close look at the analyzed past + - Gain or sensitivity + - Speed of the rolling plot / detail frequency by adjusting fftSize + - Min and max frequency shown + + Cause of inefficiency of this implementation * Each time a new slice arrives from FFTTap, the view gets a complete layout update. * Rendering of new slices is done on a background thread and involves too many steps