Skip to content

Commit

Permalink
Improve Pitch / Pitch.Class APIs (#116)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbean committed Nov 15, 2018
1 parent 7033ba5 commit bd3f7a0
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
10 changes: 10 additions & 0 deletions Sources/Pitch/NoteNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,13 @@ extension NoteNumber {

extension NoteNumber: Equatable { }
extension NoteNumber: Hashable { }

extension NoteNumber: CustomStringConvertible {

// MARK: - CustomStringConvertible

/// Printable description of `NoteNumber`.
public var description: String {
return value.description
}
}
12 changes: 11 additions & 1 deletion Sources/Pitch/Pitch.Class.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extension Pitch {
/// let light = dark.inversion // => 8
///
public var inversion: Pitch.Class {
return Pitch.Class(NoteNumber(12) - value)
return Pitch.Class(12 - value)
}

/// Value of `Pitch.Class`.
Expand All @@ -51,6 +51,16 @@ extension Pitch {
extension Pitch.Class: Equatable { }
extension Pitch.Class: Hashable { }

extension Pitch.Class: CustomStringConvertible {

// MARK: - CustomStringConvertible

/// Printable description of `Pitch.Class`.
public var description: String {
return value.description
}
}

extension Pitch.Class {

// MARK: - Nested Types
Expand Down
7 changes: 0 additions & 7 deletions Sources/Pitch/Pitch.h

This file was deleted.

22 changes: 21 additions & 1 deletion Sources/Pitch/Pitch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,17 @@ public struct Pitch: NoteNumberRepresentable {

extension Pitch {

// MARK: Computed Properties
// MARK: - Initializers

/// Creates a `Pitch` with the given `Pitch.Class`.
public init(_ pitchClass: Pitch.Class) {
self.init(pitchClass.value)
}
}

extension Pitch {

// MARK: - Computed Properties

/// - Returns: The `mod 12` representation of this `Pitch`.
public var `class`: Pitch.Class {
Expand Down Expand Up @@ -69,3 +79,13 @@ extension Pitch: Additive {
return 0
}
}

extension Pitch: CustomStringConvertible {

// MARK: - CustomStringConvertible

/// Printable description of `Pitch`.
public var description: String {
return value.description
}
}

0 comments on commit bd3f7a0

Please sign in to comment.