Ejemplo n.º 1
0
def test_learning():
    
    composer = Composer(order = 2)
    
    paths = [os.path.join("midifiles/classical_piano/c_maj/format0", path) for path in os.listdir("midifiles/classical_piano/c_maj/format0")]
    
    for path in paths:
        
        print "Learning " + os.path.basename(path)
        
        midi = parser.readFile(path)
            
        track = midi.toTrack()
        
        track.quantize(1.0/16.0)
        
        composition = Composition(120, 44100)
        
        composition.addTrack(track)
        
        composer.learnFromComposition(composition)

    print composer.marcovChains[0]
Ejemplo n.º 2
0
def test_composition():
    
    random.seed(427)
    
    scale = Scale(Note(0))

    track1 = Track()
    track2 = Track()
    
    chord = scale.getRandomChord()
    track1.appendChord(chord, 0.25)
    print chord
    
    chord = scale.getRandomChord()
    track1.appendChord(chord, 0.5)
    print chord
    
    
    chord = scale.getRandomChord()
    track2.appendChord(chord, 2.0)
    print chord
    
    chord = scale.getRandomChord()
    track2.appendChord(chord, 1.0)
    print chord
       
    comp = Composition(120, 44100)
    comp.addTrack(track1)
    comp.addTrack(track2)
    
    print
    print "Running composition..."
    for sample in range(5 * 44100):
        noteOn = comp.getNoteOnEvents()
        noteOff = comp.getNoteOffEvents()
        
        if noteOn:
            print "NoteOn events: sample = " + str(sample)
            print noteOn
            
        if noteOff:
            print "NoteOff events: sample = " + str(sample)
            print noteOff
            
        comp.advanceBySample()