Trying to add a song using minim

edited February 2018 in Arduino

Hi:

import processing.video.*;
import ddf.minim.*;
import ddf.minim.AudioPlayer;

// Size of each cell in the grid
int cellSize = 20;
// Number of columns and rows in our system
int cols, rows;
// Variable for capture device
Capture video;
Minim minim;
AudioPlayer song;

void setup() {
size(1280, 720);
frameRate(30);
cols = width / cellSize;
rows = height / cellSize;
colorMode(RGB, 255, 255, 255, 100);

// This the default video input, see the GettingStartedCapture 
// example if it creates an error
video = new Capture(this, width, height);

// Start capturing the images from the camera
video.start();  

background(0);
}

{
// we pass this to Minim so that it can load files from the data directory
minim = new Minim(this);

// loadFile will look in all the same places as loadImage does.
// this means you can find files that are in the data folder and the 
// sketch folder. you can also pass an absolute path, or a URL.
song = minim.loadFile("untitled.wav");
}


void draw() { 
if (video.available()) {
video.read();
video.loadPixels();

// Begin loop for columns
for (int i = 0; i < cols; i++) {
  // Begin loop for rows
  for (int j = 0; j < rows; j++) {

    // Where are we, pixel-wise?
    int x = i*cellSize;
    int y = j*cellSize;
    int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror       the image

    float r = red(video.pixels[loc]);
    float g = green(video.pixels[loc]);
    float b = blue(video.pixels[loc]);
    // Make a new color with an alpha component
    color c = color(r, g, b, 75);

    // Code for drawing a single rect
    // Using translate in order for rotation to work properly
    pushMatrix();
    translate(x+cellSize/2, y+cellSize/2);
    // Rotation formula based on brightness
    rotate((2 * PI * brightness(c) / 255.0));
    rectMode(CENTER);
    fill(c);
    noStroke();
    // Rects are larger than the cell for some overlap
    rect(0, 0, cellSize+6, cellSize+6);
    popMatrix();
  }
  }
  }
  }

How Can I add a song when the webcam starts and finish when you close the application window?.

And to add this behavoiour to an Arduino sensor?.

Thanks.

