Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding creating a clipped, binarized piano roll #17

Open
Yannik1337 opened this issue Mar 8, 2021 · 0 comments
Open

Understanding creating a clipped, binarized piano roll #17

Yannik1337 opened this issue Mar 8, 2021 · 0 comments

Comments

@Yannik1337
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant