Search in sources :

Example 6 with Pitch

use of com.xenoage.zong.core.music.Pitch in project Zong by Xenoage.

the class SlurReader method readToContext.

public static void readToContext(Chord chord, int noteIndex, int staffIndexInPart, Context context, MxlSlurOrTied mxlSlur) {
    Pitch pitch = chord.getNotes().get(noteIndex).getPitch();
    float noteLP = context.getMusicContext(staffIndexInPart).getLp(pitch);
    // type
    SlurType type = (mxlSlur.getElementType() == MxlElementType.Slur ? SlurType.Slur : SlurType.Tie);
    // number (tied does usually not use a number, but is distinguished by pitch)
    Integer number = mxlSlur.getNumber();
    BezierPoint bezierPoint = readBezierPoint(mxlSlur.getPosition(), mxlSlur.getBezier(), context.getTenthMm(), context.getStaffLinesCount(staffIndexInPart), noteLP, chord.getDuration());
    VSide side = readVSide(mxlSlur.getPlacement());
    // waypoint
    SlurWaypoint wp = new SlurWaypoint(chord, noteIndex, bezierPoint);
    if (type == SlurType.Tie && number == null) {
        // unnumbered tied
        OpenUnnumberedTieds openTieds = context.getOpenElements().getOpenUnnumberedTies();
        if (mxlSlur.getType() == MxlStartStopContinue.Start) {
            openTieds.startTied(wp, side);
        } else if (mxlSlur.getType() == MxlStartStopContinue.Stop) {
            OpenSlur openTied = openTieds.stopTied(wp, side, context);
            if (openTied != null)
                context.createSlur(openTied);
        }
    } else {
        // numbered
        WaypointPosition wpPos;
        if (mxlSlur.getType() == MxlStartStopContinue.Start)
            wpPos = WaypointPosition.Start;
        else if (mxlSlur.getType() == MxlStartStopContinue.Stop)
            wpPos = WaypointPosition.Stop;
        else
            wpPos = WaypointPosition.Continue;
        context.registerSlur(type, wpPos, number, wp, side);
    }
}
Also used : BezierPoint(com.xenoage.zong.core.music.format.BezierPoint) OtherReader.readBezierPoint(com.xenoage.zong.io.musicxml.in.readers.OtherReader.readBezierPoint) WaypointPosition(com.xenoage.zong.core.music.WaypointPosition) OpenSlur(com.xenoage.zong.io.musicxml.in.util.OpenSlur) Pitch(com.xenoage.zong.core.music.Pitch) SlurType(com.xenoage.zong.core.music.slur.SlurType) OtherReader.readVSide(com.xenoage.zong.io.musicxml.in.readers.OtherReader.readVSide) VSide(com.xenoage.utils.math.VSide) SlurWaypoint(com.xenoage.zong.core.music.slur.SlurWaypoint) OpenUnnumberedTieds(com.xenoage.zong.io.musicxml.in.util.OpenUnnumberedTieds)

Example 7 with Pitch

use of com.xenoage.zong.core.music.Pitch in project Zong by Xenoage.

the class StemReader method getOuterNoteLp.

/**
 * Gets the line position of the note at the bottom or top side of the given chord.
 */
private static float getOuterNoteLp(Context context, Chord chord, VSide side, int staff) {
    MusicContext mc = context.getMusicContext(staff);
    List<Pitch> pitches = chord.getPitches();
    return mc.getLp(side == VSide.Top ? getLast(pitches) : getFirst(pitches));
}
Also used : Pitch(com.xenoage.zong.core.music.Pitch) MusicContext(com.xenoage.zong.core.music.MusicContext)

Example 8 with Pitch

use of com.xenoage.zong.core.music.Pitch in project Zong by Xenoage.

the class OpenUnnumberedTieds method startTied.

/**
 * Starts a tie.
 */
