use of com.xenoage.zong.core.music.chord.Note in project Zong by Xenoage.
the class MidiConverter method writeVoice.
/**
* Writes the given voice into the MIDI sequence.
* @param voiceMp the staff, measure and voice index
* @param repetition the index of the current {@link Repetition}
*/
private void writeVoice(MP voiceMp, int repetition) {
val voice = score.getVoice(voiceMp);
for (VoiceElement element : voice.getElements()) {
// ignore rests. only chords are played
if (false == MusicElementType.Chord.is(element))
continue;
val chord = (Chord) element;
// grace chords are not supported yet - TODO: ZONG-104: Play grace chords
if (chord.isGrace())
continue;
// start beat of the element
Fraction duration = chord.getDuration();
val startBeat = voice.getBeat(chord);
val rep = repetitions.get(repetition);
if (false == rep.contains(Companion.time(voiceMp.measure, startBeat)))
// start beat out of range: ignore element
continue;
// MIDI ticks
val startMidiTime = timeMap.getByRepTime(repetition, Companion.time(voiceMp.measure, startBeat));
long startTick = startMidiTime.tick;
long endTick = startTick + durationToTick(duration, resolution);
long stopTick = endTick;
if (false == options.midiSettings.durationFactor.equals(Companion.get_1())) {
// custom duration factor
stopTick = startTick + round((endTick - startTick) * options.midiSettings.durationFactor.toFloat());
}
// play note
if (startTick < stopTick) {
float volume = dynamics.getVolumeAt(voiceMp.withBeat(startBeat), repetition);
int midiVelocity = round(midiMaxValue * volume);
for (Note note : chord.getNotes()) {
addNoteToTrack(note.getPitch(), voiceMp.staff, startTick, stopTick, midiVelocity, 0);
}
}
// TODO Timidity doesn't like the following midi events
/*MetaMessage m = null;
if (musicelement instanceof Clef)
{
Clef c = (Clef) musicelement;
m = createMidiEvent(c, tracknumber);
}
else if (musicelement instanceof NormalTime)
{
NormalTime t = (NormalTime) musicelement;
m = createMidiEvent(t, resolution, tracknumber);
}
else if (musicelement instanceof Key)
{
Key k = (Key) musicelement;
m = createMidiEvent(k, tracknumber);
}
else if (musicelement instanceof Tempo)
{
Tempo tempo = (Tempo)musicelement;
m = MidiTempoConverter.createMetaMessage(tempo);
}
if (m != null)
{
MidiEvent event = new MidiEvent(m, starttick);
track.add(event);
}*-/
currenttickinvoice = endtick;
}*/
}
}
use of com.xenoage.zong.core.music.chord.Note in project Zong by Xenoage.
the class VoiceElementWriteTest method createTestScoreEighths.
/**
* Creates a score with a single staff, a single measure,
* two voices with each 8 quarter notes which are beamed.
*/
private Score createTestScoreEighths() {
Score score = ScoreFactory.create1Staff();
new VoiceAdd(score.getMeasure(atMeasure(0, 0)), 1).execute();
for (int iVoice : range(2)) {
Voice voice = score.getVoice(atVoice(0, 0, iVoice));
List<Chord> beamChords = new ArrayList<>();
for (int i = 0; i < 8; i++) {
Chord chord = new Chord(new Note(Companion.pi(0, 0, 4)), Companion.fr(1, 8));
// add elements by hand, since the corresonding command is tested itself in this class
chord.setParent(voice);
voice.getElements().add(chord);
beamChords.add(chord);
}
// create beam
Companion.beamFromChords(beamChords);
}
// ensure that assert method works correctly. if not, fail now
assertTestScoreEighthsOriginalState(score);
return score;
}
use of com.xenoage.zong.core.music.chord.Note in project Zong by Xenoage.
the class VoiceElementWriteTest method grace.
private Chord grace(int step) {
Chord chord = new Chord(new Note(Companion.pi(step, 0)), Companion.fr(0, 4));
chord.setGrace(new Grace(true, Companion.fr(1, 16)));
return chord;
}
use of com.xenoage.zong.core.music.chord.Note in project Zong by Xenoage.
the class VoiceTest method grace.
public static Chord grace(int step) {
Chord chord = new Chord(new Note(Companion.pi(step, 0)), Companion.fr(0, 4));
chord.setGrace(new Grace(true, Companion.fr(1, 16)));
return chord;
}
use of com.xenoage.zong.core.music.chord.Note in project Zong by Xenoage.
the class ChordReader method addChordNote.
/**
* Reads the given note element, which is part of
* a chord (but not the first note element of the chord), and adds it to the given chord.
* Also the notations of this note are read.
*/
private static void addChordNote(Context context, MxlNote mxlNote, Chord chord, int staffIndexInPart) {
// only pitch is interesting for us, since we do not allow
// different durations for notes within a chord or other strange stuff
MxlFullNoteContent mxlFNC = mxlNote.getContent().getFullNote().getContent();
if (mxlFNC.getFullNoteContentType() == MxlFullNoteContentType.Pitch) {
Pitch pitch = ((MxlPitch) mxlFNC).getPitch();
Note note = new Note(pitch);
chord.addNote(note);
// notations
if (mxlNote.getNotations() != null) {
new NotationsReader(mxlNote.getNotations()).readToNote(chord, chord.getNotes().indexOf(note), staffIndexInPart, context);
}
}
}
Aggregations