Nokia123543 commited on
Commit
566ced7
·
verified ·
1 Parent(s): 3797eb0

fix: muscriptor_dynamics.py

Browse files
Files changed (1) hide show
  1. muscriptor_dynamics.py +11 -8
muscriptor_dynamics.py CHANGED
@@ -160,10 +160,11 @@ def read_midi(path):
160
  args = body[i:i + count]
161
  i += count
162
  if high == 0x90 and args[1] > 0:
163
- sounding[(channel, args[0])] = tick
164
  elif high == 0x80 or (high == 0x90 and args[1] == 0):
165
- start = sounding.pop((channel, args[0]), None)
166
- if start is not None:
 
167
  notes.append([start, tick - start, args[0], channel])
168
  else:
169
  if status is None:
@@ -174,14 +175,16 @@ def read_midi(path):
174
  args = body[i:i + count]
175
  i += count
176
  if high == 0x90 and args[1] > 0:
177
- sounding[(channel, args[0])] = tick
178
  elif high == 0x80 or (high == 0x90 and args[1] == 0):
179
- start = sounding.pop((channel, args[0]), None)
180
- if start is not None:
 
181
  notes.append([start, tick - start, args[0], channel])
182
 
183
- for (channel, pitch), start in sounding.items():
184
- notes.append([start, 0, pitch, channel])
 
185
 
186
  tempo.sort(key=lambda item: item[0])
187
 
 
160
  args = body[i:i + count]
161
  i += count
162
  if high == 0x90 and args[1] > 0:
163
+ sounding.setdefault((channel, args[0]), []).append(tick)
164
  elif high == 0x80 or (high == 0x90 and args[1] == 0):
165
+ stack = sounding.get((channel, args[0]))
166
+ if stack:
167
+ start = stack.pop(0)
168
  notes.append([start, tick - start, args[0], channel])
169
  else:
170
  if status is None:
 
175
  args = body[i:i + count]
176
  i += count
177
  if high == 0x90 and args[1] > 0:
178
+ sounding.setdefault((channel, args[0]), []).append(tick)
179
  elif high == 0x80 or (high == 0x90 and args[1] == 0):
180
+ stack = sounding.get((channel, args[0]))
181
+ if stack:
182
+ start = stack.pop(0)
183
  notes.append([start, tick - start, args[0], channel])
184
 
185
+ for (channel, pitch), stack in sounding.items():
186
+ for start in stack:
187
+ notes.append([start, 0, pitch, channel])
188
 
189
  tempo.sort(key=lambda item: item[0])
190