1,000 computer generated melodies…

For the past couple days, I’ve been working on getting my melody generation program to output MIDI files so I wouldn’t have to convert them manually from a text file, which takes an annoying amount of time. And… I’ve done it, haha! So now I can tell my program… hey, I want 1,000 melodies, go. And it spits it all out over the course of a couple minutes. So here are 1,000 short little MIDI files my program wrote just a few moments ago, in a zip file:

Zip file with 1000 computer generated melodies

Some notes:

1. – Again, the program is currently restricted to 8-bar melodies in 4/4 time, and must start with the I chord and end on the tonic.

2. – For the sake of a little variety, I set the tempo to be a random BPM between 80 and 150, and the key signature to be random between A major and D major (it starts in C major then just shifts all notes up or down).

3. – There is one small bug you might hear in some of the melodies: the bass notes are shifted offbeat. I’m workin’ on it. Fortunately it doesn’t seem to happen often.

Melody project: the great reprogramming – update 6

It’s week 3 of the great reprogramming of my upcoming melody generator! While I could continue tweaking the main algorithms endlessly, I’m at the point now where I feel I need to branch off into three directions:

1. I need to get the program to output MIDI files automatically so I don’t have to keep interpreting text files.

2. I need to get the program to write in different time signatures, different bar lengths, etc.

3. I need to figure out how exactly I’m gonna get this program on the Android.

My main goal for now is #1… being able to output MIDIs, I can then have the program write 100 melodies or so in a row, and then go through the results and pick out the melodies I like, and perhaps orchestrate them into a little piece or something…

Yet even more computer generated melodies…

Here are yet more computer generated melodies from my in-development automatic melody generator. I have made a lot of changes to the algorithm since I posted the last set of examples, but I’m not sure how much you can actually hear. Still more work to be done… anyway, here are 12 more melodies…

Computer generated melodies

Enjoy!

I’ll probably spend another week on the main algorithms, then I’ll start trying to add more diverse capabilities, like different time and key signatures.

Some comments on The Wise Man’s Fear…

I’m reading The Wise Man’s Fear by Patrick Rothfuss, only on page 150 of about 1000, so this will take a while. Unfortunately it’s due back at the library soon, so I might just have to buy it because I doubt I’d be willing to stop reading once it’s due. It’s an addicting book.

Anyway, I just want to make some comments about a couple passages… I’m only on page 150, so I doubt there’ll be any drastic spoilers, but if you’re planning on reading the novel yourself and don’t want anything at all revealed to you, go away now.

So there’s this crazy professor teacher in the novel named Elodin, and as class starts he makes his students tell him an interesting fact. If he already knows it or finds it boring, they have to keep going until they come up with something interesting, or admit defeat. This sounds like a pretty fun game, but only really if you’re the teacher and get to be the “interesting decider.” If I ever had a teacher that really did that, I wouldn’t like it… I’d feel used and abused! And I’m somewhat wary of these romanticized student-teacher relationships that crop up so much in fiction.

Anyway, here’s one of the students’ facts, from page 132:

“You can divide infinity an infinite number of times, and the resulting pieces will still be infinitely large,” Uresh said in his odd Lenatti accent. “But if you divide a non-infinite number an infinite number of times, the resulting pieces are non-infinitely small. Since they are non-infinitely small, but there are an infinite number of them, if you add them back together, their sum is infinite. This implies any number is, in fact, infinite.”

“Wow,” Elodin said after a long pause.

Um… what? Elodin shouldn’t be impressed by such foolish logic! It sounds like a middle-schooler who just discovered the concept of infinity. Infinity is not a number, you cannot do math with it. There’s no such thing as “an infinite number.” Fool! Elodin should reprimand him!

Later on, some characters are trying to explain to another character how the novel’s magic system works (a certain magic called “sympathy”), on page 148:

“Heat, light, and motion are all just energy,” I said. “We can’t create energy or make it disappear. But sympathy lets us move it around or change if from one type into another.”

