Exemplo n.º 1
0
  @Override
  public void tick() {
    if (notesPerTick >= 1) {
      /* Easy, just release that amount of notes */
      for (int i = 0; i < (int) notesPerTick; i++) {
        if (strategy.isNext()) {
          /* Get the next note to be played */
          Note note = strategy.getNext();
          if (note != null) {
            /* Add it to the history of played notes */
            if (note.getStatus() == Note.NOTE_ON) {
              history.addNote(note);
            } else {
              history.removeNote(note);
            }
            /* Send it to the next block */
            nextBlock.process(note);
          }
        }
      }
      strategy.resetReceived();
    } else {
      /* Keep track of how long we've been waiting to play a note */
      countdown--;
      if (countdown == 0) {
        if (strategy.isNext()) {
          /* Get the next note to be played */
          Note note = strategy.getNext();
          if (note != null) {
            /* Add it to the history of played notes */
            if (note.getStatus() == Note.NOTE_ON) {
              history.addNote(note);
            } else {
              history.removeNote(note);
            }
            /* Send it to the next block */
            note.setTick(musicManager.getClient().getTime());
            nextBlock.process(note);
          }
        }
        countdown = timeToNote;
        strategy.resetReceived();
      }
    }

    for (Note note : offNotes) {
      note.setTick(musicManager.getClient().getTime());
      nextBlock.process(note);
    }
    offNotes.clear();
  }
Exemplo n.º 2
0
 @Override
 public ArrayList<Note> modify(Note note) {
   if (note.getStatus() == Note.NOTE_ON) {
     strategy.update(note);
   } else if (note.getStatus() == Note.NOTE_OFF) {
     Note note2 = new Note(Note.NOTE_ON, note.getPitch());
     if (strategy.contains(note)) {
       strategy.update(note);
     } else if (history.contains(note2)) {
       offNotes.add(note);
     }
   }
   return new ArrayList<Note>();
 }