Hi,
After finishing the Jazz_Solo assignment I downlaoded a .mid file online to create my own music. When creating the training and test set I get this error. Is the code only made for the Jazz file or did I do something wrong?
IndexError Traceback (most recent call last)
/opt/conda/lib/python3.7/site-packages/music21/stream/init.py in getitem(self, k)
402 try:
→ 403 match = self.elements[k]
404 except IndexError:
IndexError: tuple index out of range
During handling of the above exception, another exception occurred:
StreamException Traceback (most recent call last)
in
----> 1 X, Y, n_values, indices_values, chords = load_music_utils(‘data/orginal_metheny.mid’)
2 print(‘number of training examples:’, X.shape[0])
3 print(‘Tx (length of sequence):’, X.shape[1])
4 print(‘total # of unique values:’, n_values)
5 print(‘shape of X:’, X.shape)
~/work/W1A3/data_utils.py in load_music_utils(file)
18
19 def load_music_utils(file):
—> 20 chords, abstract_grammars = get_musical_data(file)
21 corpus, tones, tones_indices, indices_tones = get_corpus_data(abstract_grammars)
22 N_tones = len(set(corpus))
~/work/W1A3/preprocess.py in get_musical_data(data_fn)
133 def get_musical_data(data_fn):
134
→ 135 measures, chords = __parse_midi(data_fn)
136 abstract_grammars = __get_abstract_grammars(measures, chords)
137
~/work/W1A3/preprocess.py in __parse_midi(data_fn)
26 midi_data = converter.parse(data_fn)
27 # Get melody part, compress into single voice.
—> 28 melody_stream = midi_data[5] # For Metheny piece, Melody is Part #5.
29 melody1, melody2 = melody_stream.getElementsByClass(stream.Voice)
30 for j in melody2:
/opt/conda/lib/python3.7/site-packages/music21/stream/init.py in getitem(self, k)
405 raise StreamException(
406 f’attempting to access index {k} ’
→ 407 + f’while elements is of size {len(self.elements)}’
408 )
409 # setting active site as cautionary measure
StreamException: attempting to access index 5 while elements is of size 2