def writePhrase(motifs,  fname, degrees = True):
    pitches = []
    mpitches = ([i.l0p for i in motifs])
    for i in range(0, len(mpitches)):
        pitches.extend(mpitches[i][:len(motifs[i].l0d)])
    if degrees:
        pitches = sc.degreesToNotes(pitches)
    durs = fh.concat([i.l0d for i in motifs])
    score = listsToStream(pitches, durs)
    score.write(fmt = 'musicxml', fp = fname)
def showCells(cells,  degrees = True):
    pitches = []
    mpitches = ([i.pits for i in cells])
    for i in range(0, len(mpitches)):
        pitches.extend(mpitches[i][:len(cells[i].pits)])
    if degrees:
        pitches = sc.degreesToNotes(pitches)
    durs = fh.concat([i.durs for i in cells])
    score = listsToStream(pitches, durs)
    score.show()
def writeCells(cells,  fname, degrees = True):
    pitches = []
    mpitches = ([i.pits for i in cells])
    for i in range(0, len(mpitches)):
        pitches.extend(mpitches[i][:len(cells[i].pits)])
    if degrees:
        pitches = sc.degreesToNotes(pitches)
    durs = fh.concat([i.durs for i in cells])
    score = listsToStream(pitches, durs)
    score.write(fmt = 'musicxml', fp = fname)
def cellsToPart(cells, leading = True, octave = 5):
    durs = fh.concat([i.durs for i in cells])
    pitches = [i.pits for i in cells]
    #if there is a stretch where too low or high, fix
    midi_pitches = []
    for i in range(0, len(pitches)):
        midi_pitches.extend(sc.degreesToNotes(pitches[i], scale = scales["C major"], octave = octave))

    #pitches, durs = smooth.smoothOut(pitches, durs, leading)
    score = listsToPart(midi_pitches, durs)
    return score
def motifsToPart(motifs, key_area, leading = True, octave = 5):
    durs = fh.concat([i.l0d for i in motifs])
    pitches = [i.l0p for i in motifs]
    """
    prev = pitches[0][0]
    tot_durs = [sum(durs[:i]) for i in range(0, len(durs)) ]
    n = 0

    for i in range(0, len(pitches)):
        if i > 0:
            prev = pitches[i - 1][-1]
        for j in range(1, len(pitches[i])):
            if tot_durs[n] % 1.0 != 0:
                if pitches[i] == prev:
                    pitches[i] += random.choice([1,-1]) 
            if pitches[i][j] > 14:
                if abs(prev - pitches[i][j] - 7) < 4:
                    pitches[i][j] = pitches[i][j] - 7
            elif pitches[i][j] < 0:
                if abs(prev - pitches[i][j] + 7) < 4:
                    pitches[i][j] = pitches[i][j] + 7
            #elif abs(pitches[i][j] - prev) > 4:
            #    pitches[i][j] = pth.getClosestPCDegree(pitches[i][j - 1], pitches[i][j])
            prev = pitches[i][j]
        n += 1 
    """
    #if there is a stretch where too low or high, fix
    midi_pitches = []    
    for i in range(0, len(pitches)):
        if key_area[i] == 0:
            midi_pitches.extend(sc.degreesToNotes(pitches[i], scale = scales["C major"], octave = octave))
        elif key_area[i] == 7:
            new_pitches = sc.degreesToNotes(pitches[i], scale = scales["G major"], octave = octave)
            midi_pitches.extend(new_pitches)

    #pitches, durs = smooth.smoothOut(pitches, durs, leading)
    score = listsToPart(midi_pitches, durs)
    return score
def cellsToPart(cells, octave = 5):
    notes = []
    for cell in cells:

        degrees = cell.pits
        pits = sc.degreesToNotes(degrees, octave = octave, scale = cell.scale)
        durs = cell.durs
        for i in range(0, len(pits)):
            if durs[i] > 0:
                n = note.Note(pits[i])
                n.quarterLength = abs(durs[i])
                notes.append(n)
            else:
                n = note.Rest()
                n.quarterLength = abs(durs[i])
                notes.append(n)
    part = stream.Part()
    part.append(notes)
    return part
def showDegreesDurs(degrees, durs):
    pitches = sc.degreesToNotes(degrees)
    score = listsToStream(pitches, durs)
    score.show('musicxml')    
def listsDegreesToPart(degrees, durations, octave = 5, scale = scales["major"]):
    pitches = sc.degreesToNotes(degrees, octave, scale)
    return listsToPart(pitches, durations)
def showListsDegrees(pitches, durs):
    pitches = sc.degreesToNotes(pitches)
    showLists(pitches, durs)
def chunkToPart(chunk):
    pits = sc.degreesToNotes(chunk.pits)
    durs = chunk.durs
    return listsToPart(pits, durs)
示例#11
0
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)]))
degs.append(0)
durs = [1 for i in range(0, 14)] + [2] + [1 for i in range(0, 14)] + [2]
score = mh.listsDegreesToPart(degs, durs)
#score.show('musicxml')

#Etude 4: up and down the scale with intervals of 2, plus a random walk in the middle of each measure
degs = []
instr_cells['Piano 1'].extend(counter.genCounter(period3phrase1))
instr_cells['Piano 2'].extend(gb.genBass(period3phrase1))

period3phrase2 = period3.sub_chunks[1]
instr_cells['Flute'].extend(period3phrase2.cells)
instr_cells['Piano 1'].extend(counter.genCounter(period3phrase2))
instr_cells['Piano 2'].extend(acc.genAlbertiEighths(period3phrase2, leading_eighths = False))


#create parts from instr_cells
parts = OrderedDict()
for instr in instrs:
    parts[instr] = stream.Part()
    parts[instr].insert(0, instrument.fromString(instr))
    for cell in instr_cells[instr]:
        pits = sc.degreesToNotes(degrees=cell.pits, octave=octaves[instr], scale = [i + cell.key for i in [0,2,4,5,7,9,11]])
        durs = cell.durs
        for i in range(0, len(pits)):
            if durs[i] > 0:
                n = note.Note(pits[i])
                n.quarterLength = durs[i]
            else:
                n = note.Rest()
                n.isRest = True
                n.quarterLength = abs(durs[i])
            parts[instr].append(n)

#insert into stream
s = stream.Stream()
for part in parts.values():
    s.insert(0, part)