示例#1
0
 def test_major_add9(self):
     # major add 9 is a major chord with a Major ninth
     base = Chord("C")
     base0 = list(base.components(visible=False))
     base1 = list(base.components(visible=True))
     c = Chord("CMadd9")
     com0 = c.components(visible=False)
     self.assertEqual(com0, base0 + [14])
     com1 = c.components(visible=True)
     self.assertEqual(com1, base1 + ["D"])
示例#2
0
    def _assert_components(self, chord, qualities, notes):
        """ Validates if a chord is made up of specified qualities and notes.

        :param str chord: A chord, specified as a string, e.g. "C7"
        :param qualities: The expected qualities of the chord, as a list of numbers
        :param notes: The expected notes of the chord, either as a list of strings,
          e.g. ["C", "E", "G", "Bb"] or a string, e.g. "C E G Bb"
        """
        c = Chord(chord)
        com0 = c.components(visible=False)
        self.assertEqual(com0, qualities)
        com1 = c.components(visible=True)
        if isinstance(notes, str):
            notes = notes.split()
        self.assertEqual(com1, notes)
示例#3
0
def main():
    file = 'data/chord.csv'
    if os.path.isfile(file):
        with open(file, 'r') as f:
            reader = csv.reader(f)
            chords = list(reader)
    data = []
    pbar = tqdm.tqdm(total=len(chords) * 12)
    for num, title, chord in chords:
        for k in range(0, 12):
            note = []
            for j in chord.split():
                if 'N,C' in j or 'N.C' in j or '>' in j or j[
                        0] == '/' or j[:
                                       2] == '(/' or '↓' in j or j == '-' or j == '':
                    continue
                if j[0] == '(' and j[-1] == ')':
                    j = j[1:-1]
                elif not '(' in j and j[-1] == ')':
                    j = j[:-1]
                elif not ')' in j and j[0] == '(':
                    j = j[1:]
                try:
                    chord1 = Chord(j)
                    chord1.transpose(k)
                    notes = chord1.components(False)
                except Exception as e:
                    # print(e, 'error', j)
                    notes = []
                note.append(notes)
            data.append(note)
            pbar.update(1)
    pbar.close()
    return data
示例#4
0
def toMidi(chord_prog):
    midi = MIDIFile(1)
    track = 0
    channel = 0
    time = 0
    duration = 2
    volume = 60

    for chord in chord_prog:  #iterate through chords in progression
        #  try:
        ch = Chord(chord)  #get pyChord object of chord
        # except:
        #ValueError("Sorry! Couln't parse complex chord! Try again :(")
        comps = ch.components()  #get chord components using pyChord
        for item in comps:
            pitch = NOTES[item]  #get each pitch
            midi.addNote(track,
                         channel,
                         pitch,
                         time,
                         duration,
                         volume,
                         annotation=None)  #add MIDI note
        time += 2

    with open(str(chord_prog) + ".mid", 'wb') as output_file:
        midi.writeFile(output_file)  #output to MIDI file
def chord2note(chordname):
    a = Chord(chordname)
    notelist = []
    notelist.append(note2value(chordname[0] + str(2)))
    for i in a.components():
        notelist.append(note2value(i + str(4)))
    return sorted(notelist)
示例#6
0
    def set_notes(self):
        ''' Define a lista de notas que a tonalidade pode usar. '''
        notas = []
        for i in self.field:
            nota = Chord(i)
            notas += nota.components()

        notas = list(set(notas))

        return notas
示例#7
0
 def test_dim7_chord(self):
     c = Chord("Cdim7")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [0, 3, 6, 9])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["C", "Eb", "Gb", "A"])
示例#8
0
 def test_aug_chord(self):
     c = Chord("Eaug")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [4, 8, 12])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["E", "G#", "C"])
示例#9
0
 def test_seventh_chord(self):
     c = Chord("G7")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [7, 11, 14, 17])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["G", "B", "D", "F"])
示例#10
0
 def test_slash_chord(self):
     c = Chord("CM9/D")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [-10, 0, 4, 7, 11])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["D", "C", "E", "G", "B"])
示例#11
0
 def test_dim_chord(self):
     c = Chord("Ddim")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [2, 5, 8])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["D", "F", "G#"])
