Permalink
Browse files

Added code to make circles of 5ths and 4ths into infinite rings, so I…

… can keep pulling from them indefinitely.
  • Loading branch information...
1 parent 95a6443 commit a9068530d4a16dcfd3de86fb49770f66ff2f13e4 @gilesbowkett committed Aug 20, 2008
Showing with 23 additions and 10 deletions.
  1. +23 −10 lib/pitches.rb
View
33 lib/pitches.rb
@@ -17,16 +17,16 @@
# but positions in the scale.
OCTAVES = {-1 => (0..11), # starting note is C-1
- 0 => (12..23),
- 1 => (24..35),
- 2 => (36..47),
- 3 => (48..59),
- 4 => (60..71),
- 5 => (72..83),
- 6 => (84..95),
- 7 => (96..107),
- 8 => (108..119),
- 9 => (120..127)} # the 9th octave is incomplete and only goes as far as G
+ 0 => (12..23),
+ 1 => (24..35),
+ 2 => (36..47),
+ 3 => (48..59),
+ 4 => (60..71),
+ 5 => (72..83),
+ 6 => (84..95),
+ 7 => (96..107),
+ 8 => (108..119),
+ 9 => (120..127)} # the 9th octave is incomplete and only goes as far as G
# chords! this can also happen with scales!
MINOR_7TH = [0, 2, 6, 9]
@@ -39,3 +39,16 @@
CIRCLE_OF_FIFTHS = %w{C, G, D, A, E, B, F#, C#, G#, D#, A#, F}
# relative minor is always x + 3
# this data structure is of course a ring
+CIRCLE_OF_FOURTHS = CIRCLE_OF_FIFTHS.reverse
+
+[CIRCLE_OF_FIFTHS, CIRCLE_OF_FOURTHS].each do |array|
+ class << array
+ def next
+ @current ||= -1
+ @current += 1
+ @current = 0 if @current >= size
+ self[current]
+ end
+ end
+end
+# this makes them into ring structures. I may need to do this for all these arrays.

0 comments on commit a906853

Please sign in to comment.