__author__ = 'halley'
import random
from constants import *
import music21helpers as mh

#pick a chord progression that fits the given last chord
def chooseChords(num_chords, first_chord = [0,2,4], end_chords = [[0,2,4]]):
    chords = [first_chord]
    for i in range(1, num_chords - len(end_chords) - 1):
        next_chord = random.choice(chord_movements[chords[-1][0]])
        chords.append([next_chord + j for j in [0,2,4]])
    penultimate_chord_choices = chord_movements[chords[-1][0]]
    penultimate_chord_choices = filter(lambda i: end_chords[0][0] in chord_movements[i], penultimate_chord_choices)
    penultimate_choice = random.choice(penultimate_chord_choices)
    chords.append([penultimate_choice + j for j in [0,2,4]])
    chords.extend(end_chords)
    return chords


chords = chooseChords(num_chords = 8, end_chords = [[4,6,8],[0,2,4]])
print(chords)
pits = [tuple(i) for i in chords]
durs = [2.0 for i in chords]

part =  mh.listsDegreesToPart(pits, durs)

part.show()
예제 #2
0
@author: halley
"""
import functionalhelpers as fh
import music21helpers as mh
from music21 import *
import scale as sc
from constants import *
import rhythms as rhy
import pitchhelpers as pth

#Etude 1: up and down the scale
durs = fh.concat([[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1.0] for i in range(0,8)])
degs = fh.concat([map(lambda j: j + i, [0,1,2,3,4,3,2,1,0]) for i in range(0,8)])

score = mh.listsDegreesToPart(degs, durs)
score.insert(0, meter.TimeSignature('5/4'))
#score.show('musicxml')


#Etude 2: up and down different scales
durs = fh.concat([[0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,1.0] for i in range(0,8)])
degs = fh.concat([sc.degreesToNotes([0,1,2,3,4,3,2,1,0], scale = map(lambda j: j + i, scales["major"])) for i in scales["major"] + [12]])
score = mh.listsToPart(degs, durs)
score.insert(0, meter.TimeSignature('5/4'))
#score.show('musicxml')

#Etude 3: up and down scale with intervals of 2
degs = fh.concat([[j, j + 2] for j in range(0,7)])
degs.append(7)
degs.extend(fh.concat([[j, j - 2] for j in range(7,0,-1)]))