Skip to content

Commit

Permalink
Merge pull request #145 from orchetect/object-properties
Browse files Browse the repository at this point in the history
API Unification for Object Properties
  • Loading branch information
orchetect authored Oct 27, 2022
2 parents a4f0424 + 710f5b2 commit 5fb631b
Show file tree
Hide file tree
Showing 95 changed files with 1,646 additions and 1,317 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ struct ContentView: View {
}

Group {
if let nsImg = item.getImageAsNSImage() {
if let nsImg = item.imageAsNSImage {
Image(nsImage: nsImg)
.resizable()
} else {
Expand All @@ -76,14 +76,14 @@ struct ContentView: View {
// filter out endpoints that have an entity because
// they are already being displayed in the Devices tree
let items = midiManager.endpoints.inputs.sortedByName()
.filter { $0.getEntity() == nil }
.filter { $0.entity == nil }

ForEach(items) { item in
let detailsView = DetailsView(object: item.asAnyMIDIIOObject())

NavigationLink(destination: detailsView) {
Group {
if let nsImg = item.getImageAsNSImage() {
if let nsImg = item.imageAsNSImage {
Image(nsImage: nsImg)
.resizable()
} else {
Expand All @@ -101,14 +101,14 @@ struct ContentView: View {
// filter out endpoints that have an entity because
// they are already being displayed in the Devices tree
let items = midiManager.endpoints.outputs.sortedByName()
.filter { $0.getEntity() == nil }
.filter { $0.entity == nil }

ForEach(items) { item in
let detailsView = DetailsView(object: item.asAnyMIDIIOObject())

NavigationLink(destination: detailsView) {
Group {
if let nsImg = item.getImageAsNSImage() {
if let nsImg = item.imageAsNSImage {
Image(nsImage: nsImg)
.resizable()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ struct DetailsView: View {
@State private var showAll: Bool = false

func generateHTML(_ endpoint: AnyMIDIIOObject) -> String {
let flatProperties = endpoint.getPropertiesAsStrings(onlyIncludeRelevant: !showAll)
let flatProperties = endpoint.propertiesAsStrings(onlyIncludeRelevant: !showAll)

let htmlStart = """
<HTML>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@

### HUI Strings and Characters

- ``HUICharacterProtocol``
- ``HUIStringProtocol``
- ``HUICharacter``
- ``HUIString``
- ``HUIStringCharsValidation``
- ``HUILargeDisplaySlices``

### Protocols

- ``HUIDecoderProtocol``
- ``HUIEventProtocol``
- ``HUIDecoder``
- ``HUIEvent``
- ``HUISwitchProtocol``
- ``HUISurfaceStateProtocol``
- ``HUISurfaceModelState``
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,3 @@
### Value Type Protocols

- ``MIDIUnsignedInteger``

### Deprecated

- ``MIDI``
13 changes: 6 additions & 7 deletions Sources/MIDIKit/MIDIKit.docc/MIDIKitIO/MIDIKitIO-Internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,12 @@
- ``MIDIIOObjectType``
- ``AnyMIDIIOObject``

- ``MIDIIOEndpointProtocol``
- ``MIDIIODevicesProtocol``
- ``MIDIIOEndpointsProtocol``
- ``MIDIIOManagedProtocol``
- ``MIDIIOReceivesMIDIMessagesProtocol``
- ``MIDIIOSendsMIDIMessagesProtocol``
- ``MIDIIOReceiveHandlerProtocol``
- ``MIDIEndpoint``
- ``MIDIDevicesProtocol``
- ``MIDIEndpointsProtocol``
- ``MIDIManaged``
- ``MIDIManagedReceivesMessages``
- ``MIDIManagedSendsMessages``

### Value Type Protocols

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In order to begin sending MIDI events, there are two primary mechanisms:

### Send events from a created Output

To send events, call the ``MIDIIOSendsMIDIMessagesProtocol/send(event:)`` method on the ``MIDIManager/managedOutputs`` dictionary.
To send events, call the ``MIDIManagedSendsMessages/send(event:)`` method on the ``MIDIManager/managedOutputs`` dictionary.

The dictionary key corresponds to the `tag` property that was specified at the time of creating the connection in the ``MIDIManager``.

Expand All @@ -21,7 +21,7 @@ try conn?.send(event: .noteOn(60, velocity: .midi1(127), channel: 0x2))

### Send events from a managed Output Connection

To send events, call the ``MIDIIOSendsMIDIMessagesProtocol/send(event:)`` method on the ``MIDIManager/managedOutputConnections`` dictionary.
To send events, call the ``MIDIManagedSendsMessages/send(event:)`` method on the ``MIDIManager/managedOutputConnections`` dictionary.

The dictionary key corresponds to the `tag` property that was specified at the time of creating the connection in the ``MIDIManager``.

Expand All @@ -34,8 +34,8 @@ try conn?.send(event: .noteOn(60, velocity: .midi1(127), channel: 0x2))

### Send Methods

- ``MIDIIOSendsMIDIMessagesProtocol/send(event:)``
- ``MIDIIOSendsMIDIMessagesProtocol/send(events:)``
- ``MIDIManagedSendsMessages/send(event:)``
- ``MIDIManagedSendsMessages/send(events:)``

### Protocols

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ try midiManager.addOutput(

For the `uniqueID:` parameter it is best to use ``MIDIIdentifierPersistence/userDefaultsManaged(key:suite:)`` which automatically manages the endpoint's Core MIDI identity and restores it each time the same virtual endpoint is created, which other applications rely on to uniquely identify your endpoint so that they can reconnect to it in future.

To send events, call the ``MIDIIOSendsMIDIMessagesProtocol/send(event:)`` method on the ``MIDIManager/managedOutputs`` dictionary in the ``MIDIManager`` instance.
To send events, call the ``MIDIManagedSendsMessages/send(event:)`` method on the ``MIDIManager/managedOutputs`` dictionary in the ``MIDIManager`` instance.

```swift
let output = midiManager.managedOutputs[outputTag]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
//
// HUICharacterProtocol.swift
// HUICharacter.swift
// MIDIKit • https://github.com/orchetect/MIDIKit
// © 2021-2022 Steffan Andrews • Licensed under MIT License
//

import Foundation

public protocol HUICharacterProtocol: CustomStringConvertible
public protocol HUICharacter: CustomStringConvertible
where Self: RawRepresentable, RawValue == UInt8, Self: CaseIterable {
/// Returns the user-facing display string of the character.
var string: String { get }
Expand All @@ -21,15 +21,15 @@ where Self: RawRepresentable, RawValue == UInt8, Self: CaseIterable {
static func unknown() -> Self
}

internal protocol _HUICharacterProtocol: HUICharacterProtocol {
internal protocol _HUICharacter: HUICharacter {
/// Internal:
/// Table of characters. Array index corresponds to raw HUI encoding value.
static var stringTable: [String] { get }
}

// MARK: - Default Implementation

extension _HUICharacterProtocol {
extension _HUICharacter {
/// Returns the user-facing display string of the character.
public var string: String {
Self.stringTable[Int(rawValue)]
Expand All @@ -45,15 +45,15 @@ extension _HUICharacterProtocol {

// MARK: - CustomStringConvertible

extension HUICharacterProtocol /* : CustomStringConvertible */ {
extension HUICharacter /* : CustomStringConvertible */ {
public var description: String {
string
}
}

// MARK: - Sequence Category Methods

extension RangeReplaceableCollection where Element: HUICharacterProtocol {
extension RangeReplaceableCollection where Element: HUICharacter {
/// Returns the HUI character sequence as a single concatenated string of characters.
public var stringValue: String {
map { $0.string }.joined()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public enum HUILargeDisplayCharacter: UInt8, CaseIterable {
case leftArrow = 0x7F
}

extension HUILargeDisplayCharacter: _HUICharacterProtocol {
extension HUILargeDisplayCharacter: _HUICharacter {
// swiftformat:options --wrapcollections preserve
// swiftformat:options --maxwidth none
static let stringTable = [
Expand Down Expand Up @@ -215,7 +215,7 @@ extension HUILargeDisplayCharacter: _HUICharacterProtocol {
]
}

extension HUILargeDisplayCharacter: HUICharacterProtocol {
extension HUILargeDisplayCharacter: HUICharacter {
/// Suitable default case for use as a default/neutral character.
public static func `default`() -> Self {
.space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Foundation
import MIDIKitCore

/// HUI large text display 40-character string.
public struct HUILargeDisplayString: HUIStringProtocol, Equatable, Hashable {
public struct HUILargeDisplayString: HUIString, Equatable, Hashable {
public typealias Element = HUILargeDisplayCharacter

public static let staticCount = 40
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public enum HUISmallDisplayCharacter: UInt8, CaseIterable {
case shadedSquare = 0x7F
}

extension HUISmallDisplayCharacter: _HUICharacterProtocol {
extension HUISmallDisplayCharacter: _HUICharacter {
static let stringTable = [
"ì", "", "", "", "", "¿", "", "Ø", // 0x00 ...
"ø", "", "", "", "", "", "", "", // ... 0x0F
Expand All @@ -186,7 +186,7 @@ extension HUISmallDisplayCharacter: _HUICharacterProtocol {
]
}

extension HUISmallDisplayCharacter: HUICharacterProtocol {
extension HUISmallDisplayCharacter: HUICharacter {
public static func `default`() -> Self {
.space
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import Foundation

/// HUI small text display 4-character string.
public struct HUISmallDisplayString: HUIStringProtocol, Equatable, Hashable {
public struct HUISmallDisplayString: HUIString, Equatable, Hashable {
public typealias Element = HUISmallDisplayCharacter

public static let staticCount = 4
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
//
// HUIStringProtocol.swift
// HUIString.swift
// MIDIKit • https://github.com/orchetect/MIDIKit
// © 2021-2022 Steffan Andrews • Licensed under MIT License
//

import Foundation

public protocol HUIStringProtocol: CustomStringConvertible
public protocol HUIString: CustomStringConvertible
where Self: Equatable & Hashable,
Element: Equatable & Hashable
{
associatedtype Element: HUICharacterProtocol
associatedtype Element: HUICharacter
static var defaultChars: [Element] { get }

/// Fixed (static) char length for the string.
Expand Down Expand Up @@ -38,7 +38,7 @@ public protocol HUIStringProtocol: CustomStringConvertible

// MARK: - Default Implementation

extension HUIStringProtocol {
extension HUIString {
public static var defaultChars: [Element] {
.init(
repeating: .default(),
Expand Down Expand Up @@ -67,23 +67,23 @@ extension HUIStringProtocol {

// MARK: - CustomStringConvertible

extension HUIStringProtocol /* : CustomStringConvertible */ {
extension HUIString /* : CustomStringConvertible */ {
public var description: String {
stringValue
}
}

// MARK: - Equatable

extension HUIStringProtocol /* : Equatable */ {
extension HUIString /* : Equatable */ {
public static func == (lhs: Self, rhs: Self) -> Bool {
lhs.chars == rhs.chars
}
}

// MARK: - Hashable

extension HUIStringProtocol /* : Hashable */ {
extension HUIString /* : Hashable */ {
public func hash(into hasher: inout Hasher) {
hasher.combine(chars)
}
Expand All @@ -92,7 +92,7 @@ extension HUIStringProtocol /* : Hashable */ {
// MARK: - Validation PropertyWrapper

@propertyWrapper
public struct HUIStringCharsValidation<Str: HUIStringProtocol> {
public struct HUIStringCharsValidation<Str: HUIString> {
private var value: [Str.Element]

public var wrappedValue: [Str.Element] {
Expand All @@ -117,7 +117,7 @@ public struct HUIStringCharsValidation<Str: HUIStringProtocol> {

/// Utility:
/// Pads/truncates char array to static char length.
func pad<S: HUIStringProtocol>(
func pad<S: HUIString>(
chars: [S.Element],
for stringType: S.Type
) -> [S.Element] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public enum HUITimeDisplayCharacter: UInt8, CaseIterable {
case spaceDot = 0x30
}

extension HUITimeDisplayCharacter: _HUICharacterProtocol {
extension HUITimeDisplayCharacter: _HUICharacter {
// swiftformat:options --wrapcollections preserve
// swiftformat:options --maxwidth none

Expand All @@ -96,7 +96,7 @@ extension HUITimeDisplayCharacter: _HUICharacterProtocol {
]
}

extension HUITimeDisplayCharacter: HUICharacterProtocol {
extension HUITimeDisplayCharacter: HUICharacter {
public static func `default`() -> Self {
.space
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Foundation
/// The time display consists of eight 7-segment displays (called digits).
/// Every digit except the last (rightmost) has the ability
/// to show a trailing decimal point (dot).
public struct HUITimeDisplayString: HUIStringProtocol, Equatable, Hashable {
public struct HUITimeDisplayString: HUIString, Equatable, Hashable {
public typealias Element = HUITimeDisplayCharacter

public static let staticCount = 8
Expand Down
Loading

0 comments on commit 5fb631b

Please sign in to comment.