Problem interpolation from 359 to 1°?

Hello,
I want to sample a movement.
You can sample a circular movement by pressing once the mouse.
It works in one way when i go straight forward but not the if i give a modulo.
The problem is in void draw here
// virtualV2= (virtualV2)%400; // problem Here!

Can you show me the good way to resolve this problem?

// MANAGE ARDUINO && TENNSY
//import processing.serial.*;
//Serial DueSerialNativeUSBport101;

//int v1=0;
//int v1InMainLoop=0;

int actualSec;
int lastSec;

int virtualV2;

boolean bRecording = false;
boolean mouseRecorded;
float currTime;
float nextSamplePeriod = 2.0;

class Sample {
  float t, x, y;
  Sample( float t, float x, float y ) {
    this.t = t;  this.x = x;  this.y = y;
  }
}
class Sampler {
  ArrayList<Sample> samples;
  float startTime;
  float sampleLengthTime;
  float period;
  int playbackFrame;
  Sampler( float newPeriod, float now, float x, float y ) {
    samples = new ArrayList<Sample>();
    startTime = now;
    addSample( now, x, y );
    playbackFrame = 0;
    period = newPeriod;
  }
  void addSample( float now, float x, float y ) {
    samples.add( new Sample( now - startTime, x, y ) );
    sampleLengthTime = now - startTime;
    if( sampleLengthTime > period )
      bRecording = false;
      mouseRecorded = false;
    // round up the period to the next power of 2
    //period = sampleLengthTime < 1 ? 1 :
    //  pow( 2, max( 0, ceil( log( sampleLengthTime ) / log(2) ) ) );
  }
  void draw( float now ) {
    if( samples.size() < 2 ) return;

    // draw the sample trail
    stroke( 255 );
    beginShape(LINES);
    for( int i=1; i<samples.size(); i++) {
      vertex( samples.get(i-1).x, samples.get(i-1).y );
      vertex( samples.get(i).x, samples.get(i).y );
    }
    endShape();

    // draw the current sample point
    //float st = (now - startTime) % period;
    float st = now % period;
    if( st > sampleLengthTime ) return;
    if( st < samples.get( playbackFrame ).t ) playbackFrame = 0;
    while( samples.get( playbackFrame+1).t < st )
      playbackFrame = (playbackFrame+1) % (samples.size()-1);

    Sample s0 = samples.get( playbackFrame );
    Sample s1 = samples.get( playbackFrame+1 );
    float t0 = s0.t;
    float t1 = s1.t;
    float dt = (st - t0) / (t1 - t0);
    float x = lerp( s0.x, s1.x, dt );
    float y = lerp( s0.y, s1.y, dt );
       
    float X = map (x, 0, 400, 0,  TWO_PI);
    float Y = map (y, 0, 400, 0,  TWO_PI);
  
    noStroke();
    fill( 255, 40, 40 );
    circle ( 100* cos (X)+400, 100*sin (Y)+400, 20);
  }
}

Sampler sampler;
ArrayList<Sampler> samplers;

void setup() {

 //** printArray(Serial.list());
  
//**  DueSerialNativeUSBport101 = new Serial(this, Serial.list()[2], 9600);

  // Read bytes into a buffer until you get a linefeed (ASCII 10):
//***  DueSerialNativeUSBport101.bufferUntil('\n');

  size( 800, 800, P3D );

  frameRate( 30 );

  samplers = new ArrayList<Sampler>();
}

void draw() {

      print( " INTERNAL CLOCK LastSec " )  ; print( " actualSec " ) ; println( actualSec ) ;
       
     if  (actualSec!=lastSec){
         lastSec=actualSec;   
     }
         actualSec = second()%2;  // Values from 0 - 10
         
  //v1InMainLoop=  mouseY;// doesn't work
  //v1InMainLoop=  v1;// // doesn't work
   mouseY=virtualV2;
   mouseX=virtualV2;
 // mouseY= v1;// // work almost but there is one or two bad datas playedback in a loop
//activeSamplingMeasure();
  activeSamplingSecond();
  samplingMovementPro();  
    
  virtualV2+=5;
//  virtualV2= (virtualV2)%400;  // problem Here!
  
  float x = map (virtualV2, 0, 400, 0,  TWO_PI);
  float y = map (virtualV2, 0, 400, 0,  TWO_PI);
  
  circle ( 100* cos (x)+200, 100*sin (y)+200, 20);

  }
 
