Close

Processing sketch

A project log for Wooden sensor box w/ 2 rotary disks

A homebuilt wooden sensor box i made, mainly for controlling PureData.

Jan GoddeJan Godde 11/09/2015 at 19:050 Comments

This is the Processing code i used in the second demo video demonstrating the rotary disks.

It is receiving the Teensy data from the serial port (for communication syntax, see Arduino code in the other project log entry).

The wheel resolution (see LEDMode in Arduino code) is being controlled here.

All the values are being scaled.

// ***** wheelController Software *****
//  ******** Jan Godde, 2015 ********
// PROCESSING RECEIVE SKETCH FOR arduinoSendWheelsMore SKETCH
//     USING PHASE VOCODER IN PD IN soundWheel.pd SKETCH

import processing.serial.*;
import org.puredata.processing.PureData;
PureData pd; // don't forget: expr operator seems not to be working with pdp5!
final int REVOL = 308; // resolution optimized: 4 x (77 black bars)

Serial myPort;

String thisString = "0";
int[] splitString = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1};

int LEDMode;
int wheel2Mode;
float pos1, pos2;

float ribbon1, ribbon2, fader1, fader2, fsr1, fsr2;
float knob1, knob2, knob3, knob4;
float lefttouch, righttouch, mono, wheeltouch1, wheeltouch2;

float[] inputValue = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; //fader, pressure, knobs, 2 wheels
float[] touch = {0, 0, 0, 0, 0}; //2 touch ducking - 1 touch mono (middle) - 2 wheel touch
float[] ribbon = {0, 0};

void setup()
{
  pd = new PureData(this, 44100, 0, 2);
  pd.openPatch("wheelSound.pd");
  pd.start();
  
  size(1200,700);
  background(0);
  noStroke();
  smooth();
  
  LEDMode = 0;
  wheel2Mode = 0;
  
  String portName = Serial.list()[4]; // N° 4
  myPort = new Serial(this, portName, 57600);
  //myPort.bufferUntil('\n');
  myPort.clear();
}

void draw()
{
  myPort.clear();
    
  lefttouch = constrain( map(touch[0], 1000, 5700, 0, 1000), 0, 1000 );
  righttouch = constrain( map(touch[1], 1050, 5700, 0, 1000), 0, 1000 );
  mono = constrain( map(touch[2], 1000, 5700, 0, 1000), 0, 1000 );
  wheeltouch1 = constrain( map(touch[3], 1500, 6500, 0, 1000), 0, 1000 );
  wheeltouch2 = constrain( map(touch[4], 1500, 6500, 0, 1000), 0, 1000 );
  
  fader1 = constrain( map(inputValue[0], 0, 1023, 0, 1000), 0, 1000 ); //fader1
  fader2= constrain( map(inputValue[1], 0, 1023, 0, 1000), 0, 1000 ); //fader2
  fsr1 = constrain( map(inputValue[2], 0, 700, 0, 1000), 0, 1000 );  //fsr1
  fsr2 = constrain( map(inputValue[3], 200, 700, 0, 1000), 0, 1000 );//fsr2
  knob1 = constrain( map(inputValue[4], 0, 1023, 0, 1000), 0, 1000 ); //knob1
  knob2 = constrain( map(inputValue[5], 0, 1023, 0, 1000), 0, 1000 ); //knob2
  knob3 = constrain( map(inputValue[6], 0, 1023, 0, 1000), 0, 1000 ); //knob3
  knob4 = constrain( map(inputValue[7], 0, 1023, 0, 1000), 0, 1000 ); //knob4
  
  ribbon1 = constrain( map(ribbon[0], 450, 750, 0, 1000), 0, 1000 );
  ribbon2 = constrain( map(ribbon[1], 450, 750, 0, 1000), 0, 1000 );
        
  drawWheels(inputValue[8], inputValue[9], wheeltouch1, wheeltouch2);
  
  pos1 = constrain( map(inputValue[8], 0, ((LEDMode+1)*REVOL), 0, 1000), 0, 1000 );
  pos2 = constrain( map(inputValue[9], 0, ((LEDMode+1)*REVOL), 0, 1000), 0, 1000 );

  // send all values from 0...1000
  pd.sendFloat("vol1", (float)fader1); //fader1
  pd.sendFloat("vol2", (float)fader2); //fader2
  pd.sendFloat("pvrev1", (float)knob2); //knob2
  pd.sendFloat("pvrev2", (float)knob3); //knob3
  pd.sendFloat("drywet1", (float)knob1); //knob1
  pd.sendFloat("drywet2", (float)knob4); //knob4
  pd.sendFloat("pos1", (float)pos1); // wheel 1 position
  pd.sendFloat("pos2", (float)pos2); // wheel 2 position
  pd.sendFloat("transpose1", (float)fsr1); //fsr1
  pd.sendFloat("transpose2", (float)fsr2); //fsr2
  pd.sendFloat("touch7", (float)lefttouch); 
  pd.sendFloat("touch9", (float)righttouch); 
  pd.sendFloat("touch8", (float)mono); // "mono" channel cross-talk
  pd.sendFloat("wheeltouch1", (float)wheeltouch1); // wheel touch 1 & 2
  pd.sendFloat("wheeltouch2", (float)wheeltouch2);
  pd.sendFloat("wheel2mode", (float)wheel2Mode); // scratch mode on/off on wheel 2
  pd.sendFloat("ribbon1", (float)ribbon1);
  pd.sendFloat("ribbon2", (float)ribbon2);
}

void drawWheels(float pos1, float pos2, float touch1, float touch2)
{
  background(0);
  noFill();
  //fill(255);
  strokeWeight(4);
  stroke(255);
  ellipse(310, 350, 500, 500);
  ellipse(890, 350, 500, 500);
    strokeWeight(20);
    
    pushMatrix();
    translate(310,350);
    rotate(radians((pos1/(REVOL*wheelResolution()))*360));
    stroke(55+((touch1/1000)*200));
    line(0,0,0,-220);
    popMatrix();
    
    pushMatrix();
    translate(890,350);
    rotate(radians((pos2/(REVOL*wheelResolution()))*360));
    stroke(55+((touch2/1000)*200));
    line(0,0,0,-220);
    popMatrix();
}

void serialEvent (Serial myPort){
  thisString = myPort.readStringUntil('\n');
  if (thisString != null){
    thisString = trim(thisString);
    splitString = int(split(thisString, ' '));

    if (splitString.length == 19){
      inputValue[0] = int(splitString[0]);
      inputValue[1] = int(splitString[1]);
      inputValue[2] = int(splitString[2]);
      inputValue[3] = int(splitString[3]);
      inputValue[4] = int(splitString[4]);
      inputValue[5] = int(splitString[5]);
      inputValue[6] = int(splitString[6]);
      inputValue[7] = int(splitString[7]);
      touch[0] = int(splitString[8]);
      touch[1] = int(splitString[9]);
      touch[2] = int(splitString[10]);
      touch[3] = int(splitString[11]);
      touch[4] = int(splitString[12]);
      inputValue[8] = int(splitString[13]); // wheel left position
      inputValue[9] = int(splitString[14]); // wheel right position
      LEDMode = int(splitString[15]);
      wheel2Mode = int(splitString[16]);
      ribbon[0] = int(splitString[17]);
      ribbon[1] = int(splitString[18]);
    }
  }
}

float wheelResolution(){
  switch(LEDMode){
    case 0:
      return 1.0;
    case 1:
      return 2.0;
    case 2:
      return 3.0;
    case 3:
      return 4.0;
    case 4:
      return 5.0;
  }
  return 1.0;
}

Discussions