Quantcast
Channel: Processing Forum
Viewing all 1768 articles
Browse latest View live

Re : please help with serial and point

$
0
0
oh well,
casting the line2 variable to float and changing  teller++ to teller=teller+1 fixed it.
 
 

serial.list() limitations on mac?

$
0
0
Hi there. I'm running 2.0b6. When I do println(serial.list()); i get just ten values and I can't access the desired port. When I try doing 
 myPort = new Serial(this, "/dev/slave", 9600);
it seems the program doesn't work as expected - it just doesn't see the port (I can change it to any other non-existing value, and again, no-errors, just nothing). 
Is there any ways to get to other ports listed in my /dev directory? 

All MIDI Devices Unavailable?

$
0
0
Hi,

I hope I've picked the right location for this post.

I am a beginner with processing and with Java in general.  I'm trying to figure out how to simply construct a midi note on message and send it to an internal midi port application, that can then route it to a software synthesizer.

I'm using javax.sound.midi for this, and processing 2.0b6.

This is some code I have written to check what devices exist:


import javax.sound.midi.*;

MidiDevice.Info[] infos = MidiSystem.getMidiDeviceInfo();
MidiDevice device;

try {
  device = MidiSystem.getMidiDevice(infos[11]);
} catch (MidiUnavailableException e) {}
for (int i = 0; i < infos.length; i++) {
  print(infos[i]);
}

That code prints the following:

Gervill
Axiom Pro 61 HyperControl In
Axiom Pro 61 MIDI In
Axiom Pro 61 USB A In
Axiom Pro 61 USB B In
Network MIDI
Internal MIDI Port 1
Internal MIDI Port 2
Microsoft MIDI Mapper
Microsoft GS Wavetable Synth
Axiom Pro 61 HyperControl Out
Axiom Pro 61 MIDI Out
Network MIDI
Internal MIDI Port 1
Internal MIDI Port 2
Real Time Sequencer

However, every single one of those devices, if it is not in the try, catch block that discards MidiUnavailableException, will throw just that exception.  Yet none of my devices should be in use for anything, so I'm not sure why all of them throw this error.  Any thoughts?

How to log sensor arduino data into a file.

$
0
0
I have been trying to log arduino data into a file but all i could get is an empty file,my code is here below,I need some assistance on how i could better it.
import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
   mySerial = new Serial( this, Serial.list()[0], 9600 );
   output = createWriter( "timedg.csv" );
 
}
void draw() {
    if (mySerial.available() > 0 ) {
         String value = mySerial.readString();
         if ( value != null ) {
              output.println( value );
            

         }
    }
}

Re : Split only returning first index

$
0
0
That could be. I just wrote my own parsing characters into the code that I use .indexof to find and cut out the values I need. It is not elegant, but it works. Thanks for the help.

Re : How to log sensor arduino data into a file.

$
0
0
You need to call output.close() when you finish receiving data.

Re : PImage Memory Leak Example

Re : How to log sensor arduino data into a file.

$
0
0
Hey PhiLho,look at the code below and see if that is what you meant,i have tried it and it still gives me a blank file.I would suppose you post your code here.



import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
   mySerial = new Serial( this, Serial.list()[0], 9600 );
   output = createWriter( "newp.txt" );
   //print(Serial.list());
}
void draw() {
    if (mySerial.available() > 0 ) {
         String value = mySerial.readString();
         if ( value != null ) {
              output.println( value );
               output.close();
             

         }
    }
 
}


Scaling text

$
0
0
Hello, I am trying to create text that changes in size according to the frequency of the song being played. I have managed to get it to work, however one problem that I am facing is that the text does not scale in a center alignment (I want the size of the text to change but the position remain the same), but rather it scales outwards, is there any way I can work around this? Thank you so much for reading this and helping!

Here is my code:

import ddf.minim.*;
import ddf.minim.signals.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;

Minim minim;

AudioPlayer song;

FFT fft;

PFont Header;

int leftcol = 50;

int row1 = 35;

float[] Channel = new float[10];

void setup(){
  size(600,600);
  
  Header = loadFont("font1.vlw");
  
  minim = new Minim(this);
  
  song = minim.loadFile("craveyou.mp3", 512);
  
  song.play();
  
  song.mute();
  
  fft = new FFT(song.bufferSize(), song.sampleRate());
  
  fft.logAverages(32,1);
  
}

void draw(){
  calculateFFT();
  
  background(0);
  
  smooth(8);
  textFont(Header, Channel[4]);
  fill(255);
  textAlign(CENTER,CENTER);
  text("a", width/2, height/2);
  
  
}

void stop(){
  song.close();
  minim.stop();
  super.stop();
}

