Music Generator


hisaki

Still Fresh
Joined
Sep 9, 2007
Messages
56
I've been toying with the idea of procedurally created music for a while now. I know it's nothing new but I'd like to have a go at it and see what I can come up with.

I've been trying to get back in to learning C++ as well and I've come up with a small program that generates a midi file. Nothing interesting yet, just pre-programmed notes. I figured I had to start somewhere.

Midi files probably aren't too useful for games, but if things progress well I could maybe write a library that outputs tracker modules.

I'm not very confident in my ability to program in C++ yet, so I was hoping I could get someone to check out my code before I continue on to the more interesting part of actually making something that generates music.

So my question is, would anyone care to review my code and give me some feedback?

You can get it here if you're interested: http://madpaperlantern.com/music_generator.zip
 
So... whats the use of this? I skimmed over the code but I couldn't see much useful stuff in there. There are libraries to handle midi files etc. and unless there is something like a tracker GUI I don't see much sense in this. And if you have a GUI you wouldn't want to limit yourself to midi.
I couldn't compile this because I was missing a makefile and I couldn't be arsed to create one myself.
But as long you had fun writing this you shouldn't really bother :)

The code is clean but as I mentioned before: a makefile would be nice, then possibly more details about the source-pdfs and the "Stolen from somewhere, forgot where" should be doublechecked too.
Another thing (which is very subjective) is the use of (/* */) for the comments in some places as it makes it hard to block comment out larger parts for testing (midi_compiler.cpp:152).
I was also wondering wether the defines.h was really necessary.

However, I can't comment too much on it as I'm not into C++. C is what I use for most things as I don't like many things added by C++.

Personally, I'll most likely use a modded version of 4klang in my games. I'm in the process of disassembling and recompiling the 4klang player code for ARM (More on this will follow soon *hopefully*). MadTracker is my current choice for the tracker (only started to learn music making a few days ago) but on Pandora I'll probably use MilkyTracker with pre-compiled samples.
 
JayFoxRox said:
So... whats the use of this? I skimmed over the code but I couldn't see much useful stuff in there. There are libraries to handle midi files etc. and unless there is something like a tracker GUI I don't see much sense in this. And if you have a GUI you wouldn't want to limit yourself to midi.
I couldn't compile this because I was missing a makefile and I couldn't be arsed to create one myself.
But as long you had fun writing this you shouldn't really bother :) \

Yeah, it doesn't really do much yet. Like I wrote, it's a first step. I haven't really touched C++ in ages, and before that I only made a very simple program once.

The goal is to make a program that outputs a piece of music based on very limited input. A lot of randomly picked notes but within predefined structures. I'm not a 100% sure yet how it'll work, I'm gonna make it up as I go along. Maybe read up on some composing techniques too, seeing if I can implement any.

I wrote this in code::blocks, so it takes care of stuff you'd need makefiles for. I'll try to include one next time I'm publishing code though :)

The code is clean but as I mentioned before: a makefile would be nice, then possibly more details about the source-pdfs and the "Stolen from somewhere, forgot where" should be doublechecked too.
Another thing (which is very subjective) is the use of (/* */) for the comments in some places as it makes it hard to block comment out larger parts for testing (midi_compiler.cpp:152).
I was also wondering wether the defines.h was really necessary.

However, I can't comment too much on it as I'm not into C++. C is what I use for most things as I don't like many things added by C++.

Yeah, I should be a bit more careful where I find things and possible licenses. It was only a small piece of code though.

The defines file is a bit silly right now with only one define. But as the program gets bigger it might be useful. Are there better ways of doing this? I guess if it's only a few defines they could go in some other header somewhere?
 
Last edited by a moderator:
The program is c++, but the code isn't really c++ style. This isn't necessarily *bad*, but if this is the way you want to structure your code, I'd just use C. I use C++ when i feel Object Orientation has some sort of benefit, there is none of that in the code design.
 
WombleGoneBad said:
The program is c++, but the code isn't really c++ style. This isn't necessarily *bad*, but if this is the way you want to structure your code, I'd just use C. I use C++ when i feel Object Orientation has some sort of benefit, there is none of that in the code design.

Heh, I discovered structs before making it object oriented.

My programming style is a bit of a mess as I write PHP and Javascript for a living, and we have to support PHP4 (and now they're forcing me to use jquery instead of prototype). I did have quite a few Java classes back in college though, so I guess I should be ok if I read up a bit.

That is a good point. I should rewrite it to be more object oriented before continuing. The benefit now might not be too great for such a small program, but I intend to eventually expand on it.

I guess the argument for having the current code in C++ is vectors and strings. But I guess there are libraries for those in plain C too?
 
Last edited by a moderator:
hisaki said:
I guess the argument for having the current code in C++ is vectors and strings. But I guess there are libraries for those in plain C too?
There's glib, but I always just use C++ because it has those features, and it's mostly backwards-compatible with C libraries.
 
Last edited by a moderator:
lulzfish said:
hisaki said:
I guess the argument for having the current code in C++ is vectors and strings. But I guess there are libraries for those in plain C too?
There's glib, but I always just use C++ because it has those features, and it's mostly backwards-compatible with C libraries.

Fair enough. Its just not what I do. If performance is important I find it useful to know exactly what is going on in your datatypes, Its rare that you cant make domain specific optimizations vs these generalized datatypes. I rarely use std even in OO code. OO isn't always a good idea and C can limit you in a good way, JayFoxRox doesn't feel the need for C++ or OO, and neither does Linus Torvalis. assembler optimization with c++ tends to be more difficult too of course.

I guess its just whatever works for you, i tend to use OO with C++ more than C. Its partly how my brain works, and partly the nature of the problems i am trying to solve.
 
Last edited by a moderator:
Thanks for the input everyone :)

