def make_song(self, p_nothing=0.6):
     for i in range(self.beats - 100):
         if i > self.chord_done:
             self.is_playing_chord = False
             self.is_playing_arp = False
         volume = random.randrange(70, 100)
         duration = random.randrange(1, 16)
         randchoice = random.random()
         if randchoice <= self.p_chord and not (self.one_handed
                                                and self.is_playing_chord):
             self.is_playing_chord = True
             self.chord_done = i + duration
             chord = self.note.make_chord()
             if random.random() < 0.7:
                 duration = random.randrange(2, 6)
                 self.chord_done = i + duration
                 self.is_playing_arp = True
                 for j, note in enumerate(chord):
                     d = j * duration / len(chord)
                     self.midi.addNote(self.track, 1, note, i + d, 2,
                                       volume + random.randrange(-20, 20))
             else:
                 for note in chord:
                     self.midi.addNote(self.track, 0, note, i, duration,
                                       volume + random.randrange(-20, 20))
         elif randchoice <= p_nothing:
             self.midi.addNote(self.track, 0, self.note.make_note(), i,
                               duration, volume)
     self.writeMidi()
 def make_sound(self, i, p_chord=0.2, p_arp=0.2, p_single=0.2):
     r = random.random()
     if r < p_chord:
         return [self.make_chord(), 'chord']
     elif r < (p_chord + p_arp):
         return [self.make_arpeggio(), 'arpeggio']
     else:
         return [self.make_note(i, self.beat), 'note']
 def make_arpeggio(self):
     chord = self.make_chord()
     chord.sort()
     r = random.random()
     if r < 0.3:
         random.shuffle(chord)
     elif r < 0.6:
         chord.reverse()
     return chord
Ejemplo n.º 4
0
    def make_chord(self, p_rand=0.1, n_notes=4, p_double=0.5):
        isdouble = False
        if random.random() < p_double:
            isdouble = True
            n_notes *= 2
        if random.random() <= p_rand:
            return [self.make_note() for i in range(n_notes)]

        chord = random.choice(base_chords)
        octave = (random.choice(self.octave_range) * 12)
        if isdouble:
            double_octave = (random.choice(self.octave_range) * 12)
            while double_octave == octave:
                octave = (random.choice(self.octave_range) * 12)
            c = [note + double_octave for note in chord]
            c.extend([note + octave for note in chord])
            return c
        return [note + octave for note in chord]
 def make_song(self, p_nothing=0.6):
     for i in range(self.beats - 100):
         volume = random.randrange(70, 100)
         duration = random.randrange(1, 16)
         randchoice = random.random()
         if randchoice <= self.p_chord:
             for note in self.note.make_chord():
                 self.midi.addNote(self.track, 0, note, i, duration,
                                   volume + random.randrange(-20, 20))
         elif randchoice <= p_nothing:
             self.midi.addNote(self.track, 0, self.note.make_note(), i,
                               duration, volume)
     self.writeMidi()
 def rand_duration(self, upper=4, lower=1, allow_partials=True):
     if allow_partials and random.random() < 0.5:
         return random.choice([0.25, 0.5, 0.75, 1])
     else:
         return random.randint(lower, upper)