public void startTied(SlurWaypoint wp, VSide side) {
    Chord chord = wp.getChord();
    Pitch pitch = chord.getNotes().get(wp.getNoteIndex()).getPitch();
    // already a tied open for this pitch? then remember it, too
    if (openTieds.get(pitch) != null)
        openEarlierTieds.put(pitch, openTieds.get(pitch));
    // add new tied
    OpenSlur openTied = new OpenSlur();
    openTied.type = SlurType.Tie;
    openTied.start = new OpenSlur.Waypoint(wp, side);
    openTieds.put(pitch, openTied);
}
Also used : Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 9 with Pitch

use of com.xenoage.zong.core.music.Pitch in project Zong by Xenoage.

the class OpenUnnumberedTieds method stopTied.

/**
 * Ends an existing tie and returns the {@link OpenSlur}.
 * When the tie does not exist, null is returned.
 */
public OpenSlur stopTied(SlurWaypoint wp, VSide side, Context context) {
    Chord chord = wp.getChord();
    Pitch pitch = chord.getNotes().get(wp.getNoteIndex()).getPitch();
    // get tied for this pitch
    OpenSlur openTied = openTieds.remove(pitch);
    if (openTied == null) {
        context.reportError("Can not stop non-existing tied");
        return null;
    }
    // does start chord exist? could have been overwritten by backup element
    MP startMp = openTied.start.wp.getChord().getMP();
    if (startMp == null) {
        context.reportError("Tied can not be closed; start chord does not exist");
        return null;
    }
    // then close the earlier open tied instead, if there is one
    if (startMp.equals(context.getMp())) {
        // remember last tied
        openTieds.put(pitch, openTied);
        // use earlier tied instead
        openTied = openEarlierTieds.remove(pitch);
        if (openTied == null) {
            context.reportError("Tied can not be stopped on starting position, " + "and there is no earlier tied");
            return null;
        }
    }
    openTied.stop = new OpenSlur.Waypoint(wp, side);
    return openTied;
}
Also used : MP(com.xenoage.zong.core.position.MP) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 10 with Pitch

use of com.xenoage.zong.core.music.Pitch in project Zong by Xenoage.

the class MidiChordPlayerTry method main.

public static void main(String... args) throws Exception {
    SynthManager.init(false);
    MidiChordPlayer player = new MidiChordPlayer();
    Instrument instrument = Instrument.Companion.getDefaultInstrument();
    Pitch pitch = Companion.pi(2, 0, 4);
    player.playNote(pitch, instrument);
    sleep();
    Chord chord = chord(new Pitch[] { Companion.pi(2, 0, 4), Companion.pi(4, 0, 4) }, Companion.fr(1));
    player.playChord(chord, instrument);
    sleep();
    player.playChord(chord, instrument, (byte) 127);
    sleep();
    SynthManager.close();
}
Also used : Instrument(com.xenoage.zong.core.instrument.Instrument) Pitch(com.xenoage.zong.core.music.Pitch) Chord(com.xenoage.zong.core.music.chord.Chord)

Aggregations

Pitch (com.xenoage.zong.core.music.Pitch)24 Chord (com.xenoage.zong.core.music.chord.Chord)12 Test (org.junit.Test)11 MP (com.xenoage.zong.core.position.MP)4 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)4 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)4 Staff (com.xenoage.zong.core.music.Staff)3 Note (com.xenoage.zong.core.music.chord.Note)3 Rest (com.xenoage.zong.core.music.rest.Rest)3 Score (com.xenoage.zong.core.Score)2 Measure (com.xenoage.zong.core.music.Measure)2 Voice (com.xenoage.zong.core.music.Voice)2 VoiceElement (com.xenoage.zong.core.music.VoiceElement)2 Grace (com.xenoage.zong.core.music.chord.Grace)2 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)2 Cursor (com.xenoage.zong.io.selection.Cursor)2 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)2 MxlCueNote (com.xenoage.zong.musicxml.types.choice.MxlCueNote)2 MxlGraceNote (com.xenoage.zong.musicxml.types.choice.MxlGraceNote)2 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)2