Hello Jeremy,
I have mixed my program to trig sample into the example of DrumMachine in order to trig samples later. But I have always on the console
[0] "/dev/cu.BeatsPill-SPPDev-1"
[1] "/dev/cu.Bluetooth-Incoming-Port"
[2] "/dev/cu.JBLFlip3-SPPDev"
[3] "/dev/cu.UEBOOM-LWACP"
[4] "/dev/cu.usbmodem14201"
[5] "/dev/tty.BeatsPill-SPPDev-1"
[6] "/dev/tty.Bluetooth-Incoming-Port"
[7] "/dev/tty.JBLFlip3-SPPDev"
[8] "/dev/tty.UEBOOM-LWACP"
[9] "/dev/tty.usbmodem14201"
2771, 0, 0, 0, 1,
360
0
0
0
Error, disabling serialEvent() for /dev/cu.usbmodem14201
null
I have tried to stop program, unplug the serial port, plug it again and re start the program but I have always
Error, disabling serialEvent() for /dev/cu.usbmodem14201
null.
But I can use the sequencer properly.
I put the program below
import processing.opengl.*;
/**
* This sketch is a more involved use of AudioSamples to create a simple drum machine.
* Click on the buttons to toggle them on and off. The buttons that are on will trigger
* samples when the beat marker passes over their column. You can change the tempo by
* clicking in the BPM box and dragging the mouse up and down.
* <p>
* We achieve the timing by using AudioOutput's playNote method and a cleverly written Instrument.
* <p>
* For more information about Minim and additional features,
* visit http://code.compartmental.net/minim/
*/
import ddf.minim.*;
import ddf.minim.ugens.*;
Minim minim;
AudioOutput out;
Sampler kick;
Sampler snare;
Sampler hat;
boolean[] hatRow = new boolean[16];
boolean[] snrRow = new boolean[16];
boolean[] kikRow = new boolean[16];
ArrayList<Rect> buttons = new ArrayList<Rect>();
int bpm = 120;
int beat; // which beat we're on
// here's an Instrument implementation that we use
// to trigger Samplers every sixteenth note.
// Notice how we get away with using only one instance
// of this class to have endless beat making by
// having the class schedule itself to be played
// at the end of its noteOff method.
class Tick implements Instrument
{
void noteOn( float dur )
{
if ( hatRow[beat] ) hat.trigger();
if ( snrRow[beat] ) snare.trigger();
if ( kikRow[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 = 14;
h = 30;
steps = _steps;
stepId = _id;
}
public void draw()
{
if ( steps[stepId] )
{
fill(0,255,0);
}
else
{
fill(255,0,0);
}
rect(x,y,w,h);
}
public void mousePressed()
{
if ( mouseX >= x && mouseX <= x+w && mouseY >= y && mouseY <= y+h )
{
steps[stepId] = !steps[stepId];
}
}
}
import processing.serial.*; // import data from Arduino
Serial myPort; // The serial port
int v0 = 0;
int v1 = 0;
int v2 = 0;
int v3 = 0;
int v4 = 0;
int x;
void setup()
{
printArray(Serial.list());
myPort = new Serial(this, Serial.list()[4], 115200);
// Read bytes into a buffer until you get a linefeed (ASCII 10):
myPort.bufferUntil('\n');
size(395, 200);
minim = new Minim(this);
out = minim.getLineOut();
// load all of our samples, using 4 voices for each.
// this will help ensure we have enough voices to handle even
// very fast tempos.
kick = new Sampler( "BD.wav", 4, minim );
snare = new Sampler( "SD.wav", 4, minim );
hat = new Sampler( "CHH.wav", 4, minim );
// patch samplers to the output
kick.patch( out );
snare.patch( out );
hat.patch( out );
for (int i = 0; i < 16; i++)
{
buttons.add( new Rect(10+i*24, 50, hatRow, i ) );
buttons.add( new Rect(10+i*24, 100, snrRow, i ) );
buttons.add( new Rect(10+i*24, 150, kikRow, i ) );
}
beat = 0;
// start the sequencer
out.setTempo( bpm );
out.playNote( 0, 0.25f, new Tick() );
}
void draw()
{
background(0);
fill(255);
//text(frameRate, width - 60, 20);
for(int i = 0; i < buttons.size(); ++i)
{
buttons.get(i).draw();
}
stroke(128);
if ( beat % 4 == 0 )
{
fill(200, 0, 0);
}
else
{
fill(0, 200, 0);
}
// beat marker
rect(10+beat*24, 35, 14, 9);
}
void mousePressed()
{
for(int i = 0; i < buttons.size(); ++i)
{
buttons.get(i).mousePressed();
}
}
void serialEvent(Serial myPort) {
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
// if you got any bytes other than the linefeed:
println(myString);
int values[] = int(trim(split(myString, ',')));
// ATTENTION LANCE ARDUINO pendant 5 sec puis Processing
v0 = (int)map(values[0], 0, 2771, 0, 360);
v1 = (int)map(values[1], 0, 2771, 0, 360);
v2 = (int)map(values[2], 0, 2771, 0, 360);
v3 = (int)map(values[3], 0, 2771, 0, 360);
v4 = (int)map(values[4], 0, 2771, 0, 360);
println (v0); println (v1); println (v2); println (v3);
if (v0>=350) snare.trigger();
if (v1>=350) snare.trigger();
if (v2>=350) snare.trigger();
if (v3>=350) snare.trigger();
if (v4>=350) snare.trigger();
}