<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
      <title>Tagged with addtoggle() - Processing 2.x and 3.x Forum</title>
      <link>https://forum.processing.org/two/discussions/tagged/feed.rss?Tag=addtoggle%28%29</link>
      <pubDate>Sun, 08 Aug 2021 19:06:46 +0000</pubDate>
         <description>Tagged with addtoggle() - Processing 2.x and 3.x Forum</description>
   <language>en-CA</language>
   <atom:link href="/two/discussions/taggedaddtoggle%28%29/feed.rss" rel="self" type="application/rss+xml" />
   <item>
      <title>clearing an ArrayList</title>
      <link>https://forum.processing.org/two/discussion/28120/clearing-an-arraylist</link>
      <pubDate>Thu, 20 Sep 2018 05:16:28 +0000</pubDate>
      <dc:creator>eduzal</dc:creator>
      <guid isPermaLink="false">28120@/two/discussions</guid>
      <description><![CDATA[<p>I've around this issue a few times.
I have a particle system that contains an ArrayList of particles.
I use a separate window for the interface programmed using Control P5.</p>

<p>usually my particle system lies under a boolean, and that boolean is activated/deactivated by a cp5 toggle.
every time i toggle it to false, i want the ArrayList inside the particle system to be cleared, so the particle system starts fresh from zero instead of a simple interruption it's runtime.</p>

<p>so i put a ps.particles.clear(); in the toggle false condition. everytime it crashes and I get IndexOutOfBoundsException.
it also happened to me with a bang and a button.</p>

<p>what is the most efficient way to really clear an ArrayList?</p>

<p>here is the code with whats going on.</p>

<p>main code</p>

<pre><code>import controlP5.*;
ControlFrame cf;
RingSystem r;

boolean isRing = false;

void settings(){
   size(600,600);
}    

void setup(){

     //CONTROLP5
     cf =new ControlFrame(this, 400, displayHeight, "MENU", width, height);

     //RING SETUP
     cPos=new PVector(width/2, height/2, 0);
     r=new RingSystem(cPos);
}

void draw(){
  if (isRing) {
    if (frameCount%30==0) r.addRing();
    r.display();
  }
}
</code></pre>

<p>Ring System</p>

<pre><code>class RingSystem{
 ArrayList&lt;Ring&gt; rings;
 PVector origin;
 RingSystem(PVector _origin){
   rings=new ArrayList&lt;Ring&gt;();
   origin=_origin.copy();
 }

 void addRing(){
  rings.add(new Ring(origin)); 
 }

 void display(){
   for(int i=rings.size()-1; i&gt;0; i--){
    Ring r=rings.get(i);
    r.update();
    r.display();
    if(r.isDead()){
     rings.remove(i); 
    }
   }
 }
}
</code></pre>

<p>Ring/Particle</p>

<pre><code>class Ring {
  PVector origin;
  float dim=0;
  float dimMax=400;
  float life=0;
  float alpha;

  Ring(PVector _origin) {
    origin=_origin.copy();
  }

  void update() {
    life++;
    //origin.y++;
    //dim=cos(radians(life))*life;
    dim=life;
    alpha=map(life,height*2,0,0,255);
  }

  void display() {
    pushMatrix();
    stroke(0, 255, 255,alpha);
    strokeWeight(6);
    noFill();
    translate(origin.x, origin.y, origin.z);
    //rotateX(radians(90));
    ellipse(0, 0, dim, dim);
    popMatrix();
  }

  boolean isDead() {
    if (life&gt;height*2) {
      return true;
    } else {
      return false;
    }
  }
}
</code></pre>

<p>Control Frame</p>

<pre><code>public class ControlFrame extends PApplet {

  ControlP5 cp5;
  Object parent;

  public void setup() {
    cp5 = new ControlP5(this);  

    cp5.addToggle("ringToggle")
      .setPosition(160, 50)
      .setSize(80, 80)
      .setValue(false)
      ;
}
  void ringToggle(boolean toggle) {
    if (toggle==true) {
      isRing=true;
    } else {
      isRing=false;

      r.removeAll(rings);
      for (int i=0; i&lt;r.rings.size(); i++) {
        Ring ri=r.rings.get(i);
        r.rings.remove(i);
      }
    }
  }
</code></pre>

<p>}</p>
]]></description>
   </item>
   <item>
      <title>Button Shapes ControlP5</title>
      <link>https://forum.processing.org/two/discussion/27700/button-shapes-controlp5</link>
      <pubDate>Thu, 05 Apr 2018 19:50:15 +0000</pubDate>
      <dc:creator>nvwingh</dc:creator>
      <guid isPermaLink="false">27700@/two/discussions</guid>
      <description><![CDATA[<p>Hi everyone, I am looking for Rounded Toggle Buttons or Sliders in the shape of following image..</p>

<p><img src="https://forum.processing.org/two/uploads/imageupload/665/WSTULH6F10UI.png" alt="427-512" title="427-512" /></p>

<p>Can anyone advise me in the right direction?</p>

<p>Kind regards</p>
]]></description>
   </item>
   <item>
      <title>Video tracking for progress bar using movie and ControlP5</title>
      <link>https://forum.processing.org/two/discussion/25606/video-tracking-for-progress-bar-using-movie-and-controlp5</link>
      <pubDate>Sun, 17 Dec 2017 06:55:17 +0000</pubDate>
      <dc:creator>Izzy280</dc:creator>
      <guid isPermaLink="false">25606@/two/discussions</guid>
      <description><![CDATA[<p>Hello, I have been coding a progress bar using some examples that I found. The bar is almost done but it doesn't constantly update. Can someone assist me in getting it to update while the video is playing?
<a href="https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar#latest" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar#latest</a>
`</p>

<pre><code>//using processing video and movie
import processing.video.*;
import controlP5.*;
import java.awt.geom.*;
ControlP5 cp5;
Movie movie;

boolean play;
int speed = 1;
int progress;

   void setup() {
   size(1280, 360);
   cp5 = new ControlP5(this);
    background(0);
    // Load and play the video in a loop
    movie = new Movie(this, "video.mov");
   movie.play();
    movie.speed(speed);

 //Progress Bar
  ProgressBar p;
  p = new ProgressBar(cp5, "progress"); 
 p.setPosition(130, 345).setSize(350, 10).setRange(0,  (int) 
movie.duration()).listen(true);
//callback listener for Timeline object
 p.addCallback(new CallbackListener() {
  public void controlEvent(CallbackEvent theEvent) {
   if(theEvent.getAction() == ControlP5.ACTION_PRESS) {
    float x = theEvent.getController().getPointer().x();
    float a1 = 0;
    float a2 = theEvent.getController().getWidth();
    float b1 = theEvent.getController().getMin();
    float b2 = theEvent.getController().getMax();
    float val = map(x,a1,a2,b1,b2);
    theEvent.getController().setValue(val);
    println("now change movie time to ", val, movie.time());
   movie.jump((float) val);
      }
    }
  }
  );
 // a toggle to switch between play and pause mode
 cp5.addToggle("play")
.setPosition(10,375)
.setSize(50,19)
.getCaptionLabel().align(CENTER,CENTER);
 }
  void movieEvent(Movie m) {
  m.read();
 }
 void draw() {
   if (play) {
   // update the progressBar value/position
   // replace with audio-track position: progress = player.position();

 image(movie, width/2, 0, width/2, height);

   if (movie.available()) movie.read();
   progress = (int) movie.time();
 }
  }
      class ProgressBar extends Controller&lt;ProgressBar&gt; {
      public ProgressBar(ControlP5 theControlP5, String theName) {
      super(theControlP5, theName);
      setView(new ControllerView&lt;ProgressBar&gt;() {

   public void display(PGraphics pg, ProgressBar c) {
     pg.fill(!isMouseOver() ? c.getColor().getForeground():c.getColor().getActive());
    pg.rect(0, 0, c.getWidth(), c.getHeight());

    float val = map(c.getValue(),c.getMin(), c.getMax(), 0, c.getWidth()); 
    pg.fill(255);
    pg.rect(0, 0, val, c.getHeight());
  }
}
);
}

     public ProgressBar setValue(float theValue) {
     return super.setValue(constrain(theValue, getMin(), getMax()));
 }

  public ProgressBar setRange(int theStart, int theEnd) {
  _myMin = theStart;
  _myMax = theEnd;
  return this;
  }
}
</code></pre>

<p>`</p>
]]></description>
   </item>
   <item>
      <title>How to create a bar-chart where the "table.sort" change on request with a button!</title>
      <link>https://forum.processing.org/two/discussion/23993/how-to-create-a-bar-chart-where-the-table-sort-change-on-request-with-a-button</link>
      <pubDate>Fri, 01 Sep 2017 13:48:18 +0000</pubDate>
      <dc:creator>nachoman</dc:creator>
      <guid isPermaLink="false">23993@/two/discussions</guid>
      <description><![CDATA[<p>This is my first processing question for my first processing project, so sorry everybody for my ignorance of the software and of the forum rules, I'll be deeply thankful if anyone will be so kind to answer!</p>

<p>My problem is the following one:
I would like to do a bar chart representing my 100 favorite songs (according to iTunes reproductions!), where you can change the <strong>table.sort</strong>, the disposition of the song in genre, artist, n° of reproduction, etc... with some buttons to do it.
I've tried to do something with cp5 button, but the main problem is that if i maintain <strong>noLoop()</strong> the graph don't change, but if I take it away the graph goes crazy.
I report down here the code and the CSV table!</p>

<p>Help me please, free hugs and the give of my final project if you do!</p>

<p>CODE:</p>

<pre><code>import controlP5.*;

ControlP5 cp5;

Table table;
int c;
PFont font;
boolean Bottone = false;


void setup() {
  //size(800, 600);
  fullScreen();
  background(255);
  smooth();
  table = loadTable("My Music Numbers_first 100.csv", "header");
  font = createFont("Chivo-Regular-13.vlw", 13);//aggiunta la font

    cp5= new ControlP5(this); 

  cp5.addToggle("Bottone")
     .setPosition(20,180)
     .setSize(90,15)
     ;

}


void draw() {
  //questa linea e la successiva per invertire l'asse delle y
  /*scale(1, -1);
  translate(0, -height);*/

    font = createFont("CircularStd-Bold", 40);
    textFont(font);
    textSize(32);
    fill(#B0F566);
    textAlign(CENTER);
    text("My Favourite Tracks",(width/2),100);
    textSize(18);
    fill(#83B45B);
    text("A data—visualization of the 100 songs that I love most",(width/2),150);


    for (int i = 0; i&lt;table.getRowCount(); i++) {

    // Access each row of the table one at a time, in a loop.
    TableRow riga = table.getRow(i);
    int posizione = riga.getInt("posizione");
    String n = riga.getString("artista");
    String titolo = riga.getString("titolo");
    int score = riga.getInt("riproduzioni");
    int durata = riga.getInt("durata");
    String album = riga.getString("album");
    int anno = riga.getInt("anno");
    String genere = riga.getString("genere");
    String nazione = riga.getString("nazione");
    int x = 200+(i*10);
    int y = height/2;

    table.sort("riproduzioni");

     if (genere.equals("Alternativa/Indie") == true) {
      c = #B0F566;
    } 
    if (genere.equals("Reggae") == true) {
      c = #4AF2A1;
    } 
    if (genere.equals("Pop") == true) {
      c = #5CC9F5;
    } 
    if (genere.equals("Rock") == true) {
      c = #6638F0;
    }

    if (genere.equals("Hip Hop") == true) {
      c = #E8235E;
    }
    if (genere.equals("Rap") == true) {
      c = #FF1A1A;
    }
    if (genere.equals("Ska") == true) {
      c = #1EF7D1;
    }
    if (genere.equals("Dance Elettronica") == true) {
      c = #FFF41A;
    }
    if (genere.equals("Neofolk") == true) {
      c = #10FF00;
    } 
    if (genere.equals("Soul") == true) {
      c = #2420C4;
    }
    if (genere.equals("Punk") == true) {
      c = #CB7777;
    }

    if (Bottone == true) {
    table.sort("genere");

  } else {
    table.sort("riproduzioni");
  }

    fill(c);
    rectMode(CENTER);
    noStroke();
    rect(x, y, 10, score*4,7);
    //noLoop();

    println(titolo + " " + score);
  }
}
</code></pre>

<p>CSV (named "My Music Numbers_first 100.csv"):</p>

<p>posizione,artista,titolo,riproduzioni,durata,album,anno,genere,nazione
001,The Vaccines,All in White,112,04:34,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
002,The Vaccines,Norgaard,079,01:38,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
003,Alt-J,Dissolve Me,065,04:00,An Awesome Wave,2012,Alternativa/Indie,Inghilterra
004,Bon Iver,Skinny Love,063,03:58,For Emma| Forever Ago,2007,Alternativa/Indie,USA
005,Alt-J,Breezeblocks,058,03:47,An Awesome Wave,2012,Alternativa/Indie,Inghilterra
006,The Vaccines,Wetsuit,053,03:50,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
007,Bob Marley &amp; The Wailers,Stir It Up,048,03:41,Catch a Fire,1973,Reggae,Inghilterra
008,The Libertines,Don't Look Back Into The Sun,048,03:21,The Libertines,2004,Alternativa/Indie,Inghilterra
009,Tame Impala,Feels Like We Only Go Backwards,047,03:13,Lonerism,2012,Alternativa/Indie,Australia
010,The Vaccines,A Lack Of Understanding,044,02:59,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
011,Babyshambles,Maybeline,041,03:16,Sequel to the Prequel,2013,Alternativa/Indie,Inghilterra
012,Gazebo Penguins,Difetto,041,02:23,Raudo,2013,Alternativa/Indie,Italia
013,Alt-J,Matilda,041,03:48,An Awesome Wave,2012,Alternativa/Indie,Inghilterra
014,King Harvest,Dancing in the Moonlight,040,02:52,Dancing in the Moonlight,1973,Pop,USA
015,Gazebo Penguins,Finito il cafe,039,03:05,Raudo,2013,Alternativa/Indie,Italia
016,Alt-J,Something Good,038,03:42,An Awesome Wave,2012,Alternativa/Indie,Inghilterra
017,Egg,Shoe,038,03:45,Shoe EP,2009,Rock,Inghilterra
018,The Vaccines,Blow It Up,037,02:36,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
019,I Cani,Corso Trieste,034,03:28,Glamour,2013,Pop,Italia
020,I Cani,Post Punk,034,04:46,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
021,The Vaccines,Under Your Thumb,034,02:20,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
022,Chiddy Bang,By Your Side,034,03:48,inedito,2012,Hip Hop,USA
023,Gazebo Penguins,Casa dei Miei,033,02:28,Raudo,2013,Alternativa/Indie,Italia
024,I Cani,Hipsteria,033,03:39,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
025,U2,California (There Is No End to Love),033,04:00,Songs of Innocence,2014,Rock,Irlanda
026,Gazebo Penguins,Domani e' gennaio,032,02:57,Raudo,2013,Alternativa/Indie,Italia
027,Babyshambles,Fireman,031,01:42,Sequel to the Prequel,2013,Alternativa/Indie,Inghilterra
028,Babyshambles,Nothing Comes to Nothing,030,03:15,Sequel to the Prequel,2013,Alternativa/Indie,Inghilterra
029,Gazebo Penguins,Correggio,030,02:00,Raudo,2013,Alternativa/Indie,Italia
030,I Cani,Le coppie,030,03:09,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
031,I Cani,Il pranzo di santo stefano,030,02:09,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
032,The Vaccines,Post Break-Up Sex,030,02:54,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
033,Babyshambles,Farmer's Daughter,028,05:05,Sequel to the Prequel,2013,Alternativa/Indie,Inghilterra
034,Gazebo Penguins,Ogni scelta e' in perdita,028,03:23,Raudo,2013,Alternativa/Indie,Italia
035,I Cani,Velleita',028,04:47,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
036,Mecna,Cerotti,028,02:52,inedito,2012,Rap,Italia
037,Mighty Oaks,Brother,028,03:16,Brother,2012,Alternativa/Indie,Germania
038,The Vaccines,Tiger Blood,028,02:08,Come Of Age,2012,Alternativa/Indie,Inghilterra
039,Mecna,31/07,027,03:16,Bagagli a mano,2011,Rap,Italia
040,Paolo Nutini,10/10,027,02:57,Sunny Side Up,2009,Ska,Inghilterra
041,The Vaccines,If You Wanna,027,02:54,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
042,U2,The Miracle (Of Joey Ramone),027,04:15,Songs of Innocence,2014,Rock,Irlanda
043,Big Sean,Too Fake,027,04:12,Finally Famous Vol. 3: Big,2010,Hip Hop,USA
044,Flume,Holdin On,027,02:35,Flume,2012,Dance Elettronica,Australia
045,Deluxe,Pony,027,03:29,Polishing Peanuts,2011,Dance Elettronica,Francia
046,Bob Marley &amp; The Wailers,One Love,026,02:53,Exodus,1977,Reggae,Giamaica
047,Drowners,Ways to Phrase a Rejection,026,01:46,Drowners,2014,Alternativa/Indie,USA
048,The Vaccines,Wreckin' Bar (Ra Ra Ra),026,01:22,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
049,The Hives,Hate To Say I Told You So,026,03:20,Veni Vidi Vicious,2000,Alternativa/Indie,Svezia
050,Bon Iver,Holocene,025,05:36,Bon Iver| Bon Iver,2011,Alternativa/Indie,USA
051,I Cani,FBYC (Sfortuna),025,03:35,Glamour,2013,Pop,Italia
052,The Libertines,Music When The Lights Go Out,025,03:02,The Libertines,2004,Alternativa/Indie,Inghilterra
053,The Vaccines,Teenage Icon,025,03:05,Come Of Age,2012,Alternativa/Indie,Inghilterra
054,Cee Lo Green,Fuck You,025,03:54,The Lady Killer,2010,Pop,USA
055,Oscar Isaac,Hang Me| Oh Hang Me,025,03:23,Inside Llewyn Davis,2013,Neofolk,USA
056,The Tallest Man on Earth,Love is all,025,04:17,The Wild Hunt,2010,Neofolk,Svezia
057,The Vaccines,If You Wanna,025,02:54,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
058,Bob Marley &amp; The Wailers,No Woman No Cry,024,07:12,Natty Dread,1975,Reggae,Giamaica
059,Bob Marley &amp; The Wailers,Three Little Birds,024,03:02,Exodus,1980,Reggae,Giamaica
060,Drowners,Luv| Hold Me Down,024,02:51,Drowners,2014,Alternativa/Indie,USA
061,Gazebo Penguins,Non moriro',024,02:53,Raudo,2013,Alternativa/Indie,Italia
062,The Tallest Man on Earth    ,Thousand Ways,024,02:53,The Wild Hunt,2010,Neofolk,Svezia
063,The Vaccines,No Hope,024,04:10,Come Of Age,2012,Alternativa/Indie,Inghilterra
064,The Vaccines,Wolf Pack,024,02:24,What Did You Expect From The Vaccines?,2011,Alternativa/Indie,Inghilterra
065,Justice,D.A.N.C.E. ,024,04:03,Cross,2007,Dance Elettronica,Francia
066,Arctic Monkeys,Mardy Bum,023,02:55,Whatever People Say I Am| That's What I'm Not,2006,Alternativa/Indie,Inghilterra
067,Babyshambles,New Pair,023,03:06,Sequel to the Prequel,2013,Alternativa/Indie,Australia
068,Mumford &amp; Sons,Below My Feet,023,05:00,Babel,2012,Neofolk,Inghilterra
069,Otis Redding    ,Respect,023,02:10,Otis Blue: Otis Redding Sings Soul,1965,Soul,USA
070,Grouplove,Itchin' On A Photograph,023,04:23,Never Trust a Happy Song,2011,Rock,USA
071,Ingrid Michaelson,You And I,023,02:36,Girls and Boys,2006,Alternativa/Indie,USA
072,Bob Marley &amp; The Wailers,Get Up Stand Up,022,03:20,Burnin',1973,Reggae,Giamaica
073,Drowners,Long Hair,022,01:49,Drowners,2014,Alternativa/Indie,USA
074,I Cani,Non c'e' niente di twee,022,04:04,Glamour,2013,Pop,Italia
075,I Cani,Storia di un impiegato,022,03:53,Glamour,2013,Pop,Italia
076,I Cani,I pariolini di diciott'anni,022,03:46,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
077,Mumford &amp; Sons,The Cave,022,03:38,Sigh No More,2009,Neofolk,Inghilterra
078,The Tallest Man on Earth,Thrown Right at Me,022,02:59,Sometimes the Blues Is Just a Passing Bird,2010,Neofolk,Svezia
079,U2,Every Breaking Wave,022,04:12,Songs of Innocence,2014,Rock,Irlanda
080,Rancid,Ruby Soho,022,02:52,...And Out Come the Wolves,1995,Punk,USA
081,Sam Smith,Stay With Me,022,02:55,In the Lonely Hour,2014,Soul,Inghilterra
082,The Killers,Mr. Brightside,022,03:47,Hot Fuss,2004,Alternativa/Indie,USA
083,Bob Marley &amp; The Wailers,I Shot The Sheriff,021,03:54,Burnin',1973,Reggae,Giamaica
084,Chance The Rapper,Cocoa Butter Kisses ,021,05:07,Acid Rap,2013,Rap,USA
085,Coez,Lontana da me,021,03:43,Non erano fiori,2013,Pop,Italia
086,I Cani,Door Selection,021,02:40,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
087,I Cani,Perdona e dimentica,021,03:37,Il sorprendente album d'esordio de i cani,2011,Pop,Italia
088,Mumford &amp; Sons,Sigh No More,021,03:28,Sigh No More,2009,Neofolk,Inghilterra
089,The Black Keys,Lonely Boy,021,03:13,El Camino,2011,Alternativa/Indie,USA
090,The Libertines,What Katie Did,021,03:50,The Libertines,2004,Alternativa/Indie,Inghilterra
091,The Vaccines,I Wish I Was A Girl,021,02:52,Come Of Age,2012,Alternativa/Indie,Inghilterra
092,The Vaccines,Bad Mood,021,03:14,Come Of Age,2012,Alternativa/Indie,Inghilterra
093,Bob Marley &amp; The Wailers,Jamming,020,03:35,Exodus,1977,Reggae,Giamaica
094,Bon Iver    ,Beth/Rest,020,06:26,Bon Iver|Bon Iver,2011,Alternativa/Indie,USA
095,Bon Iver,Minnesota|WI,020,03:32,Bon Iver|Bon Iver,2011,Alternativa/Indie,USA
096,Gazebo Penguins,Mio Nonno,020,01:47,Raudo,2013,Alternativa/Indie,Italia
097,I Cani,Come vera nabokov,020,04:03,Glamour,2013,Pop,Italia
098,Mumford &amp; Sons,Roll Away Your Stone,020,04:24,Sigh No More,2009,Neofolk,Inghilterra
099,The Black Keys,Little Black Submarines,020,04:11,El Camino,2011,Alternativa/Indie,USA
100,The Cure,Just Like Heaven,020,3:30,Kiss Me Kiss Me Kiss Me,1987,Alternativa/Inside,Inghilterra</p>
]]></description>
   </item>
   <item>
      <title>ControlP5 caption label: secondary label text overwrite initial text</title>
      <link>https://forum.processing.org/two/discussion/23327/controlp5-caption-label-secondary-label-text-overwrite-initial-text</link>
      <pubDate>Thu, 06 Jul 2017 00:00:24 +0000</pubDate>
      <dc:creator>bob97086</dc:creator>
      <guid isPermaLink="false">23327@/two/discussions</guid>
      <description><![CDATA[<p>I am trying to change the label on a toggle control from the controlP5 library. The toggle is initialized to "true" with a caption label text of "Running". (Of course, cp5 displays all-caps RUNNING.) When the toggle (identified as "RunPauseToggle") is clicked on, the draw() loop is suspended (Pause mode) until the next toggle. The code fragments -- thanks to kfrajer -- make the run/pass action work. But I can't make the PAUSE text appear alone, it overwrites the preceding RUNNING label.</p>

<p>Here are the important bits. First, near the top is:</p>

<p><code>boolean runPause = true;</code></p>

<p>In the setup() block, among other lines, is this:</p>

<pre><code>    RunPauseToggle = cp5.addToggle("runPause")
       .setPosition(ctrlOffsetX, ctrlOffsetY)
       .setSize(100, ctrlSizeY)
       .setFont(font)
       .setCaptionLabel("Running")
       .setColorCaptionLabel(0)
       .setValue(true)
       .setMode(ControlP5.SWITCH)
       ;
</code></pre>

<p>At the beginning of the draw() loop is this:</p>

<pre><code>void draw() {
    if(runPause == false){
        RunPauseToggle.setCaptionLabel("Paused");
        return;
    } else {
        RunPauseToggle.setCaptionLabel("Running");
    }
</code></pre>

<p>As above, the first toggle of RunPauseToggle suspends draw() but writes PAUSED over RUNNING. The 2nd toggle displays a clean copy of RUNNING. This behavior continues on successive toggles. I've tried setting the label to all blanks ("     ") and to no text ("") ahead of the "Paused" command line but that doesn't work. I've browsed the heck out of the forum but without finding a working example of what I want to do.</p>

<p>Thanks for looking and (fingers crossed) responding.</p>
]]></description>
   </item>
   <item>
      <title>ControlP5 control labeling "Examples" automatic, mine not there</title>
      <link>https://forum.processing.org/two/discussion/23287/controlp5-control-labeling-examples-automatic-mine-not-there</link>
      <pubDate>Sun, 02 Jul 2017 21:06:21 +0000</pubDate>
      <dc:creator>bob97086</dc:creator>
      <guid isPermaLink="false">23287@/two/discussions</guid>
      <description><![CDATA[<p>Learning ControlP5 a bit painful but that's OK except for occasional puzzles such as:</p>

<p>In CP5 examples the creation of a toggle control is this:</p>

<pre><code>      cp5.addToggle("toggle")
         .setPosition(40,250)
         .setSize(50,20)
         .setValue(true)
         .setMode(ControlP5.SWITCH)
         ;
</code></pre>

<p>This generates not only the default coloration (black/blue) but places the "toggle" characters in all-caps below the graphic.
My nearly-identical code is this:</p>

<pre><code>    cp5.addToggle("run-pause")
       .setPosition(900, 50)
       .setSize(50, 40)
       .setValue(true)
       .setMode(ControlP5.SWITCH)
       ;
</code></pre>

<p>It creates the expected blue/black widget but no "RUN-PAUSE" text below the control.
Why?
Sure, I can add a text label and would do so to provide better captions for certain controls but it's still a puzzle.</p>
]]></description>
   </item>
   <item>
      <title>How can i save Toogle state in csv?</title>
      <link>https://forum.processing.org/two/discussion/22879/how-can-i-save-toogle-state-in-csv</link>
      <pubDate>Fri, 02 Jun 2017 17:36:19 +0000</pubDate>
      <dc:creator>newen</dc:creator>
      <guid isPermaLink="false">22879@/two/discussions</guid>
      <description><![CDATA[<p>I would like to write a program which works a LED.
If the toggle true the white circle has disappear and save the toggle state 1 in csv
If the toggle false the white circle has appear and save the toggle state 0 in the same row.
But the program just save the same number what i define in int x1 and not the toggle state what i want.
Int this point i can get.</p>

<p>import controlP5.*;
Table table;
ControlP5 cp5;</p>

<p>int col = color(255);
controlP5.Toggle b;</p>

<p>boolean setVisible=true;
int inside = -1;
int x1= 0;</p>

<p>void setup() {
  size(400,400);
  smooth();</p>

<p>table = new Table();</p>

<p>cp5 = new ControlP5(this);
  table.addColumn("kapcsolo1",Table.INT);</p>

<p>TableRow newRow = table.addRow();
  newRow.setInt("kapcsolo1", x1);</p>

<p>saveTable(table, "data/new.csv");
  // create a toggle and change the default look to a (on/off) switch look
  b = cp5.addToggle("toggle")
     .setPosition(40,250)
     .setSize(50,20)
     .setValue(true)
     .setMode(ControlP5.SWITCH)
     .setVisible(true)
     ;</p>

<p>}</p>

<p>void draw() {
  background(0);</p>

<p>pushMatrix();</p>

<p>translate(280,100);
  if(inside==1)
  ellipse(0,0,100,100);</p>

<p>popMatrix();
}</p>

<p>void toggle(boolean theFlag) {
  if(theFlag==true) {
    inside=inside<em>-1;
    x1=1;
  } else {
    inside=inside</em>-1;
    x1=0;
  }
}</p>
]]></description>
   </item>
   <item>
      <title>controlP5 Toggle button</title>
      <link>https://forum.processing.org/two/discussion/6490/controlp5-toggle-button</link>
      <pubDate>Fri, 25 Jul 2014 01:30:35 +0000</pubDate>
      <dc:creator>philspitler</dc:creator>
      <guid isPermaLink="false">6490@/two/discussions</guid>
      <description><![CDATA[<p>Hi, I have 10 buttons in a UI and it all works great, the issue I have is that I want the active button to remain highlighted</p>

<p>I added the  .setSwitch(true) to each button which acts like a toggle but the issues that when I click another button, the first button still stay highlighted.</p>

<p>How can I have a selected state?</p>

<p>Any idea?</p>

<p>Thanks.</p>

<p>Phil</p>
]]></description>
   </item>
   <item>
      <title>NullPointerExeption error in array</title>
      <link>https://forum.processing.org/two/discussion/16533/nullpointerexeption-error-in-array</link>
      <pubDate>Wed, 11 May 2016 00:23:11 +0000</pubDate>
      <dc:creator>spyguy518</dc:creator>
      <guid isPermaLink="false">16533@/two/discussions</guid>
      <description><![CDATA[<p>I continue to get a "NullPointerExeption" error on an array (defined on line 12) that takes data from a Serial port (data from two potentiometers) , and splits it. The array appears to be initialized correctly. Does anybody know what may be causing this? I have included the code (which is very long) below. Thank you for any help.</p>

<pre><code>import processing.serial.*;

// initialize all variables
Serial myPort;  // Create object from Serial class
public String input;  // Data received from the serial port
PFont font;
int xPosB= 1;         // horizontal position of the graph
int xPosT= 1;
boolean allOn = false;
boolean brakeOn = false;
boolean throttleOn = false;
String arrdata[] =  input.split("/n", 2);

// remove non-numerical characters to create graphable string
String graphableB[] = arrdata[0].split("Brake:", 2);
String graphableT[] = arrdata[1].split("Throttle:", 2);
//convert to integer for graphing
int inByteT = int(graphableT[2]);
int inByteB = int(graphableB[2]);


void setup() {
  size(925, 800);

  //initialize text
  font = createFont("Agency FB", 16, true); //create font
  textFont(font, 36);

  //initialize data acquisition
  //String data = Integer.toString(input); 
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);

  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[0], 9600);

  // don't generate a serialEvent() unless you get a newline character:
  myPort.bufferUntil('\n');

  // set inital background:
  background(#717070);

  //P5 Setup
  // create a toggle and change the default look to a (on/off) switch look

  import controlP5.*;

  ControlP5 cp0;
  ControlP5 cp1;
  ControlP5 cp2;

  smooth();
  cp0 = new ControlP5(this);
  cp1 = new ControlP5(this);
  cp2 = new ControlP5(this);

  cp0.addToggle("allOn")
    .setPosition(40, 250)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    .setCaptionLabel("ALL")
    ;

  cp1.addToggle("brakeOn")
    .setPosition(40, 190)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    .setCaptionLabel("BRAKE")
    ;

  cp2.addToggle("throttleOn")
    .setPosition(40, 130)
    .setSize(50, 20)
    .setValue(true)
    .setMode(ControlP5.SWITCH)
    .setCaptionLabel("THROTTLE")
    ;
}

void draw(){

  //initialize text print
  background(255);
  textFont(font, 16);
  fill(#FF0324);

  if ( myPort.available() &gt; 0) {  // If data is available,
    input = myPort.readString();    // read it and store it in data
    text(arrdata[0], 400, 400);
    text(arrdata[1], 500, 500);
  } else {
    text("NO DATA", 350, 350);
  }

  graphDrawBrake(allOn, brakeOn);
  graphDrawThrottle(allOn, throttleOn);
}


void graphDrawBrake (boolean allOn, boolean brakeOn) {

  while (allOn == true) {
    while (brakeOn == true) {
      // draw the line:
      stroke(#FF0000);
      line(xPosB, height, xPosB, height - inByteB);

      // at the edge of the screen, go back to the beginning:
      if (xPosB &gt;= 400) {
        xPosB = 0;
        background(#717070);
      } else {
        // increment the horizontal position:
        xPosB++;
      }
    }
  }
}

void graphDrawThrottle (boolean allOn, boolean throttleOn) {

  while (allOn == true) {
    while (throttleOn == true) {
      // draw the line:
      stroke(#50D85A);
      line(xPosT, height, xPosT, height - inByteT);

      // at the edge of the screen, go back to the beginning:
      if (xPosT &lt; 400 || xPosT &gt;= 800) {
        xPosT = 400;
        background(#717070);
      } else {
        // increment the horizontal position:
        xPosT++;
      }
    }
  }
}
</code></pre>
]]></description>
   </item>
   <item>
      <title>Status bar with movie and ControlP5</title>
      <link>https://forum.processing.org/two/discussion/13716/status-bar-with-movie-and-controlp5</link>
      <pubDate>Mon, 30 Nov 2015 20:49:52 +0000</pubDate>
      <dc:creator>Jose_Aparecido</dc:creator>
      <guid isPermaLink="false">13716@/two/discussions</guid>
      <description><![CDATA[<p>Hello guys,</p>

<p>I'm trying to put a bar to control the time / position when running a film, based on this example:
<a href="https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar" target="_blank" rel="nofollow">https://forum.processing.org/two/discussion/8103/using-a-controlp5-slider-as-video-progress-bar</a></p>

<p>To show the bar as the elapsed time, ran regular ...</p>

<p>But how do if you want to advance the film? It did not work when I tried movie.position () (as sound).</p>

<p>Someone could give a tip, or where can I find some documentation on the subject?</p>

<p>Below the code I am using as an example:</p>

<pre><code>import controlP5.*;
import processing.video.*;                              

ControlP5 cp5;
Movie movie1;

float md, mt;

int progress;
boolean play;

void setup() {
  size(600, 400);
  cp5 = new ControlP5(this);

  movie1 = new Movie(this, "D:/Projetos/Videos/Branca_de_Neve.mpg");
  movie1.play();

  ProgressBar p; // custom Controller class, see implementation below
  p = new ProgressBar(cp5, "progress"); // "progress" here will be linked to variable progress
  //p.setPosition(100, 300).setSize(200, 20).setRange(0, 1000).listen(true);
  p.setPosition(70, 330).setSize(350, 10).setRange(0,  (int) movie1.duration()).listen(true);

  // callback listener for TimeLine object   
  p.addCallback(new CallbackListener() {
    public void controlEvent(CallbackEvent theEvent) {
      if(theEvent.getAction() == ControlP5.ACTION_PRESS) {
        float x = theEvent.getController().getPointer().x();
        float a1 = 0;
        float a2 = theEvent.getController().getWidth();
        float b1 = theEvent.getController().getMin();
        float b2 = theEvent.getController().getMax();
        float val = map(x,a1,a2,b1,b2);
        theEvent.getController().setValue(val);
        println("now change movie time to ", val, movie1.time());

        //movie1.position(); //????
      }
    }
  }
  );

  // a toggle to switch between play and pause mode
  cp5.addToggle("play")
     .setPosition(10,375)
     .setSize(50,19)
     .getCaptionLabel().align(CENTER,CENTER);
}


void draw() {
  background(0);
  if (play) {
    // update the progressBar value/position
    // replace with audio-track position: progress = player.position();

    if (movie1.available()) movie1.read();
    image(movie1, 70, 40);

    //progress++;
    progress = (int) movie1.time();
  }
}

class ProgressBar extends Controller&lt;ProgressBar&gt; {

  public ProgressBar(ControlP5 theControlP5, String theName) {
    super(theControlP5, theName);

    setView(new ControllerView&lt;ProgressBar&gt;() {
      public void display(PGraphics pg, ProgressBar c) {

        pg.fill(!isMouseOver() ? c.getColor().getForeground():c.getColor().getActive());
        pg.rect(0, 0, c.getWidth(), c.getHeight());

        float val = map(c.getValue(),c.getMin(), c.getMax(), 0, c.getWidth()); 
        pg.fill(255);
        pg.rect(0, 0, val, c.getHeight());
      }
    }
    );
  }

  public ProgressBar setValue(float theValue) {
    return super.setValue(constrain(theValue, getMin(), getMax()));
  }

  public ProgressBar setRange(int theStart, int theEnd) {
    _myMin = theStart;
    _myMax = theEnd;
    return this;
  }
}
</code></pre>

<p>Thanks for listening</p>
]]></description>
   </item>
   <item>
      <title>Events with two windows using ControlP5 + Processing 3</title>
      <link>https://forum.processing.org/two/discussion/13446/events-with-two-windows-using-controlp5-processing-3</link>
      <pubDate>Sun, 08 Nov 2015 21:38:55 +0000</pubDate>
      <dc:creator>gperez</dc:creator>
      <guid isPermaLink="false">13446@/two/discussions</guid>
      <description><![CDATA[<p>Hi.
I have a project wich runs in two windows. One is intended to control the other. So, in the first one I'm drawing CP5 controls. But I'n not being able to handle the events in the second window. I mean, I don't know how to capture events in a second window.</p>

<p>Default code would be:
  cp5.addToggle("toggleValue")</p>

<p>Well, that tries to resolve the event in the same window.</p>

<p>I can see you can pass a misterious object as first param, so I tried things like:
  cp5.addToggle(secondWindow, "toggleValue")</p>

<p>But that wont work either. The error is always this:
<strong>Exception in thread "Thread-2" java.lang.NullPointerException</strong></p>

<p>I think is previous versions one could create windows using controlWindow. Not sure. I'm using processing 3. And I'm creating the windows myself (in Eclipse context)</p>

<p>So, any clue on how to define a event listener or something like that?</p>

<p>Thanks in advance.</p>
]]></description>
   </item>
   </channel>
</rss>