void calculateFFT(){
  fft.forward(song.mix);
  
  Channel[0] = map(fft.getAvg(0), 0, 69, 0, 255);
  Channel[1] = map(fft.getAvg(1), 0, 106, 0, 225);
  Channel[2] = map(fft.getAvg(2), 0, 119, 0, 255);
  Channel[3] = map(fft.getAvg(3), 0, 66, 0, 255);
  Channel[4] = map(fft.getAvg(4), 0, 29, 0, 255);
  Channel[5] = map(fft.getAvg(5), 0, 16, 0, 255);
  Channel[6] = map(fft.getAvg(6), 0, 15, 0, 255);
  Channel[7] = map(fft.getAvg(7), 0, 7, 0, 255);
  Channel[8] = map(fft.getAvg(8), 0, 3, 0, 255);
  Channel[9] = map(fft.getAvg(9), 0, 0, 0, 255);
}

Re : Scaling text

$
0
0


I'd thought that
  1.   textAlign(CENTER,CENTER);
does this... why not?

You can use textwidth and textheight (does it exist??) and say

  1.   text("a", width/2 - textwidth ("a") / 2 , height/2 - textheight ("a") / 2  );

(not tested)

textwidth and textheight (does it exist??) should know the current size of your "a"



Re : Scaling text

$
0
0
The alignment is working, but some fonts won't say how many pixels they increase in size correctly, so the alignment is not adjusting properly. You can get the textAscent, apply a calc on it, then use this as the start position for your Y. Also note this behaviour changes if you use P2D, P3D or OPENGL.

textAscent(). http://processing.org/reference/textAscent_.html

Here is my suggestion to start fixing this:

  1. void draw(){
  2.   calculateFFT();
  3.  
  4.   background(0);
  5.  
  6.   smooth(8);
  7.   textFont(Header, Channel[4]);
  8.  
  9.   fill(255);
  10.   textAlign(CENTER,CENTER);
  11.   float yStartPos = calculateAscent(Channel[4]);
  12.   text("H", (width/2), yStartPos);
  13. }

  14. float calculateAscent(float value) {
  15.   float base = height / 2;
  16.   float scalar = 0.1; // Different for each font, change this until you get the result you want
  17.  
  18.   float a = textAscent() * scalar;  // Calc ascent
  19.   stroke(100); // for the reference line
  20.   line(0,base-a,width,base-a); // ref purposes
  21.   return base-a;
  22. }

Re : Scaling text

$
0
0
Will do, thanks for the suggestions guys!

Re : PImage Memory Leak Example

Re : How to log sensor arduino data into a file.

$
0
0
Try to add a simple println(value); after reading it, to see if you have something in the console.

PVector functions and CPU vector processing? (SSE functions)

$
0
0
Hi there,
I discovered that the PVector class methods don't use the Processors vector registers and commands (SSE).
So I was wondering if there are any plans to use calculations with the vector unit of the processor in future builds,
as it might significantly improve speed.

Yet I have only experience in using vector units with plain c+asm, not yet in java, otherwise I'd look into it myself.

cheers :)

using timer

$
0
0
am new to processing and am having this issue on using the timer class.
 
i have a movie and two images. what i want to do is, load the movie first then after 10 second, the first image will show and after the next 4seconds, the last image will show. plz any help on coding will be helpful

Re : using timer

$
0
0
What is this "timer class"? Are you using a library? Either way, what do you have so far?

Re : using timer

$
0
0
this is how far i have gone. now the movie plays, but my problem is using the timer to change.
now i want the movie 10 play for 40seconds then loads the first .png file and after the 30seconds displays the second .png.
i dont really know what am missing out cuz am still new to processing
 
 
import processing.video.*;
Movie movie;
PImage helpimg;
PImage baseimg;
Timer time;
//int time1 = 3000;
int time2 = 4000;
float a = 0;

 

void setup() {
  size(1000, 600);
  background(0);
  movie = new Movie(this, "intro.mov");
  movie.play();
 
}

void draw() {
  background(0);
  image(movie, 0, 0);
  int currentTimer = millis();
 
  if (currentTimer < time2)
            {
              helpimg = loadImage("help.png");
            }
}
void movieEvent(Movie m)
          {
            m.read();
          }

 

         

 

 

video input with elements

$
0
0
for my assignment, i had to upload a video, thus the code below works, the major problem that i have is that now i need to add elements into it such as pulses and designs, but every time i add anything the output is zero, the movie won't play nor can i add anything extra.....any suggestions? ...i am not a pc genius, just taking this class. 
thank you
diana

import processing.video.*;

Movie theMov; 
boolean isPlaying;
boolean isLooping;

void setup() { 
  size(840, 680);

  theMov = new Movie(this, "ballet.mov");
  theMov.loop();  //plays the movie over and over
  isPlaying = false;
  isLooping = true;
}

