def add_note(self,
              note,
              time,
              duration,
              volume=random.randint(85, 100),
              channel=0):
     self.midi.addNote(self.track, channel, note, time, duration,
                       volume + random.randrange(-20, 20))
 def add_chord(self,
               chord,
               time,
               duration,
               volume=random.randint(85, 100),
               channel=1):
     for j, note in enumerate(chord):
         self.midi.addNote(self.track, j % 12, note % 127, time, duration,
                           volume + random.randrange(-20, 20))
 def add_arpeggio(self,
                  chord,
                  time,
                  duration,
                  volume=random.randint(85, 100),
                  channel=2):
     for j, note in enumerate(chord):
         d = j * duration / len(chord)
         print('note', note, 'dur', d)
         self.midi.addNote(self.track, j % 12, note % 127, time + d,
                           duration / len(chord),
                           volume + random.randrange(-20, 20))
 def add_notes(self,
               notes,
               time,
               volume=random.randint(85, 100),
               channel=2):
     d = 0
     j = 0
     for note, dur in notes:
         d += dur
         j += 1
         print(f"Note {note} dur {dur}")
         self.midi.addNote(self.track, j % 12, note % 127, time + d, dur,
                           volume + random.randrange(-20, 20))
 def motif(self, upper=16):
     num_parts = random.randint(8, upper)
     motif = []
     for i in range(num_parts):
         sound = self.make_sound(i, p_chord=0.1)
         upper = 4
         lower = 1
         if sound[1] == "arpeggio":
             upper = 8
             lower = 4
             motif.append([
                 sound,
                 self.rand_duration(upper=upper,
                                    lower=lower,
                                    allow_partials=False)
             ])
         else:
             motif.append(
                 [sound,
                  self.rand_duration(upper=upper, lower=lower)])
     return motif
 def make_notes(self, i):
     num_notes = random.randint(4, 16)
     notes = []
     for j in range(num_notes):
         notes.append([self.make_note(i, j), self.rand_duration(upper=2)])
     return notes
 def chord_progression(self):
     num_chords = random.randint(2, 8)
     chords = []
     for _ in range(num_chords):
         chords.append([self.make_chord(), self.rand_duration(upper=8)])
     return chords
 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)