Beispiel #1
0
def demo_random_new(argv):
    mid = Song()
    track = mid.add_track()

    # header = MidiFile('AutumnL.mid')

    for i in range(1000):
        note = np.random.randint(60, 100)
        # key down
        track.append(
            Message(
                'note_on',
                note=note,
                velocity=np.random.randint(30, 70),
                time=0 if np.random.rand() > 0.8 else np.random.randint(
                    100, 300),
            ))

        # key up
        track.append(
            Message(
                'note_on',
                note=note,
                velocity=0,
                time=np.random.randint(100, 300),
            ))
    mid.save('new_song.mid')
Beispiel #2
0
def demo_copy(argv):
    mid = Song()
    track = mid.add_track()

    source = MidiFile('playground/AutumnL.mid')
    # only copy notes
    Song._copy(source, track, filter_f=lambda x: x.type == 'note_on')
    mid.save('playground/AutumnL_copy.mid')