void draw() { 
  background(0);
  image(theMov, mouseX-theMov.width/2, mouseY-theMov.height/2);

void movieEvent(Movie m) { 
  m.read(); 

void keyPressed() {
  if (key == 'p') {
    // toggle pausing
    if (isPlaying) {
      theMov.pause();
    } else {
      theMov.play();
      println(5);
    }
    isPlaying = !isPlaying;

  } else if (key == 'l') {
    // toggle looping
    if (isLooping) {
      theMov.noLoop();
    } else {
      theMov.loop();
    }
    isLooping = !isLooping;

  } else if (key == 's') {
    // stop playing
    theMov.stop();
    isPlaying = false;

  } else if (key == 'j') {
    // jump to a random time
    theMov.jump(random(theMov.duration()));
  }
}

I am trying to create a sort of photoBooth In Processing

$
0
0
Hi,  I am a new programming student and for my school final I am trying to create a sort of PhotoBooth using the camera on a mac or any kind of computer camera with different filters that are triggered with arrow keys like tints and distortions basically some of the things that are in Mac's Photo Booth I made mock buttons that have a pressed down look too for fun but that doesn't seem to work properly since they are all supposed to be displayed but aren't.


Here are the Files for everything in my program:
Main
Button
Background Picture
  1. import processing.video.*;//opens up processing libraries


    int s;// saved time

    int t = 5000;// 5 seconds

    //class
    Capture video;//class for cideo

    Button[] button = new Button[4];//class will be called button


    PImage img;//class img

    boolean state; // keyPressed
    //===================================
    void setup() {
      size(1500, 1098);
      background(0);

      img = loadImage("Octoton Background Big.jpg"); //image file name
      frameRate(30);
      imageMode(CENTER);
      //Inititialize class
      for (int i = 0; i< button.length; i++) {
        button[i] = new Button(250+(i*75), 250);
      }

      button[0].setColor(0, 255, 0);//green
      button[1].setColor(0, 0, 255);//blue
      button[2].setColor(255, 255, 0);//yellow
      button[3].setColor(142, 56, 142);//purple

      video = new Capture (this, 640, 480, 30);//(video, width, height, frameRate)
      video.start();

      s = millis(); //sets s to millis
      ellipseMode(CENTER);
    }
    //======================END SETUP===================



    void draw () {

      if (keyPressed) {
        if (keyCode == UP) {
          image(img, width/2, height/2);// background drawn 
          //for (int i = 0; i< button.length; i++) {
          button[0].display(true);
          state = true;
        }
      }
      else {
        image(img, width/2, height/2); // background drawn 
        //for (int i = 0; i< button.length; i++) {
        button[0].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }   
      image(video, width/2, height/2+100);

      if (keyPressed) {
        if (keyCode == DOWN) {
          image(img, width/2, height/2);// background drawn 
          //for (int i = 0; i< button.length; i++) {
          button[1].display(true);
          state = true;
        }
      }
      else {
        image(img, width/2, height/2); // background drawn 
        //for (int i = 0; i< button.length; i++) {
        button[1].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }   
      image(video, width/2, height/2+100);
      if (keyPressed) {
        if (keyCode == LEFT) {
          image(img, width/2, height/2);// background drawn 
          //for (int i = 0; i< button.length; i++) {
          button[2].display(true);
          state = true;
        }
      }
      else {
        image(img, width/2, height/2); // background drawn 
        //for (int i = 0; i< button.length; i++) {
        button[2].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }   
      image(video, width/2, height/2+100);
      if (keyPressed) {
        if (keyCode == RIGHT) {
          image(img, width/2, height/2);// background drawn 
          //for (int i = 0; i< button.length; i++) {
          button[3].display(true);
          state = true;
        }
      }
      else {
        image(img, width/2, height/2); // background drawn 
        //for (int i = 0; i< button.length; i++) {
        button[3].display(false);//button deafault displayed
      }
      if (video.available()) {// if there is something to see it will be available
        video.read();// read what is available
      }   
      image(video, width/2, height/2+100);
    }
    //=======================CLASS=================
    class Button {
      color col; // color variable
      int x;
      int y;

      Button(int tempX, int tempY) { // constructor
      x = tempX;
      y = tempY;
      }


      void display(boolean tempState) {


        fill(155);//gray

        ellipse(x, 258, 60, 30); // Base of button

        if (tempState == true) {
          Pressed();
        }
        else {
          notPressed();
        }
      }

      //=======================notPressed=================
      void notPressed () {
        //Button Default

        fill(col);//color set 

        ellipse(x, 254, 50, 20);
        ellipse(x, 253, 50, 20);
        ellipse(x, 252, 50, 20);
        ellipse(x, 251, 50, 20);
        ellipse(x, 250, 50, 20);
        ellipse(x, 249, 50, 20);

        ellipse(x, 248, 50, 20);
        ellipse(x, 247, 50, 20);
        ellipse(x, 246, 50, 20);
        ellipse(x, 245, 50, 20);
      }


      //=======================Pressed=================
      void Pressed() {
        // Button Pressed

          fill(col);//color set

        ellipse(x, 254, 50, 20);
        ellipse(x, 253, 50, 20);
        ellipse(x, 252, 50, 20);
        ellipse(x, 251, 50, 20);
        ellipse(x, 250, 50, 20);
      }

      //=======================setColor=================
      void setColor(int tempR, int tempG, int tempB) {
        col = color(tempR, tempG, tempB);
      }
    }

     

Viewing all 1768 articles
Browse latest View live