I've installed gnuwin32 and use a small makefile to compile now. I feel a bit more comfortable coding in notepad++.

I've also started to rewrite what I have so far to make use of classes.

I'll post again when my program actually does something :)
 
For procedural midi generation you don't need speed. Write it in a language you are more comfortable with. I personally would do it in Python, as most of the people in #openpandora and at my college are sick of me talking about I'm sure. ruby would also be a good choice. Heck, .mid is such a simple file format, why don't you just write it in PHP?

There's honestly pretty much no advantage to writing it in C++, and a lot of disadvantages. (I'm referring to this specific case, not saying C++ is always useless)


I did a project for procedural music generation for one of my classes last year. I fed my program some MIDI files and it trained a neural network to recognize a scale based upon listening to a solo track of a piece of music.

In order to have lots of music to train my NN I just created a sample set (recorded myself playing some solos in a certain key) and then extrapolated it out with a 2 or 3 order markov chain. The point of the project was using a neural network to learn a scale (in this case it learned the blues scale by listening to some blues soloing I did).

If you want to talk to me about procedural music generation stuff, PM me or something. It's not something I'm that far into but it's a field that interests me a lot!
 
If you are interested in music soft programming, this programm will help you.

It is a visual editor, based on graph design (like visio, simulink and rational rose), but it also suports c and x86 asm subroutines.

You can easily sketch up your synth or effect before doing it in your code.

http://synthmaker.co.uk/
 
I haven't looked at your code, as I am myself chin-deep in MIDI C/C++ code for a Pandora-specific sequencer project, but I imagine you are on the right path if you're actually making tunes with it.

My project is mostly related to live sequencing, but things like quantization and playback metrics are all realms worthy of a bit of generator-style code.
 
rabidpoobear said:
For procedural midi generation you don't need speed. Write it in a language you are more comfortable with. I personally would do it in Python, as most of the people in #openpandora and at my college are sick of me talking about I'm sure. ruby would also be a good choice. Heck, .mid is such a simple file format, why don't you just write it in PHP?

There's honestly pretty much no advantage to writing it in C++, and a lot of disadvantages. (I'm referring to this specific case, not saying C++ is always useless)

You're probably right about that. This project is more about me learning C++ and brushing up on object oriented programming (not quite visible in the code I've posted here, but I've since rewritten it). I have actually made midis with PHP before. It was a simple script that 'improvised' within a scale for a few notes. That's why I thought this might be a good first project. I'm not sure if it is, it's becoming pretty complicated without actually doing much yet.

I don't think it's the C++ part I'm having trouble with though. Heh, the errors I have to google are getting few and far in between. Although it would definitely be a lot faster in PHP.

Maybe a simple platform game would have been a better first project. I'm notoriously bad at making graphics though. Maybe I should try making a C++ version of this: http://madpaperlantern.com/jplatform/ (and actually turn it in to a game). That way it'd be more easy to get something out on the Pandora too.


rabidpoobear said:
I did a project for procedural music generation for one of my classes last year. I fed my program some MIDI files and it trained a neural network to recognize a scale based upon listening to a solo track of a piece of music.

In order to have lots of music to train my NN I just created a sample set (recorded myself playing some solos in a certain key) and then extrapolated it out with a 2 or 3 order markov chain. The point of the project was using a neural network to learn a scale (in this case it learned the blues scale by listening to some blues soloing I did).

If you want to talk to me about procedural music generation stuff, PM me or something. It's not something I'm that far into but it's a field that interests me a lot!

That sounds really complicated, I wonder if I'm not in over my head a little. I guess I should read up on neural networks, seems interesting. For my program I'm hoping to implement some common composing techniques. I'm not sure how yet though. Whenever I composed music myself it was basically just trial and error, so I'll have to read up on music theory as well.

It is an interesting field though. I have a horrible habit of not finishing anything I start, but so far even when I'm stuck I feel inspired enough to keep trying.


apexsol said:
If you are interested in music soft programming, this programm will help you.

It is a visual editor, based on graph design (like visio, simulink and rational rose), but it also suports c and x86 asm subroutines.

You can easily sketch up your synth or effect before doing it in your code.

http://synthmaker.co.uk/

That's pretty interesting, reminds me of synthedit and buzz machines.


torpor said:
I haven't looked at your code, as I am myself chin-deep in MIDI C/C++ code for a Pandora-specific sequencer project, but I imagine you are on the right path if you're actually making tunes with it.

My project is mostly related to live sequencing, but things like quantization and playback metrics are all realms worthy of a bit of generator-style code.

Oh, it's not making actual tunes yet, still pretty far from. All it does right now is create a very bad chord progression.

I am very interested in your project though. Hopefully the Pandora will be just what I need to get into creating music again.
 
Last edited by a moderator:
Back
Top