示例#1
0
def generateMidi(pitches):

    for i in range(pitches):
        pitches[i] = gerNum(pitches[i])
    track = 0
    channel = 0
    time = 0
    duration = 1
    tempo = 120  # default tempo for now
    volume = 100

    newMidi = MIDIFile(1)

    newMidi.adjust_origin = True

    newMidi.addTempo(track, time, tempo)

    for i, pitch in enumerate(pitches):
        newMidi.addNote(track, channel, pitch, time + i, duration, volume)

    ofp = input('What would you like to name the output file? ') + '.mid'
    with open(ofp, "wb") as midi_output:
        newMidi.writeFile(midi_output)
示例#2
0
def generateMidi(pitches):

    for i in range(len(pitches)):
        pitches[i] = getNum(pitches[i])
    track = 0
    channel = 0
    time = 0
    duration = 1
    tempo = 120  # default tempo for now
    volume = 100

    newMidi = MIDIFile(1)

    newMidi.adjust_origin = True

    newMidi.addTempo(track, time, tempo)

    for i, pitch in enumerate(pitches):
        newMidi.addNote(track, channel, pitch, time + i, duration, volume)

    ts = datetime.datetime.now()
    ofp = "Twinkle{}.mid".format(ts.strftime("%H-%M-%S"))
    with open(ofp, "wb") as midi_output:
        newMidi.writeFile(midi_output)