salu133445 / pypianoroll Goto Github PK
View Code? Open in Web Editor NEWA toolkit for working with piano rolls
Home Page: https://salu133445.github.io/pypianoroll/
License: MIT License
A toolkit for working with piano rolls
Home Page: https://salu133445.github.io/pypianoroll/
License: MIT License
Hello,
Firstly I am very new to this, someone has told me of your work.
I am able to create piano roll, but cannot seem to display it other than at 640x480 size. I have tried for a very long time, but cannot seem to be able to use a defined "figure":
fig = plt.figure('10.5,4.8')
I always get 640x480 when I issue plt.plot command.
Are there any worked examples of this I can look at please?
First, thanks for your awesome project!
pypianoroll/pypianoroll/multitrack.py
Line 752 in c436465
Should it be pm.time_signature_changes[idx+1].time
at this line?
Traceback (most recent call last):
File "/Users/dorian/.anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 57, in _wrapfunc
return getattr(obj, method)(*args, **kwds)
TypeError: '<' not supported between instances of 'TimeSignature' and 'TimeSignature'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "test.py", line 6, in <module>
mt = ppr.Multitrack('1_15c2c8fe4f85f63fe32e8830c4a274fd.mid')
File "/Users/dorian/.anaconda3/lib/python3.6/site-packages/pypianoroll/multitrack.py", line 84, in __init__
self.parse_midi(filepath)
File "/Users/dorian/.anaconda3/lib/python3.6/site-packages/pypianoroll/multitrack.py", line 644, in parse_midi
collect_onsets_only, threshold, first_beat_time)
File "/Users/dorian/.anaconda3/lib/python3.6/site-packages/pypianoroll/multitrack.py", line 754, in parse_pretty_midi
pm.time_signature_changes[idx+1])
File "/Users/dorian/.anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 1075, in searchsorted
return _wrapfunc(a, 'searchsorted', v, side=side, sorter=sorter)
File "/Users/dorian/.anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 67, in _wrapfunc
return _wrapit(obj, method, *args, **kwds)
File "/Users/dorian/.anaconda3/lib/python3.6/site-packages/numpy/core/fromnumeric.py", line 47, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: '<' not supported between instances of 'TimeSignature' and 'TimeSignature'
Hi all and thank you for this very handy module!
I am facing an issue, I have some midi files which, once imported with pypianoroll, have the first notes skipped.
Please use the attached midi file to reproduce the error.
Code to reproduce the error:
import pypianoroll
import matplotlib.pyplot as plt
k = pypianoroll.parse("chor-038.mid")
k.plot()
plt.show()
By the way it happened with a number of files.
Thank you by advance!!
chor-038.mid.zip
pypianoroll/pypianoroll/multitrack.py
Line 730 in afff439
Hello, this line should be arg_sorted = np.argsort(tc_times)
.
Consider the following code:
import pypianoroll as pproll
from pretty_midi import PrettyMIDI
mt = pproll.from_pretty_midi(midi=PrettyMIDI(path_to_midi), resolution=custom_resolution)
mt.validate()
Calling mt.validate()
will always raise ValueError("'tempo' must be a 1D NumPy array.")
and ValueError("'downbeat' must be a 1D NumPy array.")
as both arrays have a shape similar to (timestep_count, 1)
instead of (timestep_count,)
This should not be the case, as one would expect, that validating a just imported MIDI should raise no errors.
When calling multitrack.plot()
with a lower dpi, some notes disappear since interpolation is set to "none" when calling plt.imshow()
. To avoid this issue, we should use interpolation="antialiased"
by default.
Greetings:
I am getting the following error:
ValueError: Expect BinaryTrack or StandardTrack, but got <class 'pypianoroll.track.Track'>.
checking the class of my variable using a dunder method I am getting the following type:
pypianoroll.multitrack.Multitrack
when using the suggested values (BinaryTrack or StandardTrack) I am getting the following error:
AttributeError: object has no attribute 'tempo'
Hello and thank you for freely providing us this great work!
I am using a 5 track midi. I can use read() function to read it as a multitrack object. Also I am able to save it to .npz and I can recreate a midi file using write function.
I would like to save each track in different .npz files, and also create different .midi files for each track. When I try to save a track
I get this error:
AttributeError: 'StandardTrack' object has no attribute 'resolution'
When I try to write a track to midi I get this error:
AttributeError: 'StandardTrack' object has no attribute 'tempo'
Is there a way I could do this?
Thank you in advance,
Chris
In your documentation, you show the clip()
and the binarize function (binarize()
).
I have trouble understanding the output. My goal is to create a binary piano roll with the 16th note as the shortest allowed note, and limit the pitch from C0 to C8 (24-108). For every time stamp, the value should be 1 iff the note is played, and 0 otherwise. Thus, my desired output shape is (num_tracks, time_steps, 84), with the 84 being a multi-hot vector indicating if a pitch is played at a time step.
The following code is my attempt, the sample_file
is
sample.zip
#read midi, set shortest note duration to sixteenth note
multitrack = pypianoroll.read(sample_file, resolution=16) #set resolution to 16th note
#clip to range note pitches C0 to C8
clipped_multitrack = clipped = multitrack.clip(24, 108)
#get pianoroll for all tracks
normal_pianoroll = clipped_multitrack.stack()
print(normal_pianoroll.shape)
print(normal_pianoroll[0][0])
The output is
(4, 3264, 128)
[24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 49
24 24 24 24 24 24 49 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24 24
24 24 24 24 24 24 24 24]
What is the 24 standing for? And why is the last channel 128, and not 108-24=84, as I have clipped the pitch range?
To binarize, I run:
#binarize
binarized_multitrack = clipped_multitrack.binarize()
binary_pianoroll = binarized_multitrack.stack()
print(binary_pianoroll.shape)
print(binary_pianoroll[0][0])
for which the output is:
(4, 3264, 128)
[ True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True True True True True
True True True True True True True True]
Why is the last channel always "True", does that indicate that every pitch is always played?
Thanks in advance for your help in clarifying things!
If you want to deepcopy an object of MultiTrack, the type of class for every track in the object will change into Track, no matter they are StandardTrack or BinaryTrack objects before.
Because in source code, the copy method for StandardTrack and BinaryTrack is inherit from the super class Track, and it is not overrided.
So once you call the copy method, you will create a Track object, even if the original track is a StandardTrack or BinaryTrack object.
Memory usage gradually increases when processing many files with pypianoroll, especially buffer memory (does not clear after program terminates). Maybe file buffers aren't being closed properly when reading files? This causes some serious slow downs and even corrupted files on my computer.
windows10+anaconda3+pycharm2020.3环境,照作者指示安装了,请问如何调试运行?
In inputs.from_pretty_midi
, setting the kwarg mode="max"
sums velocities and setting it to "sum"
preserves only the maximum.
pypianoroll/pypianoroll/inputs.py
Lines 308 to 314 in 18a68d4
In new version, multitrack.tempo needs to be a np.ndarray. However, the codehere directly judges np.ndarray which will return an error "ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
Maybe what we need here is
... elif multitrack.tempo is not None: ...
In addition, after fixing this error, a new error have arisen in pretty-midi.
Both python3.8 and python3.6 have above errors.
Is it my environment that causes these problems?
The current implementation of to_pretty_midi
does not support tempos and time signatures. We should convert the tempo array into tempo change events and the downbeat array into time signature events.
Hello, Where is the function get_ merged_pianoroll() in Multitrack in 0.1.3 version, I can't find it in the new one
Hi,
first of all thanks for your work, this library have been very useful to me.
Since the 1.0.0 update when loading a npz file pypianoroll will look for the 'resolution' instead of 'beat_resolution' previously, all the npz files from the LPD dataset cannot be read anymore.
I fixed this by editing pypianoroll to read either 'resolution' and 'beat_resolution' attributes but this can't be considered as a permanent fix.
Anyway I was wondering if you intended to update the LPD dataset (I think I can do it on my own but didn't take the time to do it yet) ?
For some reason pypianoroll.plot.plot_multitrack()
cannot be found. Instead, it is in pypianoroll.multitrack.plot_multitrack()
, which is a bit different from documentation.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-137-238f3cd64c5c> in <module>
19 # plt.show()
20
---> 21 fig, axs = pypianoroll.plot.plot_multitrack(multitrack, xtick='step', mode='stacked')
22 fig.set_size_inches(200, 5)
23 plt.show()
AttributeError: 'function' object has no attribute 'plot_multitrack'
Hello Hao-wen. I find the number of tracks are different by pypianoroll and pretty-midi on a number of files. I assume they should have the same track number because pypinaoroll is based on pretty-midi data. I attach one file with that issue for your reference. Thanks.
For some reason when I try to plot multitrack in stacked
mode, this happens:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-136-3da8578445a1> in <module>
19 # plt.show()
20
---> 21 fig, axs = pypianoroll.multitrack.plot_multitrack(multitrack, xtick='step', mode='stacked')
22 fig.set_size_inches(200, 5)
23 plt.show()
~/anaconda3/lib/python3.7/site-packages/pypianoroll/plot.py in plot_multitrack(multitrack, filename, mode, track_label, preset, cmaps, xtick, ytick, xticklabel, yticklabel, tick_loc, tick_direction, label, grid, grid_linestyle, grid_linewidth)
469
470 fig, ax = plt.subplots()
--> 471 stacked = multitrack.get_stacked_pianorolls()
472
473 colormap = matplotlib.cm.get_cmap(cmaps[0])
AttributeError: 'Multitrack' object has no attribute 'get_stacked_pianorolls'
I looked through the docs and it seems it's a typo in pyplot.plot.plot_multitrack()
, because indeed Multitrack class has a function get_stacked_pianoroll()
, not get_stacked_pianorolls()
I am following your "Getting Started" section here:
!pip install pypianoroll
import numpy as np
import pypianoroll
from pypianoroll import Multitrack, Track
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
plt.rcParams["figure.figsize"] = (20,3)
import seaborn as sns
# Create a piano roll matrix, where the first and second axes represent time
# and pitch, respectively, and assign a C major chord to the piano roll
pianoroll = np.zeros((96, 128))
example_1 = [60]
pianoroll[0:10, example_1] = 100
for i in range(10):
pianoroll[i, [70]] = 100
# Create a `pypianoroll.Track` instance
track = Track(name="Piano", program=0, is_drum=False,
pianoroll=pianoroll)
# Plot the piano roll
ax = track.plot()
plt.savefig("single_track.png", dpi=100)
plt.show()
How can one differentiate between a note kept pressed over a long duration (e.g. one bar), and a note played repeatedly over the same time range?
Consider a 4/4 signature, with 16 notes of 16th duration. They would be stroked repeatedly. Now, for the same bar, one could hold a whole note, which in terms of duration is the same as 16 16th notes.
How and where can this difference be modeled? In my code I tried to set the note individually at every step, but they get merged into a note hold over the according duration.
Thanks for your help!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.