Skip to content

Commit

Permalink
Starting point to go into detail (#28)
Browse files Browse the repository at this point in the history
* Link to Cookbook instead repository

* remove uneeded markdown

* Added disclaimer that documentation lacks detail

* Added public keyword to the most prominent and useful structs, classes, attributes and initialisers
  • Loading branch information
mahal committed Mar 5, 2024
1 parent 4f3b897 commit 2b7b074
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 12 deletions.
8 changes: 7 additions & 1 deletion Sources/Keyboard/KeyContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@ import Tonic

/// This handles the interaction for key, so the user can provide their own
/// visual representation.
struct KeyContainer<Content: View>: View {
public struct KeyContainer<Content: View>: View {
let content: (Pitch, Bool) -> Content

var pitch: Pitch
@ObservedObject var model: KeyboardModel

var zIndex: Int

/// Initialize the Container
/// - Parameters:
/// - model: KeyboardModel holding all the keys
/// - pitch: Pitch of this key
/// - zIndex: Layering in z-axis
/// - content: View defining how to render a specific key
init(model: KeyboardModel,
pitch: Pitch,
zIndex: Int = 0,
Expand Down
7 changes: 1 addition & 6 deletions Sources/Keyboard/Keyboard.docc/Keyboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SwiftUI music keyboard

## Overview

Code is hosted on Github: [](https://github.com/AudioKit/Keyboard/)
See the [AudioKit Cookbook](https://github.com/AudioKit/Cookbook/) for examples and see the source code for API of all Keyboard elements. This documentation gives a rudimentary overview but lacks most of the finer details.

![Demo Screenshot](demo)

Expand All @@ -21,8 +21,3 @@ Keyboard aims to be an easy-to-use musical keyboard with:
- Good user interface
- Good performance. We rely on SwiftUI's drag gestures

## Topics

### <!--@START_MENU_TOKEN@-->Group<!--@END_MENU_TOKEN@-->

- <!--@START_MENU_TOKEN@-->``Symbol``<!--@END_MENU_TOKEN@-->
3 changes: 2 additions & 1 deletion Sources/Keyboard/Keyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import SwiftUI
public struct Keyboard<Content>: View where Content: View {
let content: (Pitch, Bool) -> Content

@StateObject var model: KeyboardModel = .init()
/// model contains the keys, their status and touches
@StateObject public var model: KeyboardModel = .init()

var latching: Bool
var noteOn: (Pitch, CGPoint) -> Void
Expand Down
8 changes: 5 additions & 3 deletions Sources/Keyboard/KeyboardModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import SwiftUI
import Tonic

class KeyboardModel: ObservableObject {
/// Observable model calling back on noteOn and noteOff and storing the touch locations
public class KeyboardModel: ObservableObject {
var keyRectInfos: [KeyRectInfo] = []
var noteOn: (Pitch, CGPoint) -> Void = { _, _ in }
var noteOff: (Pitch) -> Void = { _ in }
Expand Down Expand Up @@ -35,12 +36,13 @@ class KeyboardModel: ObservableObject {
}
}

@Published var touchedPitches = PitchSet() {
/// all touched notes
@Published public var touchedPitches = PitchSet() {
willSet { triggerEvents(from: touchedPitches, to: newValue) }
}

/// Either latched keys or keys active due to external MIDI events.
@Published var externallyActivatedPitches = PitchSet() {
@Published public var externallyActivatedPitches = PitchSet() {
willSet { triggerEvents(from: externallyActivatedPitches, to: newValue) }
}

Expand Down
3 changes: 2 additions & 1 deletion Sources/Keyboard/MIDIMonitorKeyboard.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ extension GraphicsContext {
}
}

/// MIDIMonitorKeyboard
@available(iOS 15, macOS 12, *)
struct MIDIMonitorKeyboard: View {
public struct MIDIMonitorKeyboard: View {

var layout: KeyboardLayout
var activatedPitches: PitchSet
Expand Down

0 comments on commit 2b7b074

Please sign in to comment.