<jupyter_start><jupyter_text>Chapter 7: Compose Downloading DataBelow is my own implementation of the notebook where we learn about the notation for music data. You can find midi files for Bach's Cello Suites [here](http://www.jsbach.net/midi/midi_solo_cello.html). Below we download a music file from the site using `wget`.<jupyter_code>!wget http://www.jsbach.net/midi/cs1-2all.mid<jupyter_output><empty_output><jupyter_text>Playing the MusicI will be playing the midi files by converting them to .wav files using [FluidSynth](http://www.fluidsynth.org/).<jupyter_code>!apt install fluidsynth
!cp /usr/share/sounds/sf2/FluidR3_GM.sf2 ./font.sf2
!fluidsynth -ni font.sf2 cs1-2all.mid -F output.wav -r 1000
from IPython.display import Audio
from scipy.io import wavfile

rate, data = wavfile.read('output.wav')
Audio(data.T, rate=rate, autoplay=True)<jupyter_output><empty_output><jupyter_text>Musical NotationWe use the `music21` package to parse the midi files.<jupyter_code>from music21 import converter

original_score = converter.parse('cs1-2all.mid').chordify()
original_score.show('text')
from music21 import chord, note

notes = []
durations = []

for el in original_score.flat:
  if isinstance(el, chord.Chord):
    notes.append('.'.join(n.nameWithOctave for n in el.pitches))
  elif isinstance(el, note.Note):
    if el.isRest:
      notes.append(str(el.name))
    else:
      notes.append(el.nameWithOctave)
  durations.append(el.duration.quarterLength)
print('\nduration', 'pitch')
for n, d in zip(notes, durations):
    print(d, '\t', n)<jupyter_output>duration pitch
0.0 	 B3
0.0 	 G2.D3.B3
0.0 	 B3
0.0 	 A3
3.75 	 G3
0.0 	 F#3
0.25 	 G3
1.0 	 D3
0.25 	 E3
0.25 	 F#3
0.25 	 G3
0.25 	 A3
0.25 	 B3
0.25 	 C4
0.25 	 D4
0.25 	 B3
0.25 	 G3
0.25 	 F#3
0.25 	 G3
0.25 	 E3
0.25 	 D3
0.25 	 C3
0.25 	 B2
0.25 	 C3
0.25 	 D3
0.25 	 E3
0.25 	 F#3
0.25 	 G3
0.25 	 A3
0.25 	 B3
0.25 	 C4
0.25 	 A3
0.25 	 G3
0.25 	 F#3
0.25 	 G3
0.25 	 E3
0.25 	 F#3
0.25 	 G3
0.25 	 A2
0.25 	 D3
0.25 	 F#3
0.25 	 G3
0.25 	 A3
0.25 	 B3
0.25 	 C4
0.25 	 A3
0.25 	 B3
0.25 	 G3
0.25 	 G3
0.25 	 D3
0.25 	 D3
0.25 	 B2
0.25 	 B2
0.25 	 G2
0.25 	 G2
0.25 	 B3
0.25 	 C4
0.25 	 B3
0.25 	 A3
0.25 	 G3
0.75 	 A3
0.25 	 B3
0.25 	 C4
0.25 	 A3
0.25 	 G3
0.25 	 F#3
0.25 	 G3
0.25 	 A3
0.25 	 E-3
0.25 	 C4
0.25 	 B3
0.25 	 A3
0.25 	 G3
0.25 	 F#3
0.75 	 G3
0.25 	 E3
0.25 	 E3
0.25 	 B2
0.25 	 B2
0.25 	 G2
0.25 	 G2
0.25 	 E2
0.25 	 E2
0.25 	 B2
0.25 	 E3
0.25 	 G3
0.25 	 F#3
0.25 	 A3
0.75 	 G3
0.25 	 F#3
0.25 	 E3
0.25 	 F#3
0.25 	 G3
0.25 	 C#4
0.25 	 G3
0.25 	 F#3
0.25 	 G3[...]
{'fraction_non_alphanumeric': 0.11945525291828794, 'fraction_numerical': 0.15797665369649805, 'mean_word_length': 2.4417670682730925, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '453310', 'license': 'Apache-2.0', 'n_tokens_mistral': 1470, 'n_tokens_neox': 1256, 'n_words': 336, 'path': '7-compose/Notation.ipynb', 'repo_name': 'DCtheTall/generative-deep-learning', 'size': '2570'}