Skip to content

Commit

Permalink
Add analysisMode to AmplitudeView
Browse files Browse the repository at this point in the history
  • Loading branch information
hoopes committed Jan 16, 2024
1 parent a5b6c27 commit 7e8d048
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions Sources/AudioKitUI/Visualizations/AmplitudeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class AmplitudeModel: ObservableObject {
var nodeTap: AmplitudeTap!
var node: Node?
var stereoMode: StereoMode = .center
var analysisMode: AnalysisMode = .peak
@Environment(\.isPreview) var isPreview

init() {
Expand All @@ -19,7 +20,7 @@ class AmplitudeModel: ObservableObject {
func updateNode(_ node: Node) {
if node !== self.node {
self.node = node
nodeTap = AmplitudeTap(node, stereoMode: stereoMode, analysisMode: .peak, callbackQueue: .main) { amp in
nodeTap = AmplitudeTap(node, stereoMode: stereoMode, analysisMode: analysisMode, callbackQueue: .main) { amp in
self.pushData(amp)
}
nodeTap.start()
Expand All @@ -43,26 +44,30 @@ public struct AmplitudeView: View {
@StateObject var amplitudeModel = AmplitudeModel()
let node: Node
let stereoMode: StereoMode
let analysisMode: AnalysisMode
let numberOfSegments: Int
let fillType: FillType

public init(_ node: Node, stereoMode: StereoMode = .center, numberOfSegments: Int = 20) {
public init(_ node: Node, stereoMode: StereoMode = .center, analysisMode: AnalysisMode = .peak, numberOfSegments: Int = 20) {
self.node = node
self.stereoMode = stereoMode
self.analysisMode = analysisMode
self.fillType = .gradient(gradient: Gradient(colors: [.red, .yellow, .green]))
self.numberOfSegments = numberOfSegments
}

public init(_ node: Node, color: Color, stereoMode: StereoMode = .center, numberOfSegments: Int = 20) {
public init(_ node: Node, color: Color, stereoMode: StereoMode = .center, analysisMode: AnalysisMode = .peak, numberOfSegments: Int = 20) {
self.node = node
self.stereoMode = stereoMode
self.analysisMode = analysisMode
self.fillType = .solid(color: color)
self.numberOfSegments = numberOfSegments
}

public init(_ node: Node, colors: Gradient, stereoMode: StereoMode = .center, numberOfSegments: Int = 20) {
public init(_ node: Node, colors: Gradient, stereoMode: StereoMode = .center, analysisMode: AnalysisMode = .peak, numberOfSegments: Int = 20) {
self.node = node
self.stereoMode = stereoMode
self.analysisMode = analysisMode
self.fillType = .gradient(gradient: colors)
self.numberOfSegments = numberOfSegments
}
Expand Down

0 comments on commit 7e8d048

Please sign in to comment.