Is motion really energy? Doesn’t he mean acceleration? I guess you could still say something in motion has kinetic energy, but that implies that it was accelerated at some point. Perhaps, since we live in a frictionful gravity world, motion and acceleration can be thought to be same, since if you’re not constantly accelerating, friction due to gravity will bring you to a stop. Anyway, this magic system seems to obey the first law of thermodynamics; good enough for me.

But then…

“I can see how heat and light are related,” [Denna] said thoughtfully. “The sun is bright and warm. Same with a candle.” She frowned. “But motion doesn’t fit into it. A fire can’t push something.”

“Think about friction,” Sim chimed in. “When you rub something it gets hot.”

…

[Kvothe talking:] “It’s a good example. The hub of a wagon wheel will be warm to the touch. That heat comes from the motion of the wheel. A sympathist can make the energe go the other way, from heat into motion.”

So a sympathist can basically break the second law of thermodynamics? That’s fine, I don’t quite believe in it anyway. But… why explain the relationship between heat and motion with friction? The heat from friction isn’t really directly caused by motion, it’s caused by countless atomic collisions from opposing electromagnetic forces. (You’re not going to get much heat from static friction, are you?) I would explain heat and motion more thermodynamically: heat is motion, the non-uniform motion of countless particles. Of course the heat from a fire can push something, it’s just hard (if not thermodynamically impossible) to get enough energy directed at something specific to make that possible, so we tend to use it’s energy more indirectly, like using it to create steam, or taking advantage of the potential difference in density between the heated material and the surroundings (like the heated air in hot air balloons).

Then again, I’m not a scientist… and on page 149 a character says:

“There’s a special kind of thinking called Alar,” Wilem said. “You believe something so strongly that it becomes so.”

So I can’t be too picky. All is fair in fiction.

More computer generated melodies! Woohoo!

Even though I’ve still got plenty of work to do on my automatic melody generator, it’s at the point now where I’m finding it quite addicting. Here are a bunch of melodies it came up with today (I think there are 12 altogether, each stated twice):

Computer generated melodies

Again, I don’t think the melodies sound super fantastic by themselves, but there are definitely some surprisingly good phrases, in my opinion.

Some notes:

1 – Again, it’s still limited to 8-bar melodies in 4/4 time in C major that begin and end on the I chord and can only use the basic triads. I still have algorithmic changes to make before I start expanding its abilities in this area. (For the audio above, I transposed it up a step to D major; sounded just a bit better to me.)

2 – The program is “creating” its own “melodic knowledge” and, as you might hear, the biggest problem this creates is that it likes to write large melodic leaps every now and then, which can sound funky. It didn’t do this before because it based its melodies on observations, and large melodic leaps like that would never (or rarely) be observed. So I’m going to have to hardwire an interval limit into the algorithm, perhaps letting the user set it.

3 – In the last two melodies, I gave the program the ability to use to 16th notes. You don’t hear them in the other melodies because the program wasn’t allowed to use them, but it’s an easy ability to give the program. Triplets, on the other hand, will be tricky… I guess I’ll have to figure out those at some point. Meh… that can come much later…

4 – The program outputs a text file with note values and accompanying chords; it doesn’t actually output the sound you hear in the MP3 … I had to manually enter the info into Overture 4 and use Garritan Personal Orchestra to create the actual sounds.

Melody project: the great reprogramming – update 5

As I stated yesterday, I’m now working on getting my program to create its own melodic knowledge rather than depend on melodic patterns found in pre-existing melodies. This turns out to be harder than I thought it would be — or at least more time consuming. I’m sure it’s possible, it will just take more programming. So I’m continuing to work on that. If I can’t get it done by the end of the week, I’ll give up on it for a while. In the end, perhaps I’ll use a combo of both methods.

Uh… yeah, that’s pretty much it for today.

Melody project: the great reprogramming – update 4

