He starts with a basic sine wave and builds up abstractions until he has a Bach canon.
links aside, he uses (and is a project contributor) http://overtone.github.com/
ps: they also provide a nice emacs setup https://github.com/overtone/emacs-live
I agree. That is 1 million times better. Sometimes I wonder why I don't think of these things. I'll probably fix the code and use something like that... except in Python, obv.
Thank you;
It is something I practice a lot, maybe because it's in Ruby's culture, or just because I enjoy making code look pretty.
When I look at your two for loops that twice make a range, and have a bunch of magic numbers, all kinds of alarm bells go off. It should be one loop if possible, if there are magic numbers they should be in a constant at the top of the file.
Actually, the way you construct the seedList is interesting. A Haskell programmer might have done the same thing, because keeping indexes is ugly in Haskell, and doing operations on infinite lists (which you emulate by appending a copy) are pretty. Perhaps you are just a functional programmer, using a non-functional language :D
It would look better if it was in Scheme or Clojure, but that stuff's too scary for most readers. At least that's the story I'll maintain here.
Of all the bits and pieces I've looked at over the years explaining the circle of fifths this is the one that stands out for me as the easiest to remember. Being able to re-derive from basic principles is so much better than memorization.
Thank you again!
def notes_name(numbers):
notes = "C C# D D# E F F# G G# A A# B".split()
return [notes[(number % 12)] for number in numbers]
def transposition(notes, start):
index = start - notes[0]
return [(n + index) % 12 for n in notes]
def gen_scales():
c_scale = [0, 2, 4, 5, 7, 9, 11]
return [notes_name(transposition(c_scale, note)) for note in range(0, 12)]
for scale in gen_scales():
print " ".join(scale)
EDIT: make the code prettier notes_name([n*7 for n in range(0, 12)]) notes = concat $ repeat ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"]
majorSteps = [1,1,0,1,1,1,0]
scale key steps =
key : skip notesFromKey majorSteps
where
(_:notesFromKey) = dropWhile ((/=) key) notes
skip list skips =
fst $ foldl next ([], list) skips
where
next (m, xs) s = (m ++ [xs !! s], drop (s + 1) xs)
edit: cleaned it up a lot. This is Haskell by the way. The loop is replaced by a 'fold' in the skip function that reduces the list by skipping through it taking the skip distances from the skips argument. notes = cycle ["c", "c#", "d", "d#", "e", "f", "f#", "g", "g#", "a", "a#", "b"]
majorSteps = [2, 2, 1, 2, 2, 2] :: [Int]
scale note = map (dropWhile (/= note) notes !!) . scanl (+) 0
I think it's less clear, but if you want to avoid the rescan via (!!), then scale note = map head . scanl (flip drop) (dropWhile (/= note) notes)
Both result in λ> scale "d" majorSteps
["d","e","f#","g","a","b","c#"]