pedrozath / coltrane

🎹🎸A music theory library with a command-line interface
MIT License
2.35k stars 64 forks source link

Interval methodlolgy is not iniutive. #11

Closed art-of-dom closed 6 years ago

art-of-dom commented 6 years ago

When talking about intervals from a music theory perspective, the default is to assume the interval is assenting rather than descending. This is very important because reversing the operation creates undesired structures.

For example, a major chord is defined as a set of Root, Major 3rd, and a Perfect 5th. When building these ascending with a root of C, you end up with the nodes C, E, G which is what you expect. If you use the same intervals, but take them as descending instead, you end up with C, Ab, F which is a F minor chord.

Coltrane only seems to be able handle talking about descending intervals when figuring out the intervals based on two notes. From exploring the docs and trying in irb, I can only seem to create descending intervals means to use the gem, I'd have to think about a lot of operations in reverse to get the correct interval.

(currently works) D down to C interval example:

2.5.0 :019 > interval = Coltrane::Note['D'] - Coltrane::Note['C']
 => #<Coltrane::IntervalClass:0x0000000001646ff8 @cents=200> 
2.5.0 :020 > interval.name
 => "M2" 

(proposed operation and current results) C up to D interval example:

2.5.0 :021 > interval = Coltrane::Note['C'] + Coltrane::Note['D']
 => #<Coltrane::Note:0x0000000001671b40 @alteration=0, @integer=2> 
2.5.0 :022 > interval.name
 => "D" 
pedrozath commented 6 years ago

Hey thanks for reporting.

Do you mean the following behavior would be more appropriate for you?

Note['C'] - Note['D'] == Interval.major_second
#=> true
art-of-dom commented 6 years ago

Honestly, the exact behaviour is less important than making it clear what the result is supposed to be. If you don't specific whether the interval is going up or down, most people assume it's going up. So either it should be clear in the documentation or you should be able to have another operator to represent an interval going up.

A picture might be better to explain this.

c_d-vs-d_c

The first interval is a C up to a D (or D down to a C) which is a Major second while the second is a D up to a D (or C down to a D) which is a minor seventh.

By the way, I have two other things about intervals I will be posting soon. I'm debating whether or not to use Coltrane for a music project I have, but I need the theory side to be extremely solid especially for intervals.

pedrozath commented 6 years ago

Fixed. Update to 3.0.0.pre and use the following syntax:

include Coltrane::Theory

# ascending by default
Interval.new(Note['C'], Note['E']).name
# => "M3"

# override to get descending
Interval.new(Note['C'], Note['E'], ascending: false).name
# => "m6"

Lemme know if it works and if you find any other issues. And thanks a lot for your help!