Skip to content

Instantly share code, notes, and snippets.

@mmuszynski
Created January 30, 2018 20:34
Show Gist options
  • Save mmuszynski/20a9c4d81d51dae1f8a30b16a46cddae to your computer and use it in GitHub Desktop.
Save mmuszynski/20a9c4d81d51dae1f8a30b16a46cddae to your computer and use it in GitHub Desktop.
public struct MusicNote {
public var pitch: MusicPitch
public var rhythm: MusicRhythm = .quarter
public init(pitch: MusicPitch, rhythm: MusicRhythm) {
self.pitch = pitch
self.rhythm = rhythm
}
public init(pitchName: MusicPitchName, accidental: MusicAccidental, octave: Int, rhythm: MusicRhythm) {
let pitch = MusicPitch(name: pitchName, accidental: accidental, octave: octave)
self.init(pitch: pitch, rhythm: rhythm)
}
///Accidental of the note's pitch.
public var accidental: MusicAccidental {
get {
return self.pitch.accidental
}
set {
self.pitch.accidental = newValue
}
}
///PitchAccidental of the note's pitch. Provides more information than just accidental value, such as location in staff for drawing.
public var pitchAccidental: MusicPitchAccidental {
return self.pitch.pitchAccidental
}
///Name of the note's pitch
public var name: MusicPitchName {
get {
return self.pitch.name
}
set {
self.pitch.name = newValue
}
}
///Octave of the note's pitch
public var octave: Int {
get {
return self.pitch.octave
}
set {
self.pitch.octave = newValue
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment