Skip to content

Instantly share code, notes, and snippets.

@kroger
Last active August 29, 2015 14:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kroger/7a878601577ec3aadc86 to your computer and use it in GitHub Desktop.
Save kroger/7a878601577ec3aadc86 to your computer and use it in GitHub Desktop.
harmonize-scale
cond = cond_interval_count(((0, 1), (1, 2)))
filter_sets(cond)
def cond_interval_count(count_list):
return lambda i, s: all([i.count(interval) == count for
count, interval in count_list])
filter_sets(lambda intervals, size: size > 4 and 1 not in intervals)
def filter_sets(condition):
sets = {}
for forte, pc_set in musiclib.PC_SETS.items():
intervals = musiclib.intervals(pc_set)
size = len(pc_set)
if condition(intervals, size):
sets[forte] = pc_set
return sets
filter_sets(lambda i, s: all([s > 4, i.count(1) == 1, i.count(2) == 1]))
def harmonize_first_note(scale, interval, size):
i = (interval - 1)
indexes = [x % len(scale) for x in range(0, size * i, i)]
return [scale[index] for index in indexes]
def harmonize_scale(scale, interval, size=3):
scales = musiclib.rotate_set(sorted(scale))
return [harmonize_first_note(scale, interval, size) for scale in scales]
scale = [0, 2, 4, 5, 7, 9, 11]
harmonize_first_note(scale, 3, 3)
>>> [0, 4, 7]
harmonize_scale(scale, 4, 4)
>>> [[0, 5, 11, 4], [2, 7, 0, 5], [4, 9, 2, 7], [5, 11, 4, 9],
[7, 0, 5, 11], [9, 2, 7, 0], [11, 4, 9, 2]]
harmonize_scale(scale, 3, 4)
>>> [[0, 4, 7, 11], [2, 5, 9, 0], [4, 7, 11, 2], [5, 9, 0, 4],
[7, 11, 2, 5], [9, 0, 4, 7], [11, 2, 5, 9]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment