Exemple #1
0
 def test_relative_minor(self):
     known = {'C': 'a', 'E': 'c#', 'B': 'g#', 'G': 'e', 'F': 'd'}
     for k in known.keys():
         self.assertEqual(
             known[k], keys.relative_minor(k),
             'The minor of %s is not %s, expecting %s' %
             (k, keys.relative_minor(k), known[k]))
Exemple #2
0
 def test_relative_minor(self):
     known = {"C": "a", "E": "c#", "B": "g#", "G": "e", "F": "d"}
     for k in known:
         self.assertEqual(
             known[k],
             keys.relative_minor(k),
             "The minor of %s is not %s, expecting %s" %
             (k, keys.relative_minor(k), known[k]),
         )
Exemple #3
0
 def test_relative_minor(self):
     known = {
             'C': 'a',
             'E': 'c#',
             'B': 'g#',
             'G': 'e',
             'F': 'd'
             }
     for k in known.keys():
         self.assertEqual(known[k], keys.relative_minor(k),
                 'The minor of %s is not %s, expecting %s' % (k,
                     keys.relative_minor(k), known[k]))
Exemple #4
0
def reharmonize(chords, scores, bars, key, mode):
    if mode == 'minor':
        new_key = Keys.relative_minor(key)
    for i in range(0, len(chords)):
        if (chords[i] == 'bbbbbI'): continue
        if random.random() > 0.2:
            subs = Progressions.substitute([chords[i]], 0)
            for j in range(0, 5):
                sub = random.choice(subs)
                if not (sub.endswith('dim')) and not (
                        sub.endswith('dim7')) and score(sub, bars[i], new_key):
                    if i == 0:
                        if sub == chords[i + 1]: continue
                    if i == len(chords) - 1:
                        if sub != chords[i - 1]: continue
                    if sub != chords[i - 1] and sub != chords[i + 1]:
                        chords[i] = sub
                        break
Exemple #5
0
def transpose_to_relative_minor(track, original_key, harmonic):
    transposed_track = copy.deepcopy(track)
    if original_key in keys.major_keys:
        old_scale = keys.get_notes(original_key)
        new_key = keys.relative_minor(original_key)
        new_scale = keys.get_notes(new_key)

        if harmonic:
            new_scale[6] = notes.augment(new_scale[6])
            new_scale[6] = notes.reduce_accidentals(new_scale[6])

        input_notes = transposed_track.get_notes()
        for bar in input_notes:

            #Check if the nc contained in the bar/"note" is a pause, then do nothing
            nc = bar[-1]
            if nc is None:
                continue

            #Otherwise
            else:
                #For every actual note in the note containers (important if there is a chord)
                for note in nc:
                    #old_note = copy.deepcopy(note)
                    if note.name in old_scale:
                        index = old_scale.index(note.name)
                        note.name = new_scale[index]

                    else:
                        note.transpose("b3")
                        note.name = notes.reduce_accidentals(note.name)

                    # Fix octaves
                    if note.name[0] == 'A' or note.name[0] == 'B':
                        note.octave_down()

    else:
        print("input key is not major key")
    return transposed_track
Exemple #6
0
def get_relative(key):
    """Get the relative key of key"""
    return keys.relative_minor(key) if key[0].isupper() else keys.relative_major(key)