def check_results(results, results_real):
    def extend(chords, durations):
        chords_extended = []
        durations_extended = []

        for i in range(0, len(durations)):
            n = round(float(durations[i]) / 0.1)

            j = 0
            for j in range(0, n):
                chords_extended.append(chords[i])
                durations_extended.append("0.1")

        return (chords_extended, durations_extended)

    # storing chords and durations that program found in the analyzed file

    my_chords, my_durations = extend(results[0], results[1])
    i = 0

    # storing actual chords and durations of the analyzed file
    real_chords, real_durations = extend(results_real[0], results_real[1])
    j = 0

    # current time is left border of chunk being checked and current_time_r is right
    current_time = 0
    current_time_r = float(real_durations[j])

    # variables to store succesful percentage
    total_percentage = 0
    percentage = 0

    # running through chords that are found
    for m in range(0, len(my_chords)):
        if (current_time < current_time_r):
            if (my_chords[i] == real_chords[j]):
                print("{} Matching {}".format(my_chords[i], real_chords[j]))

                current_time = current_time + float(my_durations[i])

                # calculating percentage
                percentage = round(float(my_durations[i]) / duration * 100, 2)
                total_percentage = total_percentage + percentage
                print("Total percentage increased by ", percentage)

                i = i + 1
            else:  # If my chord doesnt match actual chords check if some of its tone do

                print("{} Doesn't match {}".format(my_chords[i],
                                                   real_chords[j]))

                try:  # if chord isnt none
                    my_chord = Chord(my_chords[i])
                    real_chord = Chord(real_chords[j])

                    my_notes = reference_sort(my_chord.components())
                    real_notes = reference_sort(real_chord.components())

                    m = 0
                    for note in my_notes:
                        if (note == real_notes[m]):
                            percentage = round(
                                float(my_durations[i]) / duration * 100 /
                                len(my_notes), 2)
                            total_percentage = total_percentage + percentage
                            print(
                                "Chord isnt right but some notes are, percentage increased by: ",
                                percentage)
                        m = m + 1
                except:
                    pass

                current_time = current_time + float(my_durations[i])

                i = i + 1
        else:
            if (j < len(real_durations) - 1):
                j = j + 1

                current_time_r = current_time_r + float(real_durations[j])

                if (my_chords[i] == real_chords[j]):
                    print("{} Matching {}".format(my_chords[i],
                                                  real_chords[j]))

                    current_time = current_time + float(my_durations[i])

                    # calculating percentage
                    percentage = round(
                        float(my_durations[i]) / duration * 100, 2)
                    total_percentage = total_percentage + percentage
                    print("Total percentage increased by ", percentage)

                    i = i + 1
                else:
                    print("{} Doesn't match {}".format(my_chords[i],
                                                       real_chords[j]))

                    try:
                        my_chord = Chord(my_chords[i])
                        real_chord = Chord(real_chords[j])

                        my_notes = reference_sort(my_chord.components())
                        real_notes = reference_sort(real_chord.components())

                        m = 0
                        for note in my_notes:
                            if (note == real_notes[m]):
                                percentage = round(
                                    float(my_durations[i]) / duration * 100 /
                                    len(my_notes), 2)
                                total_percentage = total_percentage + percentage
                                print(
                                    "Chord isnt right but some notes are, percentage increased by: ",
                                    percentage)
                            m = m + 1
                    except:
                        pass

                    current_time = current_time + float(my_durations[i])

                    i = i + 1

        #print(current_time , ' ' , current_time_r)
    print()
    return total_percentage
示例#13
0
def analyze_chord(symbol: str) -> List[str]:
    chord = Chord(symbol)
    return chord.components()
from pychord import Chord
import pychord

chord_am7 = Chord("Am7")
chord_am7_info = chord_am7.info()

chord_am7_comp = chord_am7.components()

bbb = pychord.note_to_chord(["C", "E", "G"])
print(chord_am7_info)
示例#15
0
 def test_sixth_chord(self):
     c = Chord("C6")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [0, 4, 7, 9])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["C", "E", "G", "A"])
示例#16
0
 def test_seventh_chord(self):
     c = Chord("G7")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [7, 11, 14, 17])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["G", "B", "D", "F"])
示例#17
0
 def test_sus4_chord(self):
     c = Chord("Fsus4")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [5, 10, 12])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["F", "Bb", "C"])
