Load images to PGraphics (export to Syphon)

edited December 2013 in How To...

What I'm trying to make:

  1. Listen to MIDI commands
  2. Load all images from folder
  3. Each frame show images, that correspond to pressed keys (MIDI notes on)
  4. Send picture to Syphon

I have app, that works as I wanted on Processing display. But what I see on Syphon incoming signal [in other app] is missing these images. I think it might be connected to way that I display these images.

Here is how it looks like in Processing app:

https://www.monosnap.com/image/HN8crWfkUpJvc5CZnFFrFRTgZ

Here is how it looks in Syphon (no change from initial state):

https://www.monosnap.com/image/Mq4RujuW3uQlYeAq4uGVn8JbY

Here is my code:

PImage img;
import themidibus.*; //Import the library
MidiBus myBus; // The MidiBus

import codeanticode.syphon.*;
PGraphics canvas;
SyphonServer server;

int notes = 13; // number of masks
int firstNotePitch = 24; // shifting notes to take C0
int knobsNum = 8;

PImage pi[] = new PImage[notes];
boolean notesOn[] = new boolean[100];
float knobValues[] = new float[knobsNum+1];

void setup() {
  MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
  myBus = new MidiBus(this, 0, 2); // Create a new MidiBus using the device index to select the Midi input and output devices respectively.

  size(1280, 720, P3D);
  canvas = createGraphics(1280, 720, P3D);

  for(int i=0; i<notes; i++) {
    pi[i] = loadImage("mask"+i+".png");
  }

  frameRate(30); 

  // Create syphon server to send frames out.
  server = new SyphonServer(this, "MIDI masks2");
}

// I BELIEVE THAT MY PROBLEMS ARE HERE
void draw() {
  canvas.background(#ff9900);
  for(int i=0; i<notes; i++) {
    if (notesOn[i]) {
      image(pi[i], 0, 0);
    }
  }
  server.sendImage(canvas);
}

void noteOn(int channel, int pitch, int velocity) {
  println("Pitch:"+pitch);
  int pitchShifted = pitch - firstNotePitch;
  notesOn[pitchShifted] = true;
}

void noteOff(int channel, int pitch, int velocity) {
  // Receive a noteOff
  int pitchShifted = pitch - firstNotePitch;
  notesOn[pitchShifted] = false;
}

void controllerChange(int channel, int number, int value) {
  // Receive new value on knob modification
  knobValues[number] = value/127.000;
}

I guess, that problem is the way I put images into scene. What is proper way to do that?

Thank you in advance!

Answers

  • solution is here http://forum.processing.org/two/discussion/comment/3810#Comment_3810

    my final code is: PImage img; import themidibus.*; //Import the library MidiBus myBus; // The MidiBus

    import codeanticode.syphon.*;
    PGraphics canvas;
    SyphonServer server;
    
    int notes = 13; // number of masks
    int firstNotePitch = 24; // shifting notes to take C0
    int knobsNum = 8;
    
    PImage pi[] = new PImage[notes];
    boolean notesOn[] = new boolean[100];
    float knobValues[] = new float[knobsNum+1];
    
    SFD send; // object for Syphon out sending
    
    void setup() {
      MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
      myBus = new MidiBus(this, 1, 2); // Create a new MidiBus using the device index to select the Midi input and output devices respectively.
    
      for (int i=0; i<notes; i++) {
        pi[i] = loadImage("mask"+i+".png");
      }
    
      size(1280, 720, P3D);
      canvas = createGraphics(1280, 720, P3D);
    
      frameRate(30); 
    
      send = new SFD(this); // new Syphon Server
    }
    
    void draw() {
      drawMidi();
      send.update(); 
    }
    
    void drawMidi() {
      background(0);
      for (int i=0; i<notes; i++) {
        if (notesOn[i]) {
          image(pi[i], 0, 0);
        }
      }
    }
    
    void noteOn(int channel, int pitch, int velocity) {
      println("Pitch:"+pitch);
      int pitchShifted = pitch - firstNotePitch;
      notesOn[pitchShifted] = true;
    }
    
    void noteOff(int channel, int pitch, int velocity) {
      // Receive a noteOff
      int pitchShifted = pitch - firstNotePitch;
      notesOn[pitchShifted] = false;
    }
    
    void controllerChange(int channel, int number, int value) {
      // Receive new value on knob modification
      // knobValues[number] = value/127.000;
    }
    

    and class SDF in separate file

    import codeanticode.syphon.*;
    class SFD{
      public PGraphics canvas;
      public SyphonServer server;
      PApplet that;
      SFD(PApplet tthat){
        that = tthat;
        canvas = createGraphics(that.width, that.height, P3D);
        // Create syhpon server to send frames out.
        server = new SyphonServer(that, "Processing Syphon");
      }
    
      void update(){
        that.loadPixels();
        canvas.loadPixels();
    //    for(int i=0;i<that.pixels.length;i++){
    //      canvas.pixels[i] = that.pixels[i];
    //    }
        arrayCopy(that.pixels, canvas.pixels);
        canvas.updatePixels();
        server.sendImage(canvas);
      }
    }
    
Sign In or Register to comment.