Reading several files using multiple audioplayers, minim library

edited November 2016 in Library Questions

Hello,

I am trying to read several files using multiple audioplayers with minim library.

There are 4 .wav files corresponding to a zone, when one plays the others stop.

I am stuck with the index and would very much appreciate some help.

Thanks a lot in advance !

best, laurent

import ddf.minim.*;

Minim minim;
String [] fileNames = {"MOUSE", "WORDS", "FLOW", "VORTEX"};
int numSounds = fileNames.length-1;
int Border = 50;
/**AudioPlayer sounds1;
 AudioPlayer sounds2;
 AudioPlayer sounds3;
 AudioPlayer sounds4;*/
AudioPlayer [] sounds = new AudioPlayer[numSounds];
int idx;

void setup () {
  size(1080, 1080, P2D);
  minim = new Minim (this);
  /*sounds1 = minim.loadFile("MOUSE.wav");
   sounds2 = minim.loadFile("WORDS.wav");
   sounds3 = minim.loadFile("FLOW.wav");
   sounds4 = minim.loadFile("VORTEX.wav");*/

    for (byte idx = 0; idx != numSounds;
sounds[idx] = minim.loadFile (fileNames [idx++] +".wav"));

}
void draw() {
  background (255);
  fill(255, 0, 0);
  rect(25, 25, 50, 50);

  fill(0, 0, 255);
  rect(125, 25, 50, 50);
}

void mouseMoved() {
  if (mouseX > Border && mouseX < 350) {
    sounds [(int)(idx)].play(); 

    println("sound0:"+sounds);
  } else if (mouseX < 750) {

  } else {
  } 
  if (mouseX < Border && mouseX > height-Border) {
  }

}
    void stop() {
      for ( byte idx = 0; idx != numSounds; sounds[idx++].close() );
      minim.stop();
      super.stop();
    }

