11
11
get_subdivisions ,
12
12
TimingConsts
13
13
)
14
- from musicaiz .structure import Note
14
+ from musicaiz .structure import Note , Instrument
15
15
16
16
17
17
COLOR_EDGES = [
@@ -131,13 +131,12 @@ def _add_new_bar_subdiv(subdivisions):
131
131
"ticks" : subdivisions [- 1 ]["ticks" ] + range_ticks ,
132
132
})
133
133
134
- def _notes_loop (self , notes : List [Note ], show_pitch_labels : bool = True ):
134
+ def _notes_loop (self , notes : List [Note ]):
135
135
plt .ylabel ("Pitch" )
136
136
#highest_pitch = get_highest_pitch(track.instrument)
137
137
#lowest_pitch = get_lowest_pitch(track.instrument)
138
138
# plt.ylim((0, (highest_pitch - lowest_pitch) - 1))
139
139
140
- pitches = []
141
140
for note in notes :
142
141
plt .vlines (x = note .start_ticks ,
143
142
ymin = note .pitch ,
@@ -226,14 +225,14 @@ def _notes_loop(self, notes: List[Note]):
226
225
x0 = note .start_ticks ,
227
226
y0 = note .pitch ,
228
227
x1 = note .end_ticks ,
229
- y1 = note .pitch + 1 ,
228
+ y1 = note .pitch + 1 ,
230
229
line = dict (
231
230
color = COLOR_EDGES [0 ],
232
231
width = 2 ,
233
232
),
234
233
fillcolor = COLOR [0 ],
235
234
)
236
-
235
+
237
236
# this is to add a hover information on each note
238
237
self .fig .add_trace (
239
238
go .Scatter (
@@ -246,23 +245,22 @@ def _notes_loop(self, notes: List[Note]):
246
245
],
247
246
y = [
248
247
note .pitch ,
249
- note .pitch + 1 ,
250
- note .pitch + 1 ,
248
+ note .pitch + 1 ,
249
+ note .pitch + 1 ,
251
250
note .pitch ,
252
251
note .pitch
253
- ],
252
+ ],
254
253
fill = "toself" ,
255
254
mode = "lines" ,
256
- name = f"pitch={ note .pitch } <br>\n " \
257
- f"velocity={ note .velocity } <br>\n " \
258
- f"start_ticks={ note .start_ticks } <br>\n " \
255
+ name = f"pitch={ note .pitch } <br>\n "
256
+ f"velocity={ note .velocity } <br>\n "
257
+ f"start_ticks={ note .start_ticks } <br>\n "
259
258
f"end_ticks={ note .end_ticks } <br>" ,
260
259
opacity = 0 ,
261
260
showlegend = False ,
262
261
)
263
262
)
264
263
265
-
266
264
def plot_grid (self , subdivisions ):
267
265
# all the pitch values to be written in the axis
268
266
#self.fig.update_xaxes(range[0, len(subdivisions) - 1])
@@ -296,10 +294,9 @@ def plot_grid(self, subdivisions):
296
294
self .fig .add_vline (x = s ["ticks" ], line_width = 0.2 , line_color = "blue" )
297
295
prev_bar , prev_beat = s ["bar" ], s ["bar_beat" ]
298
296
299
-
300
297
def plot_instrument (
301
298
self ,
302
- track ,
299
+ track : Instrument ,
303
300
bar_start : int ,
304
301
bar_end : int ,
305
302
subdivision : str ,
@@ -309,7 +306,6 @@ def plot_instrument(
309
306
time_sig : str = TimingConsts .DEFAULT_TIME_SIGNATURE .value ,
310
307
bpm : int = TimingConsts .DEFAULT_BPM .value ,
311
308
resolution : int = TimingConsts .RESOLUTION .value ,
312
- print_measure_data : bool = True ,
313
309
show : bool = True
314
310
):
315
311
@@ -333,11 +329,11 @@ def plot_instrument(
333
329
total_bars = bar_end - bar_start
334
330
subdivisions = get_subdivisions (total_bars , subdivision , time_sig , bpm , resolution )
335
331
self .plot_grid (subdivisions )
336
-
332
+
337
333
# this is to add the yaxis labels# horizontal line for pitch grid
338
334
labels = [i for i in range (min (pitches ) - 1 , max (pitches ) + 2 )]
339
335
for pitch in labels :
340
- self .fig .add_hline (y = pitch + 1 , line_width = 0.1 , line_color = "white" )
336
+ self .fig .add_hline (y = pitch + 1 , line_width = 0.1 , line_color = "white" )
341
337
# if we do have too many pitches, we won't label all of them in the yaxis
342
338
if max (pitches ) - min (pitches ) > 24 :
343
339
cleaned_labels = [label for label in labels if label % 2 == 0 ]
@@ -357,7 +353,9 @@ def plot_instrument(
357
353
),
358
354
)
359
355
360
- self .fig .update_layout (legend = {"xanchor" :"center" , "yanchor" :"top" })
356
+ self .fig .update_layout (legend = {
357
+ "xanchor" : "center" , "yanchor" : "top"
358
+ })
361
359
362
360
if save_plot :
363
361
self .fig .write_html (Path (path , filename + ".html" ))
0 commit comments