def create_mapseq(melody, map_file): '''Takes a melody and a map file. Uses the information contained in the map file (sequence length, number of sections and transitions, sequence structure) to build a composite (mapped) sequence.''' sequence = [] seq_info = Map.from_map_file(map_file) notes = tools.generate_sequence(melody, seq_info.length) section_lengths = iter(seq_info.sections) transition_lengths = iter(seq_info.transitions) for i, section in enumerate(seq_info.structure): # Adding Sections sequence.extend(tools.generate_section(generator=notes, length=next(section_lengths), mapping=seq_info.mapping, section=section)) try: # Adding Transitions next_section = info.structure[i + 1] sequence.extend(tools.generate_transition(generator=notes, length=next(transition_lengths), mapping=info.mapping, section=section, next_section=next_section)) except IndexError: pass return sequence
def create_chordseq(melody, map_file, increase): '''Creates a variant of the mapped sequence with chords occurring randomly throughout (chorded sequence). The chords are of variable length, and are created by taking a base note and adding other notes from the same section onto it. The chords appear more frequently as the sequence progresses, similar to the pauses in a sparse sequence with fading == False.''' sequence = [] info = Map.from_map_file(map_file) notes = tools.generate_sequence(melody, info.length) section_lengths = iter(info.sections) transition_lengths = iter(info.transitions) prob = 0.0 for i, letter in enumerate(info.structure): note_set = info.mapping[letter] section = tools.generate_section(generator=notes, length=next(section_lengths), mapping=info.mapping, section=letter) for note in section: sequence.append(tools.update_chord(note, prob, note_set, increase)) prob += 1 / float(info.length) try: next_section = info.structure[i + 1] note_set = info.mapping[letter] + info.mapping[info.structure[i + 1]] transition = tools.generate_transition(generator=notes, length=next(transition_lengths), mapping=info.mapping, section=letter, next_section=next_section) for note in transition: sequence.append(tools.update_chord(note, prob, note_set, increase)) prob += 1 / float(info.length) except IndexError: pass return sequence
def test_0_length(self): generator = (i for i in [1, 2, 1, 1, 2, 2, 1]) transition = tools.generate_transition(generator, 0, MAPPING, 'A', 'B') self.assertEqual(list(transition), [])
def test_wrong_section(self): generator = (i for i in [1, 2, 1, 1, 2, 2, 1]) transition = tools.generate_transition(generator, 7, MAPPING, 'A', 'D') self.assertRaises(KeyError, list, transition)
def test_set(self): generator = (i for i in [1, 2, 1, 1, 2, 2, 1]*10) transition = tools.generate_transition(generator, 70, MAPPING, 'A', 'B') self.assertEqual(set(transition), {1, 2, 3, 4})