We are about to switch to a new forum software. Until then we have removed the registration on this forum.
full new version with load and save:
see comments below:
Chrisir ;-)
// Escape is de-activated.
// using selectInput and selectOutput here.
// using also setting path dataPath() and file ending "json".
// fileNameForScreen shows the current file name throughout.
// Uses a JSONArray within a JSONObject.
JSONObject json; // WITHIN this object is an array named animals, see json.setJSONArray("animals", values);
// fileNameForScreen shows the current file name throughout
String fileNameForScreen = "Not a file";
void setup() {
size(660, 660);
background(110);
json = new JSONObject();
// TWO possible test arrays
String[] species = { "Capra hircus", "Panthera pardus", "Equus zebra" };
String[] names = { "Goat", "Leopard", "Zebra" };
// String[] species = { "Cw", "Pp", "Ez" };
// String[] names = { "G", "Leo", "Z" };
//
// build values (JSONArray)
JSONArray values = new JSONArray();
for (int i = 0; i < species.length; i++) {
JSONObject animal = new JSONObject();
animal.setInt("id", i);
animal.setString("species", species[i]);
animal.setString("name", names[i]);
values.setJSONObject(i, animal);
}//for
// add values (JSONArray) to json
// comment this out to generate an error
json.setJSONArray("animals", values);
// generate another error for testing outputJSONArray:
//json = null;
}
void draw() {
background(110);
// show Menu
noFill();
stroke(0);
rect(width-49, 27,
45, 80-27);
fill(0);
text("Load\n\n" + "Save",
width-44, 44);
// show file name
fill(255); // white
text(fileNameForScreen,
min(width-44, width - textWidth(fileNameForScreen) - 11), 15);
// show array
outputJSONArray(json, "animals");
}
// --------------------------------------------------------------------------
void keyPressed() {
// De-activate Escape key
if (key==ESC) {
key=0; // kill Escape
}
}
void mousePressed() {
// println (mouseY);
// right screen border?
if (mouseX>width-50) {
checkMouseOnMenu();
}
}
void checkMouseOnMenu() {
// using selectInput and selectOutput here.
// also setting path and file ending json.
if (mouseY>20&&mouseY<47) {
//Load
String fileString = dataPath("") + "\\" +"*.json" ;
println(fileString);
File toLoad = new File( fileString ) ;
selectInput("Load a file:", "fileSelectedForLoad", toLoad);
} else if (mouseY>48&&mouseY<77) {
//Save
String fileString = dataPath("") + "\\*.json" ;
println(fileString);
File toSave = new File( fileString ) ;
selectOutput("Save to a file:", "fileSelectedForSave", toSave);
} else {
// ignore
}
}
// ---------------------------------------------------------------------------------
void fileSelectedForLoad(File selection) {
File loading;
loading = selection;
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User loaded " + selection.getAbsolutePath());
if (loading != null) {
json = loadJSONObject(loading.getAbsolutePath());
fileNameForScreen=loading.getName();//https://docs.oracle.com/javase/7/docs/api/java/io/File.html
}
}//else
//
}
void fileSelectedForSave(File selection) {
File saving;
saving = selection;
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
String saveString = saving.getAbsolutePath();
saveString=saveString.trim();
// ending json ok?
if (saveString.indexOf(".json") < 0) {
saveString+=".json"; // very rough approach...
saving = new File(saveString);
}
println("User saved to " + selection.getAbsolutePath());
if (saving != null) {
saveJSONObject(json, saving.getAbsolutePath());
fileNameForScreen=saving.getName();//https://docs.oracle.com/javase/7/docs/api/java/io/File.html
}
}//else
//
}
// ---------------------------------------------------------------------------------
void outputJSONArray(JSONObject json, String nameOfJSONArray) {
// output of an JSONArray named "nameOfJSONArray" in an an JSONObject json.
// The function is not generic since column names "species" etc. must be correct as below.
// error check I.
if (json==null) {
fill(255, 33, 0); // red
text( "No json object", 30, 30+2);
return;
}//if
JSONArray valuesLoaded = json.getJSONArray(nameOfJSONArray);
// error check II.
if (valuesLoaded==null) {
String error = "No json array named "
+ nameOfJSONArray
+ " in json object.";
fill(255, 33, 0); // red
text(error, 30, 30+2);
return;
}//if
fill(40, 255, 17); // black
for (int i = 0; i < valuesLoaded.size(); i++) {
JSONObject animal = valuesLoaded.getJSONObject(i);
int id = animal.getInt("id");
String species = animal.getString("species");
String name = animal.getString("name");
// println(id + ", " + species + ", " + name);
text(id + ", " + species + ", " + name, 40, 50+35*i); // small table
}//for
//
}//func
//
hello! im trying to write a kind of user interface to manage JSON files. What i want is user can store data in JSON files. when mousePressed save a new JSON FILE. here`s my code with a null pointer exception:
JSONObject json;
File saving;
File loading;
void setup() {
json = new JSONObject();
}
void draw(){
}
void mousePressed() {
selectInput("Select a file to process:", "fileSelected");
saveJSONObject(json, saving.getAbsolutePath());
}
void fileSelected(File selection) {
saving = selection;
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
}
}
This is something I had up on this forum since last summer, but it was in a question thread so I thought I should share this here in the proper category as well.
Current version: v1.2
This LaTeX listings template will color your Processing code as you see them in the Processing editor. You can just post your code like you normally would using the listings package, and you will automatically get your code in the proper colors. Except one minor inconvenience, that I will explain here.
For a function name that is the same as an already defined keyword (Such as "boolean" and "boolean()"), you have to use [escapechar = "char"] and \color{"color"}{"text"} to color them properly. Example:
\begin{lstlisting}[escapechar = ?]
boolean;
?\color{function}{boolean}?(1);
\end{lstlisting}
Copy and paste the below template if you want to use it. Alternatively, you can copy only the necessary parts. If in that case, note that \usepackage{listings} and \usepackage{color} is a must for this to work.
Also note, I have licensed this work with CreativeCommons license CC-BY-SA, so please remember to give some credit to me ;)
If you find any typos or any other errors, please tell me and I'll try to fix them as much as possible.
Download version:
http://www.mediafire.com/file/cw861uy156xftkv/article_listing_Processing_v1.2.tex
GitHub Gist:
https://gist.github.com/ebigunso/af355220e932f72d03289c576622aa29
Full template below:
\documentclass{article}
\usepackage{graphicx}
\usepackage{url}
\usepackage{verbatim}
\usepackage{listings}
\usepackage{color}
% Processing language definition template for LaTeX listings package v1.2
%
% Credits to ebigunso for creating this LaTeX listings language definition template for Processing
% This template is licensed with CreativeCommons license CC-BY-SA 4.0
% license info:
% https://creativecommons.org/licenses/by-sa/4.0/legalcode
%Define Colors
\definecolor{black}{RGB}{0,0,0}
\definecolor{gray}{RGB}{102,102,102} %#666666
\definecolor{function}{RGB}{0,102,153} %#006699 lightblue
\definecolor{lightgreen}{RGB}{102,153,0} %#669900
\definecolor{bluegreen}{RGB}{51,153,126} %#33997e
\definecolor{magenta}{RGB}{217,74,122} %#d94a7a
\definecolor{orange}{RGB}{226,102,26} %#e2661a
\definecolor{purple}{RGB}{125,71,147} %#7d4793
\definecolor{green}{RGB}{113,138,98} %#718a62
\lstdefinelanguage{Processing}{
%keyword1&2&6
morekeywords = [3]{abstract, break, class, continue, default, enum, extends, false, final, finally, implements, import, instanceof, interface, native, new, null, package, private, protected, public, static, strictfp, throws, transient, true, void, volatile, length, assert, case, return, super, this, throw},
%keyword3
morekeywords = [4]{catch, do, for, if, else, switch, synchronized, while, try},
%keyword4
morekeywords = [5]{width, height, pixelHight, displayHeight, displayWidth, focused, frameCount, frameRate, key, keyCode, keyPressed, mouseButton, mousePressed, mouseX, mouseY, pixels, pixelWidth, pmouseX, pmouseY},
%keyword5
morekeywords = [6]{Array, ArrayList, Boolean, Byte, BufferedReader, Character, Class, Double, Float, Integer, HashMap, PrintWriter, String, StringBuffer, StringBuilder, Thread, boolean, byte, char, color, double, float, int, long, short, FloatDict, FloatList, IntDict, IntList, JSONArray, JSONObject, PFont, PGraphics, PImage, PShader, PShape, PVector, StringDict, StringList, Table, TableRow, XML},
%literal2
morekeywords = [7]{ADD, ALIGN_CENTER, ALIGN_LEFT, ALIGN_RIGHT, ALPHA, ALPHA_MASK, ALT, AMBIENT, ARC, ARROW, ARGB, BACKSPACE, BASELINE, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CHATTER, CHORD, CLAMP, CLICK, CLOSE, CMYK, CODED, COMPLAINT, COMPOSITE, COMPONENT, CONCAVE_POLYGON, CONTROL, CONVEX_POLYGON, CORNER, CORNERS, CROSS, CUSTOM, DARKEST, DEGREES, DEG_TO_RAD, DELETE, DIAMETER, DIFFERENCE, DIFFUSE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_2D, DISABLE_DEPTH_MASK, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_NATIVE_FONTS, DISABLE_OPENGL_ERRORS, DISABLE_PURE_STROKE, DISABLE_TEXTURE_MIPMAPS, DISABLE_TRANSFORM_CACHE, DISABLE_STROKE_PERSPECTIVE, DISABLED, DODGE, DOWN, DRAG, DXF, ELLIPSE, ENABLE_ACCURATE_2D, ENABLE_DEPTH_MASK, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_ERRORS, ENABLE_PURE_STROKE, ENABLE_TEXTURE_MIPMAPS, ENABLE_TRANSFORM_CACHE, ENABLE_STROKE_PERSPECTIVE, ENTER, EPSILON, ERODE, ESC, EXCLUSION, EXIT, FX2D, GIF, GRAY, GREEN_MASK, GROUP, HALF, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FOAT, MIN_INT, MITER, MODEL, MOVE, MULTIPLY, NORMAL, NORMALIZED, NO_DEPTH_TEST, NTSC, ONE, OPAQUE, OPEN, ORTHOGRAPHIC, OVERLAY, PAL, PDF, P2D, P3D, PERSPECTIVE, PI, PIE, PIXEL_CENTER, POINT, POINTS, POSTERIZE, PRESS, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, RAD_TO_DEG, RADIUS, RADIANS, RECT, RED_MASK, RELEASE, REPEAT, REPLACE, RETURN, RGB, RIGHT, ROUND, SCREEN, SECAM, SHAPE, SHIFT, SPAN, SPECULAR, SPHERE, SOFT_LIGHT, SQUARE, SUBTRACT, SVG, SVIDEO, TAB, TARGA, TAU, TEXT, TFF, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLES, TRIANGLE_STRIP, TUNER, TWO, TWO_PI, UP, WAIT, WHITESPACE},
%function1
morekeywords = [8]{start, stop, breakShape, createPath, str, loadMatrix, parseBoolean, parseByte, parseChar, parseFloat, parseInt, saveFile, savePath, sketchFile, sketchPath, abs, acos, alpha, ambient, ambientLight, append, applyMatrix, arc, arrayCopy, asin, atan, atan2, background, beginCamera, beginContour, beginRaw, beginRecord, beginShape, bezier, bezierDetail, bezierPoint, bezierTangent, bezierVertex, binary, blend, blendColor, blendMode, blue, box, brightness, camera, ceil, clear, clip, color, colorMode, concat, constrain, copy, cos, createFont, createGraphics, createImage, createInput, createOutput, createReader, createShape, createWriter, cursor, curve, curveDetail, curvePoint, curveTangent, curveTightness, curveVertex, day, degrees, delay, directionalLight, displayDensity, dist, ellipse, ellipseMode, emissive, endCamera, endContour, endRaw, endRecord, endShape, exit, exp, expand, fill, filter, floor, frustum, fullScreen, get, green, hex, hint, hour, hue, image, imageMode, join, launch, lerp, lerpColor, lightFalloff, lights, lightSpecular, line, loadBytes, loadFont, loadImage, loadJSONArray, loadJSONObject, loadPixels, loadShader, loadShape, loadStrings, loadTable, loadXML, log, loop, mag, map, match, matchAll, max, millis, min, minute, modelX, modelY, modelZ, month, nf, nfc, nfp, nfs, noClip, noCursor, noFill, noise, noiseDetail, noiseSeed, noLights, noLoop, norm, normal, noSmooth, noStroke, noTint, ortho, parseJSONArray, parseJSONObject, parseXML, perspective, list, pixelDnsity, point, pointLight, popMatrix, popStyle, pow, print, printArray, printCamera, println, printMatrix, printProjection, pushMatrix, pushStyle, quad, quadraticVertex, radians, random, randomGaussian, randomSeed, rect, rectMode, red, redraw, requestImage, resetMatrix, resetShader, reverse, rotate, rotateX, rotateY, rotateZ, round, saturation, save, saveBytes, saveFrame, saveJSONArray, saveJSONObject, saveStream, saveStrings, saveTable, saveXML, scale, screenX, screenY, screenZ, second, selectFolder, selectInput, selectOutput, set, shader, shape, shapeMode, shearX, shearY, shininess, shorten, sin, size, smooth, sort, specular, sphere, sphereDetail, splice, split, splitTokens, spotLight, sq, sqrt, stroke, strokeCap, strokeJoin, strokeWeight, subset, tan, text, textAlign, textAscent, textDescent, textFont, textLeading, textMode, textSize, texture, textureMode, textureWrap, textWidth, thread, tint, translate, triangle, trim, unbinary, unhex, updatePixels, vertex, year},
%function2
morekeywords = [9]{cache, readLine, close, flush, print, println, charAt, equals, indexOf, substring, toLowerCase, toUpperCase, getDouble, getLong, getColumnTitles, getColumnTypes, getColumnType, setDouble, setLong, add, clear, div, get, hasKey, keyArray, keys, mult, remove, set, size, sortKeys, sortKeysReverse, sortValues, sortValuesReverse, sub, valueArray, values, append, array, hasValue, max, min, mult, remove, reverse, shuffle, sort, sortReverse, increment, getBoolean, getFloat, getInt, getIntArray, getJSONArray, getJSONObject, getString, getStringArray, isNull, setBoolean, setFloat, setInt, setJSONArray, setJSONObject, setString, beginDraw, endDraw, blend, copy, filter, loadPixels, mask, resize, save, updatePixels, addChild, beginContour, beginShape, disableStyle, enableStyle, endContour, endShape, getChild, getChildCount, getVertex, getVertexCount, isVisible, resetMatrix, rotate, rotateX, rotateY, rotateZ, scae, setFill, setStroke, setVertex, setVisible, translate, angleBetween, cross, dist, dot, fromAngle, heading, lerp, limit, mag, magSq, normalize, randm2D, random3D, setMag, lower, upper, addColumn, addRow, clearRows, findRow, findRows, getColumnCount, getRow, getRowcount, getStringColumn, matchRow, matchRows, removeColumn, removeRow, removeTokens, rows, trim, getColumnTitle, format, getAttributeCount, getChildren, getContent, getNam, getParent, hasAttribute, hasChildren, listAttributes, listChildren, removeChild, setContent, setName, toString},
%function4
morekeywords = [10]{draw, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseMoved, mouseReleased, mouseWheel, settings, setup},
keywordstyle = [3]\color{bluegreen},
keywordstyle = [4]\color{lightgreen},
keywordstyle = [5]\color{magenta},
keywordstyle = [6]\color{orange},
keywordstyle = [7]\color{green},
keywordstyle = [8]\color{function},
keywordstyle = [9]\color{function},
keywordstyle = [10]\color{function},
sensitive = true,
morecomment = [l][\color{gray}]{//},
morecomment = [s][\color{gray}]{/*}{*/},
morecomment = [s][\color{gray}]{/**}{*/},
morestring = [b][\color{purple}]",
morestring = [b][\color{purple}]'
}
\renewcommand{\ttdefault}{pcr}
\lstset{
language={Processing},
basicstyle={\small\ttfamily},
identifierstyle={\small},
commentstyle={\small\itshape},
keywordstyle={\small},
ndkeywordstyle={\small},
stringstyle={\small\ttfamily},
frame={tb},
breaklines=true,
columns=[l]{fullflexible},
numbers=left,
xrightmargin=0em,
xleftmargin=3em,
numberstyle={\scriptsize},
stepnumber=1,
numbersep=1em,
lineskip=-0.5ex,
}
% Use escapechar and \color{<color>}{<text>} to color function names properly, that is already defined as a different color keyword.
%
% \begin{lstlisting}[escapechar = ?]
% boolean;
% ?\color{function}{boolean}?(1);
% \end{lstlisting}
\title{}
\author{}
\date{}
\begin{document}
\maketitle
\section{}
\begin{thebibliography}{9}
\end{thebibliography}
\end{document}
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons on the right and below;\n" //testo e posizione testo
+"use Backspace to delete last data point of each list.\n\n"
+"Use 1 and 2 to set the active table which is marked by the horizontal line on top.\n"
+"New, Load and Save are referring to the active table (and also Backspace).\n\n"
+"You can click now above each column to activate it.\n"
+"You can press m to hide/show data text and x to show / hide quick help."
+"\n\nHit any key to return to main program.",
113, 122, width-200, 422);
}
// --------------------------------------------------
// functions to show buttons funzione per mostrare i bottoni
void showButtons() {
//
strokeWeight(2);
stroke(0);
textSize(15);
fill(0);
if ( overSave() ) {
fill(#FF0303);
}
rect(width-50, height-740, 40, 20, 5);// modificato posizione bottone "salve"
fill(255);
text("Save",
width-50+2, height-740+9+6);
// ---
fill(0);
if ( overLoad() ) {
fill(#49C3FA);
}
rect(width-50, height-710, 40, 20, 5);// modificato posizione" load"
fill(255);
text("Load",
width-50+2, height-710+9+6);
// ---
fill(0);
if ( overNew() ) {
fill(#1FFF03);
}
rect(width-50, height-680, 40, 20, 5);// modificato posizione "new"
fill(255);
text("New",
width-50+4, height-680+9+6);
// ---
fill(0);
if ( overHelp() ) {
fill(#1AAF03);
}
rect(width-50, height-650, 40, 20, 5);// modificato posizione "help"
fill(255);
text("Help",
width-50+4, height-650+9+6);
}
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25 ;
}
boolean overLoad() { //modificato
return mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 ;
}
boolean overNew() { //modificato
return mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 ;
}
boolean overHelp() { //modificato
return mouseX > width -50 &&
mouseY > height-650 &&
mouseY < height-650+25 ;
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state==help) {
goBackToMainState();
return;
}
if (state!=normal)
return;
//
if ( keyCode == BACKSPACE ) {
//
backspaceOnActiveList();
//
}
// ----
else if ( keyCode == DELETE ) {
//
// ignore
//
} else if ( keyCode == ESC ) {
//
// If yellow help box is ON
if (showHelpText1) {
showHelpText1 = false; // yellow help box off
} else {
// else toggle
showText = !showText; // data text / tables
}//else
// kill Esc so we stay in the program
key=0;
//
}
// ------
else {
if ( key != CODED ) {
//
switch(key) {
case '0':
activeArrayListHasNumber = 0;
break;
case '1':
activeArrayListHasNumber = 1;
break;
case '2':
activeArrayListHasNumber = 2;
break;
case '3':
activeArrayListHasNumber = 3;
break;
case 'x':
showHelpText1 = !showHelpText1; // yellow help box
break;
case 'm':
showText = !showText; // data text / tables
break;
//
}//switch
//
}//if
}//else
}// func
void mousePressed() {
if (state==help) {
goBackToMainState();
return;
}
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
} else if ( overHelp() ) {
state=help;
}
//---
else if ( overNew() ) {
//
if ( activeArrayListHasNumber==0 ) {
points1.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==1 ) {
points2.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==2 ) {
points3.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==3 ) {
points4.clear(); //cancellare punti con new
}// else if
// set name
fileNames[activeArrayListHasNumber] = "not a File";
//
}
//---
boolean done = false;
if (mouseY>390 && mouseY<425){
for (int i=0; i < arrayOfXValuesFrom.length; i++) {
if (mouseX>arrayOfXValuesFrom[i] &&
mouseX<arrayOfXValuesTo[i]) {
//
activeArrayListHasNumber=i;
done = true;
break;
}//if
}//for
}//if
if (!done) {
// points.add(new PVector(points.size(), mouseY/10));
if ( activeArrayListHasNumber == 0 ) {
points1.add(new PVector(points1.size(), MasA));
// points1.add(new PVector(points1.size(), mouseY));
} else if ( activeArrayListHasNumber == 1 ) {
points2.add(new PVector(points2.size(), MasA));
//points2.add(new PVector(points2.size(), mouseY));
} else if ( activeArrayListHasNumber == 2 ) {
points3.add(new PVector(points3.size(), MasA));
//points3.add(new PVector(points3.size(), mouseY));
} else if ( activeArrayListHasNumber == 3 ) {
//points2.add(new PVector(points2.size(), MasA.getValue()));
//points4.add(new PVector(points4.size(), mouseY));
points4.add(new PVector(points4.size(), MasA));
}
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
// prepara la descrizione del file che avviene nel dialogo
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// println ("La finestra è stata chiusa o l'utente ha premuto annulla.");
// torna indietro
state=normal; // go back
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs;
strs = new String[0];
if (activeArrayListHasNumber==0) {
strs = new String[points1.size()];
int i=0;
for (PVector pv : points1) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//
else if (activeArrayListHasNumber==1) {
strs = new String[points2.size()];
int i=0;
for (PVector pv : points2) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
else if (activeArrayListHasNumber==2) {
strs = new String[points3.size()];
int i=0;
for (PVector pv : points3) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
else if (activeArrayListHasNumber==3) {
strs = new String[points4.size()];
int i=0;
for (PVector pv : points4) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
// get file name for list
fileNames[activeArrayListHasNumber] = nameFromPath(savePath);
} //func
void loadIt() {
// load
if (activeArrayListHasNumber==0)
{
points1.clear();
} else if (activeArrayListHasNumber==1)
{
points2.clear();
} else if (activeArrayListHasNumber==2)
{
points3.clear();
} else if (activeArrayListHasNumber==3)
{
points4.clear();
}
fileNames[activeArrayListHasNumber] = nameFromPath(loadPath);
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
if (activeArrayListHasNumber==0)
{
points1.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else if (activeArrayListHasNumber==1)
{
points2.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else if (activeArrayListHasNumber==2)
{
points3.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else if (activeArrayListHasNumber==3)
{
points4.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
//
}//for
}//func
// -------------------------------------------------
void showData1() {
//
// show data 1
PVector prev = new PVector(-1, -1);
int y=50;
if (activeArrayListHasNumber==0) {
stroke(255, 2, 2); // RED
line (900, 405, 990, 405); //linea sopra tabella
line (870, 260, 1330, 260);
line (870, 280, 1330, 280);// linee text file
ellipse (865, 270, 6, 6);
}
for (PVector pv : points1) {
if (showText) {
fill(255, 2, 2); // RED
// show data
text(pv.x, 970-50, y+410);
text(pv.y, 970, y+410);
}
fill(0, 2, 2);
stroke(255, 2, 2); // RED
float yvalue = map( pv.y, 0,1, 700, 180); //mappatura linea grafica RED
if (prev.x!=-1) {
line(80 + pv.x*55, yvalue,
prev.x, prev.y);// linea grafico red
}
stroke(150);
ellipse (80 + pv.x*55, yvalue, 4, 4);
prev = new PVector(80 + pv.x*55, yvalue);
y+=20; //next line
}//for
if (showText) {
// middle line
stroke(255, 2, 2); // RED
line(1275-330,440, 1275-330,720);
}
//
}
void showData2() {
//
// show data 2
if (activeArrayListHasNumber==1) {
// activeArrayListHasNumber is FALSE, right side is active
stroke(2, 255, 2); // GREEN
line (1010, 405, 1100, 405);
line (870, 290, 1330, 290);
line (870, 310, 1330, 310);// linee text file
ellipse (865, 300, 6, 6);
}
// https : // forum.processing.org/two/discussion/26719/save-and-load-array-list#latest
import processing.serial.*;
import controlP5.*;
import grafica.*;
Serial myPort; // The serial port:
ControlP5 controlP5; // controlP5 object
Knob myKnob1, myKnob2, myKnob3, myKnob4; // knobs
// buttons above columns
int[] arrayOfXValuesFrom = { 13, 220, 390, 570 };
int[] arrayOfXValuesTo = { 193, 340, 550, 710 };
// text for file names for each column
String[] fileNames = { "not a file",
"not a file",
"not a file",
"not a file" };
// 4 columns
ArrayList<PVector> points1 = new ArrayList(); // 1st
ArrayList<PVector> points2 = new ArrayList(); // 2nd
ArrayList<PVector> points3 = new ArrayList(); // 3rd
ArrayList<PVector> points4 = new ArrayList(); // 4th
// active column
int activeArrayListHasNumber = 0;
// some flags for texts
boolean showHelpText1 = false;
boolean showText = true;
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
float deg, val;
final String pathFolder="";//CARTELLA DI PERCORSO
final String fileExtension = ".txt";//estensione file
// unique numbers for constants:
final int normal = 0;
final int save = 1;
final int load = 2;
final int help = 3;
/// current state (must be one of them)
/// stato attuale (deve essere uno di loro)
int state=normal;
// Paths
String savePath="";
String loadPath="";
// --------------------------------------------------------------------------
void setup() {
size(1350, 750);
// not necessary
for (int i = 0; i < 3; i++) {
points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
for (int i = 0; i < 13; i++) {
points2.add(new PVector(i, 30 + 10*noise(i*0.1)));
}//for
for (int i = 0; i < 5; i++) {
points3.add(new PVector(i, 40 + 10*noise(i*0.1)));
}//for
for (int i = 0; i < 7; i++) {
points4.add(new PVector(i, 50 + 10*noise(i*0.1)));
}//for
//ControlP5
PFont f= createFont ("Georgia", 25);
{
controlP5 = new ControlP5(this); //ControlP5
myKnob1 = controlP5.addKnob(" Massa ARIA")
//.setRange(0,1024)
.setRange(0, 5)
.setValue(0)
.setPosition(width-370, height-185)//posizione 605
.setTickMarkLength(10)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
;
myKnob1 .getCaptionLabel()
. setFont(f);
myKnob1.getValueLabel()
.setFont(f)
;
;
myKnob2 = controlP5.addKnob("P. Cil")
.setRange(0, 500)
.setValue(0)
.setPosition(width-370, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob2 .getCaptionLabel()
. setFont(f);
myKnob2.getValueLabel()
.setFont(f)
;
myKnob3 = controlP5.addKnob("P. Atm ")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob3 .getCaptionLabel()
. setFont(f);
myKnob3.getValueLabel()
.setFont(f)
;
myKnob4 = controlP5.addKnob("temp")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-185)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob4 .getCaptionLabel()
. setFont(f);
myKnob4.getValueLabel()
.setFont(f)
;
}
// myPort = new Serial(this, "com3", 9600); // ?????
// myPort.bufferUntil(lf);
}
void draw() {
switch (state) {
case normal:
drawForStateNormal() ;
break;
case save:
// wait for Save Dialog
waitForSaveDialog();
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
case help:
// help
drawForStateHelp() ;
break;
default:
//Error
println("Fail 192; unknown state: "
+state);
exit();
break;
//
} //switch
//
}//func
// ------------------------------------------------
void drawForStateNormal() {
background(245);
{
strokeWeight(2);
stroke(#FF0B03);
fill(0);
rect(width-380, height-490, 360, 90, 20);// retangolo diff. press.
fill(255);
textSize(28);
text("Diff.Press.", width-270, height-405); //diff.press
textSize(40);
text(( myKnob2.getValue()- myKnob3.getValue()), width-270, height-445); //diff.press
}
{
fill(0);
strokeWeight(2);
stroke(#FF0B03);
rect(width-380, height-390, 360, 190, 20);// retangolo press
rect(width-380, height-195, 360, 190, 20);// rettangolo massa Temp
}
textSize(14);
showData1();
showData2();
showData3();
showData4();
// title
fill(255, 2, 2);
textAlign(CENTER);
text("My little\nGraph program",
width-223, 19, 130, 422);
//reset
textAlign(LEFT);
//// help
if (showHelpText1) {
float widthOfBox = 210;
fill(240, 544, 2); // yellow
stroke(0); // black
rect(420, 27, widthOfBox, 322);
fill(0); // black
text("Use mouse above columns (or 0..3) to set the active table "
+"which is marked by the horizontal line on top.\n\n"
+"New, Load and Save are referring to the active table (and Backspace).\n"
+"m to hide / show text data.\n\nHit x to hide / show this text.",
425, 30, widthOfBox-10, 522);
}
// ----------------------
// buttons
showButtons();
// gray lines above columns
for (int i=0; i < arrayOfXValuesFrom.length; i++) {
if (activeArrayListHasNumber!=i) {
stroke(111); //
strokeWeight(2.8);
line (arrayOfXValuesFrom [i], 10,
arrayOfXValuesTo[i], 10);
strokeWeight(0.8);
line (arrayOfXValuesFrom [i]+10, 14,
arrayOfXValuesTo[i]-10, 14);
line (arrayOfXValuesFrom [i]+10, 10-4,
arrayOfXValuesTo[i]-10, 10-4);
}//if
fill(0);
text (fileNames[i],
arrayOfXValuesFrom [i], height-18);
}//for
// reset
strokeWeight(1.0);
//
} //draw
void drawForStateHelp() {
// Help
background(245);
myKnob1.setVisible(false);
myKnob2.setVisible(false);
myKnob3.setVisible(false);
myKnob4.setVisible(false);
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons on the right and below;\n" //testo e posizione testo
+"use Backspace to delete last data point of each list.\n\n"
+"Use 1 and 2 to set the active table which is marked by the horizontal line on top.\n"
+"New, Load and Save are referring to the active table (and also Backspace).\n\n"
+"You can click now above each column to activate it.\n"
+"You can press m to hide/show data text and x to show / hide quick help."
+"\n\nHit any key to return to main program.",
113, 122, width-200, 422);
}
// --------------------------------------------------
// functions to show buttons funzione per mostrare i bottoni
void showButtons() {
//
strokeWeight(2);
stroke(0);
textSize(15);
fill(0);
if ( overSave() ) {
fill(#FF0303);
}
rect(width-50, height-740, 40, 20, 5);// modificato posizione bottone "salve"
fill(255);
text("Save",
width-50+2, height-740+9+6);
// ---
fill(0);
if ( overLoad() ) {
fill(#49C3FA);
}
rect(width-50, height-710, 40, 20, 5);// modificato posizione" load"
fill(255);
text("Load",
width-50+2, height-710+9+6);
// ---
fill(0);
if ( overNew() ) {
fill(#1FFF03);
}
rect(width-50, height-680, 40, 20, 5);// modificato posizione "new"
fill(255);
text("New",
width-50+4, height-680+9+6);
// ---
fill(0);
if ( overHelp() ) {
fill(#1AAF03);
}
rect(width-50, height-650, 40, 20, 5);// modificato posizione "help"
fill(255);
text("Help",
width-50+4, height-650+9+6);
}
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25 ;
}
boolean overLoad() { //modificato
return mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 ;
}
boolean overNew() { //modificato
return mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 ;
}
boolean overHelp() { //modificato
return mouseX > width -50 &&
mouseY > height-650 &&
mouseY < height-650+25 ;
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state==help) {
goBackToMainState();
return;
}
if (state!=normal)
return;
//
if ( keyCode == BACKSPACE ) {
//
backspaceOnActiveList();
//
}
// ----
else if ( keyCode == DELETE ) {
//
// ignore
//
} else if ( keyCode == ESC ) {
//
// If yellow help box is ON
if (showHelpText1) {
showHelpText1 = false; // yellow help box off
} else {
// else toggle
showText = !showText; // data text / tables
}//else
// kill Esc so we stay in the program
key=0;
//
}
// ------
else {
if ( key != CODED ) {
//
switch(key) {
case '0':
activeArrayListHasNumber = 0;
break;
case '1':
activeArrayListHasNumber = 1;
break;
case '2':
activeArrayListHasNumber = 2;
break;
case '3':
activeArrayListHasNumber = 3;
break;
case 'x':
showHelpText1 = !showHelpText1; // yellow help box
break;
case 'm':
showText = !showText; // data text / tables
break;
//
}//switch
//
}//if
}//else
}// func
void mousePressed() {
if (state==help) {
goBackToMainState();
return;
}
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
} else if ( overHelp() ) {
state=help;
}
//---
else if ( overNew() ) {
//
if ( activeArrayListHasNumber==0 ) {
points1.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==1 ) {
points2.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==2 ) {
points3.clear(); //cancellare punti con new
} else if ( activeArrayListHasNumber==3 ) {
points4.clear(); //cancellare punti con new
}// else if
// set name
fileNames[activeArrayListHasNumber] = "not a File";
//
}
//---
boolean done = false;
if (mouseY<25) {
for (int i=0; i < arrayOfXValuesFrom.length; i++) {
if (mouseX>arrayOfXValuesFrom[i] &&
mouseX<arrayOfXValuesTo[i]) {
//
activeArrayListHasNumber=i;
done = true;
break;
}//if
}//for
}//if
if (!done) {
// points.add(new PVector(points.size(), mouseY/10));
if ( activeArrayListHasNumber == 0 ) {
// points1.add(new PVector(points1.size(), myKnob1.getValue()));
points1.add(new PVector(points1.size(), mouseY));
} else if ( activeArrayListHasNumber == 1 ) {
//points2.add(new PVector(points2.size(), myKnob1.getValue()));
points2.add(new PVector(points2.size(), mouseY));
} else if ( activeArrayListHasNumber == 2 ) {
//points2.add(new PVector(points2.size(), myKnob1.getValue()));
points3.add(new PVector(points3.size(), mouseY));
} else if ( activeArrayListHasNumber == 3 ) {
//points2.add(new PVector(points2.size(), myKnob1.getValue()));
points4.add(new PVector(points4.size(), mouseY));
}
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
// prepara la descrizione del file che avviene nel dialogo
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// println ("La finestra è stata chiusa o l'utente ha premuto annulla.");
// torna indietro
state=normal; // go back
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
// prepara la descrizione del file che avviene nel dialogo
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// println ("La finestra è stata chiusa o l'utente ha premuto annulla.");
// torna indietro
state=normal; // go back
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs;
strs = new String[0];
if (activeArrayListHasNumber==0) {
strs = new String[points1.size()];
int i=0;
for (PVector pv : points1) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//
else if (activeArrayListHasNumber==1) {
strs = new String[points2.size()];
int i=0;
for (PVector pv : points2) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
else if (activeArrayListHasNumber==2) {
strs = new String[points3.size()];
int i=0;
for (PVector pv : points3) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
else if (activeArrayListHasNumber==3) {
strs = new String[points4.size()];
int i=0;
for (PVector pv : points4) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
}//func
void loadIt() {
// load
if (activeArrayListHasNumber==0) {
points1.clear();
} else if (activeArrayListHasNumber==1)
{
points2.clear();
} else if (activeArrayListHasNumber==2)
{
points3.clear();
} else if (activeArrayListHasNumber==3)
{
points4.clear();
}
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
if (activeArrayListHasNumber==0) {
points1.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else if (activeArrayListHasNumber==1)
{
points2.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
else if (activeArrayListHasNumber==2)
{
points3.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
else if (activeArrayListHasNumber==3)
{
points4.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
//
}//for
}
// -------------------------------------------------
void showData1() {
//
// show data 1
PVector prev = new PVector(-1, -1);
int y=50;
if (activeArrayListHasNumber==0) {
stroke(255, 2, 2); // RED
line (10, 10, 198, 10);
}
for (PVector pv : points1) {
if (showText) {
fill(255, 2, 2); // RED
// show data
text(pv.x, 30, y);
text(pv.y, 110, y);
}
fill(0, 2, 2);
stroke(255, 2, 2); // RED
float yvalue = map( pv.y, 0, height, 300, 355);
if (prev.x!=-1) {
line(10 + pv.x*3, yvalue,
prev.x, prev.y);
}
noStroke();
// ellipse (10 + pv.x*3, yvalue, 4, 4);
prev = new PVector(10 + pv.x*3, yvalue);
y+=20; //next line
}//for
if (showText) {
// middle line
stroke(255, 2, 2); // RED
line( 100, 30, 100, height);
// double middle lines!!!
stroke(0); // BLACK
int x1=200;
line( x1-2, 30, x1-2, height);
line( x1+2, 30, x1+2, height);
}
//
}
void showData2() {
//
// show data 2
if (activeArrayListHasNumber==1) {
// activeArrayListHasNumber is FALSE, right side is active
stroke(2, 255, 2); // GREEN
line (200, 10,
350, 10);
}
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points2) {
if (showText) {
fill(0, 255, 2); // GREEN
// show data
text(pv.x, 210, y);
text(pv.y, 210+80, y);
}
fill(0, 2, 2);
stroke(0, 255, 2); // GREEN
float yvalue = map( pv.y, 0, height, 300, 355);
if (prev.x!=-1) {
line(10 + pv.x*3, yvalue,
prev.x, prev.y);
}
noStroke();
// ellipse (10 + pv.x*3, yvalue, 4, 4);
prev = new PVector(10 + pv.x*3, yvalue);
y+=20; //next line
}//for
if (showText) {
// middle line
stroke(0, 255, 2); // GREEN
line( 288, 30, 288, height);
// double middle lines!!!
stroke(0); // BLACK
int x1=210+80+80;
line( x1-2, 30, x1-2, height);
line( x1+2, 30, x1+2, height);
}
//
}
void showData3() {
//
// show data 3
color col3 = color(0, 2, 255); // BLUE
if (activeArrayListHasNumber==2) {
// activeArrayListHasNumber is FALSE, right side is active
stroke(col3); //
line (400, 10,
550, 10);
}
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points3) {
fill(col3); // Blue
if (showText) {
// show data
text(pv.x, 210+180, y);
text(pv.y, 210+180+80, y);
}
fill(0, 2, 2);
stroke(col3); // blue
float yvalue = map( pv.y, 0, height, 300, 355);
if (prev.x!=-1) {
line(10 + pv.x*3, yvalue,
prev.x, prev.y);
}
noStroke();
// ellipse (10 + pv.x*3, yvalue, 4, 4);
prev = new PVector(10 + pv.x*3, yvalue);
y+=20; //next line
}//for
if (showText) {
// middle line
stroke(col3); // blue
line( 467, 30, 467, height);
// double middle lines!!!
stroke(0); // BLACK
int x1=210+180+80+80;
line( x1-2, 30, x1-2, height);
line( x1+2, 30, x1+2, height);
}
//
}
void showData4() {
//
// show data 4
color col4 = color(155, 255, 112);
if (activeArrayListHasNumber==3) {
// activeArrayListHasNumber is FALSE, right side is active
stroke(col4); //
line (570, 10,
710, 10);
}
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points4) {
fill(col4); //
if (showText) {
// show data
text(pv.x, 210+180+180, y);
text(pv.y, 210+180+180+80, y);
}
fill(0, 2, 2);
stroke(col4); //
float yvalue = map( pv.y, 0, height, 300, 355);
if (prev.x!=-1) {
line(10 + pv.x*3, yvalue,
prev.x, prev.y);
}
noStroke();
// ellipse (10 + pv.x*3, yvalue, 4, 4);
prev = new PVector(10 + pv.x*3, yvalue);
y+=20; //next line
}//for
if (showText) {
// middle line
stroke(col4); //
line( 210+180+180+80-4, 30, 210+180+180+80-4, height);
}
//
}
// ---------------------------------------------------------------
void serialEvent(Serial p) {
inString = p.readString();
char primo=inString.charAt(0); // primo carattere
String cifra=inString.substring(1); // da secondo carattere in poi
float val=parseFloat(cifra); // valore da 0-255 o 0-1023, non sò cosa spedisce arduino
print("val=");
println(val);
// inString = trim(inString);
// // converte in int e mappa all'altezza dello schermo:
switch(primo) {
case ('A') :
myKnob1.setValue(val);
break;
case ('B') :
myKnob2.setValue(val);
break;
case ('C') :
myKnob3.setValue(val);
break;
case ('D') :
myKnob3.setValue(val);
break;
}
}
void goBackToMainState() {
// from help screen back to main screen
// buttons ON
myKnob1.setVisible(true);
myKnob2.setVisible(true);
myKnob3.setVisible(true);
myKnob4.setVisible(true);
//go back to main screen
state=normal;
// kill Esc so we stay in the program
key=0;
}
void backspaceOnActiveList() {
// for the key BACKSPACE
switch (activeArrayListHasNumber) {
case 0:
if (points1.size()>0)
points1.remove(points1.size()-1);
break;
case 1:
if (points2.size()>0)
points2.remove(points2.size()-1);
break;
case 2:
if (points3.size()>0)
points3.remove(points3.size()-1);
break;
case 3:
if (points4.size()>0)
points4.remove(points4.size()-1);
break;
}//switch
//
}//func
//
here
very small graphs
import processing.serial.*;
import controlP5.*;
import grafica.*;
Serial myPort; // The serial port:
ControlP5 controlP5; // controlP5 object
Knob myKnob1, myKnob2, myKnob3, myKnob4;
ArrayList<PVector> points1 = new ArrayList(); // left one
ArrayList<PVector> points2 = new ArrayList(); // right one
boolean activeArrayListIsLeft = true;
boolean showHelpText1 = true;
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
float deg, val;
final String pathFolder="";//CARTELLA DI PERCORSO
final String fileExtension = ".txt";//estensione file
// unique numbers for constants:
final int normal = 0;
final int save = 1;
final int load = 2;
///current state (must be one of them)
/// stato attuale (deve essere uno di loro)
int state=normal;
// Paths
String savePath="";
String loadPath="";
void setup() {
size(1350, 750);
// not necessary
for (int i = 0; i < 3; i++) {
points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
// not necessary
for (int i = 0; i < 13; i++) {
points2.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
//ControlP5
PFont f= createFont ("Georgia", 25);
{
controlP5 = new ControlP5(this); //ControlP5
myKnob1 = controlP5.addKnob(" Massa ARIA")
//.setRange(0,1024)
.setRange(0, 5)
.setValue(0)
.setPosition(width-370, height-185)//posizione 605
.setTickMarkLength(10)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
;
myKnob1 .getCaptionLabel()
. setFont(f);
myKnob1.getValueLabel()
.setFont(f)
;
;
myKnob2 = controlP5.addKnob("P. Cil")
.setRange(0, 500)
.setValue(0)
.setPosition(width-370, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob2 .getCaptionLabel()
. setFont(f);
myKnob2.getValueLabel()
.setFont(f)
;
myKnob3 = controlP5.addKnob("P. Atm ")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob3 .getCaptionLabel()
. setFont(f);
myKnob3.getValueLabel()
.setFont(f)
;
myKnob4 = controlP5.addKnob("temp")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-185)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob4 .getCaptionLabel()
. setFont(f);
myKnob4.getValueLabel()
.setFont(f)
;
}
}
// myPort = new Serial(this, "com3", 9600); // ?????
// myPort.bufferUntil(lf);
// }
void draw() {
switch (state) {
case normal:
drawForStateNormal() ;
break;
case save:
// wait for Save Dialog
waitForSaveDialog();
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
default:
//Error
println("Fail");
exit();
break;
//
}//switch
}//func
// ------------------------------------------------
void drawForStateNormal() {
background(245);
{
strokeWeight(2);
stroke(#FF0B03);
fill(0);
rect(width-380, height-490, 360, 90, 20);// retangolo diff. press.
fill(255);
textSize(28);
text("Diff.Press.", width-270, height-405); //diff.press
textSize(40);
text(( myKnob2.getValue()- myKnob3.getValue()), width-270, height-445); //diff.press
}
{
fill(0);
strokeWeight(2);
stroke(#FF0B03);
rect(width-380, height-390, 360, 190, 20);// retangolo press
rect(width-380, height-195, 360, 190, 20);// rettangolo massa Temp
}
textSize(14);
showData1();
showData2();
// title
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons on the right and below;\n" //testo e posizione testo
+"use Backspace OR delete key to delete last data point of each list.",
width-223, 10, 100, 422);
// help
if (showHelpText1) {
fill(255, 2, 2);
text("Use 1 and 2 to set the active table which is marked by the horizontal line on top.\n\n"
+"New, Load and Save are referring to the active table.\n\nHit x to hide / show this text.",
420, 10, 100, 422);
}
// ----------------------
// buttons
showButtons();
//
} //draw
// --------------------------------------------------
// functions to show buttons funzione per mostrare i bottoni
void showButtons() {
//
strokeWeight(2);
stroke(0);
textSize(15);
fill(0);
if ( overSave() ) {
fill(#FF0303);
}
rect(width-50, height-740, 40, 20, 5);// modificato posizione bottone "salve"
fill(255);
text("Save",
width-50+2, height-740+9+6);
// ---
fill(0);
if ( overLoad() ) {
fill(#49C3FA);
}
rect(width-50, height-710, 40, 20, 5);// modificato posizione" load"
fill(255);
text("Load",
width-50+2, height-710+9+6);
// ---
fill(0);
if ( overNew() ) {
fill(#1FFF03);
}
rect(width-50, height-680, 40, 20, 5);// modificato posizione "new"
fill(255);
text("New",
width-50+4, height-680+9+6);
}
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25 ;
}
boolean overLoad() { //modificato
return mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 ;
}
boolean overNew() { //modificato
return mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 ;
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state!=normal)
return;
//
if ( keyCode == BACKSPACE ) {
//
if (points1.size()>0)
points1.remove(points1.size()-1);
}
// ----
if ( keyCode == DELETE ) {
//
if (points2.size()>0)
points2.remove(points2.size()-1);
}
// ------
else {
if ( key != CODED ) {
//
switch(key) {
case '1':
activeArrayListIsLeft = true;
break;
case '2':
activeArrayListIsLeft = false;
break;
case 'x':
showHelpText1 = !showHelpText1;
break;
}//switch
//
}//if
}//else
}// func
void mousePressed() {
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
}
//---
else if ( overNew() ) {
//
if ( activeArrayListIsLeft ) {
points1.clear(); //cancellare punti con new
// not necessary:
for (int i = 0; i < 13; i++) {
// points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
} else {
points2.clear(); //cancellare punti con new
// not necessary:
for (int i = 0; i < 13; i++) {
// points2.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
}
//
}
//---
else {
// points.add(new PVector(points.size(), mouseY/10));
if ( activeArrayListIsLeft ) {
// points1.add(new PVector(points1.size(), myKnob1.getValue()));
points1.add(new PVector(points1.size(), mouseY));
} else {
//points2.add(new PVector(points2.size(), myKnob1.getValue()));
points2.add(new PVector(points2.size(), mouseY));
}
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
// prepara la descrizione del file che avviene nel dialogo
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// println ("La finestra è stata chiusa o l'utente ha premuto annulla.");
// torna indietro
state=normal; // go back
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs;
if (activeArrayListIsLeft) {
strs = new String[points1.size()];
int i=0;
for (PVector pv : points1) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//
else {
strs = new String[points2.size()];
int i=0;
for (PVector pv : points2) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
}//func
void loadIt() {
// load
if (activeArrayListIsLeft) {
points1.clear();
} else
{
points2.clear();
}
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
if (activeArrayListIsLeft) {
points1.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else
{
points2.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
//
}//for
}
// -------------------------------------------------
void showData1() {
//
// show data LEFT
PVector prev = new PVector(-1, -1);
int y=50;
if (activeArrayListIsLeft) {
stroke(255, 2, 2); // RED
line (10, 10, 198, 10);
}
for (PVector pv : points1) {
fill(255, 2, 2); // RED
// show data
text(pv.x, 30, y);
text(pv.y, 110, y);
fill(0, 2, 2);
stroke(255, 2, 2); // RED
float yvalue = map( pv.y, 0, height, 300, 355);
if (prev.x!=-1) {
line(10 + pv.x*3, yvalue,
prev.x, prev.y);
}
noStroke();
// ellipse (10 + pv.x*3, yvalue, 4, 4);
prev = new PVector(10 + pv.x*3, yvalue);
y+=20; //next line
}//for
// middle line
stroke(255, 2, 2); // RED
line( 100, 30, 100, height);
// double middle lines!!! ???
stroke(0); // BLACK
int x1=200;
line( x1-2, 30, x1-2, height);
line( x1+2, 30, x1+2, height);
//
}
void showData2() {
//
// show data RIGHT
if (!activeArrayListIsLeft) {
// activeArrayListIsLeft is FALSE, right side is active
stroke(2, 255, 2); // GREEN
line (200, 10,
350, 10);
}
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points2) {
fill(0, 255, 2); // GREEN
// show data
text(pv.x, 210, y);
text(pv.y, 290, y);
fill(0, 2, 2);
stroke(0, 255, 2); // GREEN
float yvalue = map( pv.y, 0, height, 300, 355);
if (prev.x!=-1) {
line(10 + pv.x*3, yvalue,
prev.x, prev.y);
}
noStroke();
// ellipse (10 + pv.x*3, yvalue, 4, 4);
prev = new PVector(10 + pv.x*3, yvalue);
y+=20; //next line
}//for
// middle line
stroke(0, 255, 2); // GREEN
line( 288, 30, 288, height);
//
}
// ---------------------------------------------------------------
void serialEvent(Serial p) {
inString = p.readString();
char primo=inString.charAt(0); // primo carattere
String cifra=inString.substring(1); // da secondo carattere in poi
float val=parseFloat(cifra); // valore da 0-255 o 0-1023, non sò cosa spedisce arduino
print("val=");
println(val);
// inString = trim(inString);
// // converte in int e mappa all'altezza dello schermo:
switch(primo) {
case ('A'):
myKnob1.setValue(val);
break;
case ('B'):
myKnob2.setValue(val);
break;
case ('C'):
myKnob3.setValue(val);
break;
case ('D'):
myKnob3.setValue(val);
break;
}
}
Basically I am very new to this android mode i tried SelectInput from Processing reference and also tried Select Library for android mode Non of them seem to work .
i want to load images from device in my sketch and use the Pixel RGB Values using get(x,y); and perform certain process on image in Android device.
i need Help in selecting Image file from Android Device Gallery Cheers
Hi, I am very new to this android mode i tried SelectInput from Processing reference and also tried Select Library for android mode Non of them seem to work .
i want to load images from device in my sketch and use the Pixel RGB Values using get(x,y); and perform certain process on image in Android device.
i need Help in selecting Image file from Android Device Gallery :D Cheers
This is what I have in mind, but I have not succeeded yet ....
Point1 and Point2 I would like to draw in the GPlot chart ....
import processing.serial.*;
import controlP5.*;
import grafica.*;
Serial myPort; // The serial port:
ControlP5 controlP5; // controlP5 object
Knob myKnob1, myKnob2, myKnob3, myKnob4;
ArrayList<PVector> points1 = new ArrayList(); // left one
ArrayList<PVector> points2 = new ArrayList(); // right one
boolean activeArrayListIsLeft = true;
boolean showHelpText1 = true;
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
float deg, val;
final String pathFolder="";//CARTELLA DI PERCORSO
final String fileExtension = ".txt";//estensione file
// unique numbers for constants:
final int normal = 0;
final int save = 1;
final int load = 2;
///current state (must be one of them)
int state=normal;
// Paths
String savePath="";
String loadPath="";
GPlot plot;
int xPos=0;
void setup() {
size(1350, 750);
// not necessary
for (int i = 0; i < 3; i++) {
points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
// not necessary
for (int i = 0; i < 13; i++) {
points2.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
//ControlP5
PFont f= createFont ("Georgia", 25);
{
controlP5 = new ControlP5(this); //ControlP5
myKnob1 = controlP5.addKnob(" Massa ARIA")
//.setRange(0,1024)
.setRange(0, 5)
.setValue(0)
.setPosition(width-370, height-185)//posizione 605
.setTickMarkLength(10)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
;
myKnob1 .getCaptionLabel()
. setFont(f);
myKnob1.getValueLabel()
.setFont(f)
;
;
myKnob2 = controlP5.addKnob("P. Cil")
.setRange(0, 500)
.setValue(0)
.setPosition(width-370, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob2 .getCaptionLabel()
. setFont(f);
myKnob2.getValueLabel()
.setFont(f)
;
myKnob3 = controlP5.addKnob("P. Atm ")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob3 .getCaptionLabel()
. setFont(f);
myKnob3.getValueLabel()
.setFont(f)
;
myKnob4 = controlP5.addKnob("temp")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-185)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob4 .getCaptionLabel()
. setFont(f);
myKnob4.getValueLabel()
.setFont(f)
;
}
}
// myPort = new Serial(this, "com3", 9600); // ?????
// myPort.bufferUntil(lf);
// }
{
// Create the first plot Crea il primo grafico
plot = new GPlot(this);
plot.setPos(200,200);//posizione
plot.setMar(0, 100, 0,100);
plot.setDim(1000, 480);//dimensione
plot.setAxesOffset(4);
plot.setTicksLength(4);
int myKnob1 =0;
GPointsArray points = new GPointsArray(myKnob1);
for (int i = 0; i < 13; i++) {
//points.add(i, 20 + 10*noise(i*0.1));
if(xPos==13){
}
{
// Set the points, the title and the axis labels
plot.setPoints(points);
plot.getYAxis().setAxisLabelText("y(?)");
plot.getXAxis().setAxisLabelText("x (?)");
}
}
}
void draw() {
// Draw the first plot
//Disegna la prima trama
plot.beginDraw();
plot.drawBox();
plot.drawXAxis();
plot.drawYAxis();
plot.drawTitle();
//plot1.drawPoints();//pallinorosso sul valore
plot.drawGridLines(GPlot.BOTH);
plot.drawLines();
plot.endDraw();
}
{
switch (state) {
case normal:
drawForStateNormal() ;
break;
case save:
// wait for Save Dialog
waitForSaveDialog();
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
default:
//Error
println("Fail");
exit();
break;
//
}//switch
}//func
void drawForStateNormal() {
background(245);
{
strokeWeight(2);
stroke(#FF0B03);
fill(0);
rect(width-380, height-490, 360, 90, 20);// retangolo diff. press.
fill(255);
textSize(28);
text("Diff.Press.", width-270, height-405); //diff.press
textSize(40);
text(( myKnob2.getValue()- myKnob3.getValue()), width-270, height-445); //diff.press
}
{
fill(0);
strokeWeight(2);
stroke(#FF0B03);
rect(width-380, height-390, 360, 190, 20);// retangolo press
rect(width-380, height-195, 360, 190, 20);// rettangolo massa Temp
}
textSize(14);
showData1();
showData2();
// title
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons on the right and below;\n" //testo e posizione testo
+"use Backspace OR delete key to delete last data point of each list.",
width-223, 10, 100, 422);
// help
if (showHelpText1) {
fill(255, 2, 2);
text("Use 1 and 2 to set the active table which is marked by the horizontal line on top.\n\n"
+"New, Load and Save are referring to the active table.\n\nHit x to hide / show this text.",
420, 10, 100, 422);
}
// buttons
showButtons();
//
} //draw
// functions to show buttons funzione per mostrare i bottoni
void showButtons() {
//
strokeWeight(2);
stroke(0);
textSize(15);
fill(0);
if ( overSave() ) {
fill(#FF0303);
}
rect(width-50, height-740, 40, 20, 5);// modificato posizione bottone "salve"
fill(255);
text("Save",
width-50+2, height-740+9+6);
// ---
fill(0);
if ( overLoad() ) {
fill(#49C3FA);
}
rect(width-50, height-710, 40, 20, 5);// modificato posizione" load"
fill(255);
text("Load",
width-50+2, height-710+9+6);
// ---
fill(0);
if ( overNew() ) {
fill(#1FFF03);
}
rect(width-50, height-680, 40, 20, 5);// modificato posizione "new"
fill(255);
text("New",
width-50+4, height-680+9+6);
}
// functions to register if mouse is over buttons funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25 ;
}
boolean overLoad() { //modificato
return mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 ;
}
boolean overNew() { //modificato
return mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 ;
}
// Inputs
void keyPressed() {
if (state!=normal)
return;
//
if ( keyCode == BACKSPACE ) { //da controllare non funziona
//
if (points1.size()>0)
points1.remove(points1.size()-1);
}
// ----
if ( keyCode == DELETE ) {
//
if (points2.size()>0)
points2.remove(points2.size()-1);
}
// ------
else {
if ( key != CODED ) {
//
switch(key) {
case '1':
activeArrayListIsLeft = true;
break;
case '2':
activeArrayListIsLeft = false;
break;
case 'x':
showHelpText1 = !showHelpText1;
break;
}//switch
//
}//if
}//else
}// func
void mousePressed() {
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
}
//---
else if ( overNew() ) {
//
if ( activeArrayListIsLeft ) {
points1.clear(); //cancellare punti con new
// not necessary:
for (int i = 0; i < 13; i++) {
// points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
} else {
points2.clear(); //cancellare punti con new
// not necessary:
for (int i = 0; i < 13; i++) {
// points2.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
}
//
}
//---
else {
// points.add(new PVector(points.size(), mouseY/10));
if ( activeArrayListIsLeft ) {
points1.add(new PVector(points1.size(), myKnob1.getValue()));
} else {
points2.add(new PVector(points2.size(), myKnob1.getValue()));
}
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
2 diventa 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
GPoint lastPoint = plot.getPointsRef().getLastPoint();
if (lastPoint == null) {
plot.addPoint(xPos, +myKnob1.getValue(), "(" + str(xPos) + " , " + str(myKnob1.getValue()) + ")");
}
else if (!lastPoint.isValid() || sq(lastPoint.getX() - xPos) + sq(lastPoint.getY() + myKnob1.getValue()) > 2500) {
//plot1.addPoint(xPos, -val, "(" + (xPos) + " , " + (-val) + ")");
}
// Reset the points if the user pressed the space bar
if (keyPressed && key == ' ') {
plot.setPoints(new GPointsArray());
}
}
void initLoad() {
// init load process
// reset
loadPath="";
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
state=normal; // go back
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs;
if (activeArrayListIsLeft) {
strs = new String[points1.size()];
int i=0;
for (PVector pv : points1) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//
else {
strs = new String[points2.size()];
int i=0;
for (PVector pv : points2) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
}//func
void loadIt() {
// load
if (activeArrayListIsLeft) {
points1.clear();
} else
{
points2.clear();
}
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
if (activeArrayListIsLeft) {
points1.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else
{
points2.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
//
}//for
}
void showData1() {
//
// show data LEFT
PVector prev = new PVector(-1, -1);
int y=50;
if (activeArrayListIsLeft) {
stroke(255, 2, 2); // RED
line (10, 10, 198, 10);
}
for (PVector pv : points1) {
fill(255, 2, 2); // RED
// show data
text(pv.x, 30, y);
text(pv.y, 110, y);
fill(0, 2, 2);
stroke(255, 2, 2); // RED
if (prev.x!=-1) {
line(10 + pv.x*30, pv.y*10,
prev.x, prev.y);
}
noStroke();
ellipse (10 + pv.x*30, pv.y*10, 4, 4);
prev = new PVector(10 + pv.x*30, pv.y*10);
y+=20; //next line
}//for
// middle line
stroke(255, 2, 2); // RED
line( 100, 30, 100, height);
// double middle lines!!! ???
stroke(0); // BLACK
int x1=200;
line( x1-2, 30, x1-2, height);
line( x1+2, 30, x1+2, height);
//
}
void showData2() {
//
// show data RIGHT
if (!activeArrayListIsLeft) {
// activeArrayListIsLeft is FALSE, right side is active
// activeArrayListIsLeft è FALSE, il lato destro è attivo
stroke(2, 255, 2); // GREEN
line (200, 10,
350, 10);
}
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points2) {
fill(0, 255, 2); // GREEN
// show data
text(pv.x, 210, y);
text(pv.y, 290, y);
fill(0, 2, 2);
stroke(0, 255, 2); // GREEN
if (prev.x!=-1) {
line(10 + pv.x*30, pv.y*10,
prev.x, prev.y);
}
noStroke();
ellipse (10 + pv.x*30, pv.y*10, 4, 4);
prev = new PVector(10 + pv.x*30, pv.y*10);
y+=20; //next line
}//for
// middle line
stroke(0, 255, 2); // GREEN
line( 288, 30, 288, height);
//
}
void serialEvent(Serial p) {
inString = p.readString();
char primo=inString.charAt(0); // primo carattere
String cifra=inString.substring(1); // da secondo carattere in poi
float val=parseFloat(cifra); // valore da 0-255 o 0-1023, non sò cosa
print("val=");
println(val);
switch(primo) {
case ('A'):
myKnob1.setValue(val);
break;
case ('B'):
myKnob2.setValue(val);
break;
case ('C'):
myKnob3.setValue(val);
break;
case ('D'):
myKnob3.setValue(val);
break;
}
}
new version with 2 tables and graphs.
Delete key and Backspace key are now referring to the different tables separately
Use key 1 and 2 to set the active table
New, Load and Save are referring to the active table.
Hit x to hide / show help text
Chrisir ;-)
import processing.serial.*;
import controlP5.*;
import grafica.*;
Serial myPort; // The serial port:
ControlP5 controlP5; // controlP5 object
Knob myKnob1, myKnob2, myKnob3, myKnob4;
ArrayList<PVector> points1 = new ArrayList(); // left one
ArrayList<PVector> points2 = new ArrayList(); // right one
boolean activeArrayListIsLeft = true;
boolean showHelpText1 = true;
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
float deg, val;
final String pathFolder="";//CARTELLA DI PERCORSO
final String fileExtension = ".txt";//estensione file
// unique numbers for constants:
final int normal = 0;
final int save = 1;
final int load = 2;
///current state (must be one of them)
/// stato attuale (deve essere uno di loro)
int state=normal;
// Paths
String savePath="";
String loadPath="";
void setup() {
size(1350, 750);
// not necessary
for (int i = 0; i < 3; i++) {
points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
// not necessary
for (int i = 0; i < 13; i++) {
points2.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
//ControlP5
PFont f= createFont ("Georgia", 25);
{
controlP5 = new ControlP5(this); //ControlP5
myKnob1 = controlP5.addKnob(" Massa ARIA")
//.setRange(0,1024)
.setRange(0, 5)
.setValue(0)
.setPosition(width-370, height-185)//posizione 605
.setTickMarkLength(10)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
;
myKnob1 .getCaptionLabel()
. setFont(f);
myKnob1.getValueLabel()
.setFont(f)
;
;
myKnob2 = controlP5.addKnob("P. Cil")
.setRange(0, 500)
.setValue(0)
.setPosition(width-370, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob2 .getCaptionLabel()
. setFont(f);
myKnob2.getValueLabel()
.setFont(f)
;
myKnob3 = controlP5.addKnob("P. Atm ")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob3 .getCaptionLabel()
. setFont(f);
myKnob3.getValueLabel()
.setFont(f)
;
myKnob4 = controlP5.addKnob("temp")
//.setRange(0,1023)
.setRange(0, 500)
.setValue(1)
.setPosition(width-180, height-185)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150, 150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob4 .getCaptionLabel()
. setFont(f);
myKnob4.getValueLabel()
.setFont(f)
;
}
}
// myPort = new Serial(this, "com3", 9600); // ?????
// myPort.bufferUntil(lf);
// }
void draw() {
switch (state) {
case normal:
drawForStateNormal() ;
break;
case save:
// wait for Save Dialog
waitForSaveDialog();
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
default:
//Error
println("Fail");
exit();
break;
//
}//switch
}//func
// ------------------------------------------------
void drawForStateNormal() {
background(245);
{
strokeWeight(2);
stroke(#FF0B03);
fill(0);
rect(width-380, height-490, 360, 90, 20);// retangolo diff. press.
fill(255);
textSize(28);
text("Diff.Press.", width-270, height-405); //diff.press
textSize(40);
text(( myKnob2.getValue()- myKnob3.getValue()), width-270, height-445); //diff.press
}
{
fill(0);
strokeWeight(2);
stroke(#FF0B03);
rect(width-380, height-390, 360, 190, 20);// retangolo press
rect(width-380, height-195, 360, 190, 20);// rettangolo massa Temp
}
textSize(14);
showData1();
showData2();
// title
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons on the right and below;\n" //testo e posizione testo
+"use Backspace OR delete key to delete last data point of each list.",
width-223, 10, 100, 422);
// help
if (showHelpText1) {
fill(255, 2, 2);
text("Use 1 and 2 to set the active table which is marked by the horizontal line on top.\n\n"
+"New, Load and Save are referring to the active table.\n\nHit x to hide / show this text.",
420, 10, 100, 422);
}
// ----------------------
// buttons
showButtons();
//
} //draw
// --------------------------------------------------
// functions to show buttons funzione per mostrare i bottoni
void showButtons() {
//
strokeWeight(2);
stroke(0);
textSize(15);
fill(0);
if ( overSave() ) {
fill(#FF0303);
}
rect(width-50, height-740, 40, 20, 5);// modificato posizione bottone "salve"
fill(255);
text("Save",
width-50+2, height-740+9+6);
// ---
fill(0);
if ( overLoad() ) {
fill(#49C3FA);
}
rect(width-50, height-710, 40, 20, 5);// modificato posizione" load"
fill(255);
text("Load",
width-50+2, height-710+9+6);
// ---
fill(0);
if ( overNew() ) {
fill(#1FFF03);
}
rect(width-50, height-680, 40, 20, 5);// modificato posizione "new"
fill(255);
text("New",
width-50+4, height-680+9+6);
}
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25 ;
}
boolean overLoad() { //modificato
return mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 ;
}
boolean overNew() { //modificato
return mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 ;
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state!=normal)
return;
//
if ( keyCode == BACKSPACE ) {
//
if (points1.size()>0)
points1.remove(points1.size()-1);
}
// ----
if ( keyCode == DELETE ) {
//
if (points2.size()>0)
points2.remove(points2.size()-1);
}
// ------
else {
if ( key != CODED ) {
//
switch(key) {
case '1':
activeArrayListIsLeft = true;
break;
case '2':
activeArrayListIsLeft = false;
break;
case 'x':
showHelpText1 = !showHelpText1;
break;
}//switch
//
}//if
}//else
}// func
void mousePressed() {
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
}
//---
else if ( overNew() ) {
//
if ( activeArrayListIsLeft ) {
points1.clear(); //cancellare punti con new
// not necessary:
for (int i = 0; i < 13; i++) {
// points1.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
} else {
points2.clear(); //cancellare punti con new
// not necessary:
for (int i = 0; i < 13; i++) {
// points2.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
}
//
}
//---
else {
// points.add(new PVector(points.size(), mouseY/10));
if ( activeArrayListIsLeft ) {
points1.add(new PVector(points1.size(), myKnob1.getValue()));
} else {
points2.add(new PVector(points2.size(), myKnob1.getValue()));
}
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
// prepara la descrizione del file che avviene nel dialogo
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// println ("La finestra è stata chiusa o l'utente ha premuto annulla.");
// torna indietro
state=normal; // go back
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs;
if (activeArrayListIsLeft) {
strs = new String[points1.size()];
int i=0;
for (PVector pv : points1) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//
else {
strs = new String[points2.size()];
int i=0;
for (PVector pv : points2) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
}//else
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
}//func
void loadIt() {
// load
if (activeArrayListIsLeft) {
points1.clear();
} else
{
points2.clear();
}
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
if (activeArrayListIsLeft) {
points1.add(new PVector(float(thisLine[0]), float(thisLine[1])));
} else
{
points2.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//else
//
}//for
}
// -------------------------------------------------
void showData1() {
//
// show data LEFT
PVector prev = new PVector(-1, -1);
int y=50;
if (activeArrayListIsLeft) {
stroke(255, 2, 2); // RED
line (10, 10, 198, 10);
}
for (PVector pv : points1) {
fill(255, 2, 2); // RED
// show data
text(pv.x, 30, y);
text(pv.y, 110, y);
fill(0, 2, 2);
stroke(255, 2, 2); // RED
if (prev.x!=-1) {
line(10 + pv.x*30, pv.y*10,
prev.x, prev.y);
}
noStroke();
ellipse (10 + pv.x*30, pv.y*10, 4, 4);
prev = new PVector(10 + pv.x*30, pv.y*10);
y+=20; //next line
}//for
// middle line
stroke(255, 2, 2); // RED
line( 100, 30, 100, height);
// double middle lines!!! ???
stroke(0); // BLACK
int x1=200;
line( x1-2, 30, x1-2, height);
line( x1+2, 30, x1+2, height);
//
}
void showData2() {
//
// show data RIGHT
if (!activeArrayListIsLeft) {
// activeArrayListIsLeft is FALSE, right side is active
stroke(2, 255, 2); // GREEN
line (200, 10,
350, 10);
}
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points2) {
fill(0, 255, 2); // GREEN
// show data
text(pv.x, 210, y);
text(pv.y, 290, y);
fill(0, 2, 2);
stroke(0, 255, 2); // GREEN
if (prev.x!=-1) {
line(10 + pv.x*30, pv.y*10,
prev.x, prev.y);
}
noStroke();
ellipse (10 + pv.x*30, pv.y*10, 4, 4);
prev = new PVector(10 + pv.x*30, pv.y*10);
y+=20; //next line
}//for
// middle line
stroke(0, 255, 2); // GREEN
line( 288, 30, 288, height);
//
}
// ---------------------------------------------------------------
void serialEvent(Serial p) {
inString = p.readString();
char primo=inString.charAt(0); // primo carattere
String cifra=inString.substring(1); // da secondo carattere in poi
float val=parseFloat(cifra); // valore da 0-255 o 0-1023, non sò cosa spedisce arduino
print("val=");
println(val);
// inString = trim(inString);
// // converte in int e mappa all'altezza dello schermo:
switch(primo) {
case ('A'):
myKnob1.setValue(val);
break;
case ('B'):
myKnob2.setValue(val);
break;
case ('C'):
myKnob3.setValue(val);
break;
case ('D'):
myKnob3.setValue(val);
break;
}
}
what do you think about it? I still do not understand how to draw the graph (y axis values read via Arduino and x axis scales from 0 to 13 where each mouse pressed advances by 1) and relative table. And the part that I think very complicated to achieve, recall a previously saved Array List and be able to superimpose it on the chart (line of another color) and add it to the table just created .........
import processing.serial.*;
import controlP5.*;
import grafica.*;
Serial myPort; // The serial port:
ControlP5 controlP5; // controlP5 object
Knob myKnob1,myKnob2,myKnob3,myKnob4;
ArrayList<PVector> points = new ArrayList();
String inString; // Input string from serial port:
int lf = 10; // ASCII linefeed
float deg, val;
final String pathFolder="";//CARTELLA DI PERCORSO
final String fileExtension = ".txt";//estensione file
// unique numbers for constants:
final int normal = 0;
final int save = 1;
final int load = 2;
///current state (must be one of them)
/// stato attuale (deve essere uno di loro)
int state=normal;
// Paths
String savePath="";
String loadPath="";
void setup() {
size(1350, 750);
// not necessary
for (int i = 0; i < 3; i++) {
points.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
//ControlP5
PFont f= createFont ("Georgia", 25);
{
controlP5 = new ControlP5(this); //ControlP5
myKnob1 = controlP5.addKnob(" Massa ARIA")
//.setRange(0,1024)
.setRange(0,5)
.setValue(0)
.setPosition(width-370,height-185)//posizione 605
.setTickMarkLength(10)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150,150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
;
myKnob1 .getCaptionLabel()
. setFont(f);
myKnob1.getValueLabel()
.setFont(f)
;
;
myKnob2 = controlP5.addKnob("P. Cil")
.setRange(0,500)
.setValue(0)
.setPosition(width-370,height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150,150)//dimensioni
// .setScrollSensitivity(120)
. setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob2 .getCaptionLabel()
. setFont(f);
myKnob2.getValueLabel()
.setFont(f)
;
myKnob3 = controlP5.addKnob("P. Atm ")
//.setRange(0,1023)
.setRange(0,500)
.setValue(1)
.setPosition(width-180,height-380)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150,150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob3 .getCaptionLabel()
. setFont(f);
myKnob3.getValueLabel()
.setFont(f)
;
myKnob4 = controlP5.addKnob("temp")
//.setRange(0,1023)
.setRange(0,500)
.setValue(1)
.setPosition(width-180,height-185)
.setColorForeground(color(#FF0004))//colore cursore
.setColorBackground(color(255))//colore sfondo
.setColorValueLabel(color(0))//colore numeri//label etichetta
.setColorActive(color(#6AFA05))
.setDragDirection(Knob.VERTICAL)
// . setColorCaptionLabel(0) //colore scritta(capition)
.lock()
.setSize(150,150)//dimensioni
.setDecimalPrecision(2) //numero dopo la virgola
.setTickMarkLength(10)
;
myKnob4 .getCaptionLabel()
. setFont(f);
myKnob4.getValueLabel()
.setFont(f)
;
}
}
// myPort = new Serial(this, "com3", 9600);
// myPort.bufferUntil(lf);
// }
void draw() {
switch (state) {
case normal:
drawForStateNormal() ;
break;
case save:
// wait for Save Dialog
waitForSaveDialog();
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
default:
//Error
println("Fail");
exit();
break;
//
}//switch
}//func
// ------------------------------------------------
void drawForStateNormal() {
background(245);
{
strokeWeight(2);
stroke(#FF0B03);
fill(0);
rect(width-380,height-490,360,90,20);// retangolo diff. press.
fill(255);
textSize(28);
text("Diff.Press.",width-270,height-405); //diff.press
textSize(40);
text(( myKnob2.getValue()- myKnob3.getValue()),width-270,height-445); //diff.press
}
{
fill(0);
strokeWeight(2);
stroke(#FF0B03);
rect(width-380,height-390,360,190,20);// retangolo press
rect(width-380,height-195,360,190,20);// rettangolo massa Temp
}
textSize(14);
showData();
// title
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons below\n" //testo e posizione testo
+"Use Backspace to delete last data point",
width-223, 20, 100, 422);
// ----------------------
// buttons
showButtons();
//
} //draw
// --------------------------------------------------
// functions to show buttons funzione per mostrare i bottoni
void showButtons() {
//
strokeWeight(2);
stroke(0);
textSize(15);
fill(0);
if ( overSave() ) {
fill(#FF0303);
}
rect(width-50, height-740, 40, 20,5);// modificato posizione bottone "salve"
fill(255);
text("Salve",
width-50+2,height-740+9+6);
// ---
fill(0);
if ( overLoad() ) {
fill(#49C3FA);
}
rect(width-50, height-710, 40, 20,5);// modificato posizione" load"
fill(255);
text("Load",
width-50+2, height-710+9+6);
// ---
fill(0);
if ( overNew() ) {
fill(#1FFF03);
}
rect(width-50, height-680, 40, 20,5);// modificato posizione "new"
fill(255);
text("New",
width-50+4, height-680+9+6);
}
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons funzione da registrare se il mouse è sui pulsanti
boolean overSave() { // modificato
return( mouseX > width-50 &&
mouseY > height-740 &&
mouseY < height-740+25) ;
}
boolean overLoad() { //modificato
return( mouseX > width-50 &&
mouseY > height-710 &&
mouseY < height-710+25 );
}
boolean overNew() { //modificato
return( mouseX > width -50 &&
mouseY > height-680 &&
mouseY < height-680+25 );
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state!=normal)
return;
// for the editor:
if ( keyCode == DELETE || keyCode == BACKSPACE ) {
//
if (points.size()>0)
points.remove(points.size()-1);
} else {
if ( key != CODED ) {
//
}
}
}
void mousePressed() {
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
}
//---
else if ( overNew() ) {
points.clear(); //cancellare punti con new
// not necessary:
for (int i = 0; i < 13; i++) {
points.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
}
//---
else {
// points.add(new PVector(points.size(), mouseY/10));
points.add(new PVector(points.size(), myKnob1.getValue()));
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
// prepara la descrizione del file che avviene nel dialogo
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
// println ("La finestra è stata chiusa o l'utente ha premuto annulla.");
// torna indietro
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs = new String[points.size()];
int i=0;
for (PVector pv : points) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
}//func
void loadIt() {
// load
// points.clear();
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
points.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//for
}
// -------------------------------------------------
void showData() {
//
// show data
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points) {
fill(0);
// show data
text(pv.x, 100, y);
text(pv.y, 200, y);
fill(0, 2, 2);
stroke(255, 2, 2);
if (prev.x!=-1) {
line(10 + pv.x*30, pv.y*10,
prev.x, prev.y);
}
noStroke();
ellipse (10 + pv.x*30, pv.y*10, 4, 4);
prev = new PVector(10 + pv.x*30, pv.y*10);
y+=20; //next line
}//for
// middle line
line( 190, 30, 190, 440);
//
}
void serialEvent(Serial p) {
inString = p.readString();
char primo=inString.charAt(0); // primo carattere
String cifra=inString.substring(1); // da secondo carattere in poi
float val=parseFloat(cifra); // valore da 0-255 o 0-1023, non sò cosa spedisce arduino
print("val="); println(val);
// inString = trim(inString);
// // converte in int e mappa all'altezza dello schermo:
switch(primo) {
case ('A'): myKnob1.setValue(val);
break;
case ('B'): myKnob2.setValue(val);
break;
case ('C'): myKnob3.setValue(val);
break;
case ('D'): myKnob3.setValue(val);
break;
}
}
I don't know about Arduino but here you can
At the beginning and when pressing New some points are added, this is not necessary. Search necessary in the code to change this.
A typical stored data file looks like this (comma separated float values)
0.0,27.690079
1.0,27.670195
2.0,27.499521
3.0,27.464329
4.0,27.39308
5.0,27.199102
6.0,26.98093
7.0,26.941555
8.0,26.824514
9.0,26.906185
10.0,26.86552
11.0,26.424377
12.0,26.095716
Chrisir ;-)
//
// from https : // forum.processing.org/two/discussion/comment/112902/#Comment_112902
// editor path and file extension
final String pathFolder="";
final String fileExtension = ".txt";
// graph content
ArrayList<PVector> points = new ArrayList();
// states of the program:
// unique numbers for constants:
final int normal = 0;
final int save = 1;
final int load = 2;
///current state (must be one of them)
int state=normal;
// Paths
String savePath="";
String loadPath="";
// ------------------------------------------------
// Core functions of processing
void setup() {
size(900, 900);
// not necessary
for (int i = 0; i < 3; i++) {
points.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
}//func
void draw() {
switch (state) {
case normal:
drawForStateNormal() ;
break;
case save:
// wait for Save Dialog
waitForSaveDialog();
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
default:
//Error
println("Fail");
exit();
break;
//
}//switch
}//func
// ------------------------------------------------
void drawForStateNormal() {
background(0);
textSize(14);
showData();
// title
fill(255, 2, 2);
text("My little Graph program\n\nUse buttons below\n"
+"Use Backspace to delete last data point",
width-123, 20, 100, 422);
// ----------------------
// buttons
showButtons();
//
} //draw
// --------------------------------------------------
// functions to show buttons
void showButtons() {
//
textSize(11);
fill(128);
if ( overSave() ) {
fill(196);
}
rect(width-40, height-20, 40, 20);
fill(255);
text("Save",
width-40+7, height-9+5);
// ---
fill(128);
if ( overLoad() ) {
fill(196);
}
rect(width-40, height-50, 40, 20);
fill(255);
text("Load",
width-40+7, height-50+9+5);
// ---
fill(128);
if ( overNew() ) {
fill(196);
}
rect(width-40, height-80, 40, 20);
fill(255);
text("New",
width-40+7, height-80+9+5);
}
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons
boolean overSave() {
return( mouseX > width-40 &&
mouseY > height-20 );
}
boolean overLoad() {
return( mouseX > width-40 &&
mouseY > height-50 &&
mouseY < height-50+25 );
}
boolean overNew() {
return( mouseX > width-40 &&
mouseY > height-80 &&
mouseY < height-80+25 );
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state!=normal)
return;
// for the editor:
if ( keyCode == DELETE || keyCode == BACKSPACE ) {
//
if (points.size()>0)
points.remove(points.size()-1);
} else {
if ( key != CODED ) {
//
}
}
}
void mousePressed() {
if (state!=normal)
return;
// for the buttons
if ( overSave() ) {
initSave();
}
//---
else if ( overLoad() ) {
initLoad();
}
//---
else if ( overNew() ) {
points.clear();
// not necessary:
for (int i = 0; i < 13; i++) {
points.add(new PVector(i, 20 + 10*noise(i*0.1)));
}//for
}
//---
else {
points.add(new PVector(points.size(), mouseY/10));
}
}//func
// -------------------------------------------------
// Save and load
void initSave() {
// init save process
// reset
savePath="";
// make date time stamp (the expression nf(n,2) means leading zero: 2 becomes 02)
String dateTimeStamp = year()
+ nf(month(), 2)
+ nf(day(), 2)
+ "-"
+ nf(hour(), 2)
+ nf(minute(), 2)
+ nf(second(), 2);
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()
+ "//"
+ pathFolder
+ "//"
+ dateTimeStamp
+ fileExtension);
// open the dialog
selectOutput("Select a file to write to", "fileSelectedSave", fileDescription);
// set state to wait
state=save;
}
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedSave(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
savePath=selection.getAbsolutePath();
}
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForSaveDialog() {
if (!savePath.equals("")) {
// waiting is over
saveIt();
// go back
state=normal;
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void saveIt() {
// save
// make array (to save it)
String[] strs = new String[points.size()];
int i=0;
for (PVector pv : points) {
strs[i]=str(pv.x)+","+str(pv.y);
i++;
}//for
// check if file extension (fileExtension, e.g. .txt) is there
int len = savePath.length();
if (len<4 || !savePath.substring( len-4 ).equals(fileExtension)) {
// file Extension is not present, we have to add it
savePath += fileExtension; // add the file Extension
}
// save
println("Saved: " + savePath);
saveStrings( savePath, strs );
}//func
void loadIt() {
// load
points.clear();
String[] strs = loadStrings( loadPath );
for (String s : strs) {
String[] thisLine=split(s, ",");
points.add(new PVector(float(thisLine[0]), float(thisLine[1])));
}//for
}
// -------------------------------------------------
// Misc
void showData() {
//
// show data
PVector prev = new PVector(-1, -1);
int y=50;
for (PVector pv : points) {
fill(255);
// show data
text(pv.x, 100, y);
text(pv.y, 200, y);
fill(255, 2, 2);
stroke(255, 2, 2);
if (prev.x!=-1) {
line(10 + pv.x*30, pv.y*10,
prev.x, prev.y);
}
noStroke();
ellipse (10 + pv.x*30, pv.y*10, 4, 4);
prev = new PVector(10 + pv.x*30, pv.y*10);
y+=20; //next line
}//for
// middle line
line( 190, 30, 190, 440);
//
}
// --------------------------------------------------
void setup() { selectInput("Select a file to process:", "fileSelected");
size(img.width, img.height);
}
void draw() {
}
void fileSelected(File file) { if (file == null) { println("Window was closed or the user hit cancel."); } else { println("User selected " + file.getAbsolutePath()); img = loadImage(file.getPath()); // Load the image into the program
} }
Can i get an alternate to select input, i have to specify the path in the location itself anf call back it.
I had a look at that thread you shared, GoToLoop and thanks!! It works great.
As I expected, the problem was in my while loop -- I thought it was what I thought was null, but I think it was more to do with the flag variable and checking the null... whatever...
At anyrate, if anybody's interested, here's the working code as I got it. Now all I have to do is figure out how to hide the code window completely:)
String[] protocol;
String[] fname;
void setup() {
selectInput("Select a file to process:", "fileSelected");
// selectInput("Please select canvas picture:", "selectImage");
while (protocol == null) delay(100);
printArray(protocol);
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
//println("User selected " + selection.getAbsolutePath());
protocol=loadStrings(selection.getAbsolutePath());
//printArray(protocol);
}
}
Hello all. I'm new to this, but not so new to basic coding, but it has been a long time since I've done any serious coding...
Here's my issue -- I have a Processing script that loads in a text file, parses it out and sends some info to an Arduino board. It works great, but I'd like to present the operator with the option of selecting a file, but I'm having trouble getting my head around the concept of "callback" stuff and in specific how to use it with the selectInput() function.
For the purposes of this, I have stripped out all the other stuff and just have the file load bits...
String[] protocol;
String[] fname;
int flag=0;
void setup() {
selectInput("Select a file to process:", "fileSelected");
while(flag==0){
if(protocol!=null){
flag=1;
}
}
println(protocol[0]);
}
void fileSelected(File selection) {
if (selection == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + selection.getAbsolutePath());
protocol = loadStrings(selection.getAbsolutePath());
}
}
My idea is that by putting the while loop it should hold the code until the variable protocol has something other than null. I have a feeling that I'm barking up the wrong tree with this and that null is the wrong thing to be checking for?
Any ideas or links to some tutorials or whatever would be greatly appreciated!!
Greg
here is an example to demonstrate the states.
This full sketch just displays the content of a text or mtl file after you loaded it.
I hope this helps.
Chrisir ;-)
// editor path and file extension
final String pathFolder="texts";
final String fileExtension = ".mtl";
// states of the program:
// unique constants:
final int normal = 0;
final int load = 1;
///current state (must be one of them)
int state=normal;
// Path
String loadPath="";
String str="nothing loaded\nuse button in the lower right corner ";
// ------------------------------------------------
// Core functions of processing
void setup() {
size(900, 900);
} // func
void draw() {
switch (state) {
case normal:
drawForStateNormal() ;
break;
case load:
// wait for Load Dialog
waitForLoadDialog();
break;
default:
//Error
println("Fail");
exit();
break;
//
} // switch
} // func
// ------------------------------------------------
void drawForStateNormal() {
background(0);
textSize(14);
// title
fill(255, 2, 2);
text("Demo for selectInput",
width-123, 20, 100, 422);
// show the text the user loaded
fill(255);
text(str,
20, 20, width-170, height-20);
// ----------------------
// button
fill(128);
if ( overLoad() ) {
fill(196);
}
rect(width-40, height-50, 40, 20);
fill(255);
text("Load",
width-40+5, height-50+9+5);
//
}//func
//----------------------------------------------------------------------------
// functions to register if mouse is over buttons
boolean overSave() {
return( mouseX > width-40 &&
mouseY > height-20 );
}
boolean overLoad() {
return( mouseX > width-40 &&
mouseY > height-50 &&
mouseY < height-50+25 );
}
boolean overNew() {
return( mouseX > width-40 &&
mouseY > height-80 &&
mouseY < height-80+25 );
}
// ---------------------------------------------------------------------------
// Inputs
void keyPressed() {
if (state!=normal)
return;
}
void mousePressed() {
if (state!=normal)
return;
// for the buttons
if ( overLoad() ) {
initLoad();
}
//
}//func
// -------------------------------------------------
// load functions
void initLoad() {
// init load process
// reset
loadPath="";
// prepare fileDescription which occurs in the dialogue
File fileDescription = new File( sketchPath()+"//"+pathFolder+"//"+"*" + fileExtension );
// open the dialog
selectInput("Select a file to load", "fileSelectedLoad", fileDescription);
// set state to wait
state=load;
}
void fileSelectedLoad(File selection) {
// the 'callback' function
if (selection == null) {
// println("Window was closed or the user hit cancel.");
// go back
state=normal;
} else {
// println("User selected " + selection.getAbsolutePath());
loadPath=selection.getAbsolutePath();
}
}
void waitForLoadDialog() {
if (!loadPath.equals("")) {
// waiting is over
loadIt();
// go back
state=normal;
}
}
void loadIt() {
// load
String[] strs = loadStrings( loadPath );
str = join(strs, "\n");
}
//
No problem.
Look at selectInput
Inside the call back function, copy the file path inside a global String variable loadPath that you declared before setup ().
Then use loadStrings together with loadPath to open the mtl.
I always use a state system to make sure I only load once loadPath is set. So once the load command gets in I tell draw() to be in a state waitForLoad (integer variable / constant) and I then start selectInput. Once loadPath is set, I load and set the state back to stateNormal (integer variable as well).
For example:
Yes you are right. What I would like is to be able to let the user browse through the files that can be found in this web directory and the file that he or she chooses will be somehow buffered and loaded into the sketch so it can then be triggered in the sampler. I will use the Minim library for the buffering I think. But it would be really nice if the browsing of the web directory could be solved first. I guess it will be kind of like selectInput or selectFolder but instead of selecting from hard drive we want to select from web directory. At the moment I have only uploaded the .wav files on a localhost until I have figured everything out and this will first of all just be a proof of concept for my school project so I only need to show that I have figured out how to make it work.
I haven't seen this kind of browsing perse before so my idea is just being based off of a product that I want to make happen. For starters a workaround will be more than welcome for now.