void samplingMovementPro() {
  
  currTime = millis() * 0.001;  // seconds since app started
  background( 0 );
  for( int i=0; i<3; i++ ) {
    float p = pow( 2, i );
    stroke( 64, p == nextSamplePeriod ? 255 : 64, 64 );
    rect( (currTime % p) / p * width, i*10, 2, 8 );
  }

  if( bRecording ) {
    samplers.get(samplers.size()-1).addSample( currTime, mouseX, mouseY ); // work almost with mouseY=v1
  //  samplers.get(samplers.size()-1).addSample( currTime, mouseX, v1InMainLoop ); // doesn't work
  //net.phase[net.size()-1]=  map (mouseY, 0, 400, 0, TWO_PI);
  }
  
  for( Sampler s : samplers )
    s.draw( currTime );
}

void mousePressed() {  
  mouseRecorded = true;
  }


void activeSamplingSecond() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) );// work almost with mouseY=v1 
//  samplers.get(samplers.size()-1).addSample( currTime, mouseX, v1InMainLoop );// doesn't work
  }
}

void activeSamplingMeasure() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  //   if (measure%4<=0 && beatTrigged == true && mouseRecorded == true){
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) ); // work almost with mouseY=v1
//  samplers.get(samplers.size()-1).addSample( currTime, mouseX, v1InMainLoop );// doesn't work
  }
}

