<jupyter_start><jupyter_text>[latex_cheat_sheet](http://tug.ctan.org/info/latex-refsheet/LaTeX_RefSheet.pdf)  [latex_cheat_sheet_2](https://wch.github.io/latexsheet/) Music Scales<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import notebook_helpers as nh

import pandas as pd # delete later
import noodler<jupyter_output><empty_output><jupyter_text>Notes:   - All formulae should be in metric  - Avoid prefixes - Music is about opinions and this notebook is full of mine, be your own judge on your path [Fundamentals](fundamentals)  [Note to Frequency](notetofrequency)  [Intervals](intervals)  [Circle of Fifths and Fourths](circles)  [Scales](scales)  [Chords](chords)  [Keys](keys)   Fundamentals Sharps and Flats Western scales are generally in semitones.  Quarter steps are ignored/commonly found in Eastern music A note can either be flat, sharp, or natural  Sharp _notes are higher in pitch than their natural counterparts  Flat _notes are lower in pitch than their natural counterparts  The term *enharmonic* refers to _notes that are the same fundamentally, but have different naming conventions.   For example, G == Fb (for an equal temperment tuning, which is what we're going to work with).  *TODO explain equal temperment. This is the second time I wrote this TODO.   Should probably, ya know, do it?*     What to remember     |   |  Symbol 	|   Pitch (relative to natural/normal)	|   	||---	|---	|---	|---	||  Sharp 	|   	|   up	|   	||   Flat	|   b	|   down	|   	| I'm sure there's a good reason they both exist, but I prefer sharps as they are visually easier to indicate.  If you like flats more, then I'd say you aren't the *sharpest* tool in the shed. See what I did there? Get it? It's a real knee slapper for ya!<jupyter_code>noodler.musack._notes
noodler._make_note_list('g#')
noodler._make_note_list('g#',only_natural=True)<jupyter_output><empty_output><jupyter_text>Keep in mind the musical alphabet doesn't follow lexicographical/typical alphabetical order.  The musical alphabet starts at C and ends on B.  So to get the musical alphabet, we can use the above function, `_make_note_list`  But pass it the letter `C` to start the list and thus alphabet, there:<jupyter_code>noodler._make_note_list('c')<jupyter_output><empty_output><jupyter_text>Two convenience functions for ingesting a note and converting it to/from a sharp () or flat (b)<jupyter_code>noodler._sharp_to_flat('G#')
noodler._flat_to_sharp('ab')<jupyter_output><empty_output><jupyter_text>Syntax/Naming Conventions In music world, things (whether it be _notes, chords, scales, etc.) follow a couple rules of thumb:- if the letter `m` or a roman numeral is capitolized, it is major/happy  - as if opposed to those other ones that are socialized and sad/unhappy    - these are commonly referred to as "lower class" or "lower case" and are minor    For example, if you see something like `m3`, it would be a minor third<jupyter_code>noodler.musack._roman_dict<jupyter_output><empty_output><jupyter_text>Throughout this notebook/library,  When referring to _notes, we can use either:- just note name   - ex: g, a, fb- scientific pitch notation  - these are note name followed by the octave  - ex: g3, a4, c-1  Below is a function that makes dealing with them simple.  It splits the note and returns a `tuple` [python object for holding things] that contains note name and octave.  If there is no octave, octave is replace with `None`<jupyter_code>noodler.split_note('g3')<jupyter_output><empty_output><jupyter_text>Note to Frequency Using standard A is 440Hz.  Defined by an ISO standard if you care  This is the A note *above* middle C  Middle C is C in the 3rd octave or C3.  So A 440Hz, is A4.<jupyter_code>a4 = 440<jupyter_output><empty_output><jupyter_text>Octave means frequency doubles.  So A5 is:<jupyter_code>a5 = a4*2
a5<jupyter_output><empty_output><jupyter_text>There is equal spacing (frequency wise) between the 12 _notes  I think this is why it's called equal tempormant or something like that?  Should double check  So the ratio between _notes is equal: TODO Describe difference to just tempormant > $\frac{f1}{f0}={r}$   and > $\frac{f2}{f1}={r}$  and > $\frac{f2}{f0}={r}^{2}$  If you keep following this/solve it out,  this becomes a power series where  > $\frac{f12}{f0}={r}^{12}$ Since we know the 12th note is an octave, and an octave means a doubling of frequency,  We now can say:  > $\frac{f12}{f0}={r}^{12}={2}$ So: > ${r}={2}^\frac{1}{12}$  or  > ${r}=\sqrt[12]{2}$   Reference: [twelth root of two](https://en.wikipedia.org/wiki/Twelfth_root_of_two) So getting a new frequency using this ratio would give:> $f_{new}={f_0}\cdot{r}$ To get the frequency at a new note, if we know the distance in semitones from the fundamental $n$, we can derive $r$ as:> ${r}={2}^\frac{n}{12}$<jupyter_code>noodler.r
noodler.magic_number<jupyter_output><empty_output><jupyter_text>TODO where did this magic number come from?  As in, why the tits is it here? Using 440Hz as our fundamental, $f_0$ we can now right it as:> $f_{new}={440}\cdot{2}^\frac{n}{12}$   Remember 440 is A4, but the musical alphabet starts at C, so we must take into account that C is actually 9 semitones from the next octaves A  > $f_{new}={440}\cdot{2}^\frac{(n-9)}{12}$<jupyter_code>noodler.note_to_frequency('a',4)
noodler.note_to_frequency('e',2)
noodler.note_to_frequency('e',6)
noodler.note_to_frequency('a',-1)
noodler.note_to_frequency('a4')
noodler.note_to_frequency('a0')
noodler.note_to_frequency('d9')
noodler.note_to_frequency('e9')
noodler.note_to_frequency('e10')
noodler.note_to_frequency('a10')
noodler.note_to_frequency("a#-1")
noodler.note_to_frequency('a#4')<jupyter_output><empty_output><jupyter_text>So there are about 9 octaves of audible sound Step sizes Semitone step sizes:    Think going from a sharp to a natural is a _half step, or distance of 1<jupyter_code>noodler._whole_step
noodler._half_step<jupyter_output><empty_output><jupyter_text>Intervals In the following dict, the useful intervals used are listed  Note use of P, it stands for perfect.  There's some ratio that attempts to rationalize why they are 'perfect'.  Should probably put that here. Fun fact:  Playing a tritone was banned in church's at one point in time. People thought that this unpleasant interval was witch craft and an attempt to summon the devil.<jupyter_code>noodler.intervals<jupyter_output><empty_output><jupyter_text>`_decompose_interval`<jupyter_code>noodler._decompose_interval("M3")<jupyter_output><empty_output><jupyter_text>`notes_for_interval`<jupyter_code>noodler.notes_for_interval('G','M7')<jupyter_output><empty_output><jupyter_text>`interval_for_notes`<jupyter_code>noodler.interval_for_notes('f5','f6')
noodler.interval_for_notes('c3','b3')
noodler.interval_for_notes('b','d')<jupyter_output><empty_output><jupyter_text>`add_interval`<jupyter_code>noodler.add_interval('g',3)
noodler.add_interval('g#2','m7')
noodler.add_interval('b2','M2')
noodler.add_interval('b2','M2+o')
noodler.add_interval('b2','-M2-o')<jupyter_output><empty_output><jupyter_text>Circle of Fifths Gives an easy to follow cheat sheet on making music<jupyter_code>circ, order = noodler.make_circle_of_fifths()
print('circle of fifths: ',circ)
print('order of _notes to become sharp: ',order)<jupyter_output>circle of fifths:  ['c', 'g', 'd', 'a', 'e', 'b', 'f#']
order of _notes to become sharp:  ['f', 'c', 'g', 'd', 'a', 'e', 'b']<jupyter_text>Lets say we want to know about the key of E major:<jupyter_code>circ.index('e')<jupyter_output><empty_output><jupyter_text>So we need 4 _notes to become sharp.  Now lets use the same circle and determine what those _notes are:<jupyter_code>order[:circ.index('e')]<jupyter_output><empty_output><jupyter_text>Go look up the key of E major. 10 doll hairs says f, c, g, and d are made sharp. You can go the other direction and make the circle out of fourths.  This is the wrong direction though as it gives you how to make scales with flats.<jupyter_code>circ, order = noodler.make_circle_of_fourths()
print('circle of fourths: ',circ)
print('order of _notes to become flat: ',order)<jupyter_output>circle of fourths:  ['c', 'f', 'bb', 'eb', 'ab', 'db', 'gb']
order of _notes to become flat:  ['b', 'e', 'a', 'd', 'g', 'c', 'f']<jupyter_text>Lets say we want to know about the key of Ab major:<jupyter_code>circ.index('ab')<jupyter_output><empty_output><jupyter_text>So we need 4 _notes to become flat.  Now lets use the same circle and determine what those _notes are:<jupyter_code>order[:circ.index('ab')]<jupyter_output><empty_output><jupyter_text>Scales Most scales are 8 long  Take your bebop elsewhere troll<jupyter_code>noodler.scales
noodler.get_numerals_of_scale('minor')
noodler.get_scale_of_mode('dorian')
noodler.make_scale(('g#','phrygian'))
noodler.make_scale(('e','minor'))<jupyter_output><empty_output><jupyter_text>Look a function can now make a scale for us.  This is exactly what artificial intelligence is.  We are teaching a program to learn how to make music.<jupyter_code>noodler.get_major_scale_by_circle('g')<jupyter_output><empty_output><jupyter_text>Chords Starting with just triads  Will expand once I know where to go with this stuff<jupyter_code>noodler.chords_df
noodler.make_chord(('g','minor'))<jupyter_output><empty_output><jupyter_text>Chords in a Key Simplest way to find the root note for chords in a key is by use of the circle of fifths  Here is a simple function that gets the 3 major chords in a major key by use of the circle of fifths  Note: the 4(IV) and 5(V) chord root _notes are next to the keys root note on the circle of fifths. Pretty neat-o<jupyter_code>noodler.get_chords_root_note_for_major_key_by_circle('e')<jupyter_output><empty_output><jupyter_text>A slightly more complicated function:  This implies you know the order of major, minor, and diminished in a major key though. :(<jupyter_code>noodler.get_chords_for_major_key('c')<jupyter_output><empty_output><jupyter_text>Make function to now find the chord given the intervals<jupyter_code>noodler.get_chord_type_by_intervals(('m3','P5'))
noodler.get_chord_type_by_intervals(('m3','P4'))<jupyter_output><empty_output><jupyter_text>Now make a function that can ingest _notes, find those intervals, then finds the chord type<jupyter_code>noodler.get_chord_type(['g2','b2','d3'])<jupyter_output><empty_output><jupyter_text>Get the chords in a given key.  Horribly named.<jupyter_code>noodler.get_chords_for_key(('g','major'))
noodler.get_chords_for_key(('f#','locrian'))<jupyter_output><empty_output><jupyter_text>Keys<jupyter_code>noodler.make_key(('f#','locrian'))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1102643710603067, 'fraction_numerical': 0.011760278483394487, 'mean_word_length': 6.2312925170068025, 'pattern_counts': {'":': 0, '<': 123, '<?xml version=': 0, '>': 134, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 1, 'zh_pornsignals.json': 0}}
{'chain_length': '31', 'dir': 'jupyter-structured-clean-dedup', 'id': '629778', 'license': 'MIT', 'n_tokens_mistral': 3752, 'n_tokens_neox': 3621, 'n_words': 1140, 'path': 'notebooks/musack.ipynb', 'repo_name': 'farrrell504/Noodler', 'size': '10629'}