Answers

  • ctrl-t in the processing editor will indent your code nicely. makes it much easier to read.

    oh god...

    for (byte idx = 0; idx != numSounds;
      sounds[idx] = minim.loadFile (fileNames [idx++] +".wav"));
    }
    

    try not to use code that you don't understand. inline post incrementing, pointless byte types, merging loop contents into the for clauses are all terrible ideas.

    i was about to suggest printing out the filenames that you are actually trying to load but with this convoluted mess it's hard to add any debug.

    for (int idx = 0; idx < numSounds; idx++) {
      sounds[idx] = minim.loadFile (fileNames[idx] +".wav"));
      println("file:" + fileNames[idx].wav + " - " + sounds[idx]);
    }
    
  • Thank you so much koogs and sorry for my mess! I fixed the code and cleaned it a bit, but still haven't found a way to play one file per zone...

    import ddf.minim.*;
    
    Minim minim;
    String [] fileNames = {"MOUSE", "WORDS", "FLOW", "VORTEX"};
    int numSounds = fileNames.length;
    int Border = 50;
    AudioPlayer [] sounds = new AudioPlayer[numSounds];
    int idx;
    
    void setup () {
      size(1080, 1080, P2D);
      minim = new Minim (this);
      for (int idx = 0; idx < numSounds; idx++) {
        sounds[idx] = minim.loadFile(fileNames[idx] +".wav");
        println("file:" + fileNames[idx] + " - "+sounds[idx]);
      }
    }
    void draw() {
      background (255);
      fill(255, 0, 0);
      rect(50, 50, 350, height);
    
      fill(0, 0, 255);
      rect(400, 50, 350, height);
    }
    
    void mouseMoved() {
    
      if (mouseX > Border && mouseX < 350) {
        sounds[idx].rewind();
        sounds[idx].play();
      } else if (mouseX < 750) {
      } else {
      } 
      if (mouseX < Border && mouseX > height-Border) {
      }
    }
    void stop() {
      for ( byte idx = 0; idx != numSounds; sounds[idx++].close() );
      minim.stop();
      super.stop();
    }
    
  • idx in line 30, where are you setting that?

  • edited December 2016

    Dear Koogs, thanks for your help. I fixed my sound problem with a friend. Now I try to switch from a String array to an other according to frameCount but don't manage to do so... Here below is a part of the code. Thanks alot in advance.

    color textCol= color(245);
    int Border = 30;
    int WORDS = 0;
    int MOUSE = 1;
    int FLOW  = 2;
    int VORTEX = 3;
    int mode = VORTEX;
    int A = 0;
    PVector offset = new PVector(Border, Border);
    
    
    Write [] phrases;
    
    String [] wordsFR= { 
      "Ici\non m'a dit d'ailleurs\nailleurs\nque j'étais d'ici", 
      "je suis d’ici d’ailleurs\nj’y suis allé, voir si j’y étais\nMais je ne m’y trouvais pas", 
      "on m’a dit : ici, là-bas, c’est idem\ntoi du pareil au même\nalors à quoi bon me chercher là? ", 
      "je me suis là et suis las\nd’être ici sans y être même\nsi je me trouve peu m'importe\nsi je te trouve devant ma porte", 
      "toi ni d'ici ni d'ailleurs\nchez toi partout pourtant\ntoi qui arrimes mon cœur\nd'ailleurs par tous les temps"
    };
    String [] wordsAR = { 
      "هنا\nقيل لي مِن هناك\nىوهناك\nقيل لي مِن هنا", 
      "أنا مِن هنا وهناك على كل حال\nومضيت لأرى إن كنتُ هناك\nأو كنتُ بحاجة لسواك", 
      "لكني ما عثرت على حالي\nقيل لي سيّان هنا أو هناك\nأنتَ أنتَ بحدّ ذاتك\nفلمَ البحث عن نفسي هاهنا؟", 
      "أراني هنا واهنٌ\nمِن كوني هنا دون أن أكون\nوما همَّ لو عثرتُ على حالي\n", 
      "أنت مَن ليس مِن هنا ولا هناك\nِن كل مكان على كل حال\nأنت مَن يمسك روابط قلبي\nفي كل حال من الأحوال"
    };
    
    String [] wordsTI = { 
      "ⵖⵢⴷ\nⵏⵏⴰⵏⵉⵢⵉⵜⴰⵙⴳⴰⴰⵏ\nⵜⴰⵙⴳⴰⴰⵏ\nⵎⴰⵛⵛⵏⴽⴽⵉⵓⵖⵉⴷⴰⴷⴳ", 
      "ⴷⴷⵉⵖⵉⵍⵎⵎⴰⵥⵕⵉⵖⵉⵙⵏⵏⵖⵉⵏⵏⵍⵍ\nⵇⵖⴰⵡⵇⴰⵖⴰⵏⴱⴷⴰⴷ\nⵓⵔⵜⵓⴼⵉⵖ", 
      "ⵏⵏⴰⵏⵉⵢⵉⵣⵓⴷⵓⴽⴰⵏⵖⵉⴷⵣⵓⴷⵖ\nⵍⵍⵉⵖⵜⴳⵉⵜⴽⵢⵢⵉⵏⵉⵜⵉⵅⴼ\nⵎⴰⵙⴰⵔⵉⵣⵉⵍⵎⵎⴰⵖⵉⴷⵜⵍⵍⵉⵖ?", 
      "ⵍⵍⵉⵖⵖⵉⴷⵎⴰⵛⵕⵎⵉ\nⵎⴰⴷⵖⵉⴷⵍⵍⵉⵖⵣⵓⵏⵓⵔⵍⵍ\nⴰⵡⴷⵢⴰⵜⵓⵔⵉⵢⵉⵣⵉⵡⵣⴻⵏⵜⴰⵎ\nⵉⵙⵓⴼⵉⵖⵉⵅⴼⵉⵏ", 
      "\nⵉⵖⴽⵎⵉⵏⵏⵓⴼⵉⵖⵜⴰⵎⴰⵏⵜⴰⴳⴳ\nⴽⵎⵎⵉⵍⵍⵉⵓⵔⵉⴳⵉⵏⵓⵍⵜⵜ\nⵓⵍⴰⵓⵍⵜⵜⵜⴰⵙⴳⴰ\nⴷⴰⵔⵓⵏⴽⵎⵎⵉⵉⴳⴰⵜⴽⴰⵢⴳⴰⵜⵜ\nⴽⵎⵎⵉⵍⵍⵉⵢⵓⴽⵔⵏⵓⵍ\nⵜⴰⵡⵉⵜⵜⵏⵖⴽⴰⵢⴳⴰⵜⵜⵜⵉ"
    };
    
    People [] visitors = new People [5];
    //int visitorsNb;
    ArrayList<Vortex> vortices;
    PImage fond;
    PFont [] fontList;
    String []languageList;
    // Sound
    SoundManager sm;
    
    void setup () {
      width =1080;
      height= 1920;
      size(1920, 1080, P2D);
    
      // OSC
      // déclaration d'un port pr la réception depuis Isadora
      // oscP5 = new OscP5(this, 2200);
      // déclarer une adresse pr l'envoi des messages : adresse IP + n° de port
      // to_isadora = new NetAddress("127.0.0.1", 1234);
    
      fond = loadImage("ICI_FOND.png");
    
      // SOUND
      sm = new SoundManager(this);
    
      // VORTICES (Case 3 : VORTEX)
      vortices = new ArrayList<Vortex>();
      for (int j = 0; j < 15; j++) {
        vortices.add(new Vortex());
      }
    
      // FONT LIST
      fontList = new PFont [3];
      fontList[0] = createFont ("Tubqal-Medium.ttf", 60); 
      fontList[1] = createFont ("QandusOriginal-Regular.ttf", 50);
      fontList[2] = createFont ("Elixir_Beta-Slender.ttf", 50);
    
    
      // ITERATIONS CLASS WRITE(PHRASES)   
      phrases = new Write [wordsFR.length];
      for (int i=0; i< phrases.length; i++) {  
        phrases[i] = new Write (wordsFR[i], offset, fontList [0], sm);
        println ("num lines : " + phrases[i].getNumLines());
        offset.add(0, (phrases[i].getNumLines())*125);
      }
    
      /*phrases = new Write [wordsAR.length]; 
       for (int i=0; i< phrases.length; i++) {  
       phrases[i] = new Write (wordsAR[i], offset, fontList [1], sm);
       offset.add(0, (phrases[i].getNumLines())*110);
       }
    
       phrases = new Write [wordsTI.length];
       for (int i=0; i< phrases.length; i++) {  
       phrases[i] = new Write (wordsTI[i], offset, fontList [2]);
       //println ("num lines : " + phrases[i].getNumLines());
       offset.add(0, (phrases[i].getNumLines())*110);
       }*/
    
      // VISITORS (VIRTUAL VISITORS TO CHECK INTERACTIVITY)
      for (int i = 0; i<visitors.length; i++) {
        visitors[i] = new People(random(0, width), random(0, height));
      }
      //popMatrix();
    }
    
  • Dear koogs, Thanks a lot for your help as usual. Well this code bellow is working, but I am sure there is a clean way to code it incrementing an idx?! I am just a poor beginner ;))

    import ddf.minim.*;
    
    Minim minim;
    String [] fileNames = {"MOUSE", "WORDS", "FLOW", "VORTEX"};
    int numSounds = fileNames.length;
    int Border = 50;
    AudioPlayer [] sounds = new AudioPlayer[numSounds];
    int idx;
    
    void setup () {
      size(1080, 1080, P2D);
      minim = new Minim (this);
      for (int idx = 0; idx < numSounds; idx++) {
        sounds[idx] = minim.loadFile(fileNames[idx] +".wav");
        println("file:" + fileNames[idx] + " - "+sounds[idx]);
      }
    }
    void draw() {
      background (255);
      fill(255, 0, 0);
      rect(50, 50, 350, height);
    
      fill(0, 0, 255);
      rect(400, 50, 350, height);
    }
    
    void mouseMoved() {
    
      if (mouseX > Border && mouseX < 350) {
        sounds[0].rewind();
        sounds[0].play();
        sounds[1].pause();
        sounds[2].pause();
        sounds[3].pause();
      } else if (mouseX < 750) {
        sounds[1].rewind();
        sounds[1].play();
        sounds[0].pause();
        sounds[2].pause();
        sounds[3].pause();
      } else {
        sounds[2].rewind();
        sounds[2].play();
        sounds[0].pause();
        sounds[1].pause();
        sounds[3].pause();
      } 
      if (mouseX < Border && mouseX > height-Border) {
        sounds[3].rewind();
        sounds[3].play();
        sounds[0].pause();
        sounds[1].pause();
        sounds[2].pause();
      }
    }
    void stop() {
      for ( byte idx = 0; idx != numSounds; sounds[idx++].close() );
      minim.stop();
      super.stop();
    }
    
  • edited November 2016 Answer ✓

    @lolonulu - One way of refactoring your mouseMoved if statements is to use the same approach that you use in setup and in stop: looping. Create a function called e.g. soundSelect() and have it rewind-and-play the selected, and pause everything else.

    void mouseMoved() {
      if (mouseX > Border && mouseX < 350) {
        soundSelect(sounds, 0);
      } else if (mouseX < 750) {
        soundSelect(sounds, 1);
      } else {
        soundSelect(sounds, 2);
      } 
      if (mouseX < Border && mouseX > height-Border) {
        soundSelect(sounds, 3);
      }
    }
    
    void soundSelect( AudioPlayer[] list, int choice){
      for (int idx = 0; idx < list.size(); idx++) {
        if(idx == choice){
          list[idx].rewind();
          list[idx].play();
        } else {
          list[idx].pause();
        }
      }
    }
    

    The advantage to this approach is that, no matter how many sounds you add to your list, your sound selections "just work" -- any the sound that is playing (no matter how many new sounds there are in the list) gets paused automatically when the next sound is selected.

  • Thank you so much Jeremy this is excatly what I was searching for! Still my sound players are part of a larger project and I still have issue with playing sounds smoothly ! (The code is quite long sorry) if you can help me with this issue that would be fantastic! I have 5 vertical zones, I'like the sounds playing independantly... Thank you very much!

    import java.util.*;
    import ddf.minim.*;
    
    color textCol= color(245);
    int Border = 30;
    int WORDS = 0;
    int MOUSE = 1;
    int FLOW  = 2;
    int VORTEX = 3;
    int mode = VORTEX;
    int zone =0;
    
    Write [] phrases;
    
    String [] wordsFR = { 
      "Ici\non m'a dit d'ailleurs\nailleurs\nque j'étais d'ici", 
      "je suis d’ici d’ailleurs\nj’y suis allé, voir si j’y étais\nMais je ne m’y trouvais pas", 
      "on m’a dit : ici, là-bas, c’est idem\ntoi du pareil au même\nalors à quoi bon me chercher là? ", 
      "je me suis là et suis las\nd’être ici sans y être même\nsi je me trouve peu m'importe\nsi je te trouve devant ma porte", 
      "toi ni d'ici ni d'ailleurs\nchez toi partout pourtant\ntoi qui arrimes mon cœur\nd'ailleurs par tous les temps"
    };
    String [] wordsAR = { 
      "هنا\nقيل لي مِن هناك\nىوهناك\nقيل لي مِن هنا", 
      "أنا مِن هنا وهناك على كل حال\nومضيت لأرى إن كنتُ هناك\nأو كنتُ بحاجة لسواك", 
      "لكني ما عثرت على حالي\nقيل لي سيّان هنا أو هناك\nأنتَ أنتَ بحدّ ذاتك\nفلمَ البحث عن نفسي هاهنا؟", 
      "أراني هنا واهنٌ\nمِن كوني هنا دون أن أكون\nوما همَّ لو عثرتُ على حالي\n", 
      "أنت مَن ليس مِن هنا ولا هناك\nِن كل مكان على كل حال\nأنت مَن يمسك روابط قلبي\nفي كل حال من الأحوال"
    };
    
    String [] wordsTI = { 
      "ⵖⵢⴷ\nⵏⵏⴰⵏⵉⵢⵉⵜⴰⵙⴳⴰⴰⵏ\nⵜⴰⵙⴳⴰⴰⵏ\nⵎⴰⵛⵛⵏⴽⴽⵉⵓⵖⵉⴷⴰⴷⴳ", 
      "ⴷⴷⵉⵖⵉⵍⵎⵎⴰⵥⵕⵉⵖⵉⵙⵏⵏⵖⵉⵏⵏⵍⵍ\nⵇⵖⴰⵡⵇⴰⵖⴰⵏⴱⴷⴰⴷ\nⵓⵔⵜⵓⴼⵉⵖ", 
      "ⵏⵏⴰⵏⵉⵢⵉⵣⵓⴷⵓⴽⴰⵏⵖⵉⴷⵣⵓⴷⵖ\nⵍⵍⵉⵖⵜⴳⵉⵜⴽⵢⵢⵉⵏⵉⵜⵉⵅⴼ\nⵎⴰⵙⴰⵔⵉⵣⵉⵍⵎⵎⴰⵖⵉⴷⵜⵍⵍⵉⵖ?", 
      "ⵍⵍⵉⵖⵖⵉⴷⵎⴰⵛⵕⵎⵉ\nⵎⴰⴷⵖⵉⴷⵍⵍⵉⵖⵣⵓⵏⵓⵔⵍⵍ\nⴰⵡⴷⵢⴰⵜⵓⵔⵉⵢⵉⵣⵉⵡⵣⴻⵏⵜⴰⵎ\nⵉⵙⵓⴼⵉⵖⵉⵅⴼⵉⵏ", 
      "\nⵉⵖⴽⵎⵉⵏⵏⵓⴼⵉⵖⵜⴰⵎⴰⵏⵜⴰⴳⴳ\nⴽⵎⵎⵉⵍⵍⵉⵓⵔⵉⴳⵉⵏⵓⵍⵜⵜ\nⵓⵍⴰⵓⵍⵜⵜⵜⴰⵙⴳⴰ\nⴷⴰⵔⵓⵏⴽⵎⵎⵉⵉⴳⴰⵜⴽⴰⵢⴳⴰⵜⵜ\nⴽⵎⵎⵉⵍⵍⵉⵢⵓⴽⵔⵏⵓⵍ\nⵜⴰⵡⵉⵜⵜⵏⵖⴽⴰⵢⴳⴰⵜⵜⵜⵉ"
    };
    
    Minim minim;
    String [] fileNames = {"MOUSE", "WORDS", "FLOW", "VORTEX"};
    int numSounds = fileNames.length;
    AudioPlayer [] sounds = new AudioPlayer[numSounds];
    int idx;
    
    People [] visitors = new People [5];
    int visitorsNb;
    ArrayList<Vortex> vortices;
    PImage fond;
    PFont [] fontList;
    
    void setup () {
      size(1080, 1280, P2D);
      //pushMatrix();
      fond = loadImage("ICI_FOND.png");
    
      // SOUND
      minim = new Minim (this);
      for (int idx = 0; idx < numSounds; idx++) {
        sounds[idx] = minim.loadFile(fileNames[idx] +".wav");
        println("file:" + fileNames[idx] + " - "+sounds[idx]);
      }
    
      // VORTICES (Case 3 : VORTEX)
      vortices = new ArrayList<Vortex>();
      for (int j = 0; j < 15; j++) {
        vortices.add(new Vortex());
      }
    
      // ITERATIONS CLASS WRITE(PHRASES)   
      phrases = new Write [wordsFR.length];
      //for (int i=0; i< phrases[wordsFR.length]; i++) {    
      PVector offset = new PVector(Border, Border);
      PFont [] listTypo = new PFont [3];
      //phrases[i] = new Write (wordsFR[i], offset);
      //println ("num lines : " + phrases[i].getNumLines());
      //offset.add(0, phrases[i].getNumLines()+1*i*150);
      //  }
    
      phrases[0] = new Write (wordsFR[0], offset, listTypo ); 
      //println ("num lines : " + phrases[0].getNumLines());
      offset.add(0, (phrases[0].getNumLines())*100);
      phrases[1] = new Write (wordsAR[1], offset, listTypo);
      offset.add(0, (phrases[1].getNumLines())*100);
      phrases[2] = new Write (wordsTI[2], offset, listTypo);
      offset.add(0, phrases[2].getNumLines()*100);
      //println ("num lines : " + phrases[2].getNumLines());
      phrases[3] = new Write (wordsFR[3], offset, listTypo);
      offset.add(0, (phrases[3].getNumLines())*100);
      phrases[4] = new Write (wordsFR[4], offset, listTypo);
      offset.add(0, (phrases[4].getNumLines())*100);
    
    
      // VISITORS (VIRTUAL VISITORS TO CHECK INTERACTIVITY)
      for (int i = 0; i<visitors.length; i++) {
        visitors[i] = new People(random(0, width), random(0, height));
        println(fileNames);
      }
      //popMatrix();
    }
    
    void draw() {
      //pushMatrix();
      //translate(0, 1080);    
      //rotate(-HALF_PI);
      fill (0); 
      stroke(0, 200);
      rect(0, 0, width, height);
      stroke(255);
      image (fond, Border-10, Border-10);
      // popMatrix();
      //println(phrases);
      //translate(0, 1500);    
      //rotate(-HALF_PI);
    
      for (int i=0; i< visitors.length; i++) {
    
        visitors[i].checkEdges();     
        visitors[i].update();
        visitors[i].display();
    
        visitorsNb = visitors.length;
        //println("Nb visitors : " + visitors.length);
        translate (0, 20);
    
        // 5 VERTICAL ZONES WITH 5 TEXTS BLOCKS
        if ( visitorsNb > 0) {
          if (visitors[i].location.y > Border && visitors[i].location.y < height-Border) {
            if (visitors[i].location.y < Border+200) {
                phrases[0].setVisitorPos(visitors[i].location);
            } else if (visitors[i].location.y < Border+400) {
                phrases[1].setVisitorPos(visitors[i].location);
            } else if (visitors[i].location.y < Border+800) {
              phrases[2].setVisitorPos(visitors[i].location);
            } else if (visitors[i].location.y < Border+1000) {
              phrases[3].setVisitorPos(visitors[i].location);
            } else {
              phrases[4].setVisitorPos(visitors[i].location);
            }
          }
        } else {
          phrases[i].setVisitorPos(visitors[i].location);
          mode = VORTEX;
        }
      }
    
      for (int j =0; j< phrases.length; j++) {
        phrases[j].display();
      }
    }
    
    
    class Particle {
    
      float friction1 = 0.97;
      float fact1 =0.05;
      float slow1 =0.9;
      float friction2 = 0.97;
      float fact2 = 5;
      float slow2 = 0.92;
      float friction3 = 0.8;
      float fact3 = 0.002;
      float mass = random(2, 6);
      color col = color(random(180, 220));
      float rad = random(0.5, 1.5);
      PVector location;
      PVector location1;
      PVector acceleration;
      PVector origin;
      PVector butOld;
      float noiseStrength = 10;
      Boolean in = false;
      int lifetime = floor(random(3000));
      float size = map(sqrt(random(1)), 0, 1, 0, 400);
      float angle1 = random(TWO_PI);
      float incr;
    
      Particle (PGraphics pg) { 
    
        acceleration = new PVector(0, 0);
        while (!in)
        {
          int x = (int)random(width);
          int y = (int)random(height);
          if (pg.pixels[y * width + x] == textCol)
          {
    
            location = new PVector(x, y);
            origin = location.get();
            in = true;
          }
        }
      }
      void update(int p_mode, PVector loc) {
    
        PVector but;
        float m;
        float angle;
        boolean isOutside = false;
    
        switch(p_mode) {
    
        case 0:
          but = origin.get();
          but.sub(location);
          but.limit(10);
          but.mult(friction1 * fact1 * mass);
          acceleration.add(but);
          acceleration.mult(slow1);
          break;
        case 1: 
          but = new PVector(loc.x, loc.y);
          but.sub(location);
          m = but.mag()< 60 ? 500 :but.mag();
          but.normalize();
          but.mult(friction2 * fact2 * mass/ (sqrt(m)));
          acceleration.add(but);
          acceleration.mult(slow2);
          break;
        case 2:
          but = new PVector(random(width), random(height));
          butOld = new PVector(location.x, location.y);
          but.sub(location);
          but.limit(10);
          m = but.mag()< 120 ? 900 :but.mag();
          but.mult(friction3 * fact1 * mass/ (sqrt(m)));
          incr+= random(.008);
          angle = noise(location.x *.006, location.y *.004, incr) * noiseStrength;
          acceleration.x = 2*cos(angle);
          acceleration.y = 2*sin(angle);
          acceleration.add(but);
          acceleration.mult(0.98);
          //lifetime--;
    
          if (but.x<-10) isOutside = true;
          else if (but.x>width+10) isOutside = true;
          else if (but.y<-10) isOutside = true;
          else if (but.y>height+10) isOutside = true;
    
          if (isOutside) {
            but.x = random(width);
            but.y = random(height);
            butOld.set(but);
          }
          butOld.set(but);
          isOutside = false;
          //stroke(col, lifetime);
          line(location.x, location.y, location.x-acceleration.x, location.y-acceleration.y);
    
          break;
        case 3:
          location1 = new PVector(size * cos(angle1) + width / 2, size * sin(angle1) + height / 2);
    
          but = new PVector(0, 0);
          for (Vortex v : vortices) {
            float d = PVector.dist(location, v.loc);
            if (d < v.range) {
              PVector f = PVector.sub(location, v.loc);
              f.normalize();
              f.mult(map(d, 0, v.range, 1, 0));
              if (v.clockwise) {
                f.rotate(HALF_PI);
              } else {
                f.rotate(-HALF_PI);
              }
              but.add(f);
            }
          }
          but.limit(10);
          location.add(but);
    
          ellipse (location.x, location.y, 2, 2);
          break;
        }
      }
      void display () {
        //fill(255);
        //rect (location.x, location.y, 5, 5);
      }
    
      void edges () {
    
        location.add(acceleration);
        if (location.x < Border) {
          location.x = Border;
          acceleration.x*=-1;
        } else if (location.x > width-Border) {
          location.x = width-Border;
          acceleration.x*=-1;
        }
        if (location.y < Border) {
          location.y = Border;
          acceleration.y*=-1;
        } else if (location.y > height - Border) {
          location.y = height - Border;
          acceleration.y *=-1;
        }
        fill(col, 0);
        ellipse (location.x, location.y, rad*1.5, rad*1.5);
      }
    }
    
    class People {
    
      PVector location;
      PVector velocity;
      PVector acceleration;
    
      People ( float x, float y) {
        location = new PVector(x, y);
        velocity = new PVector(random(- 0.1, 0.1), random (- 0.1, 0.1));
        acceleration = new PVector (random(- 0.02, 0.02), random (- 0.02, 0.02));
      }
    
      void update () {
        velocity.add(acceleration);
        location.add(velocity);
      }
    
      void display() {
        fill(255, 0, 0);
        ellipse (location.x, location.y, 20, 20);
      }
    
      void checkEdges() {
    
        if (location.x > width || (location.x < 0)) {
          velocity.x *= -1;
          acceleration.x *= -1;
        }
        if (location.y > height ||(location.y < 0)) {
          velocity.y *= -1;
          acceleration.y *= -1;
        }
      }
    }
    
    
    class Vortex {
        PVector loc;
        float range;
        boolean clockwise;
    
        Vortex() {
          loc = new PVector (random(width), random(height)); 
          range = random(100, 300);
          clockwise = random(1) <0.5 ? true:false;
        }
      }
    
    class Write {
    
      int particlesPerLetter = 50;
      Particle [] particles;
      PFont [] fontList = new PFont [3];
      int mode;
      PVector visitorPos;
      String words;
    
    
      Write(String _words, PVector origin, PFont [] fontList) {
        words = _words;
        mode = VORTEX;
        visitorPos = new PVector();
    
        fontList[0] = createFont ("Tubqal-Medium.ttf", 50); 
        fontList[1] = createFont ("QandusOriginal-Regular.ttf", 50);
        fontList[2] = createFont ("Elixir_Beta-Slender.ttf", 50);
    
        for (int j = 0; j<fontList.length; j++) {
          PGraphics pg;
          int nbParticle = particlesPerLetter * words.length();
          particles = new Particle[nbParticle];
          pg = createGraphics(width, height);
          pg.beginDraw();
          pg.fill(textCol);
          pg.textAlign(CENTER);
          pg.textFont(fontList[j], 50);
          pg.text(words, origin.x, origin.y, width-Border, height-Border);
          pg.endDraw();
    
          pg.loadPixels();
          for (int i =0; i <particles.length; i++) { 
            particles[i] = new Particle(pg);
          }
        }
    
        //println("write: "+ particles.length);
        // pg.updatePixels();
      }
    
      int getNumLines() {
    
        int n = 0;
        int lastIndex =0;
        while (lastIndex > -1) {
          lastIndex = words.indexOf("\n", lastIndex+1);
          if (lastIndex >-1) {
            n++;
          }
        }
        return n;
      }
      void display() {
    
        for (int i=0; i< particles.length; i++) {
          particles[i].update(mode, visitorPos);
          particles[i].display();
          particles[i].edges();
        }
      }
    
      void setVisitorPos(PVector pos) {
    
        visitorPos = pos.get();
        for (int i=0; i< visitors.length; i++) { 
    
          if (visitorPos.x>Border && visitorPos.x < 350) {
            mode = MOUSE;
            soundSelect(sounds, 0);
          } else if (visitorPos.x < 750) {
            mode = WORDS;
            soundSelect(sounds, 1);
          } else if (mouseX < Border && mouseX > height-Border) {
            mode = FLOW;
            soundSelect(sounds, 2);
          } else {
            mode = VORTEX;
            soundSelect(sounds, 3);
          }
        }
      }
      void soundSelect(AudioPlayer[] list, int choice) {
        for (int idx=0; idx<list.length; idx++) {
          if (idx == choice) {
            list[idx].rewind();
            list[idx].play();
          } else {
            list[idx].pause();
          }
        }
      }
    }
      void stop() {
        for ( int idx = 0; idx < numSounds; numSounds++ ) {
          minim.stop();
          super.stop();
        }
      }
    
  • I still have issue with playing sounds smoothly

    What do you mean? What, specifically, is the problem, and what are you trying to change?

  • Thanks for your help. Well as you see in the code I declare the sound together with the 'visitors' inside the setVisitorPos function and when I compile it sounds as if the sounds loop very fast but doesn't play smoothly... I thought it's coming from too many particles, but no. Then the problem is certainly between lines 124 and 141 where I set the y location for my visitors interaction over the 5 blocks of text...

  • I solved other problem, but still the sound doesn't play smoothly at all, if you have a bit of time to help me it would be great ! Thank you vermuch in advance, best

  • Hey Jeremy, Sorry to bother again, but I can't solve this sound problem alone, it's between line 133 and line 144 where I should declare my sounds zone ! Thanks a lot in advance. best, laurent

    import java.util.*;z
    import ddf.minim.*;
    
    color textCol= color(245);
    int Border = 30;
    int WORDS = 0;
    int MOUSE = 1;
    int FLOW  = 2;
    int VORTEX = 3;
    int mode = VORTEX;
    int zone =0;
    int FR = 1;
    int AR = 2;
    int TI = 3;
    int lmode = FR;
    int zoneXSelected = 0;
    int zoneX = 0;
    
    Write [] phrases;
    
    String [] wordsFR = { 
      "Ici\non m'a dit d'ailleurs\nailleurs\nque j'étais d'ici", 
      "je suis d’ici d’ailleurs\nj’y suis allé, voir si j’y étais\nMais je ne m’y trouvais pas", 
      "on m’a dit : ici, là-bas, c’est idem\ntoi du pareil au même\nalors à quoi bon me chercher là? ", 
      "je me suis là et suis las\nd’être ici sans y être même\nsi je me trouve peu m'importe\nsi je te trouve devant ma porte", 
      "toi ni d'ici ni d'ailleurs\nchez toi partout pourtant\ntoi qui arrimes mon cœur\nd'ailleurs par tous les temps"
    };
    String [] wordsAR = { 
      "هنا\nقيل لي مِن هناك\nىوهناك\nقيل لي مِن هنا", 
      "أنا مِن هنا وهناك على كل حال\nومضيت لأرى إن كنتُ هناك\nأو كنتُ بحاجة لسواك", 
      "لكني ما عثرت على حالي\nقيل لي سيّان هنا أو هناك\nأنتَ أنتَ بحدّ ذاتك\nفلمَ البحث عن نفسي هاهنا؟", 
      "أراني هنا واهنٌ\nمِن كوني هنا دون أن أكون\nوما همَّ لو عثرتُ على حالي\n", 
      "أنت مَن ليس مِن هنا ولا هناك\nِن كل مكان على كل حال\nأنت مَن يمسك روابط قلبي\nفي كل حال من الأحوال"
    };
    
    String [] wordsTI = { 
      "ⵖⵢⴷ\nⵏⵏⴰⵏⵉⵢⵉⵜⴰⵙⴳⴰⴰⵏ\nⵜⴰⵙⴳⴰⴰⵏ\nⵎⴰⵛⵛⵏⴽⴽⵉⵓⵖⵉⴷⴰⴷⴳ", 
      "ⴷⴷⵉⵖⵉⵍⵎⵎⴰⵥⵕⵉⵖⵉⵙⵏⵏⵖⵉⵏⵏⵍⵍ\nⵇⵖⴰⵡⵇⴰⵖⴰⵏⴱⴷⴰⴷ\nⵓⵔⵜⵓⴼⵉⵖ", 
      "ⵏⵏⴰⵏⵉⵢⵉⵣⵓⴷⵓⴽⴰⵏⵖⵉⴷⵣⵓⴷⵖ\nⵍⵍⵉⵖⵜⴳⵉⵜⴽⵢⵢⵉⵏⵉⵜⵉⵅⴼ\nⵎⴰⵙⴰⵔⵉⵣⵉⵍⵎⵎⴰⵖⵉⴷⵜⵍⵍⵉⵖ?", 
      "ⵍⵍⵉⵖⵖⵉⴷⵎⴰⵛⵕⵎⵉ\nⵎⴰⴷⵖⵉⴷⵍⵍⵉⵖⵣⵓⵏⵓⵔⵍⵍ\nⴰⵡⴷⵢⴰⵜⵓⵔⵉⵢⵉⵣⵉⵡⵣⴻⵏⵜⴰⵎ\nⵉⵙⵓⴼⵉⵖⵉⵅⴼⵉⵏ", 
      "\nⵉⵖⴽⵎⵉⵏⵏⵓⴼⵉⵖⵜⴰⵎⴰⵏⵜⴰⴳⴳ\nⴽⵎⵎⵉⵍⵍⵉⵓⵔⵉⴳⵉⵏⵓⵍⵜⵜ\nⵓⵍⴰⵓⵍⵜⵜⵜⴰⵙⴳⴰ\nⴷⴰⵔⵓⵏⴽⵎⵎⵉⵉⴳⴰⵜⴽⴰⵢⴳⴰⵜⵜ\nⴽⵎⵎⵉⵍⵍⵉⵢⵓⴽⵔⵏⵓⵍ\nⵜⴰⵡⵉⵜⵜⵏⵖⴽⴰⵢⴳⴰⵜⵜⵜⵉ"
    };
    
    Minim minim;
    String [] fileNames = {"MOUSE", "WORDS", "FLOW", "VORTEX"};
    int numSounds = fileNames.length;
    AudioPlayer [] sounds = new AudioPlayer[numSounds];
    int idx;
    
    People [] visitors = new People [5];
    int visitorsNb;
    ArrayList<Vortex> vortices;
    PImage fond;
    PFont [] fontList;
    
    void setup () {
      size(1080, 1280, P2D);
      //pushMatrix();
      fond = loadImage("ICI_FOND.png");
    
      // SOUND
      minim = new Minim (this);
      for (int idx = 0; idx < numSounds; idx++) {
        sounds[idx] = minim.loadFile(fileNames[idx] +".wav");
        println("file:" + fileNames[idx] + " - "+sounds[idx]);
      }
    
      // VORTICES (Case 3 : VORTEX)
      vortices = new ArrayList<Vortex>();
      for (int j = 0; j < 15; j++) {
        vortices.add(new Vortex());
      }
      // ITERATIONS CLASS WRITE(PHRASES)   
      PVector offset = new PVector(Border, Border);
      fontList = new PFont [3];
      fontList[0] = createFont ("Tubqal-Medium.ttf", 50); 
      fontList[1] = createFont ("QandusOriginal-Regular.ttf", 50);
      fontList[2] = createFont ("Elixir_Beta-Slender.ttf", 50);
    
      phrases = new Write [wordsFR.length];
      for (int i=0; i< phrases.length; i++) {  
        phrases[i] = new Write (wordsFR[i], offset, fontList [0]);
        println ("num lines : " + phrases[i].getNumLines());
        offset.add(0, (phrases[i].getNumLines())*110);
      }
      /* phrases = new Write [wordsAR.length];
       for (int i=0; i< phrases.length; i++) {  
       phrases[i] = new Write (wordsAR[i], offset, fontList [1]);
       println ("num lines : " + phrases[i].getNumLines());
       offset.add(0, (phrases[i].getNumLines())*110);
       }
       phrases = new Write [wordsTI.length];
       for (int i=0; i< phrases.length; i++) {  
       phrases[i] = new Write (wordsTI[i], offset, fontList [2]);
       //println ("num lines : " + phrases[i].getNumLines());
       offset.add(0, (phrases[i].getNumLines())*110);
       }*/
    
      // VISITORS (VIRTUAL VISITORS TO CHECK INTERACTIVITY)
      for (int i = 0; i<visitors.length; i++) {
        visitors[i] = new People(random(0, width), random(0, height));
      }
      //popMatrix();
    }
    
    void draw() {
      //pushMatrix();
      //translate(0, 1080);    
      //rotate(-HALF_PI);
      fill (0); 
      stroke(0, 200);
      rect(0, 0, width, height);
      stroke(255);
      image (fond, Border-10, Border-10);
      // popMatrix();
      //println(phrases);
      //translate(0, 1500);    
      //rotate(-HALF_PI);
    
      for (int i=0; i< visitors.length; i++) {
    
        visitors[i].checkEdges();     
        visitors[i].update();
        visitors[i].display();
    
        visitorsNb = visitors.length;
        //println("Nb visitors : " + visitors.length);
        translate (0, 20);
      }
      // 5 VERTICAL ZONES WITH 5 TEXTS BLOCKS
      if ( visitorsNb > 0) {  
    
        for (int i=0; i< visitors.length; i++) {
          if (visitors[i].location.y > Border && visitors[i].location.y < height-Border) {
            if (visitors[i].location.y < Border+250) {  
              phrases[0].setVisitorPos(visitors[i].location);
            } else if (visitors[i].location.y < Border+500) {
              phrases[1].setVisitorPos(visitors[i].location);
            } else if (visitors[i].location.y < Border+750) {
              phrases[2].setVisitorPos(visitors[i].location);
            } else if (visitors[i].location.y < Border+1000) {
              phrases[3].setVisitorPos(visitors[i].location);
            } else {
              phrases[4].setVisitorPos(visitors[i].location);
            }
            //println("phrase4:"+zoneX);
          }
        }
      } else { 
        for (int j=0; j< visitors.length; j++) {
          if (zoneX != phrases[4].zoneXSelected()) {
            phrases[j].setVisitorPos(visitors[j].location);
            zoneX = phrases[4].zoneXSelected();
            mode = VORTEX;
          }
        }
      }
      for (int j =0; j< phrases.length; j++) {
        phrases[j].display();
      }
    }
    
    class Particle {
    
      float friction1 = 0.97;
      float fact1 =0.05;
      float slow1 =0.9;
      float friction2 = 0.97;
      float fact2 = 5;
      float slow2 = 0.92;
      float friction3 = 0.8;
      float fact3 = 0.002;
      float mass = random(2, 6);
      color col = color(random(180, 220));
      float rad = random(0.5, 1.5);
      PVector location;
      PVector location1;
      PVector acceleration;
      PVector origin;
      PVector butOld;
      float noiseStrength = 10;
      Boolean in = false;
      int lifetime = floor(random(3000));
      float size = map(sqrt(random(1)), 0, 1, 0, 400);
      float angle1 = random(TWO_PI);
      float incr;
    
      Particle (PGraphics pg) { 
    
        acceleration = new PVector(0, 0);
        while (!in)
        {
          int x = (int)random(width);
          int y = (int)random(height);
          if (pg.pixels[y * width + x] == textCol)
          {
    
            location = new PVector(x, y);
            origin = location.get();
            in = true;
          }
        }
      }
      void update(int p_mode, PVector loc) {
    
        PVector but;
        float m;
        float angle;
        boolean isOutside = false;
    
        switch(p_mode) {
    
        case 0:
          but = origin.get();
          but.sub(location);
          but.limit(10);
          but.mult(friction1 * fact1 * mass);
          acceleration.add(but);
          acceleration.mult(slow1);
          break;
        case 1: 
          but = new PVector(loc.x, loc.y);
          but.sub(location);
          m = but.mag()< 60 ? 500 :but.mag();
          but.normalize();
          but.mult(friction2 * fact2 * mass/ (sqrt(m)));
          acceleration.add(but);
          acceleration.mult(slow2);
          break;
        case 2:
          but = new PVector(random(width), random(height));
          butOld = new PVector(location.x, location.y);
          but.sub(location);
          but.limit(10);
          m = but.mag()< 120 ? 900 :but.mag();
          but.mult(friction3 * fact1 * mass/ (sqrt(m)));
          incr+= random(.008);
          angle = noise(location.x *.006, location.y *.004, incr) * noiseStrength;
          acceleration.x = 2*cos(angle);
          acceleration.y = 2*sin(angle);
          acceleration.add(but);
          acceleration.mult(0.98);
          //lifetime--;
    
          if (but.x<-10) isOutside = true;
          else if (but.x>width+10) isOutside = true;
          else if (but.y<-10) isOutside = true;
          else if (but.y>height+10) isOutside = true;
    
          if (isOutside) {
            but.x = random(width);
            but.y = random(height);
            butOld.set(but);
          }
          butOld.set(but);
          isOutside = false;
          //stroke(col, lifetime);
          line(location.x, location.y, location.x-acceleration.x, location.y-acceleration.y);
    
          break;
        case 3:
          location1 = new PVector(size * cos(angle1) + width / 2, size * sin(angle1) + height / 2);
    
          but = new PVector(0, 0);
          for (Vortex v : vortices) {
            float d = PVector.dist(location, v.loc);
            if (d < v.range) {
              PVector f = PVector.sub(location, v.loc);
              f.normalize();
              f.mult(map(d, 0, v.range, 1, 0));
              if (v.clockwise) {
                f.rotate(HALF_PI);
              } else {
                f.rotate(-HALF_PI);
              }
              but.add(f);
            }
          }
          but.limit(10);
          location.add(but);
    
          ellipse (location.x, location.y, 2, 2);
          break;
        }
      }
      void display () {
        //fill(255);
        //rect (location.x, location.y, 5, 5);
      }
    
      void edges () {
    
        location.add(acceleration);
        if (location.x < Border) {
          location.x = Border;
          acceleration.x*=-1;
        } else if (location.x > width-Border) {
          location.x = width-Border;
          acceleration.x*=-1;
        }
        if (location.y < Border) {
          location.y = Border;
          acceleration.y*=-1;
        } else if (location.y > height - Border) {
          location.y = height - Border;
          acceleration.y *=-1;
        }
        fill(col, 0);
        ellipse (location.x, location.y, rad*1.5, rad*1.5);
      }
    }
    class People {
    
      PVector location;
      PVector velocity;
      PVector acceleration;
    
      People (float x, float y) {
        location = new PVector(x, y);
        velocity = new PVector(random(- 0.1, 0.1), random (- 0.1, 0.1));
        acceleration = new PVector (random(- 0.02, 0.02), random (- 0.02, 0.02));
      }
    
      void update () {
        velocity.add(acceleration);
        location.add(velocity);
      }
    
      void display() {
        fill(255, 0, 0);
        ellipse (location.x, location.y, 20, 20);
      }
    
      void checkEdges() {
    
        if (location.x > width || (location.x < 0)) {
          velocity.x *= -1;
          acceleration.x *= -1;
        }
        if (location.y > height ||(location.y < 0)) {
          velocity.y *= -1;
          acceleration.y *= -1;
        }
      }
    }
    
    class Vortex {
      PVector loc;
      float range;
      boolean clockwise;
    
      Vortex() {
        loc = new PVector (random(width), random(height)); 
        range = random(100, 300);
        clockwise = random(1) <0.5 ? true:false;
      }
    }
    
    void setVisitorPos(PVector pos) {
    
        visitorPos = pos.get();
        if ( visitorsNb > 0) {
          if (zoneX >= 0) {
            for (int i=0; i< visitors.length; i++) { 
    
              if (visitorPos.x>Border && visitorPos.x < 350) {
                mode = MOUSE;
                if (zoneX != 1) {
                  soundSelect(sounds, 0);
                  zoneX =1;
                }
              } else if (visitorPos.x < 750) {
                mode = WORDS;
                if (zoneX != 2) {
                  soundSelect(sounds, 1);
                  zoneX = 2;
                }
              } else if (mouseX < Border && mouseX > height-Border) {
                mode = FLOW;
                if (zoneX != 3) {
                  soundSelect(sounds, 2);
                  zoneX = 3;
                }
              } else {
                mode = VORTEX;
                if (zoneX != 4) {
                  soundSelect(sounds, 3);
                  zoneX =4;
                  println (zoneXSelected);
                }
              }
            }
          } //println(zoneX);
        }
      }
    
      void soundSelect(AudioPlayer[] list, int choice) {
        for (int idx=0; idx<list.length; idx++) {
          if (idx == choice) {
            list[idx].rewind();
            list[idx].play();
          } else {
            list[idx].pause();
          }
        }
      }
    }
    void stop() {
      for ( int idx = 0; idx < numSounds; numSounds++ ) {
        minim.stop();
        super.stop();
      }
    }
    
  • Hello, I would like to change language in my class according to frameCount (2 min = latin, 2 min = arabic, 2min = tifinagh). How should I proceed? Of course it's urgent! Thank you very much for your help !

    Write [] phrases; String [] wordsFR= { "Ici\non m'a dit d'ailleurs\nailleurs\nque j'étais d'ici", }; String [] wordsAR = { "هنا\nقيل لي مِن هناك\nىوهناك\nقيل لي مِن هنا", }; String [] wordsTI = { "ⵖⵢⴷ\nⵏⵏⴰⵏⵉⵢⵉⵜⴰⵙⴳⴰⴰⵏ\nⵜⴰⵙⴳⴰⴰⵏ\nⵎⴰⵛⵛⵏⴽⴽⵉⵓⵖⵉⴷⴰⴷⴳ", }; 
    void setup (){
     phrases = new Write [wordsFR.length]; for (int i=0; i< phrases.length; i++) { phrases[i] = new Write (wordsFR[i], offset, fontList [0], sm); offset.add(0, (phrases[i].getNumLines())*125); }
    }
    
  • edited December 2016

    @lolonulu -- it sounds like you need a timer. See for example this recent thread:

    https://forum.processing.org/two/discussion/comment/81162/#Comment_81162

    2 minutes = 2* 60 seconds * 1000 milliseconds. So when millis() > 120000 then two minutes has passed. Although you probably want to test first with 3 seconds while you work on your code.

  • hi jeremydouglass, thank you very much for your help. I tried to put a timer in setup with an if / else structure and frameCount to switch between the 3 instances of my class but it didn't compile! Can we switch this way? (when I change the language in my class it works...)

  • dear @jeremydouglas, in the example you posted the time structure is inside the void draw can it be outside the void draw? thks a lot!!! :)

  • edited December 2016

    Setup is run only once at the very beginning of the sketch. So checking "millis" during setup probably won't do what you want -- the clock is at zero! You need to check during the main loop. What are you trying to time?

    "I'm about to draw() -- what time is it? If it is this time, draw x. If it is this time, draw y"

    Isn't that what you want to do? So put your check in draw.

    Can it be outside? Yes, time checking with millis() can be done inside built-in interaction methods -- like keyPressed or mousePressed -- and inside functions or class methods that have been called from draw() (so they are still "inside draw" in a sense). You can also do timing in a separate thread if you like using thread(), or using Java threading.

  • Thank you very much @jeremydouglas this is very clear to me now! Since I declare different languages in my class in setup I need to create a function to switch from one to another and then declare it inside void draw? I'll post the code tomorrow to be more concrete. I want to switch language according to time...

  • Dear @jeremydouglas if I post the code to morrow would be able to check it out please ? Tomorrow for me is in 10 hours from now! Thks ;))

  • edited December 2016 Answer ✓

    Yes @lolonulu. Look at my example again. Your suggested approach with a timer function called from draw might be used by a simple switch statement in draw:

    draw(){
      // pick language #0,1,2 etc. based on the current time
      int currentLanguage = languageTimer(millis());
      // load the text
      switch(currentLanguage){
        case 0: phrases = wordsFR; break;
        case 1: phrases = wordsAR; break;
        // ... etc.
      }
      // draw the text here!
      // ... etc.
    }
    
    int languageTimer( int milliseconds ){
      // do math here on the submitted time,
      // decide which number representing a language to select and return (0,1,2...)
      // ... etc.
      return 0
    }
    
  • Thank you very much @jeremydouglas. I actualy started to write a switch case, but it doesn't compile : java.lang.RuntimeException at processing.opengl.PSurfaceJOGL$2.run(PSurfaceJOGL.java:443) at java.lang.Thread.run(Thread.java:745) Do I need to make a double array with my phrases instances in setup?!

    Here is the code:

     void setup () {
    //...
    // ITERATIONS CLASS WRITE(PHRASES)   
     languages = new String [3];
      phrases = new Write [wordsFR.length];
      for (int i=0; i< phrases.length; i++) { 
        for (int j=0; j< languages.length; j++) { 
          languages[0] = wordsFR[i];
          languages[1] = wordsAR[i];
          languages[2] = wordsTI[i];
          phrases[i] = new Write (languages[j], offset, fontList [0], sm);
          offset.add(0, (phrases[i].getNumLines())*125);
        }
      }
    //...
    
    }
    void draw () {
    //...
     int currentLanguage = languageTimer(millis());
    
      switch(currentLanguage) {
      case 0: 
        for (int i=0; i< phrases.length; i++) { 
          for (int j=0; j< languages.length; j++) { 
            languages [0] = wordsFR [i];
          }
        }
        break;
      case 1: 
        for (int i=0; i< phrases.length; i++) { 
          for (int j=0; j< languages.length; j++) { 
            languages [1] = wordsAR [i];
          }
        }
        break;
      case 3: 
        for (int i=0; i< phrases.length; i++) { 
          for (int j=0; j< languages.length; j++) { 
            languages [2] = wordsTI [i];
          }
        }
        break;
      }
    //...
    
    int languageTimer (int milliseconds) {
       println ("languageTimer :"+ languageTimer(millis()));
      int startTime;
      startTime =millis();
      if (millis() >= startTime+6000) {
        return 0;
      } else if (millis() >= startTime+9000) {
        return 1;
      } else {
        return 2;
      }
    }
    
  • It actually does compile - you found a Runtime Exception, that means there was no compiler error.

Sign In or Register to comment.