Tablet library help: How to get tablet pressure to work in code

For class I have to create a Visualization of Music/Sound project using Minim along with the Tablet Library to have an external input control. Both my professor and myself have looked at this code and can not understand why it's running into problems. The code itself seems to run fine when I take out line 39 (the stroke weight using the tablet pressure) but when that line of code is in, the code will only work periodically, it seems to be overriding certain functions within the code; it will basically stop the code from running properly. This is a work in progress and I'm currently added and tweaking other features within it, but this problem is putting me at an impasse. (currently) if it runs ideally the code is supposed to play David Bowie's "Space Oddity" with the left and right channels seen on the screen in gray scale, there should then be a line of which you can draw with that follows the Tablet pen (along with the pressure of the pen) to be used to draw a picture with thats color is manipulated with coded key presses. Help is very much appreciated since we can't seem to come to a conclusion of what the problem might be or how to fix it... Thank you

here's the code:

import codeanticode.tablet.*; import ddf.minim.*;

Minim minim; Tablet tablet; AudioPlayer player; AudioInput input; AudioPlayer song;

float r;

void setup() { size (800, 600, P3D); smooth (); background (0);

minim = new Minim (this);
tablet= new Tablet(this);
song = minim.loadFile("David_Bowie_Space Oddity_stereo_version.mp3", 800);
song.play();

}

void draw () { r = random (255); stroke (r,r,r);

// line at 150 and 450 out of 600 they reach a range of 200

for(int i = 0; i < song.bufferSize() - 1; i++) {

line ( i, 150 + song.left.get (i)*50, i+1, 150+song.left.get(i+1)*200); //left channel
line ( i , 450 + song.right.get(i)*50,i +1,450 + song.right.get(i+1)*200); //right channel

}

if (mousePressed) { strokeWeight (10 * tablet.getPressure()); line (pmouseX, pmouseY, mouseX, mouseY); }

if (keyPressed) { if (key == 'o' ||key == 'O'){ //orange stroke (234,123,62,255); } if (key == 'b' || key == 'B') { //blue stroke (20,44,123,255); } if (key == 'l' || key == 'L'){ //light blue stroke (122,203,191,255); } if (key == 'a' || key == 'A') { //black stroke (0,0,0,255); } if (key == 's' || key == 'S') { //skin stroke (241,234,179,255); } if (key == 'r' || key == 'R') { stroke (255,0,0,255); } } }

void keyPressed () { //play and pause music... also causes song to repeat when done if (key== 'p') { if (song.isPlaying() ) { song.pause(); } //when its done tell it to play again... else if (song.position() == song.length() ) { song.rewind(); song.play(); } else { song.play(); } } }

Tagged:

Answers

  • @toomaj -- Please edit your post and format the code with CTRL-o to aid other forum members in reading and testing your code.

  • edited October 2016

    I can't test this without a tablet (possibly without your same model of tablet).

    However, I suggest you start with a simple sketch to just test tablet pressure. Get that working, then integrate into your main sketch. Does the tablet library have example code for using the pressure? Are you sure that your tablet model supports pressure and is transmitting pressure data?

    Example test sketch (untested):

    import codeanticode.tablet.*;
    void setup(){ size(400,400); }
    void draw(){}
    void mousePressed(){
      strokeWeight (10 * tablet.getPressure());
      line(pmouseX, pmouseY, mouseX, mouseY);
      println(mouseX, mouseY, tablet.getPressure());
    }
    

    Edit: changed point to line so that this actually shows strokeWeight.

    Also note:

    pmouseX: If you want values relative to the previous frame, use pmouseX and pmouseY inside draw(). If you want continuous response, use pmouseX and pmouseY inside the mouse event functions.

  • Hi Toomaj, if it's not too late...

    This appears to be a bug with the tablet library (or, rather the Jpen library it uses). I'm gonna guess you've changed from the default renderer to P2D or P3D? This appears to trigger the bug. There may be other renderers/libraries that are triggering the same bug if you haven't switched from the default. Try println(tablet.getPressure()) and you'll see that it returns 0.0 for most sketches, working very occasionally when a particularly unusable sequence of mouse moves are attempted before using the tablet.

    Switch the renderer back to default (removing P2D/P3D) and watch tablet.getPressure() return accurate values again.

    The author of the Processing library was aware of this issue a few months ago and said he was addressing it. It appears to still be an issue so perhaps there's not much hope of an update. It may be solely the problem of the Jpen library he relies on and the delay lays with them. I'm not sure.

    See it here on his github page and add your feedback if it will help. There's also a hacky workaround on the same page that I'm really trying to avoid in the hope the bug gets addressed: https://github.com/codeanticode/tablet/issues/6

  • I thought I would add that from some further reading, it appears that using certain other libraries alongside tablet produces the same or a similar bug. To confirm, do as jeremydouglass mentioned, confirm tablet.getPressure() is sending out expected numbers and then add the libraries you need and try again so see if tablet.getPressure() now sends out 0.0 each time you try and draw with the pen.

Sign In or Register to comment.