Skip to content

Commit f161ab7

Browse files
author
Cannon Lock
committed
Temp
1 parent 74f33f4 commit f161ab7

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

DeepLearning.py

+19-7
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,21 @@ def train_network():
2626

2727
train(model, network_input, network_output)
2828

29-
def get_notes():
29+
def get_note_str(note, duration):
30+
return note.nameWithOctave + duration
31+
32+
def get_element_str(el, includeDuration):
33+
duration = "-" + str(round(float(el.quarterLength), 3)) if includeDuration else ""
34+
35+
if isinstance(el, note.Note):
36+
return get_note_str(el, duration)
37+
elif isinstance(el, note.Rest):
38+
return el.name + duration
39+
elif isinstance(el, chord.Chord):
40+
note_strings = [get_note_str(n, duration) for n in el.notes]
41+
return " ".join(sorted(note_strings))
42+
43+
def get_notes(includeDuration = False):
3044
""" Get all the notes and chords from the midi files in the ./midi_songs directory """
3145
notes = []
3246

@@ -44,11 +58,9 @@ def get_notes():
4458
except: # file has notes in a flat structure
4559
notes_to_parse = midi.flat.notes
4660

47-
for element in notes_to_parse:
48-
if isinstance(element, note.Note):
49-
notes.append(str(element.pitch))
50-
elif isinstance(element, chord.Chord):
51-
notes.append('.'.join(str(n) for n in element.normalOrder))
61+
for el in notes_to_parse:
62+
if isinstance(el, note.Note) or isinstance(el, chord.Chord) or isinstance(el, note.Rest):
63+
notes.append(get_element_str(el, includeDuration))
5264

5365
np.save("notes", notes)
5466

@@ -123,5 +135,5 @@ def train(model, network_input, network_output):
123135
model.fit(network_input, network_output, epochs=200, batch_size=128, callbacks=callbacks_list)
124136

125137
if __name__ == '__main__':
126-
get_notes()
138+
a = get_notes()
127139

0 commit comments

Comments
 (0)