private void readNote(int header, TGVoice voice, TGBeatData data) { TGNote note = this.factory.newNote(); // leo el valor note.setValue(readByte()); // leo la cuerda note.setString(readByte()); // leo la ligadura note.setTiedNote((header & NOTE_TIED) != 0); // leo el velocity if (((header & NOTE_VELOCITY) != 0)) { data.getVoice(voice.getIndex()).setVelocity(readByte()); } note.setVelocity(data.getVoice(voice.getIndex()).getVelocity()); // leo los efectos if (((header & NOTE_EFFECT) != 0)) { readNoteEffect(note.getEffect()); } voice.addNote(note); }
private void writeBeat(TGBeat beat, TGBeatData data, boolean hasNext) { TGVoice voice = beat.getVoice(0); int header = hasNext ? BEAT_HAS_NEXT : 0; // Berifico si hay cambio de duracion if (!voice.getDuration().isEqual(data.getDuration())) { header |= BEAT_NEXT_DURATION; data.setDuration(voice.getDuration()); } // Berifico si tiene notas if (!beat.isRestBeat()) { header |= BEAT_HAS_NOTES; } // Berifico si tiene acorde if (beat.getChord() != null) { header |= BEAT_HAS_CHORD; } // Berifico si tiene texto if (beat.getText() != null) { header |= BEAT_HAS_TEXT; } // escribo la cabecera writeHeader(header); // escribo la duracion if (((header & BEAT_NEXT_DURATION) != 0)) { writeDuration(voice.getDuration()); } // escribo las notas if (((header & BEAT_HAS_NOTES) != 0)) { writeNotes(voice, data); } // escribo el acorde if (((header & BEAT_HAS_CHORD) != 0)) { writeChord(beat.getChord()); } // escribo el texto if (((header & BEAT_HAS_TEXT) != 0)) { writeText(beat.getText()); } }
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); } }
private void readBeat(int header, TGMeasure measure, TGBeatData data) { TGBeat beat = this.factory.newBeat(); beat.setStart(data.getCurrentStart()); readVoices(header, beat, data); // leo el stroke if (((header & BEAT_HAS_STROKE) != 0)) { readStroke(beat.getStroke()); } // leo el acorde if (((header & BEAT_HAS_CHORD) != 0)) { readChord(beat); } // leo el texto if (((header & BEAT_HAS_TEXT) != 0)) { readText(beat); } measure.addBeat(beat); }
private void readVoices(int header, TGBeat beat, TGBeatData data) { for (int i = 0; i < TGBeat.MAX_VOICES; i++) { int shift = (i * 2); beat.getVoice(i).setEmpty(true); if (((header & (BEAT_HAS_VOICE << shift)) != 0)) { if (((header & (BEAT_HAS_VOICE_CHANGES << shift)) != 0)) { data.getVoice(i).setFlags(readHeader()); } int flags = data.getVoice(i).getFlags(); // leo la duracion if (((flags & VOICE_NEXT_DURATION) != 0)) { readDuration(data.getVoice(i).getDuration()); } // leo las notas if (((flags & VOICE_HAS_NOTES) != 0)) { readNotes(beat.getVoice(i), data); } // leo la direccion if (((flags & VOICE_DIRECTION_UP) != 0)) { beat.getVoice(i).setDirection(TGVoice.DIRECTION_UP); } else if (((flags & VOICE_DIRECTION_DOWN) != 0)) { beat.getVoice(i).setDirection(TGVoice.DIRECTION_DOWN); } beat.getVoice(i).getDuration().copyFrom(data.getVoice(i).getDuration()); data.getVoice(i) .setStart(data.getVoice(i).getStart() + beat.getVoice(i).getDuration().getTime()); beat.getVoice(i).setEmpty(false); } } }