-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
add new extension MIDI Parser #2035
base: master
Are you sure you want to change the base?
Conversation
The code doesn't even work |
|
But the code works fine on my end.How are you using it? |
oh wait nevermind, github mobile is just really messing up the display |
Can this code run normally on your side? |
i tried it on turbowarp |
the issue quite literally PREVENTS THE EXTENSION FROM LOADING |
Oh, sorry, it was my mistake. I duplicated "const MidiLibrary". It was my carelessness. I'll fix it right away. |
I have fixed the issue of duplicate declaration of "const MidiLibrary". |
@CHCAT1320 I added a pull request to your repo with a suggested change on how you import the tonejs/midi code. Do you think it'd make sense to merge this PR and my WebMidi one into the same extension? |
return 'MIDI library failed to load'; | ||
} | ||
|
||
const dataUrl = args.DATA_URL.trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should use cast: Scratch.Cast.toString(args.DATA_URL).trim()
midi.tracks.forEach((track, trackIndex) => { | ||
track.notes.forEach(note => { | ||
this.notesData.push({ | ||
track: trackIndex, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: consider outputting this as trackIndex + 1
since scratch indexes start at 1
instead of 0
noteName: note.name, | ||
startTime: note.time, | ||
duration: note.duration, | ||
velocity: note.velocity |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggestion: @tonejs/midi outputs a normalized value of 0-1. Consider scaling this to 0-100, since that seems to be standard scaling for scratch. (I have no preference personally)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I finished writing,I found there were no blocks for controlling note velocity,and the volume-control blocks were global.I intended to delete the velocity key.
Sure, it's my first time writing an extension, so there are many shortcomings. Thanks for your suggestions. Feel free to modify or reference it. |
// License: MIT | ||
|
||
|
||
// tonejs/midi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be a full comment block including link to the original code and maybe license text as well - check other extensions for examples
|
||
const dataUrl = args.DATA_URL.trim(); | ||
if (!dataUrl) { | ||
return 'MIDI Data URL is empty'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These error messages should probably be wrapped in Scratch.translate()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some suggestions / tips. See also the PR I passed in as well, which has fixes for some of the linting errors you're getting
Glad you're open to it. I can manage merging the changes together. Please don't hesitate to contribute to it! |
Parse MIDI files into JSON.