use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class Score method getKey.
/**
* Gets the last {@link Key} that is defined before (or at,
* dependent on the given {@link Interval}) the given
* {@link MP}, also over measure boundaries. If there is
* none, a default C major time signature is returned.
* Private keys (in measure) override public keys (in measure column header).
*/
@SuppressWarnings("unchecked")
public MPE<? extends Key> getKey(MP mp, Interval interval) {
if (!interval.isPrecedingOrAt()) {
throw new IllegalArgumentException("Illegal interval for this method");
}
// begin with the given measure. if there is one, return it.
BeatE<Key> columnKey = header.getColumnHeader(mp.measure).getKeys().getLastBefore(interval, mp.beat);
BeatE<Key> measureKey = null;
if (getMeasure(mp).getPrivateKeys() != null)
measureKey = getMeasure(mp).getPrivateKeys().getLastBefore(interval, mp.beat);
BeatE<Key> ret = selectLatest(columnKey, measureKey);
if (ret != null)
return mpE(ret.element, mp.withBeat(ret.beat));
if (interval != At) {
// search in the preceding measures
for (int iMeasure = mp.measure - 1; iMeasure >= 0; iMeasure--) {
columnKey = header.getColumnHeader(iMeasure).getKeys().getLast();
BeatEList<Key> privateKeys = getMeasure(atMeasure(mp.staff, iMeasure)).getPrivateKeys();
measureKey = (privateKeys != null ? privateKeys.getLast() : null);
ret = selectLatest(columnKey, measureKey);
if (ret != null)
return mpE(ret.element, mp.withMeasure(iMeasure).withBeat(ret.beat));
}
}
// no key found. return default key.
return mpE(new TraditionalKey(0, Mode.Major), mpb0);
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class VoicesBeatOffsetterTest method createTestScore1Voice.
private Score createTestScore1Voice() {
Score score = new Score();
score.getFormat().setInterlineSpace(1);
Cursor cursor = new Cursor(score, mp0, true);
cursor.write(new Clef(ClefType.clefTreble));
cursor.write((MeasureElement) new TraditionalKey(-3));
cursor.write(new TimeSignature(TimeType.timeType(6, 4)));
// beats: 0, 2, 3, 4, 8.
cursor.write(chord(pi(0, 0, 0), fr(1, 4)));
cursor.write(chord(pi(0, 0, 0), fr(1, 8)));
cursor.write(chord(pi(0, 0, 0), fr(1, 8)));
cursor.write(chord(pi(0, 0, 0), fr(1, 2)));
cursor.write(chord(pi(0, 0, 0), fr(1, 2)));
return score;
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class Base13a method getExpectedKeys.
default TraditionalKey[] getExpectedKeys() {
TraditionalKey[] expectedKeys = new TraditionalKey[15 * 2];
for (int fifths = -7; fifths <= 7; fifths++) {
expectedKeys[(fifths + 7) * 2 + 0] = new TraditionalKey(fifths, Mode.Major);
expectedKeys[(fifths + 7) * 2 + 1] = new TraditionalKey(fifths, Mode.Minor);
}
return expectedKeys;
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class MidiVelocityConverterTry method createTestScore.
public static Score createTestScore() {
Score ret = new Score();
Instrument instr = Instrument.defaultInstrument;
Part pianoPart = new Part("Test", "T", 1, ilist(instr));
new PartAdd(ret, pianoPart, 0, null).execute();
Cursor cursor = new Cursor(ret, mp0, true);
cursor.write((ColumnElement) new TraditionalKey(-3));
cursor.write((ColumnElement) new TimeSignature(timeType(3, 4)));
cursor.write(new Clef(ClefType.clefTreble));
Fraction f4 = fr(1, 4);
Chord attachC;
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.G, 4)));
attachC.addDirection(new Dynamic(DynamicValue.pp));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.A, 4)));
attachC.addDirection(new Dynamic(DynamicValue.ff));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.G, 4)));
attachC.addDirection(new Dynamic(DynamicValue.sfp));
/*
Chord chord;
Voice voice = measure.getVoices().get(0);
chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
chord.addDirection(new Dynamic(DynamicsType.pp));
chord = voice.addNote(pi'A', 0, 4), fr(1, 4));
chord.addDirection(new Dynamic(DynamicsType.ff));
chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
chord.addDirection(new Dynamic(DynamicsType.sfp));
*/
cursor.setMp(mp0.withVoice(1));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.C, 4)));
attachC.addDirection(new Dynamic(DynamicValue.fff));
/*
voice = measure.addVoice();
chord = voice.addNote(pi'C', 0, 4), fr(1, 4));
chord.addDirection(new Dynamic(DynamicsType.fff));
*/
cursor.setMp(mp0.withMeasure(1));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.G, 4)));
// cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.A, 4)));
attachC.addDirection(new Dynamic(DynamicValue.pp));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.G, 4)));
attachC.addDirection(new Dynamic(DynamicValue.pp));
cursor.setMp(cursor.getMP().withElement(0).withVoice(1));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.C, 5)));
/*
measure = staff.getMeasures().get(1);
voice = measure.getVoices().get(0);
chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
//chord.addDirection(new Dynamic(DynamicsType.pp));
chord = voice.addNote(pi'A', 0, 4), fr(1, 4));
chord.addDirection(new Dynamic(DynamicsType.pp));
chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
chord.addDirection(new Dynamic(DynamicsType.pp));
voice = measure.addVoice();
chord = voice.addNote(pi'C', 0, 5), fr(1, 4));
*/
cursor.setMp(mp0.withMeasure(2));
cursor.write(attachC = chord(f4, Pitch.pi(Pitch.G, 4)));
attachC.addDirection(new Dynamic(DynamicValue.sfz));
cursor.write(chord(f4, Pitch.pi(Pitch.A, 4)));
// cursor = cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
cursor.write(chord(f4, Pitch.pi(Pitch.G, 4)));
// cursor = cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
cursor.setMp(mp0.withMeasure(2).withVoice(2));
cursor.write(chord(f4, Pitch.pi(Pitch.C, 5)));
/*
measure = staff.getMeasures().get(2);
voice = measure.getVoices().get(0);
chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
chord.addDirection(new Dynamic(DynamicsType.sfz));
chord = voice.addNote(pi'A', 0, 4), fr(1, 4));
//chord.addDirection(new Dynamic(DynamicsType.pp));
chord = voice.addNote(pi'G', 0, 4), fr(1, 4));
//chord.addDirection(new Dynamic(DynamicsType.pp));
voice = measure.addVoice();
voice = measure.addVoice();
chord = voice.addNote(pi'C',0,5), fr(1,2));
*/
return cursor.getScore();
}
use of com.xenoage.zong.core.music.key.TraditionalKey in project Zong by Xenoage.
the class ScoreTest method createTestScoreClefsKeys.
/**
* Creates a score with a single staff, two measures,
* and a number of clefs, keys and chords.
* The score, the list of clefs and the list of keys is returned.
*/
private Tuple3<Score, List<ClefType>, List<Key>> createTestScoreClefsKeys() {
// create two measures:
// clef-g, key-Gmaj, C#1/4, clef-f, Db1/4, clef-g, key-Fmaj, Cnat1/4 |
// C#1/4, key-Cmaj, clef-f, C2/4.
Score score = ScoreFactory.create1Staff();
new MeasureAdd(score, 1).execute();
List<ClefType> clefs = alist();
List<Key> keys = alist();
ClefType c;
Key k;
// measure 0
Measure measure = score.getMeasure(atMeasure(0, 0));
new Clef(ClefType.clefTreble);
clefs.add(c = ClefType.clefTreble);
new MeasureElementWrite(new Clef(c), measure, fr(0, 4)).execute();
keys.add(k = new TraditionalKey(1, Mode.Major));
new MeasureElementWrite(k, measure, fr(0, 4)).execute();
new VoiceElementWrite(measure.getVoice(0), atElement(0, 0, 0, 0), chord(pi(0, 1, 4), fr(1, 4)), null).execute();
clefs.add(c = ClefType.clefBass);
new MeasureElementWrite(new Clef(c), measure, fr(1, 4)).execute();
new VoiceElementWrite(measure.getVoice(0), atElement(0, 0, 0, 1), chord(pi(1, -1, 4), fr(1, 4)), null).execute();
clefs.add(c = ClefType.clefTreble);
new MeasureElementWrite(new Clef(c), measure, fr(2, 4)).execute();
keys.add(k = new TraditionalKey(-1, Mode.Major));
new MeasureElementWrite(k, measure, fr(2, 4)).execute();
new VoiceElementWrite(measure.getVoice(0), atElement(0, 0, 0, 2), chord(pi(0, 0, 4), fr(1, 4)), null).execute();
// measure 1
measure = score.getMeasure(atMeasure(0, 1));
new VoiceElementWrite(measure.getVoice(0), atElement(0, 1, 0, 0), chord(pi(0, 1, 4), fr(1, 4)), null).execute();
keys.add(k = new TraditionalKey(0, Mode.Major));
new MeasureElementWrite(k, measure, fr(1, 4)).execute();
clefs.add(c = ClefType.clefBass);
new MeasureElementWrite(new Clef(c), measure, fr(1, 4)).execute();
new VoiceElementWrite(measure.getVoice(0), atElement(0, 1, 0, 1), chord(pi(0, 0, 4), fr(2, 4)), null).execute();
return t3(score, clefs, keys);
}
Aggregations