示例#18
0
def create_association_object():
    if settings.using_loop:
        if settings.in_melody:
            settings.scale_to_use = get_notes_in_scale('F',[3,4],'Major',1)
        else:
            midi_notes = []
            midi_notes_with_voicing = []
            chords = ['FM9', 'Am7','BbM7','A7']
            voicing = [[1,5,1,3,7,9],[1,5,1,3,7],[1,5,1,3,7,5],[1,5,1,3,7]]
            for i in range(0,len(chords)):
                midi_notes.append([])
                midi_notes_with_voicing.append([])
                c = Chord(chords[i])
                cur_notes = c.components()
                if '9' in chords[i]:
                    current_octave = 4
                else:
                    current_octave = 3
                last_note = 0      
                for n in cur_notes:
                    note = get_midi_from_letter(n,current_octave)
                    if note < last_note:
                        note = note + 12
                    midi_notes[i].append(note)
                    last_note = note
                    last_chord_with_voicing = 0
                for d in voicing[i]:
                    chord_with_voicing = midi_notes[i][int(math.floor(d/2))]
                    if chord_with_voicing < last_chord_with_voicing:
                        chord_with_voicing = chord_with_voicing + 12                   
                    midi_notes_with_voicing[i].append(chord_with_voicing)
                    last_chord_with_voicing = chord_with_voicing
            settings.scale_to_use = midi_notes_with_voicing
    else:
        settings.scale_to_use = get_notes_in_scale('F',[3,4],'Major',1)
    cross_selection_mode = 'positional'
    column_selection_mode = 'positional'
    settings.grid_type_to_show = 'positional'
    settings.scale_to_use = get_notes_in_scale('F',[1,2,3,4],'Major',1)
    #print(settings.scale_to_use)
    #settings.scale_to_use = [60,62,64,66,68,74,70,74,68,66,66,64,64,62,62,60]
    cross_notes_to_use = settings.scale_to_use
    column_notes_to_use = settings.scale_to_use
    ball_config_index_to_use = [0,0,0]

    #print(path_point_instance_obj)

    global show_scale_grid

    settings.show_scale_grid = False

    for i in range(number_of_path_point_instances):
        if path_point_instance_obj[i]['active'] == 1:
            #print('active!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!')
            ball_number = int(path_point_instance_obj[i]['ball number'])
            ball_number = ball_number - 1
            ball_number = str(ball_number)
            path_config = path_point_instance_obj[i]['path config']
            midi_channel = path_point_instance_obj[i]['midi channel']
            midi_associations['ball '+ball_number] = {}
            for path_phase in path_phases:
                midi_associations['ball '+ball_number][path_phase] = {}
                for path_type in path_types:
                    midi_associations['ball '+ball_number][path_phase][path_type] = {}
                    path_point_midi_index = path_point_path_obj[path_config][path_type][path_phase]
                    if path_point_midi_index > 0:
                        if path_point_midi_obj[path_point_midi_index]['input type'] == 'midi':
                            settings.notes_to_use = list(map(int,path_point_midi_obj[path_point_midi_index]['input'].split(',')))
                        midi_associations['ball '+ball_number][path_phase][path_type]['channel'] = midi_channel
                        midi_associations['ball '+ball_number][path_phase][path_type]['note_selection_mode'] = path_point_midi_obj[path_point_midi_index]['note selection type']
                        if 'positional' in path_point_midi_obj[path_point_midi_index]['note selection type']:
                            settings.show_scale_grid = True
                        midi_associations['ball '+ball_number][path_phase][path_type]['times_position_triggered'] = [-1]*len(settings.scale_to_use)
                        midi_associations['ball '+ball_number][path_phase][path_type]['notes'] = settings.notes_to_use
                        midi_associations['ball '+ball_number][path_phase][path_type]['magnitude'] = midi_magnitude

    print(midi_associations)
示例#19
0
 def test_overwrite(self):
     self.quality_manager.set_quality("11", (0, 4, 7, 10, 14, 17))
     chord = Chord("C11")
     self.assertEqual(chord.components(), ['C', 'E', 'G', 'Bb', 'D', 'F'])
示例#20
0
 def test_keep_existing_chord(self):
     chord = Chord("C11")
     self.quality_manager.set_quality("11", (0, 4, 7, 10, 14, 17))
     self.assertEqual(chord.components(), ['C', 'G', 'Bb', 'D', 'F'])
示例#21
0
 def test_minor_chord(self):
     c = Chord("Am")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [9, 12, 16])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["A", "C", "E"])
示例#22
0
 def test_minor_chord(self):
     c = Chord("Am")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [9, 12, 16])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["A", "C", "E"])
示例#23
0
 def test_aug_chord(self):
     c = Chord("Eaug")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [4, 8, 12])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["E", "G#", "C"])
示例#24
0
 def test_appended_chord(self):
     c = Chord("C#m7b9b5")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [1, 4, 7, 11, 14])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["C#", "E", "G", "B", "D"])
示例#25
0
 def test_sus4_chord(self):
     c = Chord("Fsus4")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [5, 10, 12])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["F", "Bb", "C"])
示例#26
0
 def test_normal_chord(self):
     c = Chord("C")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [0, 4, 7])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["C", "E", "G"])
示例#27
0
 def test_sixth_chord(self):
     c = Chord("C6")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [0, 4, 7, 9])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["C", "E", "G", "A"])
示例#28
0
 def test_dim_chord(self):
     c = Chord("Ddim")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [2, 5, 8])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["D", "F", "G#"])
示例#29
0
 def test_normal_chord(self):
     c = Chord("C")
     com0 = c.components(visible=False)
     self.assertEqual(com0, [0, 4, 7])
     com1 = c.components(visible=True)
     self.assertEqual(com1, ["C", "E", "G"])
示例#30
0
    links.append(link.get('href'))

problematic_chords = set()
problematic_songs = []

total_chords = 0
parsed_chords = 0
for link in links:
    legivel = True
    try:
        cifra = Cifra("https://www.cifraclub.com.br" + link)
        for chord in cifra.present_chords:
            total_chords += 1
            try:
                ch = Chord(chord)
                print(chord, ": ", ch.components())
                parsed_chords += 1
            except:
                print("I see a ", chord, "chord on the title", link,
                      ", but I can't read it! :(")
                legivel = False
                problematic_chords.append(chord)
                problematic_songs.append(link)
    except:
        print("There are no chords here, pal.")
    if (not legivel):
        problematic_songs.append(link)

print("Total de acordes: ", total_chords)
print("Acordes legíveis: ", parsed_chords)
print("Taxa de aproveitamento: ", (parsed_chords / total_chords) * 100, "%")