Пример #1
0
    public void run() {
      if (isRunning) {

        int lasttime = currentTime;
        currentTime += (int) (System.currentTimeMillis() - lastSystemTime);
        lastSystemTime = System.currentTimeMillis();

        if (currentTime < indexmax) {
          for (; lasttime < currentTime; lasttime++) {
            TimedMessage m = parsedFile.get(new Integer((int) currentTime));
            if (m != null) m.readMessage();
          }
          outlet(1, currentTime);
        } else {
          Atom[] end = {Atom.newAtom("/loop"), Atom.newAtom("bang")};
          pause();
          outlet(2, end);
        }

        /*
        currentTime ++;
        TimedMessage m = parsedFile.get(new Integer ((int)currentTime));
        if (m != null) m.readMessage();
        System.out.println (currentTime);
        outlet (1, currentTime);
        */
      }
    }
Пример #2
0
  public void load() {

    int lasttime = 0;
    int currenttime = 0;
    TimedMessage currentMessage = new TimedMessage();

    String word = "";
    char caract;

    if (f == null) return;
    try {
      // bon, pas super bo, mais ressort avec le return de fin de fichier
      while (true) {
        // lit premier caractere de la ligne courante, si fin de fichier, return
        if ((caract = (char) f.read()) == (char) (-1)) {
          parsedFile.put(new Integer(lasttime), currentMessage);
          indexmax = lasttime;
          Atom[] max = {Atom.newAtom("/indexmax"), Atom.newAtom(indexmax)};
          outlet(2, max);
          return;
        }

        // recherche indice temps
        word = "";
        while (caract != ' ') {
          word += caract;
          caract = (char) f.read();
        }

        currenttime = Integer.parseInt(word);

        // si temps courant > ligne precedente -> enregistre messages temps precedent
        if (currenttime > lasttime) {
          parsedFile.put(new Integer(lasttime), currentMessage);
          lasttime = currenttime;
          currentMessage = new TimedMessage();
        }

        // recupere phrase courante
        word = "";
        caract = (char) f.read();
        while (caract != '\n') {
          word += caract;
          caract = (char) f.read();
        }
        currentMessage.addMessage(Atom.parse(word));
      }
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }