We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSound,  Music Libraries › export an app using sc &oscP5 library is possible
Page Index Toggle Pages: 1
export an app using sc &oscP5 library is possible? (Read 482 times)
export an app using sc &oscP5 library is possible?
Nov 13th, 2009, 5:46am
 
Hi All,
i want to export this patch to application, is this possible

import oscP5.*;
import netP5.*;

import supercollider.*;
Synth synth1;
Synth synth2;

Cell[][] grid;

int cols = 6;
int rows = 6;

OscP5 oscP5;
int receiveAtPort;
int sendToPort;
String host;
String oscP5event;
int r = 155;
int g = 100;
int b = 100;

void setup(){
 background(0);
 size(400, 400);  
 initOsc();
  synth1 = new Synth("sine");
 synth2 = new Synth("sin_press");
 synth1.set("amp", 0.0);
 synth1.set("freq", 440);
 synth1.set("amp", 0.0);
 synth1.set("freq", 440);
 synth1.create();
 synth2.create();

   noCursor();
 grid = new Cell[cols][rows];

 for (int i = 0; i < cols; i++) {
   for (int j = 0; j < rows; j++) {
     grid[i][j] = new Cell(i*80,j*80,80,80, i+j+1);
   }
 }

}

// initialise all OSC functionality
void initOsc() {
 receiveAtPort = 12000;
 sendToPort = 57120; // supercollider (the language, not the server) listens to port 57120
 host = "127.0.0.1"; // internal IP address - if you want to send to another computer put it's IP here
 oscP5event = "oscEvent"; // the analyser method
 oscP5 = new OscP5(this, host, sendToPort, receiveAtPort, oscP5event);
}


void draw() {
 background(255);
   for (int i = 0; i < cols; i++) {
   for (int j = 0; j < rows; j++) {
     grid[i][j].ang();
     grid[i][j].osc();
     grid[i][j].display();
     grid[i][j].shine();
     grid[i][j].play();
     grid[i][j].kouti();
     grid[i][j].rand();

   }
 }

}

void mousePressed() {        
 // the arguments of the message are stored in an object array.
 Object[] tObj;
 tObj = new Object[] {
   int(mouseY), int(mouseX), "yippyy!"  };

 // a message with the address pattern /test and the arguments
 //stored in the object array tObj will be sent out
         
           oscP5.sendMsg("/test", tObj);        
 
}




class Cell {
 float x, y;
 float w, h;
 float angle;

 Cell(float tempX, float tempY, float tempW, float tempH, float tempAngle) {
   x = tempX;
   y = tempY;
   w = tempW;
   h = tempH;
   angle = tempAngle;
 }
 void ang() {
   angle *= 1.1234;
 }

 void osc() {
   for (int i = 0; i < cols; i++) {
     for (int j = 0; j < rows; j++) {
       fill(i*50, j*50, (i+j)*24, 34*j);
       ellipseMode(CENTER);
       ellipse(x, y, i*i, j*j);

       if (mousePressed){
         fill(i*sin(angle), (i+j)*23, 123*cos(angle), 45*sin(angle));
         ellipse(x+random(2), y+random(2), i*i, j*j);
         stroke(i*sin(angle), 123*cos(angle), (i-j)*23*sin(angle), 45*sin(angle));
         strokeWeight(0.3);
         line(y, x, mouseX, mouseY);
         //          synth1.set("freq", i*j*23);
             synth1.set("freq", 5*x/j);
         synth1.set("freq", 5*y/i);        
         synth1.set("amp", 0.3);
     
       }          
     }
   }
 }

 void display() {
   smooth();
   stroke(123, 23, 24);
   line(x, y, mouseX, mouseY);
 }

 void shine() {
   for (int i = 0; i < cols; i++) {
     for (int j = 0; j < rows; j++) {
       if ( (int)mouseX > x-40 && (int)mouseX < x+40 &&
         (int)mouseY > y-40 && (int)mouseY < y+40 ) {        
         fill(255, 50, 24, i*j);
         ellipseMode(CENTER);
         ellipse(x, y, i*i, j*j);

       }
     }
   }
 }

 void play() {
   for (int i = 0; i < cols; i++) {
     for (int j = 0; j < rows; j++) {
       if ( (int)mouseX > x-40 && (int)mouseX < x+40 &&
         (int)mouseY > y-40 && (int)mouseY < y+40 ) {        
          synth1.set("freq", 40*x/i);  
         synth2.set("freq", 40*y/j);  
         synth1.set("amp", 0.1);
         synth2.set("amp", 0.1);

     
       }
     }
   }
 }
 void kouti() {
   for (int i = 0; i < cols; i++) {
     for (int j = 0; j < rows; j++) {
       if ( (int)mouseX > x-40 && (int)mouseX < x+40 &&
         (int)mouseY > y-40 && (int)mouseY < y+40 ) {        
         fill(x-y, (i+j)*42, y*i/x, x-i-j-y);
         rectMode(CENTER);
//   rotate(angle*0.0012);
         rect(x*i, y*j, i*i+40*i, j*j+40*j);
     
       }
     }
   }
 }
 void rand() {
   for (int i = 0; i < cols; i++) {
     for (int j = 0; j < rows; j++) {

       if (mousePressed){
         fill(x+i*sin(angle), (i+j)*23+y-x, y-123*cos(angle), 25*sin(angle));
         noStroke();
         ellipse(x/j+random(2)*i, y/i+random(2)*j, pow(i, 0.3), pow(j, 6));
       }
     }
   }
 }


}



void stop ()
{
 synth1.free();
 synth2.free();
}

///////////////////////
sc3 code
//////////////

(
SynthDef(\sinepulse, { |outbus = 0, amp = 0.03, freq =400, pan = 0|
           var src, data, env;
           env = EnvGen.kr(Env.perc, 0.02, doneAction: 0);
           data = Lag.kr(freq, 0.13)*FSinOsc.ar(freq/124);
           src =  Linen.kr(Impulse.kr(2)*env, 0.01, 0.6, 0.58)*SinOsc.ar(freq, 0, amp/14)*data;
           Out.ar(outbus, Pan2.ar(src, pan));
           }
).load(s);

r = OSCresponder(nil, '/test', { arg time, resp, msg;
     [msg].postln;
     Synth(\sinepulse, [\freq, 800 - msg[1]-msg[2]]);      
}).add;
)
///////////////////
(
SynthDef(\sine, { |outbus = 0, amp = 0.4, freq = 440, pan = 0|
       var data;
       freq = Lag.kr(freq, 0.1);
       data = SinOsc.ar(freq, 0, amp)*FSinOsc.kr(10);
       Out.ar(outbus, Pan2.ar(data, pan));
}).store;


SynthDef(\sin_press, { |outbus = 0, amp = 0.23, freq =400, pan = 0|
           var src;
           freq = Lag.kr(freq, 0.13)*FSinOsc.kr(42);
           src = SinOsc.ar(freq, 0, amp);
           Out.ar(outbus, Pan2.ar(src, pan));
           }
).store;
)


Page Index Toggle Pages: 1