Two dimensional array of osc to max msp
in
Contributed Library Questions
•
1 year ago
Hi
I'm working on a sequencer based on a 2D cellular automata in processing which uses max msp for audio playback. I've set the processing code up so that it should send a message to max each time a cell on the CA is on. How ever I only get a message in max from "/pt1" in processing. If some one could have a look at my code and point me in the right direction I would be very grateful.
- import peasy.*;
- import toxi.geom.*;
- import oscP5.*;
- import netP5.*;
- //PeasyCam cam;
- OscP5 oscP5 = new OscP5(this, 7474);
- NetAddress myRemoteLocation = new NetAddress("127.0.0.1", 7475);
- int cols = 8;
- int rows = 8;
- CA grid [][] = new CA [cols][rows];
- void setup() {
- size(80, 80, P3D);
- smooth();
- frameRate(1);
- //cam = new PeasyCam(this, 100);
- for (int i = 0; i < cols; i ++) {
- for (int j = 0; j < rows; j ++) {
- Vec3D ptLoc = new Vec3D(i * 10, j * 10, 0);
- grid[i][j] = new CA(ptLoc, i, j, i, j);
- }
- }
- }
- void draw() {
- background(0);
- stroke(255);
- fill(255, 50);
- //rect(0, 0, 600, 600);
- for (int i = 0; i < cols; i ++) {
- for (int j = 0; j < rows; j ++) {
- Vec3D ptLoc = new Vec3D(i * 10, j * 10, 0);
- grid[i][j].run();
- }
- }
- for (int i = 0; i < cols; i ++) {
- for (int j = 0; j < rows; j ++) {
- Vec3D ptLoc = new Vec3D(i * 10, j * 10, 0);
- grid[i][j].updateType();
- }
- }
- }
- class CA {
- Vec3D loc;
- int x;
- int y;
- int type = 0;
- int futType = 0;
- float trigger;
- int oscX, oscY;
- String [][] addresses = { {"/pt1", "/pt2", "/pt3", "/pt4", "/pt5", "/pt6", "/pt7", "/pt8"},
- {"/pt9", "/pt10", "/pt11", "/p12", "/pt13", "/pt14", "/pt15", "/pt16"},
- {"/pt17", "/pt18", "/pt19", "/p20", "/pt21", "/pt22", "/pt23", "/pt24"},
- {"/pt25", "/pt26", "/pt27", "/p28", "/pt29", "/pt30", "/pt31", "/pt32"},
- {"/pt33", "/pt34", "/pt35", "/p36", "/pt37", "/pt38", "/pt39", "/pt40"},
- {"/pt41", "/pt42", "/pt43", "/p44", "/pt45", "/pt46", "/pt47", "/pt48"},
- {"/pt49", "/pt50", "/pt51", "/p52", "/pt53", "/pt54", "/pt55", "/pt56"},
- {"/pt57", "/pt58", "/pt59", "/p60", "/pt61", "/pt62", "/pt63", "/pt64"} };
- CA(Vec3D _loc, int _x, int _y, int oscX, int oscY) {
- loc = _loc;
- x = _x;
- y = _y;
- float rnd = random(100);
- if (rnd < 10) {
- type = 1;
- }
- }
- void run() {
- display();
- evalN();
- }
- void updateType() {
- type = futType;
- }
- void evalN() {
- int count = 0;
- if (grid [(x + cols - 1) % cols][(y + rows - 1) % rows].type == 1) count ++;
- if (grid [(x + cols) % cols][(y + rows - 1) % rows].type == 1) count ++;
- if (grid [(x + cols + 1) % cols][(y + rows - 1) % rows].type == 1) count ++;
- if (grid [(x + cols - 1) % cols][(y + rows) % rows].type == 1) count ++;
- if (grid [(x + cols + 1) % cols][(y + rows) % rows].type == 1) count ++;
- if (grid [(x + cols - 1) % cols][(y + rows + 1) % rows].type == 1) count ++;
- if (grid [(x + cols) % cols][(y + rows + 1) % rows].type == 1) count ++;
- if (grid [(x + cols + 1) % cols][(y + rows + 1) % rows].type == 1) count ++;
- if (type == 1 && count < 2) {
- futType = 0;
- trigger = 0.0;
- }
- if (type == 1 && count <=3 && count >= 2) {
- futType = 1;
- trigger = 1.0;
- }
- if (type == 1 && count > 3) {
- futType = 0;
- trigger = 0.0;
- }
- if (type == 0 && count == 3) {
- futType = 1;
- trigger = 1.0;
- }
- }
- void display() {
- if (type == 1) {
- stroke(255);
- strokeWeight(10);
- point(loc.x, loc.y);
- OscMessage myXOscMessage = new OscMessage(addresses[oscX][oscY]);
- myXOscMessage.add(trigger);
- oscP5.send(myXOscMessage, myRemoteLocation);
- }
- }
- }
1