It’s week 2 of melody generator programming fun! Over the weekend, I was preparing to add more knowledge to my program’s melodic knowledge database, but then I thought: Wait a sec. If the knowledge in the knowledge database comes from patterns found in other melodies, why not create a knowledge database from the patterns found in that database? That way we’d only need a small database, and we can have the program create random melodic knowledge from it. Does that make sense? I have no idea if it will work or not, but I’ll give it a try, so that’s what I’ll be working on today: a melodic knowledge generator. I’ll try to have more musical examples by tonight or tomorrow night (or… later).

Thank you for reading update #4. I will keep the blog informed of any and all progress made on this revolutionary product.

In other news, I wrote some melodies over the weekend and started to hear a piece in my head, so I finally bought Garritan World Instruments, which I hope to use soon. I should be saving my money, but when you’re high on your own melodies playing through your mind, you sometimes just can’t help it. And Garritan products are at least priced awesomely for the amount of stuff you get.

Some computer generated melodies…

Here are five melodies my computer program wrote today, all in one MP3 file:

Examples of computer generated melodies

A few things to note:

1. The program is still working within limitations of only being able to compose in C major, only being able to use the basic triads, only being able to compose 8-bar melodies in 4/4 time. I will, of course, work to remove those limitations, but there is still more work to do on the algorithm first.

2. As you can hear, some of the melodies don’t sound that great. I think they technically work (they don’t sound like random atonal garbage), but they’re not quite memorable. I really like the first one though, and the second and third one have some interesting parts. Anyway, my goal with the program isn’t to get it to output something beautiful every single time; the point is to give the user melodic ideas. As the algorithm is now working pretty fast, the user should be able to have the program generate 100 or so melodies at a time, then he can browse through the results and find whatever strikes his fancy.

3. The five melodies in that MP3 are based on melodic knowledge the program learned from just two melodies. So if they sound kinda similar now and then, that’s why. But still, it amazes me how much musical variety can emerge from such a small set of knowledge. I look forward to building the program’s knowledge database; I can’t wait to see what sort of stuff it might produce with knowledge from several hundred melodies or so.

The Lost Gate by Orson Scott Card

lostgate

Finally finished reading a book, woohoo!  It was on hold at the library, so I had to hurry up.  ‘Twas The Lost Gate by Orson Scott Card, one of my favourite writers.  ‘Twas a fun read.  Not quite Ender’s Game, but hard to put down nonetheless.  Makes you want to be a gatemage.  Makes you look forward to Portal 2, coming out soon!  Now I look forward to the sequels, for this seems to be the first book of a trilogy or something.

There are two quotes I liked.  First, from page 106:

Besides, it just felt . . . wrong.  Inelegant, perhaps, as Auntie Tweng used to say of kludgy solutions to math or programming problems.  “Yes, it works,” she would say, “but it’s not elegant.  Truth is simple and elegant.  That’s how you know it when you see it.”

Those last two sentences.  “Truth is simple and elegant.  That’s how you know it when you see it.”  Almost Occam’s razor-ish.  I’m not sure if it’s true (for it can’t explain the truth of itself), but I like the idea.

Also, in the afterword, on page 382:

I tell my students in my writing classes that suspense comes, not from knowing almost nothing, but from knowing almost everything and caring very much about the small part still unknown.

Great little writing tidbit.  Mystery can still come from not knowing much, but it’s not suspenseful (or nearly as interesting) until the focus is on that one last answer, that one final piece to the puzzle.  Search your feelings, you know it to be true.  (Plus, it’s simple and elegant.)

Oh, it’s also a fun book if you know your mythology.  Which I don’t, but I’m just assuming.

Melody project: the great reprogramming – update 3

I haven’t gotten much done today because I slept all day because I was up late reading because I have library books that are due soon because they are on hold and I can’t renew them and I want to finish them or at least get as far as I can in them before I have to return them because that’s just the way it is, OK?

Anyway, regarding the melody project… I have created a small set of symbolic knowledge with which to experiment with. I am now continuing to work on reprogramming and restructuring the main melody composition algorithm to make use of the knowledge in its new form. That’s pretty much it. An in-depth look at my meaning of this is strictly confidential.

Thank you for reading update #3. I will keep the blog informed of any and all progress made on this revolutionary product.