Beispiel #1
0
def train(trainset):

    expression = {}
    features = {}
    const = 0
    Max = 0
    Min = None
    count = 0
    print(">>> Loading scores and deviations, this will take hours and may eat all you memory")

    for query in trainset:
        print(">>> Loading: {0}".format(query))
        score = db.getScore1(query)
        deviations = db.getDeviation1(query)
        alignment = Alignment(score, deviations)
        melody = alignment.melody()
        #segments = structure.newSegmentation(tools.parseScore(melody))
        segments = structure.noteLevel(tools.parseScore(melody))
        const += len(segments)
        lengths = sum([len(s) for s in segments])
        m = max([len(s) for s in segments])
        mi = min([len(s) for s in segments])
        if m > Max:
            Max = m
        if not Min:
            Min = mi
        if mi < Min:
            Min = mi
        print('>>> Extracting features')
        expression[query] = performancefeatures.vanDerWeijExpression(alignment, segments)
        features[query] = scorefeatures.vanDerWeijFeatures(melody, segments)
        count += 1
        print('{0}/{1} done'.format(count, len(trainset)))

    print("Done, {0} segments found with an average length of: {1} (min: {2} max: {3})".format(const, lengths / float(const), Min, Max))
    tools.saveFeatures(features, expression)
Beispiel #2
0
def run():
    import database as db
    selection = db.select()
    print(">>> Extracting deviations")
    deviations = db.getDeviation1(selection)
    print(">>> Loading score")
    score = db.getScorePath1(selection)
    print(">>> Loading alignment")
    alignment = Alignment(score, deviations)
    alignment.store("alignments/a1")
    print(">>> Generating performance")
    performance = alignment.performance()
    performance.exportMidi('output/generated.mid')
    #for n in performance[0:20]:
    #  print n.info()


    #output = open('temp.txt', 'w')
    #for n in nlist:
    #  output.write(str(n) + '\n')
    #output.close()
    import sequencer as seq
    sequencer = seq.Sequencer()
    sequencer.play(performance)
Beispiel #3
0
import database as db
from sequencer import *
from alignment import *
import structure, tools
import scorefeatures as sf
import performancefeatures as pf
import perform

s = db.select()
a = Alignment(db.getScore1(s), db.getDeviation1(s))
melodyscore = a.melody()
melody = tools.parseScore(melodyscore)
onset = structure.groupings(structure.list_to_tree(structure.first_order_tree(structure.onset, melody, 0.1)), 1)
score = sf.vanDerWeijFeatures(melodyscore, onset)
performance = pf.vanDerWeijExpression(a, onset)

print(score)
print(performance)

seq = Sequencer()
seq.play(perform.vanDerWeijPerformSimple(a.score, melodyscore, onset, performance, bpm=a.deviations.bpm, converter=melody))