Code Monkey home page Code Monkey logo

pypianoroll's People

Contributors

adamoudad avatar flandolfi avatar george-ogden avatar salu133445 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pypianoroll's Issues

Problems displaying piano roll at a given size

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?

Failed to create Multitrack for some midi files

First, thanks for your awesome project!

pm.time_signature_changes[idx+1])

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'

pypianoroll.parse() is skipping the first notes

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

Shape of downbeat and tempo array does not fullfil requirements of multitrack.validate()

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.

Change interpolation mode to "antialiased"

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.

ValueError using pypianoroll.to_pretty_midi with a Multitrack object

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'

Save and write a Standardtrack object

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

Understanding creating a clipped, binarized piano roll

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!

The copy method for StandardTrack Class changes the new object's type of class

截图_20214703114731
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.
截图_20210103120147
So once you call the copy method, you will create a Track object, even if the original track is a StandardTrack or BinaryTrack object.

Possible memory leaks with pypianoroll.load()

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.

multitrack.write("xxx.mid") can't work after 1.0+ versions

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?

Support tempos and time signatures in MIDI output

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.

Issue with version

Hello, Where is the function get_ merged_pianoroll() in Multitrack in 0.1.3 version, I can't find it in the new one

LPD files cannot be read anymore : 'beat_resolution' update

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) ?

Unexpected location for function plot_multitrack()

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'

Multitrack plotting does not work with mode='stacked'

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()

How to differentiate between a note pressed continuously and repeatedly?

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.