Pitch

public struct Pitch: RawRepresentable, Codable, Equatable, Comparable, ExpressibleByIntegerLiteral, ExpressibleByStringLiteral, CustomStringConvertible

Pitch object with a Key and an octave. Could be initilized with MIDI note number and preferred accidental type.

  • key

    Key of the pitch like C, D, A, B with accidentals.

    Declaration

    Swift

    public var key: Key
  • Octave of the pitch. In theory this must be zero or a positive integer. But Note does not limit octave and calculates every possible octave including the negative ones.

    Declaration

    Swift

    public var octave: Int
  • This function returns the nearest pitch to the given frequency in Hz.

    Declaration

    Swift

    public static func nearest(frequency: Float) -> Pitch?

    Parameters

    frequency

    The frequency in Hz

    Return Value

    The nearest pitch for given frequency

  • Initilizes the Pitch with MIDI note number.

    Declaration

    Swift

    public init(midiNote: Int, isPreferredAccidentalSharps: Bool = true)

    Parameters

    midiNote

    Midi note in range of [0 - 127].

    isPreferredAccidentalSharps

    Make it true if preferred accidentals is sharps. Defaults true.

  • Initilizes the Pitch with Key and octave

    Declaration

    Swift

    public init(key: Key, octave: Int)

    Parameters

    key

    Key of the pitch.

    octave

    Octave of the pitch.

  • Calculates and returns the frequency of note on octave based on its location of piano keys. Bases A4 note of 440Hz frequency standard.

    Declaration

    Swift

    public var frequency: Float
  • Declaration

    Swift

    public typealias RawValue = Int
  • Returns midi note number. In theory, this must be in range [0 - 127]. But it does not limits the midi note value.

    Declaration

    Swift

    public var rawValue: Int
  • Initilizes the pitch with an integer value that represents the MIDI note number of the pitch.

    Declaration

    Swift

    public init?(rawValue: Pitch.RawValue)

    Parameters

    rawValue

    MIDI note number of the pitch.

  • Declaration

    Swift

    public typealias IntegerLiteralType = Int
  • Initilizes the pitch with an integer value that represents the MIDI note number of the pitch.

    Declaration

    Swift

    public init(integerLiteral value: Pitch.IntegerLiteralType)

    Parameters

    value

    MIDI note number of the pitch.

  • Converts Pitch to string with its key and octave.

    Declaration

    Swift

    public var description: String