Answers

  • The sketch path is not set. ==== JavaSound Minim Error ==== ==== java.lang.reflect.InvocationTargetException

    === Minim Error === === Couldn't load the file untitled.wav

    This is the error.

  • edited February 2018

    I have this code for a song and it works:

    import ddf.minim.*;
    import ddf.minim.AudioPlayer;
    
    Minim minim;
    AudioPlayer song;
    
    void setup() {
    
    background(0, 0, 0);
    
    //p2 play sound file
    
    //Construct a new instance of minim
    
    minim = new Minim(this);
    
    //Load the file we want to play
    
    song = minim.loadFile("data/untitled.wav");
    
    //play the file
    
    song.play();
    
    }
    
    void draw()
    {
    background(0);
    }
    

    But How I can add to the other code (the webcam effect) without errors?.

  • Lines 31 to 39 in the original should be within setup, currently they are in an unnamed block. This is why you get the error about paths not being available.

    The first lot of code is also missing song.play()

  • edited February 2018

    Ctrl-t in the editor will indent your code nicely, make it easier to read and spot errors.

  • Is this meant to be in the Arduino section?

  • Thanks koogs!, Can you specify the what is the setup?.

  • You already have a setup, line 14 of the original post. Put the code in that block.

    You have already posted a good example in your third post. Examine that, see what goes where, apply it to the first lot of code.

  • Indenting the code would make the blocks stand out more, make things more obvious.

  • Answer ✓

    the lines 31-39

    remove the { } and then move the lines inside setup

    before its }

  • Solved!, and now How Can I use the code of a PIR Sensor to start the webcam and audio?.

  • And to modify the code to reduce the cells and change the colors?.

  • weell, when you know how to detect the sensor , write in draw if(pir or what){ song.play(); video.start();}

    remove those lines from setup of course

  • The sensor is possible in Processing?, I bought one for Arduino UNO. Which lines should I remove from the code (can you tell me which lines)?.

  • Remove in setup: song.play(); video.start();

    Look at the examples- you need to check the pin

  • Thanks Chrisir!, What is check the pin?.

  • Answer ✓

    You will find it

  • Thanks! sure. Please, finally, Can you attach some webcams amazing video effects?.

  • Answer ✓

    Yes, you can

  • import processing.video.*; with that, :-).

  • What should I do if I want to add a texture of an image?.

  • Answer ✓

    Use loadImage() to load the image. Store it in a PImage variable. Then display it when you want to display it by drawing it with a call to image().

    You can look all those keywords up in the Reference to see what they do, what their parameteres are, and some examples of their use.

  • Can you put me an example?, I am a bit lost.

  • With the code that I have.

  • edited February 2018

    I am reading it but something it was wrong:

    size(100, 100);
    loadImage("data/1.png");
     }
    
    void draw() {
    
    image("data/1.png",100,100,100,100);
    }
    
    { 
    
  • Please, Can you help me?.

  • And with a video layered and with opacity?.

  • NullPointerException error. What should I do?.

  • Look at the reference for the commands loadImage and image

    Hint: you need an PImage variable

    No use to ask every mini step here instead do some research in the reference section and examples and tutorials

  • edited February 2018

    Thanks for answer, this is the code, I do not know what I am doing bad:

    import processing.video.*;
    import ddf.minim.*;
    import ddf.minim.AudioPlayer;
    
    // Size of each cell in the grid
    int cellSize = 20;
    // Number of columns and rows in our system
    int cols, rows;
    // Variable for capture device
    Capture video;
    Minim minim;
    AudioPlayer song;
    PImage photo;
    
    void setup() {
    size(1280, 720);
    frameRate(30);
    cols = width / cellSize;
    rows = height / cellSize;
    colorMode(RGB, 255, 255, 255, 100);
    
     // This the default video input, see the GettingStartedCapture 
    // example if it creates an error
     video = new Capture(this, width, height);
    
    // Start capturing the images from the camera
    video.start();  
    background(0);
    
    // we pass this to Minim so that it can load files from the data directory
    minim = new Minim(this);
    
    // loadFile will look in all the same places as loadImage does.
    // this means you can find files that are in the data folder and the 
    // sketch folder. you can also pass an absolute path, or a URL.
    song = minim.loadFile("data/untitled.wav");
    song.play();
    {
    photo = loadImage("3.jpg");
    }
    }
    
    void draw() 
    { 
    if (video.available()) {
    video.read();
    video.loadPixels();
    
     // Begin loop for columns
     for (int i = 0; i < cols; i++) {
    // Begin loop for rows
    for (int j = 0; j < rows; j++) {
    // Where are we, pixel-wise?
    int x = i*cellSize;
    int y = j*cellSize;
    int loc = (video.width - x - 1) + y*video.width; // Reversing x to mirror the               image
    
     float r = red(video.pixels[loc]);
     float g = green(video.pixels[loc]);
     float b = blue(video.pixels[loc]);
     // Make a new color with an alpha component
     color c = color(r, 50, 50, 75);
    
    // Code for drawing a single rect
    // Using translate in order for rotation to work properly
    pushMatrix();
    translate(x+cellSize/2, y+cellSize/2);
    // Rotation formula based on brightness
    rotate((2 * PI * brightness(c) / 255.0));
    rectMode(CENTER);
    fill(c);
    noStroke();
    // Rects are larger than the cell for some overlap
    rect(0, 0, cellSize+6, cellSize+6);
    popMatrix();
    }
    }
    }
    }
     {
    image(photo, width/2, height/2);
    }
    
  • Ctrl-t in the editor will indent your code nicely... This will help you see the code structure.

    I think you have a hanging code block but...

  • Please, help me.

  • I do all as it is indicated and it fails.

  • The problem is that not layered with the video.

  • Answer ✓

    ??

    hit ctrl-t in processing

    try to debug it, just read it slowly and carefully

    when, done and IF you haven't found the bug

    hit ctrl-t in processing and then post the entire sketch again

  • How Can add a video layer above the webcam detecting code?.

  • You need to work on a quick start guide for the arduino side. From your posts, it is hard to tell how much experience (if any) you have working with arduinos. You can google something like "Arduino Quick start guide PRI sensor" and I am sure you can get started easily in the arduino side. You need to work in a code that matches your electronic setup. From what I see here in the posts, you don't have much experience in Processing. I strongly recommend you explore all the example that comes with the Video section. Make copy of any of those provided examples and modify them at your leisure. Master those examples. Keep the reference page handy (https://processing.org/reference/)

    There are other resources for you to explore. For example: https://processing.org/tutorials/

    Explore the video, the sound and the Electronics tutorial. This, what I am describing here is presented here: https://processing.org/tutorials/gettingstarted/

    Other resources to explore: https://processing.org/examples/

    Kf

  • Please, just tell me how to add a video layer of this posted code, please.

  • Something like Multiply on Photoshop.

  • Is that possible in Processing?.

Sign In or Register to comment.