Permalink
Browse files

Add Note flat and Note sharp. Fix Note up for negative values.

  • Loading branch information...
1 parent 920e993 commit f65784f74fcbcc6615f434b48711ae0f71694f26 @kevinclark committed Dec 25, 2008
Showing with 15 additions and 9 deletions.
  1. +12 −9 Notes.io
  2. +3 −0 notes-spec.io
View
@@ -3,11 +3,14 @@
Note := Object clone do(
inSharps := nil
inFlats := nil
-
+
asString := method(inSharps)
- up := method(halfTones, Notes at((Notes indexOf(self) + halfTones) % (Notes size)) )
+ up := method(halfTones, Notes at(((Notes indexOf(self) + halfTones) + (Notes size)) % (Notes size)) )
down := method(halfTones, up(-halfTones))
-
+
+ flat := method( down(1) )
+ sharp := method( up(1) )
+
prime := method( self )
minorSecond := method( up(1) )
second := method( up(2) )
@@ -27,30 +30,30 @@ Notes := List clone do(
Naturals := List clone
Sharps := List clone
Flats := List clone
-
+
// Define natural notes
list("A", "B", "C", "D", "E", "F", "G") foreach(note,
setSlot(note, Note clone)
getSlot(note) updateSlot("inSharps", note)
getSlot(note) updateSlot("inFlats", note)
-
+
Naturals append(getSlot(note))
)
-
+
// Define sharps/flats
list(list("A#", "Bb"), list("C#", "Db"), list("D#", "Eb"),
list("F#", "Gb"), list("G#", "Ab")) foreach(note,
// note is list(sharpName, flatName)
setSlot(note first, Note clone)
getSlot(note first) updateSlot("inSharps", note first)
getSlot(note first) updateSlot("inFlats", note second)
-
+
setSlot(note second, getSlot(note first))
-
+
Sharps append(getSlot(note first))
Flats append(getSlot(note second))
)
-
+
appendSeq(list("A", "A#", "B", "C", "C#", "D",
"D#", "E", "F", "F#", "G", "G#") map(note, getSlot(note)))
)
View
@@ -39,4 +39,7 @@ describe(note, Note,
note("has a minorSeventh", verify(Notes C minorSeventh == Notes Bb))
note("has a seventh", verify(Notes C seventh == Notes B))
note("has an octave", verify(Notes C octave == Notes C))
+
+ note("can flat", verify(Notes A flat == Notes Ab))
+ note("can sharp", verify(Notes A sharp == Notes getSlot("A#")))
)

0 comments on commit f65784f

Please sign in to comment.