Exemple #1
0
def add_piano_closing(roman, duration, piano, show_symbols=False):
   '''Generate a closing riff and add it to the keyboard part'''
   symbol = ChordSymbol(chordSymbolFigureFromChord(roman))
   if show_symbols:
      print symbol
   piano.append(symbol)    # Leadsheet chord symbol

   filled = 0
   length_weight = 2    # Longer notes later in the bar
   root = roman.root()  # Root pitch of the chord (NOT a note object)
   while filled < duration:
      # TODO DRY with other piano func
      chord = Chord(deepcopy(roman.pitches))

      # invert chord randomly, root inversion twice as likely as others
      max_inv=len(chord.pitches)
      chord.inversion(random.randint(0,max_inv)%max_inv)

      # Add an extra root note 1 octave lower
      root = deepcopy(chord.root())
      root.octave -= 1
      chord.add(root)
      # TODO above same procedure as main riff func, but we should
      # make more fancy

      # Rhythm similar to bass method below
      length = min(random.randint(1,length_weight),duration-filled) # cap at time left
      chord.quarterLength = length/2.0

      piano.append(chord)
      filled += length
      length_weight += length # Longer notes later in the bar
Exemple #2
0
def separate_chords(chunks):
    root = []
    harmonics = []
    nbHarmonics = 0
    for chunk in chunks:
        nbNotes = len(chunk.notes)
        # Adds harmonics partitions if necessary
        while nbNotes > nbHarmonics+1:
            l = []
            harmonics.append(l)
            nbHarmonics += 1
        # Determines the root of the chord
        chord = Chord(list(n for n,i in chunk.notes))
        rootIndex = list(chord.pitches).index(chord.root())
        # Distributes the notes in the lists
        harmonicIndex = 0
        for i in range(nbNotes):
            note = (
                chunk.start,
                chunk.end,
                chunk.notes[i][0], # pitch
                chunk.notes[i][1]  # index
            )
            if i == rootIndex:
                root.append(note)
            else:
                harmonics[harmonicIndex].append(note)
                harmonicIndex += 1
    return root, harmonics
Exemple #3
0
def add_piano_riff(roman, duration, piano, show_symbols=False):
   '''Given a Roman chord, duration in eighths/quavers and a keyboard
      part, generate a riff and add it to the keyboard part'''

   # Add a chord symbol at the start
   symbol = ChordSymbol(chordSymbolFigureFromChord(roman))
   if show_symbols:
      print symbol
   piano.append(symbol)

   # Add the actual notes
   filled = 0
   while filled < duration:
      # NOTE: higher chance to rest if on beat = more syncopated rhythm to piano
      if random.randint(0, 1 + filled%2 + filled%4):
         # XXX: Must deepcopy, do not change original or it will break bassline
         chord = Chord(deepcopy(roman.pitches))


         # invert chord randomly, root inversion twice as likely as others
         max_inv=len(chord.pitches)
         chord.inversion(random.randint(0,max_inv)%max_inv)

         # TODO try randomly ommitting some chord notes

         # Randomly hold notes for longer if we have longer before
         # the next chord change
         max_length = min(duration-filled, 4)      # Cap at 1/2 bar
         length = random.randint(1,max_length)
         chord.quarterLength = length/2.0      # length is in eighths

         # Add an extra root note 1 octave lower
         root = deepcopy(chord.root())
         root.octave -= 1
         chord.add(root)

         # Add the chord at soft volume and update duration
         chord.volume = Volume(velocity=16,velocityIsRelative=False)
         piano.append(chord)
         filled += length
      else:
         piano.append(Rest(quarterLength=0.5))
         filled += 1