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 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
Notedoes 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
frequencyThe frequency in Hz
Return Value
The nearest pitch for given frequency
-
Initilizes the
Pitchwith MIDI note number.Declaration
Swift
public init(midiNote: Int, isPreferredAccidentalSharps: Bool = true)Parameters
midiNoteMidi note in range of [0 - 127].
isPreferredAccidentalSharpsMake it true if preferred accidentals is sharps. Defaults true.
-
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
rawValueMIDI 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
valueMIDI note number of the pitch.
-
Declaration
Swift
public typealias StringLiteralType = String -
Initilizes with a string.
Declaration
Swift
public init(stringLiteral value: Pitch.StringLiteralType)Parameters
valueString representation of type.
-
Converts
Pitchto string with its key and octave.Declaration
Swift
public var description: String
View on GitHub
Pitch Structure Reference