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);
}
}
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));
}
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);
}
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;
}
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();
}
Aggregations