Hello everyone
I have a problem with this drummachine. I can not add another row of sound that is from my disktop and not from Minim. The 4. row just plays the previous soundpiece? What can I do to change it?
When I set the fill() for the text, the screen get this color! I do not know if it is because of the blinking square background.
Hope you see the error! thank you
import processing.sound.*;
import cc.arduino.;
import processing.serial.;
import processing.opengl.*;
Serial myPort; //Creating a object from serial classes
SoundFile file;
import ddf.minim.;
import ddf.minim.ugens.;
Minim minim;
AudioOutput out;
Sampler kick;
Sampler snare;
Sampler hat;
Sampler coin;
boolean[] hatRow = new boolean[16];
boolean[] snrRow = new boolean[16];
boolean[] kikRow = new boolean[16];
boolean[] coiRow = new boolean[16];
ArrayList buttons = new ArrayList();
int bpm = 200; // Beats pr. minute
int beat; // Indicateing which beat we are on
class Tick implements Instrument
{
void noteOn( float dur ) //The instrument implementation
{
if ( hatRow[beat] ) hat.trigger();
if ( snrRow[beat] ) snare.trigger();
if ( kikRow[beat] ) kick.trigger();
if ( coiRow[beat] ) kick.trigger();
}
void noteOff()
{
// next beat
beat = (beat+1)%16;
// set the new tempo
out.setTempo( bpm );
// play this again right now, with a sixteenth note duration
out.playNote( 0, 0.25f, this );
}
}
// simple class for drawing the gui
class Rect
{
int x, y, w, h;
boolean[] steps;
int stepId;
public Rect(int _x, int _y, boolean[] _steps, int _id)
{
x = _x;
y = _y;
w = 20;
h = 35;
steps = _steps;
stepId = _id;
}
void draw()
{
if ( steps[stepId] )
{
fill(255);
stroke(0);
}
else
{
fill(253,69,255);
}
rect(x,y,w,h);
}
public void mousePressed()
{
if ( mouseX >= x && mouseX <= x+w && mouseY >= y && mouseY <= y+h )
{
steps[stepId] = !steps[stepId];
}
}
}
void setup()
{
size(500, 400);
minim = new Minim(this);
out = minim.getLineOut();
file = new SoundFile(this,âcoin.wavâ);
// loading all the samples, using 4 voices for each.
kick = new Sampler( âBD.wavâ, 4, minim );
snare = new Sampler( âSD.wavâ, 4, minim );
hat = new Sampler( âCHH.wavâ, 4, minim );
coin = new Sampler( âcoin.wavâ, 4, minim);
// patch samplers to the output
kick.patch( out );
snare.patch( out );
hat.patch( out );
coin.patch( out );
for (int i = 0; i < 16; i++)
{
buttons.add( new Rect(10+i24, 50, hatRow, i ) );
buttons.add( new Rect(10+i24, 100, snrRow, i ) );
buttons.add( new Rect(10+i24, 150, kikRow, i ) );
buttons.add( new Rect(10+i24, 200, coiRow, i ) );
}
beat = 0;
// start the sequencer
out.setTempo( bpm );
out.playNote( 0, 0.25f, new Tick() );
}
void draw()
{
background(255);
textSize(25);
text(âBeatmakerâ, 10, 30);
square(0, 0, 500); //square(x, y, extent) x and y is the cordinats of the placement and the extend is the size.
fill(255,292,103);
for(int i = 0; i < buttons.size(); ++i)
{
buttons.get(i).draw();
}
stroke(255);
if ( beat % 4 == 0 )
{
fill(255, 235, 242); // Light pink
}
else
{
fill(255, 217, 251); //Light purple
}
// beat marker
rect(10+beat*24, 25, 20, 9, 2);
}
void mousePressed()
{
for(int i = 0; i < buttons.size(); ++i)
{
buttons.get(i).mousePressed();
}
}