def adjust_for_precedence(self, weights): prec = {pitch.pc(p):w for p,w in self.precedences.items()} for k in weights.keys(): if k not in prec: prec[k] = 1 for p in self.prev_picks: pcp = pitch.pc(p) if pcp in prec: prec[pcp] *= 0.5 mult = {k: prec[pitch.pc(k)] for k in weights.keys()} mult = w.scale(mult, float(self.precedence) / self.left_to_select) return w.normalize(w.apply(mult, weights))
octave = max(0, prev - 36) / 12 too_close = 0 if octave == 0: too_close = 11 elif octave == 1: too_close = 4 elif octave == 2: too_close = 2 for k in weights.keys(): if abs(prev - k) <= too_close: new_map[k] *= pow(0.5, self.spacing) weights = w.apply(new_map, weights) return w.ensure_safe(weights) def adjust_for_register(self, weights): new_map = {} for k in weights.keys(): distance = abs(self.register_center-k)+1 new_map[k] = pow(distance, - self.register) weights = w.apply(new_map, weights) return w.ensure_safe(weights) if __name__ == '__main__': hm = HarmonyMap(Chord(0, 'dom7'), uniqueness=10, precedence=10, spacing=2, register=10) print hm.precedences hs = hm.select(5) hs.sort() print hs print [pitch.pc(p) for p in hs] #print hm.adjust()