16 Step 2 Layer Sequencer

Status
Not open for further replies.

cosmictea

Member
View attachment _16layersPart1.inoView attachment _16layersPart2.ino

Sorry the code is so big I had to send it in two parts. I've been working on a 16 step sequencer with two layers. It works well. There might be a few kinks left to hammer out and so I wanted to present this to the forum for anyone wanting to use it. Essentially there are 8 sampler buttons and 3 peripheral buttons. The 8 sampler buttons play a sample and whenever they are played within the sequence, it adds that sample to the sequence. There are envelopes for all audio elements (40 total playSdWavs, 80 envelopes, 1 for each channel/ear). I have it set up so the length of time you press a button is the same length of time the sample will play in the sequence. For example, if I hold a sample button down and play about half the sample, about half the sample will be inserted into the sequence.

The peripheral buttons are as follows: stepSection button, layerNumber button, and eraser button. The eraser button (button 21) erases whatever sample has been loaded onto a step in the sequence. How do you choose which step has its sample erased? The step currently playing is the one that gets erased when you press the button. The stepSection button allows me to change the samples for each button. So in the code you will see that I have a function containing sample names called "mySamples". There are 16 total sample names corresponding to the 16 samples on the SD card (audio board sd card slot). If stepSection is 1 I each sample button plays samples 1-8. If stepSection button is pressed, it is incremented to 2 and the sample buttons play samples 9-16. Finally the layerNumber determines which layer is played. Each step in the sequencer has the ability to play a sound loaded onto in in layer 1 or layer 2 or layer 3 which is the combination of layers 1 and 2. So you can make a beat on layer 1, make one on layer 2 and then play them superimposed on layerNumber 3. Each layer can play all 16 samples as long as you toggle the stepSection button. Just for clarification, each button corresponds to a sample. So for example, button 0 corresponds to sample 1 (indexed as 0 in mySamples) when stepSection is 1 and corresponds to sample 9 when stepSection is 2, button 1 corresponds to sample 2 and so on... Finally there is a tempo control, a 10k linear pot similar to the one in the PJRC audio tutorial.

I know this project has been done probably many times. I wanted to post it here in case anyone was interested in using a similar setup. Also, the code is LOOOONNNGGG. I feel that there is probably a better way to approach what I am trying to do with less code. As it stands now, structurally the code is simple, but there is an if statement for every possible combination (i.e. what happens when you press button 0 and stepSection = 1 and layerNumber =1, what happens when stepSection = 2, what about layerNumber = 2 and stepSection = 1 and so on). As a result the memory is dangerously close to maxed out. And so if you play the tempo fast and a lot of samples are playing at once, the program halts on the step it is on, and plays a loud noise as if your tv program cut out. If anyone has a better format for this code, let me know and I can alter it up. Thanks and enjoy!
 
Status
Not open for further replies.
Back
Top