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
losing instruments information when converting midi to note sequence #1464
Comments
Our MIDI conversion code preserves the concept of "instrument" (all events in a track with the same program and channel) and what MIDI program each instrument should have. Unfortunately, we do not specifically preserve MIDI channel, so when we convert from NoteSequence to MIDI, the channel assignment is arbitrary (but the programs should be correct). |
Thanks. So any advise how to use Magenta for this midi manipulation, keeping the consistancy of the midi channels ? |
@craffel am I correct in understanding that pretty_midi doesn't preserve this information? |
Yes, A simple workaround which I think should work is to add track name events to each of the channels. This name will propagate into the Instrument, and will be written out onto the instrument's channel when using |
Thanks for your answers. Actually, this functionality is required for my music program. I'm using DAW with third party sound (VST) libraries to create basic music tracks. Then, I export the midi files and use it within my python program. I'm doing midi manipulations as well as some AI stuff. All manipulations are done using Magenta and noteSequence. Then, I convert it back to midi and produce wave file with high quality, using this VST. I was trying to do direct conversion to wave using SF2 libraries, but the quality is not good enough so I have to use a better sampler. |
I'm sorry, I don't know what you mean. |
Looking at pretty_midi, in |
@cghawthorne will have to answer this, I'm not sure if note sequences use track names or not (and if not, why not).
I don't have any plans to add channel information to |
@cghawthorne I understand that changes to pretty_midi are not trivial; however I’ve spent tens hours working with Magenta for our project, and I really want to continue to use it, even more intensively. I couldn't come up with a workaround that can fit a long term solution. I would appreciate if you can help me find a workaround to maintain the midi channels information. I don’t mind to add any code at my side or contribute to Magenta. Thanks! |
I think the most straightforward thing to do would be to add an InstrumentInfo message to NoteSequence, similar to PartInfo. It could contain the track name from pretty_midi, indexed on instrument id. During conversion back to pretty_midi, that field could be used to populate the track name, which pretty_midi would then include in the midi file. Then, as long as your source has a track name that you can map to channel, all the information would be present. You could either modify whatever your output system is to use track name instead of channel, or add a post-processing step using Mido or something similar to remap the channels of the MIDI file based on their track names. I'd be happy to review a PR for adding the InstrumentInfo message and carrying the track name across. |
@cghawthorne thank you. I think it is a good solution. I'll be happy to write a PR (first contribution to Magenta :) ) for your review. |
@cghawthorne In order to test your approach I used PartInfo message and added the right functionality to midi_io.py in two places:
and:
I'm sure there is something I'm missing since I don't know which values to put in
Can you please advise what is the proper way to add message to NoteSequence? |
You should only need to modify the .proto file. The *pb2.py files are autogenerated by protobuf compiler. There are instructions in the README in the protobuf directory on how to install and run it. You can see some more information about protocol buffers here: https://developers.google.com/protocol-buffers/ |
Thank you for your help! I've just add a PR with InstrumentInfo message for your review. I changed the .proto file and add some functionality in midi_io.py. As I mentioned before, I checked it with my external code with additional logic for fixing the midi channel order, and it works. Thanks! |
Hello,
I'm doing manipulations on midi files using Magenta. I convert the midi file to NoteSequence using
The problem is that if I have unused midi channels (lets say 5 and 6) and used midi channels (lets say 7 and 8), the conversion put the used channels in place of empty ones, so I loose the instrument true setup, and when converting it back to midi and playing it with midi player, the instruments are mixed up. Any suggestion how to avoid this wrong conversion (only happens when there are some unused midi channels in the midi file). Thanks!
The text was updated successfully, but these errors were encountered: