Beispiel #1
0
  @Override
  public void render(double timestamp) {
    Objects.requireNonNull(this.model);
    try {
      int beatNum = (int) Math.round((timestamp / 60.0) * model.getTempo());
      for (Link link : model.getLinks(beatNum)) {
        if (link.getPlayIteration() == model.getIteration()) {
          model.setCurrentTime(link.getLinkedBeat() * 60.0 / model.getTempo());
          model.setIteration(model.getIteration() + 1);
          return;
        }
      }
      if (beatNum != this.lastBeat) {
        this.playNotes(beatNum);
        this.lastBeat = beatNum;
      }
    } catch (InvalidMidiDataException e) {

    }
  }
Beispiel #2
0
 /** Renders the MidiView based on the given model, by playing all of the notes in the model */
 private void playNotes(int beat) throws InvalidMidiDataException {
   for (Playable p : this.model.getNotes(beat)) {
     if (p.getStartBeat() == beat) {
       MidiMessage start =
           new ShortMessage(
               ShortMessage.NOTE_ON,
               p.getInstrumentID() - 1,
               Pitch.getMidi(p.getPitch(), p.getOctave()),
               100);
       this.receiver.send(start, p.getStartBeat() * (60000000 / model.getTempo()));
     }
     if (p.getStartBeat() + p.getDuration() == beat + 1) {
       MidiMessage stop =
           new ShortMessage(
               ShortMessage.NOTE_OFF,
               p.getInstrumentID() - 1,
               Pitch.getMidi(p.getPitch(), p.getOctave()),
               100);
       this.receiver.send(
           stop, (p.getStartBeat() + p.getDuration()) * (60000000 / model.getTempo()));
     }
   }
 }