HTTPS SSH
Genetic Algorithm Drum Machine
Author: Jennifer Hsu (jsh008@ucsd.edu)

This is a drum machine that generates rhythmic pattern variations using a canonical genetic algorithm. The drum machine is a patch in Pure Data (Pd) and it uses a Pd extern (written in C), called ga. I tested this patch in Pd-extended, so it may not work on other Pd distributions. 

To use this, first compile the ga Pd extern, and move it to the appropriate location in your Pd distribution.  For Mac computers, this means:

1. Take the pd_extern/ga.c file and move it into the Applications/Pd-XXX/Contents/Resources/doc/6.externs/ directory.  The XXX should be replaced with whatever Pd distribution you are working with. In my case, it would be Pd-extended.

2. Modify the makefile to include ga.c in the compiling process.  For my Mac, I scroll down to the line that says "pd_darwin: obj1.pd_darwin obj2.pd_darwin 
     obj3.pd_darwin obj4.pd_darwin obj5.pd_darwin dspobj~.pd_darwin" and I add ga.pd_darwin to the list.

3. Navigate to the Applications/Pd-XXX/Contents/Resources/doc/6.externs/ directory in your terminal and compile.  I type in "make pd_darwin" in my terminal for this step and push return. 

4. Copy the compiled object (ga.pd_darwin) into Applications/Pd-XXX/Contents/Resources/extra.

At this point, you can test that the extern works by opening up your copy of Pd and opening the pd_extern/ga_example.pd patch.  If the ga extern was properly compiled and loaded, you should be able to see the ga object in an object box. You should be able to send messages to the object and click the bang button with no errors.  If not, please do a search on how to compile Pd externs before moving on.

If your ga Pd extern is working properly, you can open ga_drum_machine.pd in your Pd distribution. Here is a short description of how to get it all running:

1. You need to provide your own samples.  Create a samples/ directory within the GADrumMachine directory.  Please choose 4 .wav files and move them into the samples/ directory.

2. Open Pd and open the ga_drum_machine.pd patch.

3. In the upper left hand part of the patch labeled with POLYPHONIC SAMPLERS, click the "pd players" subpatch. This will open up a new window with the subpatch.

4. There are 4 object boxes that look like [samplebank samples/xxx.wav]. Please replace each of the xxx with the names of the samples that you placed in the samples/ directory.

5. After you change the sample file in each object box, click on that [samplebank samples/xxx.wav] object.  This should open up a new patch called samplebank.pd.  Click the bang in the upper left hand corner to load the sample. Repeat this for all 4 samplebank objects.  If you save the players subpatch in the current state, you will not need to repeat this step each time you start up the drum machine patch. Feel free to close all subpatches when you complete this step.

6. Turn on the DSP processing in Pd. Make sure audio is working in Pd.

7. Click the DEFAULT SEQUENCE message box on the bottom left of the patch.  You should see the four arrays above that message box change to reflect the number sequence in the message box.

8. Turn up the output level slider at the top left part of the patch in the POLYPHONIC SAMPLERS section.

9. Click the black toggle button that is labeled with CLICK HERE TO BEGIN PLAYING.

10. Generate new rhythmic patterns for each sample by clicking on the bang buttons in the GENETIC ALGORITHM CONTROLS.

11. Control other parts of the sound with:
   a) LEVELS: control the level of each sample separately
   b) MUTE: quickly mute or unmute one of the samples
   c) CIRCULAR SHIFT: shift the pattern around in a circle to the right for each specific sample

Have fun! Send me an email at jsh008@ucsd.edu if you have any questions.