-
Notifications
You must be signed in to change notification settings - Fork 151
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
get_piano_roll sustains some notes too long #242
Comments
So,... no doubt my own code below is not sophisticated enough for general purposes, but for now, I am able to recover something that "looks right" using a simple bit of code, which is suitable for my current purposes of 'MELODY', 'PIANO', and 'TOTAL' instruments. The plot now shows distinct notes. This is the code I used: def get_piano_rolls2(midi, fs):
duration = midi.get_end_time()
n_frames = int(np.ceil(duration * fs))
# create a piano roll for each instrument
piano_rolls = {'PIANO': np.zeros((128, n_frames)),
'MELODY': np.zeros((128, n_frames)),
'TOTAL': np.zeros((128, n_frames))}
for instrument in midi.instruments:
name = instrument.name.upper()
if name in ['MELODY', 'PIANO']:
print(f"get_piano_rolls: instrument.name = {name}")
for note in instrument.notes:
start = int(np.floor(note.start * fs))
end = int(np.ceil(note.end * fs))
piano_rolls[name][note.pitch, start:end] = note.velocity
piano_rolls['TOTAL'][note.pitch, start:end] = note.velocity
if name == 'PIANO': plot_piano_roll(piano_rolls[name])
return piano_rolls |
Hi, unfortunately I don't have time to debug this directly but I highly suspect it has to do with different conventions as to how to handle a note off event after repeated note on events (e.g. you get a note on at note N on channel C, another note on for note N on channel C, and then a note off for note N at channel c). There are (at least) thre ways to handle it:
IIRC |
While I still think that the current In the Magenta notebook and in LogicPro (and your example), pedaling is not taken into account at all for the piano display. |
Hi Colin! I see a number of issues and PRs related to
get_piano_roll()
, yet I'm not sure which of them my issue fits best with so I'm opening a new one:I notice many notes in the piano roll are sustained for much longer than they should be, resulting in long horizontal lines, independent of the choice for
fs
.For example, here is a
plt.imshow()
for theget_piano_roll
output for piano instrument in file number028/028.mid
in the POP909 Dataset:The same part displayed in Logic Pro looks different; it does not have the long horizontal lines:
![Screenshot 2024-02-17 at 7 30 15 PM](https://private-user-images.githubusercontent.com/13925685/305679370-aad58f05-ec3e-4a35-8c29-35804392f3fc.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU2ODAyMzYsIm5iZiI6MTcyNTY3OTkzNiwicGF0aCI6Ii8xMzkyNTY4NS8zMDU2NzkzNzAtYWFkNThmMDUtZWMzZS00YTM1LThjMjktMzU4MDQzOTJmM2ZjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA3VDAzMzIxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU0ODI5Mjc0NzFlNWY4MGI5ODc4ZTQ4YmUyMjU4NmVmMGNiYWQyNWNkZmE0MTFjOGY1YzkwYzM0NmUzZGYxMmMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.WBTKmvOPPm0vvu8nRSC9u_YvRSyypqT58QUofXWpr-0)
Also, when I plot it using the method from the Magenta music_generation.ipynb Colab Notebook, there are no long horizontal lines:
![pr_long_way](https://private-user-images.githubusercontent.com/13925685/305679404-73538e08-6942-4ebc-8722-a64469a0f93c.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjU2ODAyMzYsIm5iZiI6MTcyNTY3OTkzNiwicGF0aCI6Ii8xMzkyNTY4NS8zMDU2Nzk0MDQtNzM1MzhlMDgtNjk0Mi00ZWJjLTg3MjItYTY0NDY5YTBmOTNjLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDclMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTA3VDAzMzIxNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQyZDRmODUzMjE3Y2ZjNTljZjczNzc1ZGM3MjQwNTliMWI0ODdlYjgzYTY2OTZkZGMzNmFlMDZlOWY1NjRlN2MmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.dgzMJgfHHNkH6dgZNEdcVJD218EF4uH1Ss6HDCRahnA)
I've tried different
fs
values (from 4 to 1000) and different image sizes to see if the long horizontal lines in the first image are just some sort of plotting artifact, but... I can't get rid of them.This issue applies to both the
instrument.get_piano_roll()
and the fullpm.get_piano_roll()
.The issue applies to several other files in that POP909 dataset, e.g.
028, 030, 038, 039, 040, 046, 047, 050, 052, 057, 061, 064, 065, 066, 068
,... I stopped counting. Logic and other viewers show them ok, butget_piano_roll
seems to incorrectly sustain notes for many, many measures.Is there something I'm doing wrong that 's leading to the "long horizontal lines"? I'd like an array that reflects something more like from the other two plotting methods.
Thanks!
The text was updated successfully, but these errors were encountered: