예제 #1
0
  public ArrayList<ArrayList<Object>> getTrueNotes() {
    float audioDuration = this.getRealDuration();
    float ratio = audioDuration / this.duration;
    ArrayList<ArrayList<Object>> novaNotas = new ArrayList<ArrayList<Object>>();
    boolean exists;
    float lastSecond;
    int theIndex;
    ArrayList<Object> lastNote;
    ArrayList<ArrayList<Object>> realNotas =
        new ArrayList<
            ArrayList<Object>>(); // Cria um ArrayList com as notas compactadas..usando tecnicas de
    // MapReduce (que sao bem simples)

    for (MIDINote nota : notas) {
      exists = false;
      lastSecond = (float) 0.0;
      theIndex = 0;
      if (realNotas.size() > 0) {
        lastNote = realNotas.get(realNotas.size() - 1);
        for (ArrayList<Object> aNota : realNotas) {
          if (((Float) aNota.get(0)).floatValue() == nota.getSecond()) {
            exists = true;
            lastNote = aNota;
          } else if (lastSecond < nota.getSecond()
              && ((Float) aNota.get(0)).floatValue() > nota.getSecond()) {
            exists = false;
            break;
          }
          lastSecond = ((Float) aNota.get(0)).floatValue();
          theIndex++;
        }
        if (exists) {
          if (!lastNote.contains(nota.getNote())) {
            lastNote.add(nota.getNote());
          }
        } else {
          lastNote = new ArrayList<Object>();
          lastNote.add(nota.getSecond());
          lastNote.add(nota);
          realNotas.add(theIndex, lastNote);
        }

      } else {
        lastNote = new ArrayList<Object>();
        lastNote.add(nota.getSecond());
        lastNote.add(nota.getNote());
        realNotas.add(lastNote);
      }
    }
    for (int c = 0; c < realNotas.size(); ++c) {
      ArrayList<Object> notasTrack = realNotas.get(c);
      ArrayList<Object> novaNotasTrack = new ArrayList<Object>();
      for (int c2 = 0; c2 < notasTrack.size(); ++c2) {
        if (c2 == 0) {
          // Primeiro item do vetor contem o tempo..portanto..
          novaNotasTrack.add(((Float) notasTrack.get(c2)).floatValue());
        } else {
          // Os outros item nao contem o tempo..portanto, contem o mesmo valor
          novaNotasTrack.add(notasTrack.get(c2));
        }
      }
      novaNotas.add(novaNotasTrack);
    }
    return novaNotas;
  }