def make_accompaniment(self): previous_a = None previous_b = None for harmonies, unused, rhythm, section_configs in zip( self.harmonies, self.unused_harmonies, self.raw_harmonic_rhythm, self.volume_sections ): bar_config = section_configs[0] bar_index = bar_config["bar_index"] accompanists = bar_config["accompanists"] if accompanists: rhythm, harmonies, unused = add_accompaniment_notes(rhythm, harmonies, unused) a_name, b_name = accompanists a = self.score[a_name] b = self.score[b_name] pitches_a = [] pitches_b = [] for h, unused_h in zip(harmonies, unused): pitch_a, pitch_b = next_accompaniment_notes( a_name, b_name, previous_a, previous_b, h, unused_h, bar_config["movement_number"] ) previous_a, previous_b = pitch_a, pitch_b pitches_a.append(pitch_a) pitches_b.append(pitch_b) bars_a = parse_rhythm(rhythm, pitches_a) bars_b = parse_rhythm(rhythm, pitches_b) a[bar_index : bar_index + len(bars_a)] = bars_a b[bar_index : bar_index + len(bars_b)] = bars_b else: previous_a = None previous_b = None
def make_piano_right_hand(self): piano_upper = self.score["Piano"][0] previous = [0, 4, 7, 10] for harmonies, unused, rhythm in zip(self.harmonies, self.unused_harmonies, self.raw_harmonic_rhythm): chords = [] for h, unused_h in zip(harmonies, unused): chord = next_piano_right_hand_chord(previous, h, unused_h) previous = chord[:] chords.append(chord) # [unused_h.remove(pitch % 12) for pitch in chord] bars = parse_rhythm(rhythm, chords) piano_upper.extend(bars)
def make_bassline(self): previous = -8 piano_lower = self.score["Piano"][1] for harmonies, unused, rhythm in zip(self.harmonies, self.unused_harmonies, self.raw_harmonic_rhythm): pitches = [] for h, unused_h in zip(harmonies, unused): p = next_piano_bass_note(previous, h) previous = p pitches.append(p) unused_h.remove(p % 12) bars = parse_rhythm(rhythm, pitches) piano_lower.extend(bars)
def parse_rhythm(self, raw_rhythm): return parse_rhythm(raw_rhythm)
def make_drones(self): synth = self.score["Synthesizer"] # Drone 1 bars = [get_one_note_bar(self.drones[0]) for _ in self.drone_sections[0]] tie(bars) synth.extend(bars) for rhythm in self.raw_harmonic_rhythm[:4]: self.harmonic_rhythm_drones.append([self.drones[0] for r in rhythm]) # Rest 1 rest_bars = [get_rest_bar() for _ in self.drone_sections[1]] synth.extend(rest_bars) for rhythm in self.raw_harmonic_rhythm[4:8]: self.harmonic_rhythm_drones.append([None for r in rhythm]) # Drone 2 bars = [get_one_note_bar(self.drones[1]) for _ in self.drone_sections[2]] tie(bars) synth.extend(bars) for rhythm in self.raw_harmonic_rhythm[8:12]: self.harmonic_rhythm_drones.append([self.drones[1] for r in rhythm]) ####################################### #### Rest 2 and Drone 3 A entrance #### ####################################### # First two volume sections are resting rest_bars = [] for section in self.volume_sections[12:14]: rest_bars.extend([get_rest_bar() for _ in section]) for rhythm in self.raw_harmonic_rhythm[12:14]: self.harmonic_rhythm_drones.append([None for r in rhythm]) # The drone comes in at a random point in the third volume section drone_3a = self.drones[2][0] entrance_section = self.raw_harmonic_rhythm[14] start = random.choice(range(len(entrance_section) - 1)) rests = ["r" for duration in entrance_section[:start]] drones = [drone_3a for duration in entrance_section[start:]] pitches = rests + drones entrance_bars = parse_rhythm(entrance_section, pitches=pitches) rhythm = [] for pitch in pitches: if pitch == "r": rhythm.append(None) else: rhythm.append(drone_3a) self.harmonic_rhythm_drones.append(rhythm) # Last volume section is droning drone_bars = [get_one_note_bar(drone_3a) for _ in self.volume_sections[15]] self.harmonic_rhythm_drones.append([drone_3a for dur in self.raw_harmonic_rhythm[15]]) synth.extend(rest_bars + entrance_bars + drone_bars) to_tie = entrance_bars + drone_bars # TODO ties ####################### #### Drone 3 A & B #### ####################### # First volume section is drone 3 A bars_1 = [get_one_note_bar(drone_3a) for _ in self.volume_sections[16]] self.harmonic_rhythm_drones.append([drone_3a for dur in self.raw_harmonic_rhythm[16]]) # Second volume section drone 3 B comes in entrance_section = self.raw_harmonic_rhythm[17] start = random.choice(range(1, len(entrance_section))) a = [drone_3a for duration in entrance_section[:start]] both = [self.drones[2] for duration in entrance_section[start:]] pitches = a + both bars_2 = parse_rhythm(entrance_section, pitches=pitches) self.harmonic_rhythm_drones.append(pitches) # Third and Fourth volume sections both drones bars_3_4 = [] for section in self.volume_sections[18:20]: bars_3_4.extend([get_one_note_bar(self.drones[2]) for _ in section]) for rhythm in self.raw_harmonic_rhythm[18:20]: self.harmonic_rhythm_drones.append([self.drones[2] for dur in rhythm]) # Fifth volume section drone 3 A exits drone_3b = self.drones[2][1] exit_section = self.raw_harmonic_rhythm[20] start = random.choice(range(1, len(exit_section))) both = [self.drones[2] for duration in exit_section[:start]] b = [drone_3b for duration in exit_section[start:]] pitches = both + b bars_5 = parse_rhythm(exit_section, pitches=pitches) self.harmonic_rhythm_drones.append(pitches) # Sixth volume section is drone 3 B bars_6 = [get_one_note_bar(drone_3b) for _ in self.volume_sections[21]] self.harmonic_rhythm_drones.append([drone_3b for dur in self.raw_harmonic_rhythm[21]]) # Seventh volume section drone 3 B exits exit_section = self.raw_harmonic_rhythm[22] start = random.choice(range(1, len(exit_section))) b = [drone_3b for duration in exit_section[:start]] rest = ["r" for duration in exit_section[start:]] pitches = b + rest bars_7 = parse_rhythm(exit_section, pitches=pitches) rhythm_drones = [] for p in pitches: if p == "r": rhythm_drones.append(None) else: rhythm_drones.append(p) self.harmonic_rhythm_drones.append(rhythm_drones) # Eighth volume section is resting bars_8 = [get_rest_bar() for _ in self.volume_sections[23]] self.harmonic_rhythm_drones.append([None for dur in self.raw_harmonic_rhythm[23]]) bars = bars_1 + bars_2 + bars_3_4 + bars_5 + bars_6 + bars_7 + bars_8 synth.extend(bars) to_tie += bars tie(to_tie) # Drone 4 bars = [get_one_note_bar(self.drones[3]) for _ in self.drone_sections[6]] tie(bars) synth.extend(bars) for rhythm in self.raw_harmonic_rhythm[24:28]: self.harmonic_rhythm_drones.append([self.drones[3] for r in rhythm]) # Rest 4 bars = [get_rest_bar() for _ in self.drone_sections[7]] synth.extend(bars) for rhythm in self.raw_harmonic_rhythm[28:]: self.harmonic_rhythm_drones.append([None for r in rhythm])
def make_soloist(self): soloists = [sec[0]["soloist"] for sec in self.volume_sections] # Is the soloist entering, playing through, exiting, or resting? actions = solo.get_actions(soloists) previous = None previous_soloist_name = None for i, section_configs in enumerate(self.volume_sections): print "\tVolume Section #{}".format(i) soloist_name = soloists[i] if soloist_name != previous_soloist_name: previous = None previous_soloist_name = soloist_name action = actions[i] bar_index = section_configs[0]["bar_index"] movement_number = section_configs[0]["movement_number"] if soloist_name: soloist = self.score[soloist_name] harmonies = self.harmonies[i] unused = self.unused_harmonies[i] rhythm = self.raw_harmonic_rhythm[i] rhythm, harmonies, unused = solo.add_notes(rhythm, harmonies, unused, soloist_name, movement_number) len_rhythm = len(rhythm) rests = [] if action == "enter": enter_index = 0 if len_rhythm == 2: enter_index = 1 if len_rhythm > 2: opts = range(1, len_rhythm - 1) enter_index = random.choice(opts) for _ in harmonies[:enter_index]: rests.append("r") harmonies, unused = harmonies[enter_index:], unused[enter_index:] if action == "exit": exit_index = 0 if len_rhythm == 2: exit_index = 1 if len_rhythm > 2: opts = range(1, len_rhythm - 1) exit_index = random.choice(opts) for _ in harmonies[exit_index:]: rests.append("r") harmonies, unused = harmonies[:exit_index], unused[:exit_index] pitches = [] for h, unused_h in zip(harmonies, unused): pitch = solo.next_soloist_note(soloist_name, previous, h, movement_number, i) if isinstance(pitch, int): previous = pitch pc = pitch % 12 if pc in unused_h: unused_h.remove(pc) elif isinstance(pitch, list): previous = pitch[0] pitches.append(pitch) if action == "enter": pitches = rests + pitches elif action == "exit": pitches = pitches + rests rhythm, pitches = solo.join_some_notes(rhythm, pitches) bars = parse_rhythm(rhythm, pitches) soloist[bar_index : bar_index + len(bars)] = bars if action == "enter" or action == "exit": notes = [] for bar in bars: for note in bar: if not is_rest(note): notes.append(note) if action == "enter": crescendo(notes) elif action == "exit": crescendo(notes, decrescendo=True) else: previous = None