diff --git a/Sources/Pitch/IntervalDescriptor/CompoundIntervalDescriptor.swift b/Sources/Pitch/IntervalDescriptor/CompoundIntervalDescriptor.swift index 9b22016..c5165b1 100644 --- a/Sources/Pitch/IntervalDescriptor/CompoundIntervalDescriptor.swift +++ b/Sources/Pitch/IntervalDescriptor/CompoundIntervalDescriptor.swift @@ -88,5 +88,19 @@ extension CompoundIntervalDescriptor { // TODO: Add intervals spanning more than one octave } +extension CompoundIntervalDescriptor: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of CompoundIntervalDescriptor. + public var description: String { + return( + interval.quality.description + + "\(interval.ordinal.steps + octaveDisplacement * 7 + 1)" + + (interval.direction == .descending ? "↓" : "") + ) + } +} + extension CompoundIntervalDescriptor: Equatable { } extension CompoundIntervalDescriptor: Hashable { } diff --git a/Sources/Pitch/IntervalDescriptor/IntervalQuality.swift b/Sources/Pitch/IntervalDescriptor/IntervalQuality.swift index ec5176d..803f3d4 100644 --- a/Sources/Pitch/IntervalDescriptor/IntervalQuality.swift +++ b/Sources/Pitch/IntervalDescriptor/IntervalQuality.swift @@ -147,7 +147,65 @@ extension IntervalQuality { } } +extension IntervalQuality.Perfect: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of IntervalQuality.Perfect. + public var description: String { + return "P" + } +} + +extension IntervalQuality.Imperfect: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of IntervalQuality.Imperfect. + public var description: String { + return "P" + } +} + +extension IntervalQuality.Extended.AugmentedOrDiminished: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of IntervalQuality.Extended.AugmentedOrDiminished. + public var description: String { + return self == .augmented ? "A" : "d" + } +} + +extension IntervalQuality.Extended: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of IntervalQuality.Extended. + public var description: String { + return String(repeating: quality.description, count: degree.rawValue) + } +} + +extension IntervalQuality: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of IntervalQuality. + public var description: String { + switch self { + case .perfect(let perfect): + return perfect.description + case .imperfect(let imperfect): + return imperfect.description + case .extended(let extended): + return extended.description + } + } +} + extension IntervalQuality.Extended: Equatable { } extension IntervalQuality.Extended: Hashable { } extension IntervalQuality: Equatable { } extension IntervalQuality: Hashable { } + diff --git a/Sources/Pitch/IntervalDescriptor/OrderedIntervalDescriptor.swift b/Sources/Pitch/IntervalDescriptor/OrderedIntervalDescriptor.swift index 1c4b867..f5faef3 100644 --- a/Sources/Pitch/IntervalDescriptor/OrderedIntervalDescriptor.swift +++ b/Sources/Pitch/IntervalDescriptor/OrderedIntervalDescriptor.swift @@ -415,9 +415,6 @@ extension OrderedIntervalDescriptor { } } -extension OrderedIntervalDescriptor.Ordinal: Equatable, Hashable { } -extension OrderedIntervalDescriptor: Equatable, Hashable { } - extension OrderedIntervalDescriptor: Invertible { // MARK: - Invertible @@ -427,3 +424,16 @@ extension OrderedIntervalDescriptor: Invertible { return .init(direction.inverse, quality.inverse, ordinal.inverse) } } + +extension OrderedIntervalDescriptor: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of UnorderedIntervalDescriptor. + public var description: String { + return "\(quality)\(ordinal.steps + 1)\(direction == .descending ? "↓" : "")" + } +} + +extension OrderedIntervalDescriptor.Ordinal: Equatable, Hashable { } +extension OrderedIntervalDescriptor: Equatable, Hashable { } diff --git a/Sources/Pitch/IntervalDescriptor/UnorderedIntervalDescriptor.swift b/Sources/Pitch/IntervalDescriptor/UnorderedIntervalDescriptor.swift index ff934ad..8b9999b 100644 --- a/Sources/Pitch/IntervalDescriptor/UnorderedIntervalDescriptor.swift +++ b/Sources/Pitch/IntervalDescriptor/UnorderedIntervalDescriptor.swift @@ -260,5 +260,15 @@ extension UnorderedIntervalDescriptor { } } +extension UnorderedIntervalDescriptor: CustomStringConvertible { + + // MARK: - CustomStringConvertible + + /// Printable description of UnorderedIntervalDescriptor. + public var description: String { + return quality.description + "\(ordinal.steps)" + } +} + extension UnorderedIntervalDescriptor.Ordinal: Equatable, Hashable { } extension UnorderedIntervalDescriptor: Equatable, Hashable { } diff --git a/Tests/PitchTests/OrderedIntervalDescriptorTests.swift b/Tests/PitchTests/OrderedIntervalDescriptorTests.swift index 71d6f99..1ef0835 100644 --- a/Tests/PitchTests/OrderedIntervalDescriptorTests.swift +++ b/Tests/PitchTests/OrderedIntervalDescriptorTests.swift @@ -66,6 +66,8 @@ class OrderedIntervalDescriptorTests: XCTestCase { let dd6 = OrderedIntervalDescriptor(.descending, .double, .diminished, .sixth) XCTAssertEqual(AA3.inverse, dd6) XCTAssertEqual(dd6.inverse, AA3) + print(AA3) + print(dd6) } func testPerfectOrdinalUnisonInverse() {