Exemplo n.º 1
0
def all_note_occurences(notes):
    note_occurences = {}
    for key, value in notes.items():
        scale_note = value['scale_note']
        if scale_note not in note_occurences.keys():
            note_occurences[scale_note] = [key]
        elif key not in note_occurences[scale_note]:
            note_occurences[scale_note].append(key)

    pprint(note_occurences)
    pickle_it(all_note_occurences_pickle, note_occurences)
Exemplo n.º 2
0
def all_scales(notes):
    major = [0, 2, 4, 5, 7, 9, 11]
    minor = [0, 2, 3, 5, 7, 9, 11]
    scales = {}

    for key, value in notes.items():
        if value['octave'] == 1:
            scale_note = value['scale_note']
            if scale_note not in scales.keys():
                scales[scale_note] = {'major': [], 'minor': []}

                scales[scale_note]['major'] = [notes[x+key]['scale_note'] for x in major]
                scales[scale_note]['minor'] = [notes[x+key]['scale_note'] for x in minor]

    pickle_it(scales_pickle, scales)
    pprint(scales)
Exemplo n.º 3
0
def all_trichords(notes):
    trichords = {}
    major = [0, 4, 7]
    minor = [0, 3, 7]
    sept = [0, 4, 7, 10]
    for key, value in notes.items():
        if value['octave'] == 1:
            scale_note = value['scale_note']
            if scale_note not in trichords.keys():
                trichords[scale_note] = {'major': [], 'minor': [], 'sept': []}

            trichords[scale_note]['major'] = [notes[x+key]['scale_note'] for x in major]
            trichords[scale_note]['minor'] = [notes[x+key]['scale_note'] for x in minor]
            trichords[scale_note]['sept'] = [notes[x+key]['scale_note'] for x in sept]

    pprint(trichords)
    pickle_it(trichords_pickle, trichords)
Exemplo n.º 4
0
def get_all_piano_frequencies():
    url = r'https://en.wikipedia.org/wiki/Piano_key_frequencies'
    html_table = get_html_tables(url)[0]
    notes = {}
    frequencies = []
    # open(piano_frequencies_pickle, 'w').close()

    rows = html_table.findAll('tr')

    for i, html_row in enumerate(rows):
        # print(html_row)
        cells = html_row.findAll('td')

        if cells:
            key_nr = int(get_text_from_table_cell(cells[0]))
            sci_name = get_text_from_table_cell(cells[2])
            frequency = float(get_text_from_table_cell(cells[3]))
            frequencies.append(frequency)

            sci_name_short = sci_name.replace(' ♯ ', '♯').replace(' ♭ ', '♭')
            sci_name_short = sci_name_short.split(' ')[0]
            scale_note, octave = split_chars_and_ints(sci_name_short, '[a-zA-Z♯♭]+')

            notes[key_nr] = {'frequency': frequency, 'octave': octave, 'scale_note': scale_note}

    frequencies = sorted(frequencies)
    # pprint(frequencies)
    min_frequency = frequencies[0]
    frequency_ranges = {}
    for i, frequency in enumerate(frequencies[:-1]):
        max_frequency = round((frequencies[i+1] +frequencies[i])/2, 2)
        frequency_ranges[frequency] = {'min_hz': min_frequency, 'max_hz': max_frequency}
        # print(frequency, max_frequency)
        min_frequency = max_frequency
    frequency_ranges[frequencies[-1]] = {'min_hz': max_frequency, 'max_hz': frequencies[-1]}

    # pprint(frequency_ranges)
    for key, value in notes.items():
        if value['frequency'] in frequency_ranges.keys():
            notes[key]['range_hz'] = frequency_ranges[value['frequency']]

    pprint(notes)
    pickle_it(piano_frequencies_pickle, notes)