Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // proController
- // http://creativecomputing.cc/p5libs/procontroll/
- // get 64 bit lib:
- // https://github.com/samaaron/jinput/blob/master/native/macosx/x86_64/libjinput-osx.jnilib
- import oscP5.*;
- import netP5.*;
- import procontroll.*;
- import java.io.*;
- OscP5 oscP5;
- NetAddressList myNetAddressList = new NetAddressList();
- int myListeningPort = 9004;
- int myBroadcastPort = 9005;
- String myConnectPattern = "/connect";
- String myDisconnectPattern = "/disconnect";
- ControllIO controll;
- ControllStick stick;
- ControllButton [] buttons = new ControllButton[8];
- void setup(){
- size(400,400);
- oscP5 = new OscP5(this, myListeningPort);
- controll = ControllIO.getInstance(this);
- //controll.printDevices();
- int deviceID = 2;
- ControllDevice device = controll.getDevice(deviceID);
- println(device.getName()+" has:");
- println(" " + device.getNumberOfSliders() + " sliders");
- println(" " + device.getNumberOfButtons() + " buttons");
- println(" " + device.getNumberOfSticks() + " sticks");
- device.printSliders();
- device.printButtons();
- device.printSticks();
- for(int i = 0; i < 8; i++){
- buttons[i] = device.getButton(i);
- }
- stick = device.getStick(0);
- }
- void draw(){
- background(255);
- fill(0);
- textSize(12);
- ArrayList<NetAddress> addresses = myNetAddressList.list();
- println(addresses);
- for( int i = 0; i < addresses.size(); i++){
- text(addresses.get(i).address(),30,(i+1)*20);
- }
- for(int i = 0; i < 8; i++){
- if( buttons[i].pressed()){
- fill(255,0,0);
- sendButton(i,1);
- }else{
- sendButton(i,0);
- fill(0);
- }
- ellipse((i+1) * width/9.0,height/2,20,20);
- }
- //println(stick.getX());
- }
- void sendButton( int buttonNum, int val ){
- OscMessage m = new OscMessage("/button");
- m.add(buttonNum); /* add an int to the osc message */
- m.add(val); /* add an int to the osc message */
- oscP5.send(m, myNetAddressList);
- }
- void oscEvent(OscMessage theOscMessage) {
- /* check if the address pattern fits any of our patterns */
- if (theOscMessage.addrPattern().equals(myConnectPattern)) {
- connect(theOscMessage.netAddress().address());
- }
- else if (theOscMessage.addrPattern().equals(myDisconnectPattern)) {
- disconnect(theOscMessage.netAddress().address());
- }
- /**
- * if pattern matching was not successful, then broadcast the incoming
- * message to all addresses in the netAddresList.
- */
- else {
- //oscP5.send(theOscMessage, myNetAddressList);
- }
- }
- private void connect(String theIPaddress) {
- if (!myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
- myNetAddressList.add(new NetAddress(theIPaddress, myBroadcastPort));
- println("### adding "+theIPaddress+" to the list.");
- } else {
- println("### "+theIPaddress+" is already connected.");
- }
- println("### currently there are "+myNetAddressList.list().size()+" remote locations connected.");
- }
- private void disconnect(String theIPaddress) {
- if (myNetAddressList.contains(theIPaddress, myBroadcastPort)) {
- myNetAddressList.remove(theIPaddress, myBroadcastPort);
- println("### removing "+theIPaddress+" from the list.");
- } else {
- println("### "+theIPaddress+" is not connected.");
- }
- println("### currently there are "+myNetAddressList.list().size());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement