Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Output [Int: Pitch.Spelling] from spell() #166

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 6 additions & 17 deletions Sources/SpelledPitch/PitchSpeller/Wetherfield/Wetherfield.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ struct PitchSpeller {

// MARK: - Instance Properties

/// The unspelled `Pitch` values to be spelled.
let pitch: (PitchSpellingNode.Index) -> Pitch?

/// The nodes within the `FlowNetwork`. The values are the encodings of the indices of `Pitch`
/// values in `pitches.
let pitchNodes: [PitchSpellingNode.Index]
Expand All @@ -53,14 +50,6 @@ extension PitchSpeller {

/// Create a `PitchSpeller` to spell the given `pitches`, with the given `parsimonyPivot`.
init(pitches: [Int: Pitch], parsimonyPivot: Pitch.Spelling = .init(.d)) {
self.pitch = { index in
switch index {
case .source, .sink:
return Pitch(value: parsimonyPivot.pitchClass.value)
case .internal(let cross):
return pitches[cross.a]
}
}
let getPitchClass: (FlowNode<Cross<Int,Tendency>>) -> Pitch.Class = { flowNode in
switch flowNode {
case .source, .sink:
Expand Down Expand Up @@ -137,7 +126,7 @@ extension PitchSpeller {

/// - Returns: An array of `SpelledPitch` values with the same indices as the original
/// unspelled `Pitch` values.
func spell() -> [Int: SpelledPitch] {
func spell() -> [Int: Pitch.Spelling] {

var assignedNodes: [AssignedNode] {
var (sourceSide, sinkSide) = flowNetwork.minimumCut
Expand All @@ -164,14 +153,14 @@ extension PitchSpeller {
case .up: pairs[node.index.a]!.0 = node
case .down: pairs[node.index.a]!.1 = node
}
}.mapValues(spellPitch)
}.mapValues(spelling)
}

private func spellPitch(_ up: InternalAssignedNode, _ down: InternalAssignedNode) -> SpelledPitch {
let pitch = self.pitch(.internal(up.index))!
private func spelling(_ up: InternalAssignedNode, _ down: InternalAssignedNode) -> Pitch.Spelling {
let pitchClass = self.getPitchClass(.internal(up.index))
let tendencies = TendencyPair(up.assignment, down.assignment)
let spelling = Pitch.Spelling(pitchClass: pitch.class, tendencies: tendencies)!
return try! pitch.spelled(with: spelling)
let spelling = Pitch.Spelling(pitchClass: pitchClass, tendencies: tendencies)!
return spelling
}

func whereEdge (contains: Bool) -> (Pitch.Class) -> GraphScheme<PitchSpellingNode.Index> {
Expand Down
36 changes: 18 additions & 18 deletions Tests/SpelledPitchTests/PitchSpellerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,127 +15,127 @@ class PitchSpellerTests: XCTestCase {
func testSpellZeroOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 60], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.c))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.c)]
XCTAssertEqual(result, expected)
}

func testSpellOneOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 61], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.c, .sharp))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.c, .sharp)]
XCTAssertEqual(result, expected)
}

func testSpellTwoOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 62], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.d))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.d)]
XCTAssertEqual(result, expected)
}

func testSpellThreeOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 63], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.e, .flat))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.e, .flat)]
XCTAssertEqual(result, expected)
}

func testSpellFourOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 64], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.e))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.e)]
XCTAssertEqual(result, expected)
}

func testSpellFiveOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 65], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.f))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.f)]
XCTAssertEqual(result, expected)
}

func testSpellSixOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 66], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.f, .sharp))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.f, .sharp)]
XCTAssertEqual(result, expected)
}

func testSpellSevenOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 67], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.g))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.g)]
XCTAssertEqual(result, expected)
}

func testSpellNineOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 69], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.a))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.a)]
XCTAssertEqual(result, expected)
}

func testSpellTenOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 70], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.b, .flat))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.b, .flat)]
XCTAssertEqual(result, expected)
}

func testSpellElevenOverDNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 71], parsimonyPivot: Pitch.Spelling(.d))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.b))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.b)]
XCTAssertEqual(result, expected)
}

func testSpellEightOverCNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 68], parsimonyPivot: Pitch.Spelling(.c))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.a, .flat))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.a, .flat)]
XCTAssertEqual(result, expected)
}

func testSpellEightOverBNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 68], parsimonyPivot: Pitch.Spelling(.b))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.g, .sharp))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.g, .sharp)]
XCTAssertEqual(result, expected)
}

func testSpellEightOverANatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 68], parsimonyPivot: Pitch.Spelling(.a))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.g, .sharp))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.g, .sharp)]
XCTAssertEqual(result, expected)
}

func testSpellEightOverGNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 68], parsimonyPivot: Pitch.Spelling(.g))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.a, .flat))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.a, .flat)]
XCTAssertEqual(result, expected)
}

func testSpellEightOverFNatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 68], parsimonyPivot: Pitch.Spelling(.f))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.a, .flat))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.a, .flat)]
XCTAssertEqual(result, expected)
}

func testSpellEightOverENatural() {
let pitchSpeller = PitchSpeller(pitches: [0: 68], parsimonyPivot: Pitch.Spelling(.e))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(.g, .sharp))]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(.g, .sharp)]
XCTAssertEqual(result, expected)
}

func testSpellSelfAsPivot() {
for letterName in LetterName.allCases {
let pitchSpeller = PitchSpeller(pitches: [0: Pitch(letterName.pitchClass)], parsimonyPivot: Pitch.Spelling(letterName))
let result = pitchSpeller.spell()
let expected: [Int: SpelledPitch] = [0: SpelledPitch(Pitch.Spelling(letterName), -1)]
let expected: [Int: Pitch.Spelling] = [0: Pitch.Spelling(letterName)]
XCTAssertEqual(result, expected)
}
}
Expand Down