def TriadIsequal(sign1, sign2):
    sp1 = evalchord.split(sign1)
    sp2 = evalchord.split(sign2)
    root1 = sp1[0]
    root2 = sp2[0]
    quality1 = Quality[sp1[1]]
    quality2 = Quality[sp2[1]]
    return (root1 == root2) and (quality1 == quality2)
def GetQualityFromSign(sign):
    sp = evalchord.split(sign)
    quality = sp[1]
    if quality in QualityMap.keys():
        return QualityMap[quality]
    else:
        return -1
Example #3
0
def lab2target_single(lab):
    if lab == "N" or lab == "X":
        return C.LABEL_N
    root, _, bass = chord.encode(lab, reduce_extended_chords=True)
    _, quality, _, _ = chord.split(lab, reduce_extended_chords=True)
    target = quality_triad_map[quality] * 12 + root
    return target
Example #4
0
def encode_chordseq_hierarchical(seq):
    vec = np.zeros((len(seq), 6), dtype=np.int32)
    for i in range(len(seq)):
        lab = seq[i]
        if (lab != "N"):
            root, bitmap, bass = chord.encode(lab,
                                              reduce_extended_chords=False)
            _, quality, scale, _ = chord.split(lab,
                                               reduce_extended_chords=False)
            vec[i, 0] = quality_triad_map[quality] * 12 + root
            vec[i, 1] = (root + bass) % 12
            vec[i, 2] = quality_sevenths_map[quality]
            vec[i, 3] = quality_ninths_map[quality]
            vec[i, 4] = quality_elevenths_map[quality]
            vec[i, 5] = quality_thirteenths_map[quality]
            """
            for sc in scale:
                tone = chord.scale_degree_to_semitone(sc)
                if tone in [9,10,11]:
                    vec[i,2] = tone - 9
                elif tone in [13,14,15]:
                    vec[i,3] = tone - 13
                elif tone in [17,18]:
                    vec[i,4] = tone - 17
                elif tone in [20,21]:
                    vec[i,5] = tone - 20
            """
        elif lab == "N" or lab == "X":
            vec[i, :] = [C.LABEL_N, 12, 3, 3, 2, 2]
    return vec
def GetChordIDSign(sign):
    sp = evalchord.split(sign)
    pitch = sp[0]
    quality = sp[1]
    if pitch == 'N':
        return const.N_CHORDS - 1
    semitone = evalchord.pitch_class_to_semitone(pitch)
    quality_id = Quality[quality]
    return quality_id * 12 + semitone
def GetBassFromSign(sign):
    sp = evalchord.split(sign)
    bass = sp[3]
    if bass == "1":
        return 0
    elif bass == "3" or bass == "b3":
        return 1
    elif bass == "5":
        return 2
    return -1
Example #7
0
def shift_label(l, shift):
    if l in ["N", "X"]:
        return l
    if shift == 0:
        return l
    l_split = chord.split(l)
    l_root, _, _ = chord.encode(l)
    l_root = (l_root + shift) % 12
    l_root_str = notes[l_root]
    return chord.join(l_root_str, l_split[1], l_split[2], l_split[3])
Example #8
0
def lab2target(seq, module=np):
    seq_target = []
    for lab in seq:
        if lab == "N":
            target = C.LABEL_N
        else:
            _, quality, _, _ = chord.split(lab, reduce_extended_chords=True)
            root, _, bass = chord.encode(lab, reduce_extended_chords=True)
            quality_id = quality_triad_map[quality]
            target = quality_id * 12 + root
        seq_target.append(target)
    return module.array(seq_target, dtype=np.int32)
Example #9
0
def filter_label_seq(labs, shift=0):
    new_seq = []
    for l in labs:
        if l == "N" or l == "X":
            l_new = l
        else:
            sp = chord.split(l)
            root, _, _ = chord.encode(l)
            if shift != 0:
                root_new = (root + shift) % 12
                sp[0] = notes[root_new]
            l_new = chord.join(sp[0], sp[1], None, sp[3])
        new_seq.append(l_new)
    return new_seq
def TransposeToC(vec, sign):
    sp = evalchord.split(sign)
    root = sp[0]
    semitone = evalchord.pitch_class_to_semitone(root)
    return np.roll(vec, -semitone)
def GetSeventhType(sign):
    sp = evalchord.split(sign)
    return SeventhType[sp[1]]