• fullscreen
  • _2_Octavas_FOTO_BA2.pde
  • _2_Octavas_MIDI_OP.pde
  • /**
     * Pixel Array. 
     * 
     * Click and drag the mouse up and down to control the signal and 
     * press and hold any key to see the current pixel being read. 
     * This program sequentially reads the color of every pixel of an image
     * and displays this color to fill the window.  
     */
     
    import ddf.minim.*;
    import ddf.minim.signals.*;
    
    Minim minim;
    AudioOutput out;
    SineWave sine;
    PImage a;
    int[] aPixels;
    int direction = 1;
    boolean onetime = true;
    float signal;
    
    void setup() 
    {
      size(500, 333);
      aPixels = new int[width*height];
      noFill();
      stroke(255);
      frameRate(50);
      a = loadImage("Cumple Feliz.jpg");
      for(int i=0; i<width*height; i++) {
        aPixels[i] = a.pixels[i];
      }
      
      
      minim = new Minim(this);
      // get a line out from Minim, default bufferSize is 1024, default sample rate is 44100, bit depth is 16
      out = minim.getLineOut(Minim.STEREO);
      // create a sine wave Oscillator, set to 440 Hz, at 0.5 amplitude, sample rate from line out
      sine = new SineWave(440, 0.5, out.sampleRate());
      // set the portamento speed on the oscillator to 200 milliseconds
      sine.portamento(10);
      // add the oscillator to the line out
      out.addSignal(sine);
    }
    
    void draw() 
    {
      if (signal > width*height-1 || 
          signal < 0) { 
        direction = direction * -1; 
      }
    
      if(mousePressed) {
        if(mouseY > height-1) { 
          mouseY = height-1; 
        }
        if(mouseY < 0) { 
          mouseY = 0; 
        }
        signal = mouseY*width+mouseX;
      } else {
        signal += (0.33*direction);  
      }
      
      
        loadPixels();
        for (int i=0; i<width*height; i++) { 
          pixels[i] = aPixels[i];  
        }
        updatePixels();
        rect(signal%width-5, int(signal/width)-5, 10, 10);
        point(signal%width, int(signal/width));
       
      // with portamento on the frequency will change smoothly
      float freq = map(hue(aPixels[int(signal)]), 0, 255, 261.63, 523.25);
      //aPixels[int(signal)];
      sine.setFreq(freq);
      // pan always changes smoothly to avoid crackles getting into the signal
      // note that we could call setPan on out, instead of on sine
      // this would sound the same, but the waveforms in out would not reflect the panning
      float pan = map(pixels[int(signal)], 0, width, -1, 1);
      sine.setPan(pan);
      
      print ("\n Brillo= " + brightness (aPixels[int(signal)]) + "   hue= " + hue (aPixels[int(signal)]) + "  Freq= " + freq);
    }
    
    
    
    
    
    
    /**
     * Pixel Array. 
     * 
     * Click and drag the mouse up and down to control the signal and 
     * press and hold any key to see the current pixel being read. 
     * This program sequentially reads the color of every pixel of an image
     * and displays this color to fill the window.  
     */
     
    import themidibus.*; //Import the library
    MidiBus myBus; // The MidiBus
    
    PImage a;
    int[] aPixels;
    int direction = 1;
    boolean onetime = true;
    float signal;
    
    void setup() 
    {
      size(640, 400);
      
      MidiBus.list(); // List all available Midi devices on STDOUT. This will show each device's index and name.
    
    	// or for testing you could ...
    	//                 Parent  In        Out
    	//                   |     |          |
    	myBus = new MidiBus(this, "", "Java Sound Synthesizer"); // Create a new MidiBus with no input device and the default Java Sound Synthesizer as the output device.
    
      
      //aPixels setup
      aPixels = new int[width*height];
      noFill();
      stroke(255);
      frameRate(30);
      a = loadImage("Cumple Feliz.jpg");
      for(int i=0; i<width*height; i++) {
        aPixels[i] = a.pixels[i];
      }
      
    }
    
    void draw() 
    {
      if (signal > width*height-1 || 
          signal < 0) { 
        direction = direction * -1; 
      }
      
    
      if(mousePressed) {
        if(mouseY > height-1) { 
          mouseY = height-1; 
        }
        if(mouseY < 0) { 
          mouseY = 0; 
        }
        signal = mouseY*width+mouseX;
        //THEMIDIBUS Code
    {  
    int channel = 0;
    
    float pitchf = map(hue(aPixels[int(signal)]), 0, 255, 60, 84);
    int pitchi = int(pitchf);
    
    	int velocity = 127;
    	
    	myBus.sendNoteOn(6, pitchi, velocity); // Send a Midi noteOn
    	delay(400);
    	myBus.sendNoteOff(6, pitchi, velocity); // Send a Midi nodeOff
    	
    	int number = 0;
    	int value = 90;}
     	
      } else {
        signal += (0.33*direction);  
      }
      
    {
        loadPixels();
        for (int i=0; i<width*height; i++) { 
          pixels[i] = aPixels[i];  
        }
        updatePixels();
        rect(signal%width-5, int(signal/width)-5, 10, 10);
        point(signal%width, int(signal/width));
    }
    }
    
    
    
    
    
    

    code

    tweaks (0)

    about this sketch

    This sketch is running as Java applet, exported from Processing.

    license

    advertisement

    Ignacio de Salterain

    Color to Midi Musical Notes

    Add to Faves Me Likey@!
    You must login/register to add this sketch to your favorites.

    My idea is to create MIDI notes based on the RGB value of the pixel under the pointer i. For making this, I create a Midi pulse maping the Pixelarray variable with the pitch value of the Midi note. CLICK ON EACH COLOR OF THE ARROW AND DISCOVER A MELODY :)
    This calibration is arbitrary: red is C? G is yellow?
    You can change the code to match different notes to other colors.

    Thanks and credits for their help to Victor A. Gil when joining both codes and to Diego Vargas when searching the variable of the color in Pixelarray: aPixels[int(signal)]

    This Applet didn't worked in my browser.
    But works fine if you run it on the editor with The MidiBus library instaled.
    You get it here:
    http://smallbutdigital.com/themidibus.php
    it worked fine for me.
    Callum Rogers
    27 Aug 2009
    Didn't work for me (I don't have quicktime)
    I don't have it and worked for me.
    You don't need Qtime
    For what??
    It's Midi over Java. You only need a Processing Editor, Java instaled and the library The Midi Bus
    You get it here:
    http://smallbutdigital.com/themidibus.php
    Lawrie Cape
    12 Mar 2010
    This is pretty cool. I've just done a project myself turning colour info into midi notes, but I use a webcam to grab source images. You can check it out here - &lt;a href="http://www.lawriecape.co.uk/theblog/index.php/flash-midi-server"&gt;http://www.lawriecape.co.uk/theblog/index.php/flash-midi-server&lt;/a&gt;
    You need to login/register to comment.