示例#1
0
def MCTD(melody_sequence, chord_sequence, chord_num=96):
    chord_index = np.argmax(chord_sequence, axis=1)
    chord_note = []
    if chord_num == 96:
        for i in chord_index:
            chord_note.append(note2number(chord962note(i)))
    else:
        for i in chord_index:
            chord_note.append(note2number(chord482note(i)))

    melody_sequence = melody_sequence.reshape(
        (melody_sequence.shape[0] * 48, 12))
    melody_index = my_argmax(melody_sequence)
    melody_index = melody_index.reshape((-1, 48))

    y = 0
    count = 0
    for melody_m, chord_m in zip(melody_index, chord_note):
        for m in melody_m:
            if m != -1:
                y += np.sqrt(
                    np.sum((np.asarray(tonal_centroid([m])) -
                            np.asarray(tonal_centroid(chord_m))))**2)
                count += 1
    if count == 0:
        return 0
    return y / count
示例#2
0
def PCS(melody_sequence, chord_sequence):
    chord_index = np.argmax(chord_sequence, axis=1)
    chord_note = []

    for i in chord_index:
        chord_note.append(
            note2number(pianoroll_to_note(INDICES_TO_PIANOROLL[i])))

    melody_sequence = melody_sequence.reshape(
        (melody_sequence.shape[0] * 48, 12))
    melody_index = my_argmax(melody_sequence)
    melody_index = melody_index.reshape((-1, 48))

    score = 0
    count = 0
    for melody_m, chord_m in zip(melody_index, chord_note):
        for m in melody_m:
            if m != -1:
                for c in chord_m:
                    # unison, maj, minor 3rd, perfect 5th, maj, minor 6,
                    if abs(m - c) == 0 or abs(m - c) == 3 or abs(
                            m - c) == 4 or abs(m - c) == 7 or abs(
                                m - c) == 8 or abs(m - c) == 9 or abs(m -
                                                                      c) == 5:
                        if abs(m - c) == 5:
                            count += 1
                        else:
                            count += 1
                            score += 1
                    else:
                        count += 1
                        score += -1
    if count == 0:
        return 0
    return score / count
示例#3
0
def CTnCTR(melody_sequence, chord_sequence):
    chord_index = np.argmax(chord_sequence, axis=1)
    chord_note = []

    for i in chord_index:
        chord_note.append(
            note2number(pianoroll_to_note(INDICES_TO_PIANOROLL[i])))

    melody_sequence = melody_sequence.reshape(
        (melody_sequence.shape[0] * 48, 12))
    melody_index = my_argmax(melody_sequence)
    melody_index = melody_index.reshape((-1, 48))

    c = 0
    p = 0
    n = 0
    for melody_m, chord_m in zip(melody_index, chord_note):
        for i in range(len(melody_m)):
            m = melody_m[i]
            if m != -1:
                if m in chord_m:
                    c += 1
                else:
                    n += 1
                    for j in range(i, len(melody_m)):
                        if melody_m[j] != -1:
                            if melody_m[j] != melody_m[i]:
                                if melody_m[j] in chord_m and abs(
                                        melody_m[i] - melody_m[j]) <= 2:
                                    p += 1
                                break
    if (c + n) == 0:
        return 0
    return (c + p) / (c + n)
示例#4
0
def CTD(chord_sequence, chord_num=96):
    chord_index = np.argmax(chord_sequence, axis=1)
    chord_note = []
    if chord_num == 96:
        for i in chord_index:
            chord_note.append(note2number(chord962note(i)))
    else:
        for i in chord_index:
            chord_note.append(note2number(chord482note(i)))

    y = 0

    for n in range(len(chord_note) - 1):
        y += np.sqrt(
            np.sum((np.asarray(tonal_centroid(chord_note[n + 1])) -
                    np.asarray(tonal_centroid(chord_note[n])))**2))

    return y / (len(chord_note) - 1)
示例#5
0
def CTD(chord_sequence):
    chord_index = np.argmax(chord_sequence, axis=1)
    chord_note = []
    for i in chord_index:
        chord_note.append(
            note2number(pianoroll_to_note(INDICES_TO_PIANOROLL[i])))

    y = 0
    for n in range(len(chord_note) - 1):
        y += np.sqrt(
            np.sum((np.asarray(tonal_centroid(chord_note[n + 1])) -
                    np.asarray(tonal_centroid(chord_note[n])))**2))

    if (len(chord_note) - 1) == 0:
        return 0

    else:
        return y / (len(chord_note) - 1)
示例#6
0
def MCTD(melody_sequence, chord_sequence):
    chord_index = np.argmax(chord_sequence, axis=1)
    chord_note = []
    for i in chord_index:
        chord_note.append(
            note2number(pianoroll_to_note(INDICES_TO_PIANOROLL[i])))

    melody_sequence = melody_sequence.reshape(
        (melody_sequence.shape[0] * 48, 12))
    melody_index = my_argmax(melody_sequence)
    melody_index = melody_index.reshape((-1, 48))

    y = 0
    count = 0
    for melody_m, chord_m in zip(melody_index, chord_note):
        for m in melody_m:
            if m != -1:
                y += np.sqrt(
                    np.sum((np.asarray(tonal_centroid([m])) -
                            np.asarray(tonal_centroid(chord_m))))**2)
                count += 1
    if count == 0:
        return 0
    return y / count