dn-m / Music

Structures for the creation, analysis, and performance of music in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Pitch] Let Pitch store center pitch and scale-factor (fractional) / interval

bwetherfield opened this issue · comments

@jsbean, I wonder if you have thoughts on this, or how to put it into practice.

At its most basic, I am imagining something like this:

public struct Pitch: NoteNumberRepresentable {

    // MARK: - Instance Properties

    /// The `NoteNumber` representation of this `Pitch`.
    public let value: NoteNumber

    /// The `scaleFactor` by which this pitch is scaled
    public let scaleFactor: Fraction

    // MARK: - Initializers

    /// Creates a `Pitch` with the given `NoteNumber` value.
    public init(_ value: NoteNumber, _ scaleFactor: Fraction = Fraction.one) {
        self.value = value
        self.scaleFactor = scaleFactor
    }
}

Alternatively, the Fraction could be an interval - the rational case, is the same as using some just interval... I'm not too sure how the interval ecosystem works !

Use cases are e.g. instantiating two pitches that are a just perfect pitch apart, with one equal-tempered and the other not...

discussed offline