diff --git a/AudioPlayer/AudioPlayer/Content/AudioPlayer/EqualizerView.swift b/AudioPlayer/AudioPlayer/Content/AudioPlayer/EqualizerView.swift index 6887612..bd8f84c 100644 --- a/AudioPlayer/AudioPlayer/Content/AudioPlayer/EqualizerView.swift +++ b/AudioPlayer/AudioPlayer/Content/AudioPlayer/EqualizerView.swift @@ -64,9 +64,7 @@ struct EqualizerView: View { .clipShape(RoundedRectangle(cornerRadius: 16)) Button { - withAnimation { - model.reset() - } + model.reset() } label: { HStack { Text("Reset") @@ -128,15 +126,18 @@ struct EQSliderView: View { } GeometryReader { innerGeo in ZStack { - Path { path in - path.move(to: CGPoint(x: innerGeo.size.width / 12, y: dragPointYLocations.first ?? 0)) - for index in 1.. Path { + var path = Path() + path.move(to: CGPoint(x: rect.size.width / 12, y: values.first ?? 0)) + for index in 1.. CGFloat { + size.width / 12 * CGFloat(index * 2 + 1) + } +} + +struct AnimatableLine : VectorArithmetic { + var values: [Double] + + var magnitudeSquared: Double { + return values.map { $0 * $0 }.reduce(0, +) + } + + mutating func scale(by rhs: Double) { + values = values.map { $0 * rhs } + } + + static var zero: AnimatableLine { + return AnimatableLine(values: [0.0]) + } + + static func - (lhs: AnimatableLine, rhs: AnimatableLine) -> AnimatableLine { + return AnimatableLine(values: zip(lhs.values, rhs.values).map(-)) + } + + static func -= (lhs: inout AnimatableLine, rhs: AnimatableLine) { + lhs = lhs - rhs + } + + static func + (lhs: AnimatableLine, rhs: AnimatableLine) -> AnimatableLine { + return AnimatableLine(values: zip(lhs.values, rhs.values).map(+)) + } + + static func += (lhs: inout AnimatableLine, rhs: AnimatableLine) { + lhs = lhs + rhs + } +} + #Preview { EqualizerView(appModel: AppModel()) }