Page 1 of 1

Python Midi File Generation

Posted: Wed Dec 10, 2014 4:52 pm
by Neuropyrox
I'm creating a music generator that uses artificial neural networks. It's programmed in Python. In order to do this project, I had to teach myself Python in the last few months. Now, everything is working fine except for one thing. I need to generate midi files note by note. To do this, I'm trying to use the Pyknon module, but it only generates the header of the midi file. The midi files that it generates should contain notes, tempos, and track names, but they don't. All I need is to generate a simple midi file note by note. I need to be able to open the file with a midi editing program that can play the file and print sheet music of it. This is only the first prototype, so there are still many other changes to be made.

The code is too long to put in here, so tell me if you need to see it.

Re: Python Midi File Generation

Posted: Wed Dec 10, 2014 10:17 pm
by MadelineB
Hello Neuropyrox,

Welcome to Science Buddies,

Perhaps you could search the internet to find Python code to create your midi files.
I did a quick search and found several possibilities.

Hope this helps! Let us know if you have more questions.

Re: Python Midi File Generation

Posted: Thu Dec 11, 2014 8:17 am
by Neuropyrox
For the past few weeks, that's exactly what I've been doing. The only information that I've found about Pyknon(the module I'm using) is creating midi files via the NoteSeq command. NoteSeq doesn't work for me because the notes are unevenly spread out. I need to generate a midi file one note at a time, and I found a command for this while searching through the code of Pyknon. AddNote is the command that I'm now trying to use, but it mysteriously won't work for me.

Re: Python Midi File Generation

Posted: Thu Dec 11, 2014 11:16 am
by bfinio
Hi Neuropyrox,

Unfortunately I'm not a Python expert, but I do have a suggestion. There are several forums online where you might be able to get much more specific help with Python programming than you'll get here at Science Buddies. One site that I'm familiar with is, which has a network of sub-sites like

but if you google "python forum", you will find many other sites. A couple pieces of advice if you decide to post anything on those forums:

1. Explain right off the bat that you are a student doing a science project, and that you have already tried to troubleshoot extensively on your own, but you are stuck. People get mad when they think a student is just trying to get an easy answer on the internet without doing their own work.

2. Explain in as much detail as possible what you're trying to do, and provide all your source code (many of those sites provide ways to paste in code without making it look mess if it's really long). Again, some people will get irritated if you don't do this.

3. Don't cross-post your question to multiple forums on the same site. That's generally against the site rules and will make people upset.

Most forums like that will have an "FAQ" or list of rules for first-time users, so in general it might help to read those before you post anything.

Hope that helps.


Re: Python Midi File Generation

Posted: Fri Dec 12, 2014 9:42 am
by Neuropyrox
I found the problem, and I feel dumb now. The whole time, I was trying to use AddNote, when it was actually addNote. Thanks for giving me those websites though. I will probably go there next time I get stuck on something.

Re: Python Midi File Generation

Posted: Wed Dec 17, 2014 12:15 pm
by hhemken

Welcome to software development! You can expect such slaps in the face on a more or less daily basis for as long as you write code. Don't worry, you will not only get used to it but will also derive all the more pleasure when things work as expected. It happend to all of us.

Good luck!