Пример #1
0
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
Пример #2
0
 def test_zero_increase(self):
     nvalue = (1,)
     nset = [(1,), (2,), (3,), (4,)]
     self.assertEqual(tools.update_chord(nvalue, 1, nset, 0), (1,))
Пример #3
0
 def test_note_not_in_set(self):
     nvalue = (1,)
     nset = [(2,), (3,), (4,)]
     self.assertEqual(len(tools.update_chord(nvalue, 1, nset, 2)), 3)
Пример #4
0
 def test_zero_prob(self):
     nvalue = (1,)
     nset = [(1,), (2,), (3,), (4,)]
     self.assertEqual(tools.update_chord(nvalue, 0, nset, 4), (1,))
Пример #5
0
 def test_update(self):
     nvalue = (1,)
     nset = [(1,), (2,), (3,), (4,)]
     self.assertEqual(set(tools.update_chord(nvalue, 1, nset, 4)),
                      {1, 2, 3, 4})