void keyPressed() {
  if( key == '1' )
    nextSamplePeriod = 1.0;
  else if( key == '2' )
    nextSamplePeriod = 2.0;
  else if( key == '4' )
    nextSamplePeriod = 4.0;
  else if( key == '8' )
    nextSamplePeriod = 8.0;
  else if( key == 'X' ) {
  if( samplers.size() > 0 )
      samplers.remove( samplers.size() - 1 );
  }
}
/*
void serialEvent(Serial DueSerialNativeUSBport101) { // receive 2 datas splited with , and the last is send with println from ARDUINO

  // read the serial buffer:
  String myString = DueSerialNativeUSBport101.readStringUntil('\n');

  // if you got any bytes other than the linefeed:
  myString = trim(myString);

  // split the string at the commas
  // and convert the sections into integers:
  int values[] = int(split(myString, ','));

  if (values.length > 0) {// v1 is the value of my stepperMotor from  0 to 4000
    v1 = (int) map (values[0], 0, 4000, 10, 410);
    print (" MouseY ");   print (mouseY);   print (" v1 ");   println (v1);     
  }
 }
 */```
1 Like

Hi @bking,

I can’t actually test your code because the Serial class/type cannot be found. Can you try to give us a code that is testable and simplified to the core issue you are facing? :wink:

1 Like

Hi,

I would like to sample the movement two seconds by pressing the mouse once.

I made a new program to make a circular movement with infinite incrementation.
Like that: virtualV2+=5. It works, the sample is well repeated.
But i want the program works with incrementation, like that: virtualV2= (virtualV2+=5)%400;

Because actually I want to record a movement passing through 399 to 1, which is actually 359° to 1°
And there is trouble when i do this.

I don’t understand

int actualSec;
int lastSec;

int virtualV2;

boolean bRecording = false;
boolean mouseRecorded;
float currTime;
float nextSamplePeriod = 2.0;

class Sample {
  float t, x, y;
  Sample( float t, float x, float y ) {
    this.t = t;  this.x = x;  this.y = y;
  }
}
class Sampler {
  ArrayList<Sample> samples;
  float startTime;
  float sampleLengthTime;
  float period;
  int playbackFrame;
  Sampler( float newPeriod, float now, float x, float y ) {
    samples = new ArrayList<Sample>();
    startTime = now;
    addSample( now, x, y );
    playbackFrame = 0;
    period = newPeriod;
  }
  void addSample( float now, float x, float y ) {
    samples.add( new Sample( now - startTime, x, y ) );
    sampleLengthTime = now - startTime;
    if( sampleLengthTime > period )
      bRecording = false;
      mouseRecorded = false;
    // round up the period to the next power of 2
    //period = sampleLengthTime < 1 ? 1 :
    //  pow( 2, max( 0, ceil( log( sampleLengthTime ) / log(2) ) ) );
  }
  void draw( float now ) {
    if( samples.size() < 2 ) return;

    // draw the sample trail
    stroke( 255 );
    beginShape(LINES);
    for( int i=1; i<samples.size(); i++) {
      vertex( samples.get(i-1).x, samples.get(i-1).y );
      vertex( samples.get(i).x, samples.get(i).y );
    }
    endShape();

    // draw the current sample point
    //float st = (now - startTime) % period;
    float st = now % period;
    if( st > sampleLengthTime ) return;
    if( st < samples.get( playbackFrame ).t ) playbackFrame = 0;
    while( samples.get( playbackFrame+1).t < st )
      playbackFrame = (playbackFrame+1) % (samples.size()-1);

    Sample s0 = samples.get( playbackFrame );
    Sample s1 = samples.get( playbackFrame+1 );
    float t0 = s0.t;
    float t1 = s1.t;
    float dt = (st - t0) / (t1 - t0);
    float x = lerp( s0.x, s1.x, dt );
    float y = lerp( s0.y, s1.y, dt );
       
    float X = map (x, 0, 400, 0,  TWO_PI);
    float Y = map (y, 0, 400, 0,  TWO_PI);
  
    noStroke();
    fill( 255, 40, 40 );
    circle ( 100* cos (X)+400, 100*sin (Y)+400, 20);
  }
}

Sampler sampler;
ArrayList<Sampler> samplers;

void setup() {


  size( 800, 800, P3D );

  frameRate( 30 );

  samplers = new ArrayList<Sampler>();
}

void draw() {

      print( " INTERNAL CLOCK LastSec " )  ; print( " actualSec " ) ; println( actualSec ) ;
       
     if  (actualSec!=lastSec){
         lastSec=actualSec;   
     }
         actualSec = second()%2;  // Values from 0 - 10

  mouseY=virtualV2;  mouseX=virtualV2;

  activeSamplingSecond();
  samplingMovementPro();  
    
//  virtualV2+=5; // no Problem
  virtualV2= (virtualV2+=5)%400;  // problem Here!
  
  float x = map (virtualV2, 0, 400, 0,  TWO_PI);
  float y = map (virtualV2, 0, 400, 0,  TWO_PI);
  
  circle ( 100* cos (x)+200, 100*sin (y)+200, 20);

  }
 
void samplingMovementPro() {
  
  currTime = millis() * 0.001;  // seconds since app started
  background( 0 );
  for( int i=0; i<3; i++ ) {
    float p = pow( 2, i );
    stroke( 64, p == nextSamplePeriod ? 255 : 64, 64 );
    rect( (currTime % p) / p * width, i*10, 2, 8 );
  }

  if( bRecording ) {
    samplers.get(samplers.size()-1).addSample( currTime, mouseX, mouseY ); // work almost with mouseY=v1

  }
  
  for( Sampler s : samplers )
    s.draw( currTime );
}

void mousePressed() {  
  mouseRecorded = true;
  }


void activeSamplingSecond() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) );// work almost with mouseY=v1 
//  samplers.get(samplers.size()-1).addSample( currTime, mouseX, v1InMainLoop );// doesn't work
  }
}

void activeSamplingMeasure() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  //   if (measure%4<=0 && beatTrigged == true && mouseRecorded == true){
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) ); // work almost with mouseY=v1

  }
}

void keyPressed() {
  if( key == '1' )
    nextSamplePeriod = 1.0;
  else if( key == '2' )
    nextSamplePeriod = 2.0;
  else if( key == '4' )
    nextSamplePeriod = 4.0;
  else if( key == '8' )
    nextSamplePeriod = 8.0;
  else if( key == 'X' ) {
  if( samplers.size() > 0 )
      samplers.remove( samplers.size() - 1 );
  }
}

Hi @bking,

Trigonometric functions are continuous, means you don’t need to map them between 0 and 360°

If you want to stick on the 400 you should use it as gradians and afterwards convert it to degrees by multiply by 0.9 and convert it to radians which you can use as input for sin/cos

To get the turns you could divide by 400 as integer an if the result changes to previous you have passed the round.

Cheers
— mnse

Other responses are getting distracted by your code and aren’t answering your question.

You want to interpolate between two values on a circle. There are two ways around the circle and when your values cross zero, the interpolation tries to go the long way around when you presumably want it to interpolate the short way. So, let’s find the shorter of the two.

Given x0 and x1, let’s find x that is t of the way from x0 to x1 modulo M, where M is 360 degrees or TWO_PI radians or 400 units of your angular sensor. I’ll assume that x0 and x1 have values between 0 and M. So, compute:

float mlerp( float x0, float x1, float t, float M ) {
   float dx = (x1 - x0 + 1.5*M) % M - 0.5*M;
   return (x0 + t * dx + M) % M;
}

dx will range from -0.5*M to 0.5*M. The 1.5*M business is to ensure that the term in the parentheses is positive since taking the remainder (%) of a negative number gives, unhelpfully, a negative result.

1 Like

Hi my new GOD,

I tried to integrate your new manner of interpolation.
But I don’t know how to use it.

I put the program below

int actualSec;
int lastSec;

int virtualV2;

boolean bRecording = false;
boolean mouseRecorded;
float currTime;
float nextSamplePeriod = 2.0;

class Sample {
  float t, x, y;
  Sample( float t, float x, float y ) {
    this.t = t;  this.x = x;  this.y = y;
  }
}
class Sampler {
  ArrayList<Sample> samples;
  float startTime;
  float sampleLengthTime;
  float period;
  int playbackFrame;
  
 //**** SCUDLY COMPUTATION TO PUT HERE ??
  float mlerp( float x0, float x1, float t, float M ) {
   float dx = (x1 - x0 + 1.5*M) % M - 0.5*M;
   return (x0 + t * dx + M) % M;
 //****
}
  
  
  Sampler( float newPeriod, float now, float x, float y ) {
    samples = new ArrayList<Sample>();
    startTime = now;
    addSample( now, x, y );
    playbackFrame = 0;
    period = newPeriod;
  }
  void addSample( float now, float x, float y ) {
    samples.add( new Sample( now - startTime, x, y ) );
    sampleLengthTime = now - startTime;
    if( sampleLengthTime > period )
      bRecording = false;
      mouseRecorded = false;
    // round up the period to the next power of 2
    //period = sampleLengthTime < 1 ? 1 :
    //  pow( 2, max( 0, ceil( log( sampleLengthTime ) / log(2) ) ) );
  }
  void draw( float now ) {
    if( samples.size() < 2 ) return;

    // draw the sample trail
    stroke( 255 );
    beginShape(LINES);
    for( int i=1; i<samples.size(); i++) {
      vertex( samples.get(i-1).x, samples.get(i-1).y );
      vertex( samples.get(i).x, samples.get(i).y );
    }
    endShape();

    // draw the current sample point
    //float st = (now - startTime) % period;
    float st = now % period;
    if( st > sampleLengthTime ) return;
    if( st < samples.get( playbackFrame ).t ) playbackFrame = 0;
    while( samples.get( playbackFrame+1).t < st )
      playbackFrame = (playbackFrame+1) % (samples.size()-1);

    Sample s0 = samples.get( playbackFrame );
    Sample s1 = samples.get( playbackFrame+1 );
    float t0 = s0.t;
    float t1 = s1.t;
    float dt = (st - t0) / (t1 - t0);
    float x = lerp( s0.x, s1.x, dt );
    float y = lerp( s0.y, s1.y, dt );
    
    //**** HOW RETRIEVING the COMPUTATION ?
    float X = map (x, 0, 400, 0,  TWO_PI);
    float Y = map (y, 0, 400, 0,  TWO_PI);
  
    noStroke();
    fill( 255, 40, 40 );
    circle ( 100* cos (X)+400, 100*sin (Y)+400, 20);
  }
}

Sampler sampler;
ArrayList<Sampler> samplers;

void setup() {


  size( 800, 800, P3D );

  frameRate( 30 );

  samplers = new ArrayList<Sampler>();
}

void draw() {

      print( " INTERNAL CLOCK LastSec " )  ; print( " actualSec " ) ; println( actualSec ) ;
       
     if  (actualSec!=lastSec){
         lastSec=actualSec;   
     }
         actualSec = second()%3;  // Values from 0 - 2

  mouseY=virtualV2;  mouseX=virtualV2;

  activeSamplingSecond();
  samplingMovementPro();  
    
//  virtualV2+=5; // no Problem
  virtualV2= (virtualV2+=5)%400;  // problem Here!
  
  float x = map (virtualV2, 0, 400, 0,  TWO_PI);
  float y = map (virtualV2, 0, 400, 0,  TWO_PI);
  
  circle ( 100* cos (x)+200, 100*sin (y)+200, 20);

  }
 
void samplingMovementPro() {
  
  currTime = millis() * 0.001;  // seconds since app started
  background( 0 );
  for( int i=0; i<3; i++ ) {
    float p = pow( 2, i );
    stroke( 64, p == nextSamplePeriod ? 255 : 64, 64 );
    rect( (currTime % p) / p * width, i*10, 2, 8 );
  }

  if( bRecording ) {
    samplers.get(samplers.size()-1).addSample( currTime, mouseX, mouseY ); // work almost with mouseY=v1

  }
  
  for( Sampler s : samplers )
    s.draw( currTime );
}

void mousePressed() {  
  mouseRecorded = true;
  }


void activeSamplingSecond() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) );// work almost with mouseY=v1 
//  samplers.get(samplers.size()-1).addSample( currTime, mouseX, v1InMainLoop );// doesn't work
  }
}

void activeSamplingMeasure() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  //   if (measure%4<=0 && beatTrigged == true && mouseRecorded == true){
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) ); // work almost with mouseY=v1

  }
}

void keyPressed() {
  if( key == '1' )
    nextSamplePeriod = 1.0;
  else if( key == '2' )
    nextSamplePeriod = 2.0;
  else if( key == '4' )
    nextSamplePeriod = 4.0;
  else if( key == '8' )
    nextSamplePeriod = 8.0;
  else if( key == 'X' ) {
  if( samplers.size() > 0 )
      samplers.remove( samplers.size() - 1 );
  }
}

Don’t put mlerp() as a member function of Sampler. Make it a global function so we can call it from anywhere.

You would use mlerp() in place of the lerp() function in the Sampler.draw(), but it will only be relevant if you are storing angles or other periodic values. For instance, if you were storing an angle in the y value:

    float x = lerp( s0.x, s1.x, dt );
    float y = mlerp( s0.y, s1.y, dt, 400 );
       
    float angle = map (y, 0, 400, 0,  TWO_PI);
  
    noStroke();
    fill( 255, 40, 40 );
    circle ( 100* cos (angle)+400, 100*sin (angle)+400, 20);

Note that we aren’t using the x value here at all. If you are only going to sample a single value, change the Sample to just store one value.

1 Like

So good. Thank you so much.
Do you think it would be difficult to reverse the movement of the sample? I think i will make a new post in a few days.
Have a nice day :slight_smile:

I put the program below if it can help someone

int actualSec;
int lastSec;

int virtualV2;

float mlerp(float x0, float x1, float t, float M ){
   float dx = (x1 - x0 + 1.5*M) % M - 0.5*M;
   return (x0 + t * dx + M) % M;
}

boolean bRecording = false;
boolean mouseRecorded;
float currTime;
float nextSamplePeriod = 2.0;

class Sample {
  float t, x, y;
  Sample( float t, float x, float y ) {
    this.t = t;  this.x = x;  this.y = y;
  }
}
class Sampler {
  ArrayList<Sample> samples;
  float startTime;
  float sampleLengthTime;
  float period;
  int playbackFrame;
  
 //**** SCULDY COMPUTATION TO PUT HERE ??
 
 //****

  
  
  Sampler( float newPeriod, float now, float x, float y ) {
    samples = new ArrayList<Sample>();
    startTime = now;
    addSample( now, x, y );
    playbackFrame = 0;
    period = newPeriod;
  }
  void addSample( float now, float x, float y ) {
    samples.add( new Sample( now - startTime, x, y ) );
    sampleLengthTime = now - startTime;
    if( sampleLengthTime > period )
      bRecording = false;
      mouseRecorded = false;
    // round up the period to the next power of 2
    //period = sampleLengthTime < 1 ? 1 :
    //  pow( 2, max( 0, ceil( log( sampleLengthTime ) / log(2) ) ) );
  }
  void draw( float now ) {
    if( samples.size() < 2 ) return;

    // draw the sample trail
    stroke( 255 );
    beginShape(LINES);
    for( int i=1; i<samples.size(); i++) {
      vertex( samples.get(i-1).x, samples.get(i-1).y );
      vertex( samples.get(i).x, samples.get(i).y );
    }
    endShape();

    // draw the current sample point
    //float st = (now - startTime) % period;
    float st = now % period;
    if( st > sampleLengthTime ) return;
    if( st < samples.get( playbackFrame ).t ) playbackFrame = 0;
    while( samples.get( playbackFrame+1).t < st )
      playbackFrame = (playbackFrame+1) % (samples.size()-1);

    Sample s0 = samples.get( playbackFrame );
    Sample s1 = samples.get( playbackFrame+1 );
    float t0 = s0.t;
    float t1 = s1.t;
    float dt = (st - t0) / (t1 - t0);
 
    float x = lerp( s0.x, s1.x, dt ); // interpolation with 'continious datas'
    float y = mlerp( s0.y, s1.y, dt, 400 ); // interpolation with 'cylical datas'
       
    float angle = map (y, 0, 400, 0,  TWO_PI);
  
    noStroke();
    fill( 255, 40, 40 );
    circle ( 100* cos (angle)+400, 100*sin (angle)+400, 20);
  }
}

Sampler sampler;
ArrayList<Sampler> samplers;

void setup() {
  size( 800, 800, P3D );
  frameRate( 30 );
  samplers = new ArrayList<Sampler>();
}

void draw() {
      print( " INTERNAL CLOCK LastSec " )  ; print( " actualSec " ) ; println( actualSec ) ;
     if  (actualSec!=lastSec){
         lastSec=actualSec;   
     }
         actualSec = second()%3;  // Values from 0 - 2

  mouseY=virtualV2;  mouseX=virtualV2;

  activeSamplingSecond();
  samplingMovementPro();  
    
//  virtualV2+=5; // no Problem
  virtualV2= (virtualV2+=5)%400;  // problem Here!
  
  float x = map (virtualV2, 0, 400, 0,  TWO_PI);
  float y = map (virtualV2, 0, 400, 0,  TWO_PI);
  
  circle ( 100* cos (x)+200, 100*sin (y)+200, 20);

  }
 
void samplingMovementPro() {
  
  currTime = millis() * 0.001;  // seconds since app started
  background( 0 );
  for( int i=0; i<3; i++ ) {
    float p = pow( 2, i );
    stroke( 64, p == nextSamplePeriod ? 255 : 64, 64 );
    rect( (currTime % p) / p * width, i*10, 2, 8 );
  }

  if( bRecording ) {
    samplers.get(samplers.size()-1).addSample( currTime, mouseX, mouseY ); // work almost with mouseY=v1

  }
  
  for( Sampler s : samplers )
    s.draw( currTime );
}

void mousePressed() {  
  mouseRecorded = true;
  }


void activeSamplingSecond() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) );// work almost with mouseY=v1 
//  samplers.get(samplers.size()-1).addSample( currTime, mouseX, v1InMainLoop );// doesn't work
  }
}

void activeSamplingMeasure() { 
   if (actualSec<=0 && actualSec!=lastSec && mouseRecorded == true) {
  //   if (measure%4<=0 && beatTrigged == true && mouseRecorded == true){
  bRecording = true;
  samplers.add( new Sampler( nextSamplePeriod, currTime, mouseX, mouseY ) ); // work almost with mouseY=v1

  }
}

void keyPressed() {
  if( key == '1' )
    nextSamplePeriod = 1.0;
  else if( key == '2' )
    nextSamplePeriod = 2.0;
  else if( key == '4' )
    nextSamplePeriod = 4.0;
  else if( key == '8' )
    nextSamplePeriod = 8.0;
  else if( key == 'X' ) {
  if( samplers.size() > 0 )
      samplers.remove( samplers.size() - 1 );
  }
}