Skip to content

Commit 01d7018

Browse files
committed
Cleanup and add midi sample
1 parent 8a3f44c commit 01d7018

File tree

2 files changed

+1
-36
lines changed

2 files changed

+1
-36
lines changed

examples/midi.py

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def load_midi_sample(path):
2020
prev_time = 0.0
2121
for msg in midi_file:
2222
time += msg.time
23-
# print(msg)
2423
if msg.is_meta:
2524
if msg.type == 'set_tempo':
2625
global TEMPO
@@ -35,31 +34,10 @@ def load_midi_sample(path):
3534
notes.append(note)
3635

3736
notes = np.array(notes)
38-
# notes = notes[0:200]
3937

4038
notes = np.expand_dims(notes, axis=0)
4139
notes = np.expand_dims(notes, axis=0)
4240

43-
# notes = []
44-
# for msg in merge_tracks(midi_file.tracks):
45-
# time += msg.time
46-
# # print(msg)
47-
# if msg.is_meta:
48-
# if msg.type == 'set_tempo':
49-
# TEMPO = msg.tempo
50-
# print(TEMPO)
51-
# else:
52-
# if msg.channel == 0:
53-
# # TODO note_off
54-
# if msg.type == 'note_on':
55-
# note = msg.bytes()
56-
# note.append(msg.time)
57-
# notes.append(note)
58-
# notes = np.expand_dims(notes, axis=0)
59-
# notes = np.expand_dims(notes, axis=0)
60-
61-
print(midi_file)
62-
6341
return notes, midi_file.ticks_per_beat
6442

6543

@@ -89,7 +67,7 @@ def export_midi(notes, path, ticks_per_beat):
8967
grid_size = (1, 1, 200)
9068
pattern_size = (1, 1, 2)
9169

92-
sample, ticks_per_beat = load_midi_sample('../samples/Mario-Sheet-Music-Overworld-Main-Theme_RH.mid')
70+
sample, ticks_per_beat = load_midi_sample('../samples/twinkle_twinkle.mid')
9371

9472
print('sample shape:', sample.shape)
9573

pattern.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,6 @@ def is_compatible(self, candidate_pattern, offset):
5656
ok_constraint = False
5757
break
5858

59-
# Old code, only for 2D
60-
# start_x = max(offset[0], 0)
61-
# start_y = max(offset[1], 0)
62-
#
63-
# end_x = min(self.shape[0] + offset[0], self.shape[0])
64-
# end_y = min(self.shape[1] + offset[1], self.shape[1])
65-
# ok_constraint = True
66-
# for x in range(start_x, end_x):
67-
# for y in range(start_y, end_y):
68-
# if candidate_pattern.get((x - offset[0], y - offset[1])) != self.get((x, y)):
69-
# ok_constraint = False
70-
# break
71-
7259
return ok_constraint
7360

7461
def to_image(self):

0 commit comments

Comments
 (0)