AudioKit / Tonic

Swift library for music theory
https://www.audiokit.io/Tonic/
MIT License
154 stars 21 forks source link

added new pitch and notes helper function #24

Closed SebastianBoldt closed 10 months ago

SebastianBoldt commented 10 months ago

Description

Currently it is impossible to extract the correct notes and their respective octaves from a chord object for a specific inversion.

I tried to obtain the correct notes and pitches for a chord by mapping all the note classes, since it was the only property available in the chord object. I used the following code:

chord.noteClasses.map {
    Note($0.letter, accidental: $0.accidental, octave: 0).pitch
}

Unfortunately, the noteClasses do not contain the octave information, making it impossible for me to obtain the correct pitches for a specific chord inversion.

Proposed Solution

I would like to be able to do something like this:

chord.pitches(octave: 1) // Return the correct pitches taking into account the inversion
chord.notes(octave: 1) // Return the correct notes taking into account the inversion
SebastianBoldt commented 10 months ago

🥳

SebastianBoldt commented 10 months ago

@aure I think we could also try to build something similar for Scales. If we obtain the Notes via the noteSet and map them to pitches they also do have the wrong octave order.

lldb) po Key.init(root: .init(.D, accidental: .natural), scale: .major).noteSet.array
â–¿ 7 elements
  ▿ 0 : C♯4
    ▿ noteClass : C♯
      - letter : Tonic.Letter.C
      - accidental : ♯
    - octave : 4
  â–¿ 1 : D4
    â–¿ noteClass : D
      - letter : Tonic.Letter.D
      - accidental : 
    - octave : 4
  â–¿ 2 : E4
    â–¿ noteClass : E
      - letter : Tonic.Letter.E
      - accidental : 
    - octave : 4
  ▿ 3 : F♯4
    ▿ noteClass : F♯
      - letter : Tonic.Letter.F
      - accidental : ♯
    - octave : 4
  â–¿ 4 : G4
    â–¿ noteClass : G
      - letter : Tonic.Letter.G
      - accidental : 
    - octave : 4
  â–¿ 5 : A4
    â–¿ noteClass : A
      - letter : Tonic.Letter.A
      - accidental : 
    - octave : 4
  â–¿ 6 : B4
    â–¿ noteClass : B
      - letter : Tonic.Letter.B
      - accidental : 
    - octave : 4
Matt54 commented 10 months ago

Did we solve issue #25 with merging this PR?

SebastianBoldt commented 10 months ago

Did we solve issue #25 by merging this PR?

@Matt54 Nope, we solved this one https://github.com/AudioKit/Tonic/issues/22

25 is about Keys

22 was about Chords