A SwiftUI view for guitar and bass fretboard visualization, built on Tonic for music theory. Part of the AudioKit ecosystem.
Add Fretboard via Swift Package Manager:
dependencies: [
.package(url: "https://github.com/AudioKit/Fretboard.git", from: "1.0.0")
]import Fretboard
import SwiftUI
struct ContentView: View {
var body: some View {
Fretboard(
playedFrets: [nil, 5, 7, 7, 5, nil],
displayedFretRange: 0...12
)
}
}- Canvas-based rendering — smooth, efficient drawing using SwiftUI Canvas
- String bending — visual bend displacement via
bendsarray - Velocity-based opacity — note circles reflect MIDI velocity
- Bass mode — 4-string layout centered on a 6-string fretboard
- Note spelling — configurable sharp/flat preference via
noteKeyparameter - Pitch-based coloring — each pitch class gets a distinct color (Helmholtz palette from Tonic)
- Accurate fret spacing — uses real guitar physics for fret positions
- Fret inlays — single dots (3, 5, 7, 9) and double dots (12, 24)
- Pickup visualization — decorative neck and bridge pickups
- Equatable — efficient SwiftUI diffing for state-driven updates
Included with the package is a demo project and a playground.
xcodebuild build -project Demo/FretboardDemo.xcodeproj \
-scheme FretboardDemo -destination "name=My Mac"swift build # Build the library
swift test # Run testsThe docs are hosted on the AudioKit.io website
MIT. See LICENSE for details.
