Search in sources :

Example 1 with Note

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;
		}*/
    }
}
Also used : lombok.val(lombok.val) Note(com.xenoage.zong.core.music.chord.Note) Fraction(com.xenoage.utils.math.Fraction) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 2 with Note

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;
}
Also used : Score(com.xenoage.zong.core.Score) Note(com.xenoage.zong.core.music.chord.Note) ArrayList(java.util.ArrayList) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 3 with Note

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;
}
Also used : Grace(com.xenoage.zong.core.music.chord.Grace) Note(com.xenoage.zong.core.music.chord.Note) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 4 with Note

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;
}
Also used : Grace(com.xenoage.zong.core.music.chord.Grace) Note(com.xenoage.zong.core.music.chord.Note) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 5 with Note

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);
        }
    }
}
Also used : MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlNormalNote(com.xenoage.zong.musicxml.types.choice.MxlNormalNote) Note(com.xenoage.zong.core.music.chord.Note) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlNote(com.xenoage.zong.musicxml.types.MxlNote) MxlCueNote(com.xenoage.zong.musicxml.types.choice.MxlCueNote) MxlGraceNote(com.xenoage.zong.musicxml.types.choice.MxlGraceNote) Pitch(com.xenoage.zong.core.music.Pitch) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlFullNoteContent(com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent)

Aggregations

Note (com.xenoage.zong.core.music.chord.Note)7 Chord (com.xenoage.zong.core.music.chord.Chord)6 Grace (com.xenoage.zong.core.music.chord.Grace)4 Pitch (com.xenoage.zong.core.music.Pitch)3 Fraction (com.xenoage.utils.math.Fraction)2 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)2 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)2 MxlCueNote (com.xenoage.zong.musicxml.types.choice.MxlCueNote)2 MxlGraceNote (com.xenoage.zong.musicxml.types.choice.MxlGraceNote)2 MxlNormalNote (com.xenoage.zong.musicxml.types.choice.MxlNormalNote)2 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)2 Score (com.xenoage.zong.core.Score)1 Voice (com.xenoage.zong.core.music.Voice)1 Rest (com.xenoage.zong.core.music.rest.Rest)1 MxlFullNoteContent (com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent)1 MxlFullNoteContentType (com.xenoage.zong.musicxml.types.choice.MxlFullNoteContent.MxlFullNoteContentType)1 MxlNoteContentType (com.xenoage.zong.musicxml.types.choice.MxlNoteContent.MxlNoteContentType)1 ArrayList (java.util.ArrayList)1 lombok.val (lombok.val)1