I have the Note Index (Each Octave has 12 notes) versus the time(in beats) data. How can I convert this data to a midi file?
Example Data:
time = [0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 9.0, 9.0, 9.0, 10.0, 10.0, 10.0, 11.0, 11.0]
notes = [57.0, 59.0, 60.0, 62.0, 64.0, 65.0, 67.0, 57.0, 60.0, 64.0, 65.0, 62.0, 59.0, 64.0, 67.0]
The instrument is Piano.
Also, observe that there are multiple notes at the same time.
Thanks in advance.
I've created a program that converts your data into a MIDI file in C++ before reading that you prefer Python. Anyway, I prefer C++ and Qt, so this example uses the drumstick-file library for the job. Disclaimer: I'm the author of drumstick, just in case somebody complains about spam or self-promotion. Here is the code:
smfbuilder.pro
smfbuilder.h
smfbuilder.cpp
Some notes about the code:
You can use two ways for configuring the drumstick dependency. Assuming that you are using Linux, either install the drumstick-devel package from your Linux distribution (or compile it from sources), and manage the dependency with pkg-config, or you define the environment variables DRUMSTICKINCLUDES and DRUMSTICKLIBS in your QtCreator project settings, or your shell.
A MIDI file is like a musical score. There are many musical parameters that your data do not specify, like tempo, tonality, time signature..., I've tried to choose reasonable values, and provide appropriate code comments.
The general strategy is to generate a sequence of midi events, in SMFBuilder::generate() that is later written to the file.
After generating the file "output.mid", this is the representation by Rosegarden: