Last active
August 29, 2015 14:03
-
-
Save kroger/7a878601577ec3aadc86 to your computer and use it in GitHub Desktop.
harmonize-scale
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cond = cond_interval_count(((0, 1), (1, 2))) | |
filter_sets(cond) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cond_interval_count(count_list): | |
return lambda i, s: all([i.count(interval) == count for | |
count, interval in count_list]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter_sets(lambda intervals, size: size > 4 and 1 not in intervals) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
filter_sets(lambda i, s: all([s > 4, i.count(1) == 1, i.count(2) == 1])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scale = [0, 2, 4, 5, 7, 9, 11] | |
harmonize_first_note(scale, 3, 3) | |
>>> [0, 4, 7] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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