private void writeNotes(TGVoice voice, TGBeatData data) {
    for (int i = 0; i < voice.countNotes(); i++) {
      TGNote note = voice.getNote(i);

      int header = (i + 1 < voice.countNotes() ? NOTE_HAS_NEXT : 0);
      header = (note.isTiedNote()) ? header |= NOTE_TIED : header;
      if (note.getVelocity() != data.getVelocity()) {
        data.setVelocity(note.getVelocity());
        header |= NOTE_VELOCITY;
      }
      header = (note.getEffect().hasAnyEffect()) ? header |= NOTE_EFFECT : header;

      writeHeader(header);

      writeNote(header, note);
    }
  }