def explore_generator(generator, **kwargs): arr = generate(generator, **kwargs) intervals = get_intervals(arr) # build_chart(intervals) expected_value_ = expected_value(arr) print('Expected value: ', expected_value_) print('Dispersion: ', dispersion(arr, expected_value_)) print('chi2: ', get_chi_squared(intervals, expected_amount[generator], **kwargs))
def ranked_roots(harmony): """return a list of the notes in the harmony in the order in which they are most likely to be used as the root. 1. top of a P4 2. bottom of a P4 3. bottom of a M3 5. top of a m3 bottom of a m2 should be demoted. >>> ranked_roots([0, 4, 7]) [0, 7, 4] >>> ranked_roots([0, 2, 4, 7, 11]) [0, 4, 7, ] """ weights = defaultdict(lambda: defaultdict(int)) weights[5][1] = 200 # Top of P4 weights[5][0] = 50 # Bottom of P4 weights[4][0] = 20 # Bottom of M3 weights[3][1] = 10 # Top of m3 weights[4][1] = 9 # Top of M3 weights[3][0] = 8 # Bottom of m3 weights[6][0] = -1 # Bottom of tritone weights[6][1] = -1 # Top of tritone weights[1][0] = -100 # Bottom of m1 weighted_notes = defaultdict(int) intervals = get_intervals(harmony) for size in intervals: for interval in intervals[size]: for i, p in enumerate(interval): weight = weights[size][i] weighted_notes[p] += weight items = weighted_notes.items() items = sorted(items, key=lambda x: x[1], reverse=True) # Shuffle rank of pitches with the same weights weight_groups = itertools.groupby(items, key=lambda x: x[1]) ranked = [] for weight, group in weight_groups: group = list(group) random.shuffle(group) ranked.extend(group) return [item[0] for item in ranked]
def ranked_roots(harmony): """ NOTE: This now ranks OPPOSITE of best root. To be used for choosing higher melody parts. return a list of the notes in the harmony in the order in which they are most likely to be used as the root. 1. bottom of a P4 2. top of a P4 3. top of a M3 5. bottom of a m3 """ weights = defaultdict(lambda: defaultdict(int)) weights[5][0] = 45 # Bottom of P4 weights[5][1] = 25 # Top of P4 weights[4][1] = 15 # Top of M3 weights[3][0] = 10 # Bottom of m3 weights[4][0] = 9 # Bottom of M3 weights[3][1] = 8 # Top of m3 weights[6][1] = -1 # Top of tritone weights[6][0] = -1 # Bottom of tritone weights[1][1] = -1 # Top of m1 weighted_notes = defaultdict(int) intervals = get_intervals(harmony) for size in intervals: for interval in intervals[size]: for i, p in enumerate(interval): weight = weights[size][i] weighted_notes[p] += weight items = weighted_notes.items() items = sorted(items, key=lambda x: x[1], reverse=True) # Shuffle rank of pitches with the same weights weight_groups = itertools.groupby(items, key=lambda x: x[1]) ranked = [] for weight, group in weight_groups: group = list(group) random.shuffle(group) ranked.extend(group) return [item[0] for item in ranked]
def count_melodies(shortest, longest=0, filename=os.path.join( '..', 'data', '''sheu_ityng_pyiparshyng_20141031_edited_thru_meas_191.xml''')): """Report any sequences of intervals that appear more than once.""" # QQQ not yet in test suite! xml_notes, divisions = R.get_notes(filename) melody = U.get_melody(xml_notes, divisions) intervals = U.get_intervals(melody) substrings = U.find_all_substrings(intervals, shortest, longest) interval_count = {} for substring in substrings: if substring[1] in interval_count: interval_count[substring[1]].append(substring[0]) else: interval_count[substring[1]] = [substring[0]] interval_count = {key: interval_count[key] for key in interval_count if len(interval_count[key]) > 1} return interval_count
def count_melodies(shortest, longest=0, filename=os.path.join( '..', 'data', '''sheu_ityng_pyiparshyng_20160813.xml''')): """Report any sequences of intervals that appear more than once.""" # QQQ not yet in test suite! # QQQ for lyrics in question here, not note-indices, see which_syll_is_note. xml_notes, divisions = R.get_notes(filename) melody = U.get_melody(xml_notes, divisions) intervals = U.get_intervals(melody) substrings = U.find_all_substrings(intervals, shortest, longest) interval_count = {} for substring in substrings: if substring[1] in interval_count: interval_count[substring[1]].append(substring[0]) else: interval_count[substring[1]] = [substring[0]] interval_count_over_1 = {key: interval_count[key] for key in interval_count if len(interval_count[key]) > 1} return interval_count_over_1, interval_count