프로세싱 예제입니다:)


import promidi.*;
import ddf.minim.*;

Minim minim;
AudioInput in;

MidiIO midiIO;

int drawtype = 2; //choose 1 ~ 4. default = 4;

float angle;
float cx, cy, cr;

int[] notes = new int[4];
int[] vels = new int[4];
boolean[] onoff = new boolean[4];
float[] timerOn = new float[4];
float[] interval = new float[4];
float[] sr = new float[4];
float[] velo = new float[4];
color[] col = new color[4];
int[] ap = new int[4];
float tradAvg;

void setup()
{
  size(800, 800);
  background(0);
  smooth();
  angle = 0;
  cx = width/2;
  cy = height/2;
  cr = 600;
  
  for(int i = 0; i < 4; i++)
  {
    ap[i] = 20;
  }
  
  col[0] = color(30, 48, 113);
  col[1] = color(20, 80, 30);
  col[2] = color(10, 30, 13);
  col[3] = color(30, 10, 10);  
  
  midiIO = MidiIO.getInstance(this);
  midiIO.printDevices();
  midiIO.openInput(2, 0); //input device, channel. set input device idx first.
  midiIO.openInput(2, 1);
  midiIO.openInput(2, 2);
  midiIO.openInput(2, 3);
  
  minim = new Minim(this);
  minim.debugOn();
  
  // get a line in from Minim, default bit depth is 16
  in = minim.getLineIn(Minim.STEREO, 512);
  tradAvg = 0;
  
}

void draw()
{
  background(255);
  stroke(0);
  round(angle+=1);
  
  
    fill(255, 200);
    ellipse(cx, cy, cr, cr);


  for(int i = 0; i < 4; i++)
  {
    float[] tvel = new float[4];
    tvel[i] = map(notes[i], 0, 127, 0, 4.0);

    float[] trad = new float[4];
    trad[i] = map(vels[i], 0, 127, 10, cr/3);
    
    float[] intv = new float[4];
    intv[i] = (4000 - interval[i])/2000;
    

    tradAvg+=trad[i];
    fill(col[i], ap[i]);
    ccc(cx, cy, cr/2 - trad[i]/2, trad[i], tvel[i]);
  }
  
    tradAvg = tradAvg/4.0;
  
    stroke(0);
    for(int i = 0; i < in.bufferSize() - 1; i++)
  {
    switch(drawtype){
      
    case 1:
    line((width/2) + cos(radians(i)) * (cr/2), height/8 + sin(radians(in.left.get(i)*200)) * (cr/2), width/2 + cos(radians(i+1)) * (cr/2), height/8 * 7 + sin(radians(in.left.get(i+1)*200)) * (cr/2));
    break;
    
    case 2:
    line((width/2) + cos(radians(i)) * (cr/2), height/2 + sin(radians(i)) * (cr/2), width/2 + cos(radians(i+1)) * (cr/2), height/2 + sin(radians(in.left.get(i+1)*200)) * (cr/2));
    break;
    
    case 3:
    line((width/2) + cos(radians(i)) * (cr/2), height/2 + sin(radians(i)) + (in.left.get(i)*300) , width/2 + cos(radians(i+1)) * (cr/2), height/2 + sin(radians((i+1))) * (cr/2) + (in.left.get(i+1)*300));    
    break;
    
    default:
    line((width/2) + cos(radians(i)) * (cr/2), height/2 + sin(radians((i))) * (cr/2) + (in.left.get(i)*200) , width/2 + cos(radians(i+1)) * (cr/2), height/2 + sin(radians((i+1))) * (cr/2) + (in.left.get(i+1)*2000));
    break;
    
    }
  }

  
}


void ccc(float xoffset, float yoffset, float rad, float sr, float vel)
{
  float[] tarr;
  tarr = new float[2];
    tarr[0] = round1(xoffset + sin(radians((angle*vel)%360)) * rad);
    tarr[1] = round1(yoffset + cos(radians((angle*vel)%360)) * rad);
    
  noStroke();
    ellipseh(tarr[0], tarr[1], sr, 5);
  
}


float round1(float in)
{
  return round(in * pow(10, 1)) / pow(10, 1);
}


void ellipseh(float px, float py, float rad, int layer)
{
  float tx, ty, tr;
  for(int i = 0; i < layer; i++)
  {
    tx = random(1.0);
    ty = random(1.0);
    tr = random(rad/10);
    
    ellipse(px + tx, py + ty, rad + tr, rad + tr);
  }
}

void stop()
{
  // always close Minim audio classes when you are done with them
  in.close();
  minim.stop();
  
  super.stop();
}



void noteOn(Note note, int device, int channel){
int vel = note.getVelocity();
int pit = note.getPitch();

notes[channel] = pit;
vels[channel] = vel;

  if(onoff[channel] == false)
  {
    timerOn[channel] = millis();
    onoff[channel] = true;
  }
}

void noteOff(Note note, int device, int channel){
  int pit = note.getPitch();

  onoff[channel] = false;
  vels[channel] = 0;  
  interval[channel] = millis() - timerOn[channel]; 
}

Advertisements