Example #1
0
def generate(model, seed, mid_name, temperature=1.0, length=512):
    '''Generate sequence using model, seed, and temperature.'''

    generated = []
    phrase = seed

    if not hasattr(temperature, '__len__'):
        temperature = [temperature for _ in range(length)]

    for temp in temperature:
        x = np.zeros((1, PHRASE_LEN, SYMBOL_DIM))
        for t, config_id in enumerate(phrase):
            x[0, t, config_id] = 1
        preds = model.predict(x, verbose=0)[0]
        next_id = sample(preds, temp)

        generated += [next_id]
        phrase = phrase[1:] + [next_id]

    mid = array_to_midiN(unfold(decode(generated), OUT_PITCHES), mid_name)
    print("the mid is + " + str(type(mid)))
    for element in mid:
        print("the intitial mid is " + str(element))
        #element = updateValue(element)
        #element.time = int(element.time)
        #print("theChecko " + str(type(element)))
    mid = updateValue(mid)
    # for element in mid.tracks:
    #     for msg in element:
    #         print("elmentsdfdf s " + str(msg))
    #
    # print("the mid_name is + " + str(mid_name))
    # midiFileToReturn = MidiFile()
    # # track = []
    # # midiFileToReturn.tracks.append(track)
    # tmpTime = 0
    # # for element in midiFileInput:
    # #    print("notrack: "+ str(element))
    # for i, element in enumerate(mid.tracks):
    #     tmpTrack = MidiTrack()
    #     midiFileToReturn.tracks.append(tmpTrack)
    #     print("inFOrefe is " + str(element))
    #     # if(element.type == "note_on" or element.type == "note_off"):
    #     # print("timoIs " + str(element.time))
    #     ##element.time = int(element.time*480)
    #     # element.time = int(element.time*480)
    #     # tmpTime+=1
    #     # track.append(element)
    #     for msg in element:
    #         msg.time = int(msg.time)
    #         print("track" + str(msg.time))
    #         tmpTrack.append(msg)

    mid.save(os.path.join(MIDI_OUT_DIR, mid_name))
    return mid
Example #2
0
def generate(model, seed, mid_name, temperature=1.0, length=512):
    '''Generate sequence using model, seed, and temperature.'''

    generated = []
    phrase = seed

    if not hasattr(temperature, '__len__'):
        temperature = [temperature for _ in range(length)]

    for temp in temperature:
        x = np.zeros((1, PHRASE_LEN, SYMBOL_DIM))
        for t, config_id in enumerate(phrase):
            x[0, t, config_id] = 1
        preds = model.predict(x, verbose=0)[0]
        next_id = sample(preds, temp)

        generated += [next_id]
        phrase = phrase[1:] + [next_id]

    mid = array_to_midiN(unfold(decode(generated), OUT_PITCHES), mid_name)
    mid = updateValue(mid)

    mid.save(os.path.join(MIDI_OUT_DIR, mid_name))
    return mid