Skip to content

Commit 83bacdb

Browse files
authored
Minor adjustments to documentation and minor adjust to SpectrogramFlatView (#86)
* Added AudioKitUI.docc with a markdown so Documentation can easily be built for iOS. * Minor adjustments to documentation * Fixed title in main docc article so it shows directly on home page of AudioKitUI * Added links to other UI related frameworks of AudioKit * Fixed amplitude. It was not sensitive enough, showing full amplitude at half the intensity. * Cleanup of commented .borders * First quadrant flipping only once in the body * Trailing white space
1 parent 3559d8b commit 83bacdb

8 files changed

Lines changed: 61 additions & 24 deletions

File tree

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@ Just like AudioKit, the example project for AudioKitUI is the [AudioKit Cookbook
3232

3333
## More!
3434

35-
Because some user interfaces are quite complex, and don't really have AudioKit as a dependency, we will be putting them in other repositories under the AudioKit umbrella.
36-
37-
### Piano Roll
38-
39-
[https://github.com/AudioKit/PianoRoll](https://github.com/AudioKit/PianoRoll)
40-
41-
<img src="https://raw.githubusercontent.com/AudioKit/PianoRoll/main/Sources/PianoRoll/PianoRoll.docc/Resources/screenshot.png" alt="piano roll screenshot" style="width:75%;">
35+
Because some user interfaces are quite complex, and don't really have AudioKit as a dependency, they are in other repositories under the AudioKit umbrella:
36+
37+
* Controls: SwiftUI Knobs, Sliders, X-Y Pads, and more [github.com/AudioKit/Controls](https://github.com/AudioKit/Controls)
38+
* Flow: Generic node graph editor [github.com/AudioKit/Flow](https://github.com/AudioKit/Flow)
39+
* Keyboard: SwiftUI music keyboard [github.com/AudioKit/Keyboard](https://github.com/AudioKit/Keyboard)
40+
* Piano Roll: Touch oriented piano roll [github.com/AudioKit/PianoRoll](https://github.com/AudioKit/PianoRoll)
41+
* PianoRollEditor: Logic Pro like piano roll editor [github.com/AudioKit/PianoRollEditor](https://github.com/AudioKit/PianoRollEditor)
42+
* MIDITrackView: View representing a MIDI Track [github.com/AudioKit/MIDITrackView](https://github.com/AudioKit/MIDITrackView)
43+
* Waveform: GPU accelerated waveform view [github.com/AudioKit/Waveform](https://github.com/AudioKit/Waveform)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ``AudioKitUI``
2+
3+
@Metadata {
4+
@TitleHeading("AudioKit User Interfaces")
5+
}
6+
7+
Waveform plots and controls that can be used to jump start your AudioKit-powered app.
8+
9+
## Requirements
10+
11+
We use SwiftUI so you need to target iOS 13+ and macOS 10.15+.
12+
13+
## Installation via Swift Package Manager
14+
15+
To add AudioKitUI to your Xcode project, select File -> Swift Packages -> Add Package Dependency. Enter `https://github.com/AudioKit/AudioKitUI` for the URL.
16+
17+
## Examples
18+
19+
Just like AudioKit, the example project for AudioKitUI is the [AudioKit Cookbook](https://github.com/AudioKit/Cookbook/).
20+
21+
## More
22+
23+
Because some user interfaces are quite complex, and don't really have AudioKit as a dependency, they are in other repositories under the AudioKit umbrella.
24+
25+
- term Controls: SwiftUI Knobs, Sliders, X-Y Pads, and more [github.com/AudioKit/Controls](https://github.com/AudioKit/Controls)
26+
- term Flow: Generic node graph editor [github.com/AudioKit/Flow](https://github.com/AudioKit/Flow)
27+
- term Keyboard: SwiftUI music keyboard [github.com/AudioKit/Keyboard](https://github.com/AudioKit/Keyboard)
28+
- term Piano Roll: Touch oriented piano roll [github.com/AudioKit/PianoRoll](https://github.com/AudioKit/PianoRoll)
29+
- term PianoRollEditor: Logic Pro like piano roll editor [github.com/AudioKit/PianoRollEditor](https://github.com/AudioKit/PianoRollEditor)
30+
- term MIDITrackView: View representing a MIDI Track [github.com/AudioKit/MIDITrackView](https://github.com/AudioKit/MIDITrackView)
31+
- term Waveform: GPU accelerated waveform view [github.com/AudioKit/Waveform](https://github.com/AudioKit/Waveform)

Sources/AudioKitUI/Controls/ADSRView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import AVFoundation
77
import UIKit
88

99
/// A click and draggable view of an ADSR Envelope (Atttack, Decay, Sustain, Release)
10+
///
1011
/// All values are normalised 0->1, so scale them how you would like in your callback
1112

1213
@IBDesignable public class ADSRView: UIView {

Sources/AudioKitUI/Helpers/MorphableShape.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,16 @@ struct MorphableShape: Shape {
3131
}
3232
}
3333

34-
// MARK: Path extension
35-
34+
/// Return points at a given offset and create AnimatableVector for control points
3635
extension Path {
37-
// return point at the curve
36+
/// return point at the curve
3837
func point(at offset: CGFloat) -> CGPoint {
3938
let limitedOffset = min(max(offset, 0), 1)
4039
guard limitedOffset > 0 else { return cgPath.currentPoint }
4140
return trimmedPath(from: 0, to: limitedOffset).cgPath.currentPoint
4241
}
4342

44-
// return control points along the path
43+
/// return control points along the path
4544
func controlPoints(count: Int) -> AnimatableVector {
4645
var retPoints = [Double]()
4746
for index in 0 ..< count {

Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramFlatView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,14 +120,11 @@ public struct SpectrogramFlatView: View {
120120
}
121121
HStack(spacing: 0.0) {
122122
ForEach(spectrogram.slices.items) { slice in
123-
// flip it as the slice was drawn in the first quadrant
124-
slice.scaleEffect(x: 1, y: -1)
125-
// .border(.green, width: 2.0)
123+
slice
126124
}
127125
// flip it so the new slices come in right and move to the left
128126
.scaleEffect(x: -1, y: 1)
129127
}
130-
// .border(.red, width: 5.0)
131128
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
132129
}.onAppear {
133130
spectrogram.sliceSize = calcSliceSize(fromFrameSize: geometry.size)

Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct SpectrogramFFTMetaData {
2020
// New data comes roughly 5.5 times per second, each 186ms.
2121
// Choose a higher value when you want to analyze low frequencies,
2222
// choose a lower value when you want fast response and high frame rate on display.
23-
let fftSize = 2048
23+
let fftSize: UInt32 = 2048
2424

2525
// Lowest and highest frequencies shown.
2626
// We use 48Hz, which is a bit lower than G1. A1 would be 440Hz/8 = 55Hz.
@@ -137,7 +137,7 @@ class SpectrogramFlatModel: ObservableObject {
137137
// main thread and user while doing the work
138138
if node !== self.node {
139139
self.node = node
140-
nodeTap = FFTTap(node, bufferSize: UInt32(nodeMetaData.fftSize * 2), callbackQueue: .global()) { fftData in
140+
nodeTap = FFTTap(node, bufferSize: nodeMetaData.fftSize * 2, callbackQueue: .global()) { fftData in
141141
self.pushData(fftData)
142142
}
143143
// normalization would mean that on each slice, the loudest would have

Sources/AudioKitUI/Visualizations/SpectrogramFlatView/SpectrogramSlice.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ struct SpectrogramSlice: View, Identifiable {
8888

8989
public var body: some View {
9090
return Image(uiImage: cachedUIImage).resizable()
91+
// flip it as the slice was drawn in the first quadrant
92+
.scaleEffect(x: 1, y: -1)
9193
}
9294

9395
// This code draws in the first quadrant, it's much easier to understand
@@ -222,7 +224,7 @@ struct SpectrogramSlice: View, Identifiable {
222224
let real = fftFloats[index-1].isNaN ? 0.0 : fftFloats[index-1]
223225
let imaginary = fftFloats[index].isNaN ? 0.0 : fftFloats[index]
224226
let frequencyForBin = fftMetaData.sampleRate * 0.5 * Double(index * 2) / Double(fftFloats.count * 2)
225-
var squared = real * real + imaginary * imaginary
227+
var squared: Float = real * real + imaginary * imaginary
226228

227229
// if the frequency is higher as we need: continue
228230
// we don't filter low frequencies, they are all pushed to the queue
@@ -257,7 +259,8 @@ struct SpectrogramSlice: View, Identifiable {
257259
maxSquared = 0.0
258260
}
259261
}
260-
let amplitude = Double(10 * log10(4 * squared / (Float(fftMetaData.fftSize) * Float(fftMetaData.fftSize))))
262+
let fftBins = CGFloat(fftMetaData.fftSize)
263+
let amplitude = Double(10 * log10(4 * CGFloat(squared) / fftBins * fftBins))
261264
points.append(CGPoint(x: frequencyChosen, y: amplitude))
262265
}
263266
return points
@@ -285,7 +288,7 @@ struct SpectrogramSlice_Previews: PreviewProvider {
285288
CGPoint(x: 8800, y: -40),
286289
CGPoint(x: 8000, y: -10)],
287290
fftMetaData: SpectrogramFFTMetaData()
288-
).scaleEffect(x: 1, y: -1)
291+
)
289292
}
290293
}
291294

Sources/AudioKitUI/Visualizations/SpectrogramFlatView/UIColor+intermediate.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,15 @@
55
import Foundation
66
import UIKit
77

8-
/// usage You can use it to get an intermediate color between two or more colors:
9-
/// let color = [.green, .yellow, .red].intermediate(0.7)
10-
/// inspired by
11-
/// https://stackoverflow.com/questions/15032562/ios-find-color-at-point-between-two-colors/59996029#59996029
8+
/// Get an intermediate color between two or more colors
9+
///
10+
/// Example: `let color = [.green, .yellow, .red].intermediate(0.7)`
11+
///
12+
/// inspired by [stackoverflow 15032562 answer Nikaaner](https://stackoverflow.com/questions/15032562/ios-find-color-at-point-between-two-colors/59996029#59996029)
1213
extension Array where Element: UIColor {
14+
/// Get an intermediate color between two or more colors
15+
///
16+
/// Example: `let color = [.green, .yellow, .red].intermediate(0.7)`
1317
public func intermediate(_ percentage: CGFloat) -> UIColor {
1418
let percentage = Swift.max(Swift.min(percentage, 1), 0)
1519
switch percentage {

0 commit comments

Comments
 (0)