Omnimaga

General Discussion => Technology and Development => Computer Projects and Ideas => Topic started by: cooliojazz on May 03, 2013, 03:34:39 am

Title: PMusic - Procedural Music Generator
Post by: cooliojazz on May 03, 2013, 03:34:39 am
So a couple days ago, I randomly thought of how awesome procedurally generated music would be, and when I looked, there is a (in my opinion) surprisingly small amount of these kind of things. So I decided to write one for fun. Right now, it is very very random sounding and it doesn't really flow at all, but it can still be kind of cool sometimes still, especially when you keep in mind it's all randomly generated :P I just started this, so it is very early, and will probably change a lot in how it sounds, but this is a very early showcase of how awesome this can be. Right now it loads up with the seed 666 by default, but you can change that. Everything about the song is randomly determined based on the seed. The program is written in java, and attached below. So try it out, and maybe post some of your favorite seeds and stuff!
Note: Large seeds work better!

Now, for those interested, here is a quick overview of he current process:
1. First, it chooses a random tempo (50-170bpm) and a random root note.
2. Based on that root note, I have a formula which transforms the set of integer numbers into the notes on a major scale based on the root note
3. For each measure, it first chooses a root note for the chord for the measure (based on the aforementioned formula), and plays the triad based on that note and in the scale for the root note. Note that I took out it choosing the seventh (a diminished chord) for now because when randomly stuck in there, most of the time it just sounds odd.
4. There are 32 ticks, or steps, in a measure, and each tick is equivalent to a 32nd note at the chosen tempo. So it then figures out how to fill up those 32 ticks with random length note from the chosen triad, varied randomly by octave, choosing lengths between half notes and thirty-second notes.
5. There is also a simple static drum beat, just to keep the sometimes very weird off-beat things that can happen from getting too disorienting
And that's about it for the current version! I hope to start adding things that make the notes and measures more dependent on each other to really make everything start going together better, and also add some generic formulas for some additional melodic parts to the song. There's also quite a few bugs I know of, but for now, enjoy!

NOTE: CHECK LATER POSTS FOR THE NEWEST VERSION.
Title: Re: PMusic - Procedural Music Generator
Post by: TIfanx1999 on May 03, 2013, 05:05:30 am
Pretty neat little idea. I'll try to check it out when I have some time. :)
Title: Re: PMusic - Procedural Music Generator
Post by: Adriweb on May 03, 2013, 06:38:19 am
Congratz, it's pretty cool :)
Title: Re: PMusic - Procedural Music Generator
Post by: ben_g on May 03, 2013, 04:18:36 pm
Whoa, it actually sounds quite good for being 100% generated!

EDIT: Maybe it would sound a bit better if you would add some repeating patterns.
Title: Re: PMusic - Procedural Music Generator
Post by: aeTIos on May 03, 2013, 04:25:57 pm
If you don't say it's randomly generated, you could even make people believe you made it yourself. congrats! :D

edit: Idont seem to be able to change the seed.edit2: nevermind the number was too big :P
Also, can you add an option to remove the drums?
Title: Re: PMusic - Procedural Music Generator
Post by: Scipi on May 03, 2013, 04:29:30 pm
Is this the start of Brave New World? O.O

I kid :P This sounds quite good. Doesn't seem random at all O_o
Title: Re: PMusic - Procedural Music Generator
Post by: Juju on May 03, 2013, 04:33:44 pm
Seems I have a problem with my installation of Java, so I can't listen right now... :/
Title: Re: PMusic - Procedural Music Generator
Post by: cooliojazz on May 03, 2013, 04:40:47 pm
Thanks guys! I think it's pretty cool myself :P
ben_g: I think that might be cool too, but I'm not sure how I would do something like that inside the procedural generation itself. Since measures are repeatable (giving the same measure number and seed will give the exact same notes every time) though, it would be easy to add a feature like that in the interface part.
aeTIos: I could, and I was actually planning on having them change with the mood and stuff too; on my "To-do" list. I mostly made it have the drum track in the first place because with how random it is, sometimes with a ton off offbeat stuff, it got kind of disorienting. It's getting better now, though, and will probably to continue to do so as I develop the algorithm, I hope.
Juju: What's wrong with it?

Here's a new version: I added dynamics variation and changed the background chord to strings. I also changed the note generation (and the new dynamics variation) to Perlin noise instead of completely random, which seems to "flow" a bit better. I even added a bit more to the gui, such as a little label that tells you the current note and chord being played! Lastly, I disabled 32nd notes for now, as they mostly just sounded odd.
Title: Re: PMusic - Procedural Music Generator
Post by: Scipi on May 03, 2013, 04:59:36 pm
https://dl.dropboxusercontent.com/u/10573921/PMusic_1.mp3

