Exemplo n.º 1
0
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 = []
durs = fh.concat([1, 0.5, 0.5, 0.5, 0.5, 1] for i in range(0,7)) + [3,1] + fh.concat([1, 0.5, 0.5, 0.5, 0.5, 1] for i in range(0,7)) + [2]
        measures[-1].append(measure)
    for measure in measures[-1]:
        if type(measure) == stream.Measure:
            elements = measure.elements
            for element in elements:
                if type(element) == stream.Voice:
                    new_elems = element.elements
                    for elem in new_elems:
                        if type(elem) == note.Note:
                            pits[-1].append(elem.midi)
                            durs[-1].append(elem.quarterLength)
                        elif type(elem) == note.Rest:
                            pits[-1].append(-36)
                            durs[-1].append(elem.quarterLength * -1)
                elif type(element) == note.Note:
                    pits[-1].append(element.midi)
                    durs[-1].append(element.quarterLength)
                elif type(element) == note.Rest:
                    pits[-1].append(-36)
                    durs[-1].append(element.quarterLength * -1)
                if type(element) == chord.Chord:
                    pits[-1].append(tuple([i.midi for i in element.pitches]))
                    durs[-1].append(element.quarterLength)


s = stream.Stream()
for i in range(0, len(pits)):
    s.insert(0, mh.listsToPart(pits[i], durs[i]))

s.show()
Exemplo n.º 3
0
# -*- coding: utf-8 -*-
"""
Created on Tue Nov 25 15:54:28 2014

@author: halley
"""
from nltk.book import *
import nltk
import music21helpers as mh
import sys

f = open(sys.argv[1], 'w+')
text = f.read()

letter_map = {'a':0, 'e':12, 'i':7, 'o':5, 'u':4, 's':2, 'r':9, 'l':11}
pits = []
for letter in text:
    if letter in letter_map:
        pits.append(letter_map[letter] + 48)
    else:
        pits.append(62)

part = mh.listsToPart(pits, [0.5 for i in pits])
part.write(fp=sys.argv[2], fmt='xml')