What does this mean for me? You will always be able to play your favorite games on Kongregate. However, certain site features may suddenly stop working and leave you with a severely degraded experience.
What should I do? We strongly urge all our users to upgrade to modern browsers for a better experience and improved security.
We suggest you install the latest version of one of these browsers:
Kongregate is a community-driven browser games portal with an open platform for all web games.
Get your games in front of thousands of users while monetizing through ads and virtual goods.
Learn more »
> *Originally posted by **[Senekis93](/forums/4/topics/291068?page=3#posts-6279982):***
> > (ex. the bass, which often comes out sounding like a fart =\_=)
> Haha, so true.
> You can also mess with the speed value at the top. Well, you can mess with pretty much everything, that’s what makes it so beautiful.
> Nice job, Metabble.
Thanks. Although, I didn’t do much. Also, if anyone wants to change the key of the scale and octave in code, I think I know how. Observe how the frequency value of the piano and bass are MIDDLE\_C. It’s declared as
`MIDDLE_C = 220.0 * (2.0 ** (3.0 / 12.0))`
in the BOOTSTRAP area. I’m not big on music theory, but I seem to have gotten a grasp of this formula. Correct me if I’m wrong, since before now I didn’t even know an octave was double the Hz of its predecessor. =\_=
Simply, the way I see it in my mind, it’s the starting hertz of the octave times the twelfth root of two to the power of the note you want within the octave. Essentially, since an octave is double the hertz of the one below it, we’re splitting this increase into twelve parts (twelfth root of two, 2^[1/12]) and multiplying for every note above _A_ we want. Of course, there’s no need to use powers when we can change the amount that we divide twelve into…
We represent the octave and key we want as:
`hZ * (2.0 ** (sT / 12.0))`
Let hZ be the starting hertz of the octave, and sT be the number of semitones away from the key belonging to that hertz (_A_).
220 Hz is the middle octave (that’s why it’s used for middle c) so halve it for every octave down you want to go, and double it for every octave up.
Semitones away from _A_ is self explanatory.
* * *
Simple edition with tables to easily change the key and octave, first go to this line:
`MIDDLE_C = 220.0 * (2.0 ** (3.0 / 12.0))`
Replace it with this line:
`MIDDLE_C = Hz * (2.0 ** (sT / 12.0))`
where _Hz_ is one of the values below, corresponding to the octave you want…
`Middle+2 = 880 Hz
Middle+1 = 440 Hz
Middle = 220 Hz
Middle-1 = 110 Hz
Middle-2 = 55 Hz
..and _sT_ is the number below belonging to the key you want.
`A = 0
A#/Bb = 1
B = 2
C = 3
C#/Db = 4
D = 5
D#/Eb = 6
E = 7
F = 8
F#/Gb = 9
G = 10
G#/Ab = 11
A = 12 (octave higher, just double hertz and make it 0)
And you’re done. Keep in mind that this is misleading since MIDDLE\_C is, well, no longer middle c. You can always define separate frequencies and change which one is used where the samples are generated (they’re the same lines as the ones I altered in my previous post). Also note that the scale, major or minor, is decided randomly, with a 50% chance of each being chosen, every time a tune is generated. To control that, too, you can change this line:
`strat = Strategy_Main(random.randint(50,50+12-1)+12, Key_Minor if random.random() < 0.6 else Key_Major, 128, 32)`
by replacing the second argument with Key\_Minor or Key\_Major.
* * *
Whew. That was a lot of work. Again, I’m not much into music theory so if I’ve gotten anything wrong, feel free to correct. :)
Also, to expand on this, you could define multiple octave/key combinations (maybe put them in an array) and then use randint to determine which one to use. That way, you can randomly generate the tune, instruments, base octave _and_ key. xD
At first I could only get fast paced songs to sound good (probably due to their inherently more chaotic nature), but lately I’ve gotten quite a few good slow songs. Swapped out one melody sample in a tune with a hollow flute one I made in CFXR and it makes a decent forest tune. The D-minor scale at 90 tempo, 3 speed has given me some more laid back, contemplative tunes.
**EDIT, figured it out, original post below the line:** Figured it out. I can alter the patsize as long as the blocksize divides evenly into it 4 times. I had trouble grasping the python syntax… especially having read almost nothing about python.
At first I thought kseq was defined as a random choice between two lists (minor, major), each containing two more lists containing four tuples, each containing two elements. That didn’t make sense. Why pick a random list (major, minor) when major, minor was passed? Then I noticed the whole thing was wrapped in curly braces and the keytype came after. I’m not familiar with the syntax, but it seems it picks either the major or minor list based on the key type (it might be dictionary definition followed by the key), then picks one of the two lists containing four tuples and assigns it to kseq. A tuple, containing a key and keytype, is popped from kseq and assigned to another tuple, k (key) and kt (keytype). The reason why blocksize needs to divide evenly 4 times into patsize is because they are used in a for…in loop which iterates, in essence, as many times as blocksize goes into patsize, popping and using tuples as it goes. After the fourth loop the last tuple has been popped out; there’s no more tuples to pop, and so there’s nothing to assign to the tuple k,kt.
EDIT2: And now there’s a different problem with an index used to access an element of rhythm being out of range once patsize \> 160. I give up, for now. Maybe it would help to know some python? \>\_\>
* * *
**Original, confuzzled, post:**
Added the ability to easily change octave along with scale key and tonic just by changing a few constants before running. Ex. SCALE\_TONIC = TONIC\_A, SCALE\_KEY = Key\_Minor and OCTAVE = 3 would get A-minor, octave 3. Can use TONIC\_R, SCALE\_KEY\_R, OCTAVE\_R to get random values for any of the three.
Also added the ability to _control the length_, but it isn’t very precise. It just extends the amount of patterns, which is 6 by default, while maintaining the scale change of the last pattern. I was going to make it so it altered the rows per pattern as well as the number of patterns, but the rows per pattern can’t go above 128 without ending up crashing. I change patsize and for some reason it tells me that an int type object isn’t iterable. It pops an object off kseq containing a key and key type and assigns it to a tuple. It works when patsize \<= 128, but as soon as patsize is above 128 it freaks. No idea why. I can still get my desired length in rows by lowering the pattern size and raising the number of patterns, but due to the algorithm used, I think it breaks up the flow of the song.
I guess I’m stick with altering the song size in 128 row chunks. :(
* * *
Final features when I’m done with this next step should be:
+ Randomly generated instruments.
+ Easy control of scale key. (Not that it wasn’t easy to begin with!)
+ Easy to use control for changing the octave. (Shifting everything up/down an octave by altering the base sample)
+ Easy to use control for the tonic of the scale. (Again, altering the base sample. Essentially shifting everything in frequency in semitones.)
+ Manipulation of the tune length via the amount of patterns, as well as the pattern length.
+ Randomizer for octave, as well as scale tonic and key.
just on a similar note, I found a similar python script by some guy, called [Pythoven](http://forums.xkcd.com/viewtopic.php?f=11&t=49360#p1900660)
I made this awesome song with it:
@ Metabble: I totally missed yourlast reply. The planned features sound amazing. You may want to drop an email to the author of the other script when you’re done.
I think it must be nice to open source something, forget about it and one day get an e-mail from someone who found your code and improved it.
@Tehdog: Nice find, I’ll give it a try later.
The soundcloud file sounds really suitable for some games. Thanks for sharing. (:
Assuming you are on Windows (Mac too I think), and assuming you mean the script from the OP, you download Python ([http://www.python.org/download/releases/2.7.3/](http://www.python.org/download/releases/2.7.3/)), download the script file, remove the .txt so it’s just called atrk-bu.py, and double click it.
If you don’t plan to change it see here:
> *Originally posted by **[tehdog22](/forums/4/topics/291068?page=2#posts-6268920):***
> Just for people who can’t easily run python or open .it files:
> Here are 54 songs in .it and .ogg (128kbps audio) file format generated by this:
> *Originally posted by **[Senekis93](/forums/4/topics/291068?page=3#posts-6310683):***
> @ Metabble: I totally missed yourlast reply. The planned features sound amazing. You may want to drop an email to the author of the other script when you’re done.
> I think it must be nice to open source something, forget about it and one day get an e-mail from someone who found your code and improved it.
TBH, I’ve probably only added/modified a few dozen lines. It was easy. For instance, to implement octave/key/tonic shift I just made a few constants which the user punches in before they compile and run. These are used instead of the default values wherever they would’ve been used. The way the user defines them is as other constants (TONIC\_A, TONIC\_D, OCTAVE\_R) which are defined as simple formulas which are evaluate to the desired frequency. I guess I could’ve implemented them as command line arguments, but they aren’t hard to change. Length is at the top with the pre-existing bitrate/sample frequency, while OCTAVE, TONIC and KEY are near the bottom. The guy who made the original script probably could’ve done this in a half hour.
It’ll probably be a while before I smooth out the length constant to make it more precise since I’m learning Objective-C at the moment. Honestly, you probably could’ve implemented these things better than I could’ve, since I’ve only been coding for some months.
I’ve built up a collection of several good pieces, and found a way on the Mac to convert the .IT files into MIDI files so I can edit them in GarageBand. First, I import the .IT into MilkyTracker and export it to a .XM. Then, I import the .XM into SunVox and export it as a MIDI.
Now I can use more realistic sounding instruments, and add all sorts of effects and filters. :)
> *Originally posted by **[Senekis93](/forums/4/topics/291068?page=3#posts-6480996):***
Thank you. I have been sitting at the computer for about an hour playing with this.