O_O That's good!
Title: Re: PMusic - Procedural Music Generator
Post by: Juju on May 03, 2013, 05:01:25 pm
Juju: What's wrong with it?
Code: [Select]
[julien@haruhi ~]$ java -jar Downloads/PMusic.jar
Exception in thread "main" java.lang.UnsatisfiedLinkError: no pulse-java in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860)
at java.lang.Runtime.loadLibrary0(Runtime.java:845)
at java.lang.System.loadLibrary(System.java:1084)
at org.classpath.icedtea.pulseaudio.SecurityWrapper.loadNativeLibrary(SecurityWrapper.java:27)
at org.classpath.icedtea.pulseaudio.EventLoop.<clinit>(EventLoop.java:97)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openImpl(PulseAudioMixer.java:654)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:588)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.openLocal(PulseAudioMixer.java:584)
at org.classpath.icedtea.pulseaudio.PulseAudioMixer.open(PulseAudioMixer.java:579)
at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:94)
at org.classpath.icedtea.pulseaudio.PulseAudioSourceDataLine.open(PulseAudioSourceDataLine.java:75)
at com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1077)
at com.sun.media.sound.SoftSynthesizer.open(SoftSynthesizer.java:1036)
at com.up.pmus.MidiPlayer.<init>(MidiPlayer.java:24)
at com.up.pmus.Main.<clinit>(Main.java:31)

Something with Pulseaudio, I guess. Something's wrong with Arch Linux's Java package. I'll check it out.
Title: Re: PMusic - Procedural Music Generator
Post by: cooliojazz on May 03, 2013, 05:05:52 pm
Scipi: Nice one! What seed is that?
Juju: Huh, yeah, that looks like an internal jre error.  :-\
Title: Re: PMusic - Procedural Music Generator
Post by: Scipi on May 03, 2013, 05:15:24 pm
It was 666 :P

I can record other cool seeds as well.

This one is 117 :P

https://dl.dropboxusercontent.com/u/10573921/PMusic_2.mp3 (https://dl.dropboxusercontent.com/u/10573921/PMusic_2.mp3)
Title: Re: PMusic - Procedural Music Generator
Post by: Juju on May 03, 2013, 05:18:39 pm
Juju: Huh, yeah, that looks like an internal jre error.  :-\
Apparently for some reason the headless version got installed during a system upgrade instead of the non-headless one...

Quoting the package descriptions:
Code: [Select]
[julien@haruhi ~]$ sudo pacman -Ss jre
extra/jre7-openjdk 7.u21_2.3.9-1
    Free Java environment based on OpenJDK 7.0 with IcedTea7 replacing binary plugs - Full Java runtime environment - needed for
    executing Java GUI and Webstart programs
extra/jre7-openjdk-headless 7.u21_2.3.9-1 [installé: 7.u17_2.3.8-1]
    Free Java environment based on OpenJDK 7.0 with IcedTea7 replacing binary plugs - Minimal Java runtime - needed for executing
    non GUI Java programs

EDIT: Actually the jre package in the AUR was outdated. As simple as that. Brb fixing it.
Title: Re: PMusic - Procedural Music Generator
Post by: ben_g on May 03, 2013, 06:42:28 pm
This sounds even better than before!

I like seed 1234567890. After a while, it gets really good.

When the project is finished, could you release some information abouth how to do this? It sounds very interesting to do.
Title: Re: PMusic - Procedural Music Generator
Post by: Juju on May 03, 2013, 07:19:36 pm
Yay got it to work. So yeah it sounds pretty good. Seed 0 throws a divide by 0 error after one measure though.
Title: Re: PMusic - Procedural Music Generator
Post by: Rhombicuboctahedron on May 03, 2013, 11:03:52 pm
Awesome!
The only sad thing is that there are billions of songs, and some may get really good 100 seconds into it (I like 117 90 seconds into but others might not listen that long) and we will never know what is good
Also, try 497, 503 and 510
Title: Re: PMusic - Procedural Music Generator
Post by: Spenceboy98 on May 03, 2013, 11:53:57 pm
13579 and 24680 sound cool.
Title: Re: PMusic - Procedural Music Generator
Post by: cooliojazz on May 04, 2013, 01:43:54 am
Yeah, but isn't that kind of the cool thing about generated music at the same time? Someone who is willing to spend time listening can always find cool new things at every turn.

Watch as I change one tiny thing and every seed sounds completely different, MUAHAHAHAHAHA!!! Actually, not really, mostly this update just makes each seed a bit lower in pitch.
Major changes: Added a shuffle method which automatically increments the seed every 30 seconds, for those who quickly tire of the same seed. Added a bass part which plays quarter and eighth notes on the root of the chord, varied by octave. Added a drum checkbox for those who dislike the drums playing.
Minor things: Balanced parts a bit. The root note has a slightly smaller range of values. Made internal code more awesome.
New version is attached. Should I leave the old versions attached to the other posts in case someone likes the old versions better or something for some reason?
Title: Re: PMusic - Procedural Music Generator
Post by: Darl181 on May 04, 2013, 01:59:58 am
This is pretty cool. Kind of fun mashing random numbers into it to see what it comes up with :P
327098723409872 Sounds interesting.

How big can a seed get? Guessing there's a max size because after enough numbers it doesn't change.
Title: Re: PMusic - Procedural Music Generator
Post by: cooliojazz on May 04, 2013, 02:04:07 am
haha, isn't it? And 9223372036854775807 (Long.MAX_SIZE) is the largest possible seed, though theoretically it should let you type in any size of number, it just might crash when you click change :P
Title: Re: PMusic - Procedural Music Generator
Post by: Axenntio on May 06, 2013, 10:27:20 am
Very good sound d*0*b
You can try to make a midi export :o
We select how pattern we want and he automaticaly export in .mid
(Hard isn't it ? :p)
Title: Re: PMusic - Procedural Music Generator
Post by: cooliojazz on May 08, 2013, 01:06:52 am
Not terribly actually :P I was already using midi to play the notes, so I just needed to redirect them to a file. I was already planning on doing that, but you hurried that to the foremost task haha. New version!


New stuff
-There are now modes. Instead of choosing chords 1-6, it will either choose chords 1-5 (Major mode; 3 major, 2 minor), 2-6 (Minor mode; 2 major, 3 minor) , or 3-7 (Combo mode; 2 major, 2 minor, 1 diminished). This makes it more likely for a song to have a more definite feel. The mode of the current seed is displayed in the title bar.

-Midi exporting! When the Midi Export checkbox is checked, every time you change the seed, all the notes played since last time you changed the seed are exported in midi format to the file "[seed].mid" where seed is the current seed. This may seem a bit weird, to only save when changing seeds, but for simple automatic exporting from an infinite source, it only makes sense to save when the source changes :P (Or stream the data, but psh, who writes those kinds of systems ;) Seriously though, diong this would require me to not abuse the built in midi file writer, which im not ready to move away from quite yet.)

-Lots of minor things about how exactly it changes seeds which you probably won't notice unless you are very closely paying attention XD

New version attached!

NOTICE: I am 100% not responsible for the huge amount of files that will be generated if you turn on both exporting and shuffle and leave it running for an hour (That would generate ~120 files for those curious). *Cooliojazz runs*
Title: Re: PMusic - Procedural Music Generator
Post by: MGOS on May 08, 2013, 10:51:06 am
This program is awesome! I thought of making something similar for android which detects the bpm you're running and auto-generates some music for jogging.
1789 sounds really nice :)
Title: Re: PMusic - Procedural Music Generator
Post by: Axenntio on May 08, 2013, 11:59:21 am
Yea MIDI File !
This program is very awesome !
And the generating sound very cool !

Ear !
I use the midi file into FL Studio and I've add instrument with de same notes.
Title: Re: PMusic - Procedural Music Generator
Post by: Darl181 on May 09, 2013, 03:17:28 am
New version doesn't run for me, in either 6 or 7 :/  The window opens and has the fields and everything, it just doesn't play.
Spoiler For terminal output:
lobster4breakfast@meridian:~/Music$ java -jar PMusic.jar
Exception in thread "main" java.lang.NoSuchMethodError: javax.sound.midi.MetaMessage.<init>(I[BI)V
   at com.up.pmus.Main.changeSeed(Main.java:260)
   at com.up.pmus.Main.setupStuff(Main.java:235)
   at com.up.pmus.Main.main(Main.java:51)
Edit: verbose paste from irc http://pastebin.com/tnaAZCWg
Title: Re: PMusic - Procedural Music Generator
Post by: DJ Omnimaga on June 07, 2013, 10:44:38 pm
Darn that is quite interesting. Some seeds gives some rather good results, such as 8000.

If there are some epically sounding songs that can be generated with this program, this program could almost be used in a video game for generating soundtrack :P