use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class ScoreHeaderTest method getTimeAtOrBeforeTest.
@Test
public void getTimeAtOrBeforeTest() {
// create a little test score, where there is no time signature
// in the first measure, but a 3/4 time in the second one
// and a 4/4 in the fourth one
Score score = ScoreFactory.create1Staff4Measures();
ScoreHeader header = score.getHeader();
TimeSignature time1 = new TimeSignature(TimeType.Companion.getTime_3_4());
header.getColumnHeader(1).setTime(time1);
TimeSignature time2 = new TimeSignature(TimeType.Companion.getTime_4_4());
header.getColumnHeader(3).setTime(time2);
// test method
assertEquals(TimeSignature.Companion.getImplicitSenzaMisura(), header.getTimeAtOrBefore(0));
assertEquals(time1, header.getTimeAtOrBefore(1));
assertEquals(time1, header.getTimeAtOrBefore(2));
assertEquals(time2, header.getTimeAtOrBefore(3));
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class VoiceElementIteratorTest method createTestScore.
/**
* Test score with 4 staves and 4 measures. In staves 1 and 3, the measures 1 and 3 have each
* two voices with 4 quarter rests. The other measures have a single voice and
* a full rest.
*/
public static Score createTestScore() {
Score score = new Score();
Cursor cursor = new Cursor(score, MP.mp0, true);
for (int staff : range(4)) {
for (int measure : range(4)) {
if ((staff == 1 || staff == 3) && (measure == 1 || measure == 3)) {
// 2 voices with each 4 quarter notes
for (int voice : range(2)) {
cursor.setMp(atElement(staff, measure, voice, 0));
for (int i = 0; i < 4; i++) cursor.write(new Rest(Companion.fr(1, 4)));
}
} else {
// full rest
cursor.setMp(atElement(staff, measure, 0, 0));
cursor.write(new Rest(Companion.fr(1)));
}
}
}
return score;
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class MidiScorePlayerTry method main.
public static void main(String... args) throws MidiUnavailableException {
int timeFactor = 1000;
Score score = ScoreRevolutionary.createScore();
SynthManager.init(false);
MidiScorePlayer.init();
MidiScorePlayer player = midiScorePlayer();
player.addPlaybackListener(new MidiScorePlayerTry());
player.openScore(score);
System.out.println("Play");
player.start();
try {
Thread.sleep(2 * timeFactor);
} catch (InterruptedException ex) {
}
player.pause();
System.out.println("Pause");
try {
Thread.sleep(2 * timeFactor);
} catch (InterruptedException ex) {
}
System.out.println("Play");
player.start();
try {
Thread.sleep(3 * timeFactor);
} catch (InterruptedException ex) {
}
player.stop();
System.out.println("Stop");
try {
Thread.sleep(2 * timeFactor);
} catch (InterruptedException ex) {
}
player.start();
try {
Thread.sleep(3 * timeFactor);
} catch (InterruptedException ex) {
}
player.stop();
SynthManager.close();
}
use of com.xenoage.zong.core.Score in project Zong by Xenoage.
the class MidiVelocityConverterTry method createTestScore.
public static Score createTestScore() {
Score ret = new Score();
Instrument instr = Instrument.Companion.getDefaultInstrument();
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(Companion.timeType(3, 4)));
cursor.write(new Clef(ClefType.Companion.getClefTreble()));
Fraction f4 = Companion.fr(1, 4);
Chord attachC;
cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
attachC.addDirection(new Dynamic(DynamicValue.pp));
cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getA(), 4)));
attachC.addDirection(new Dynamic(DynamicValue.ff));
cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 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.Companion.pi(Pitch.Companion.getC(), 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.Companion.pi(Pitch.Companion.getG(), 4)));
// cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getA(), 4)));
attachC.addDirection(new Dynamic(DynamicValue.pp));
cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 4)));
attachC.addDirection(new Dynamic(DynamicValue.pp));
cursor.setMp(cursor.getMP().withElement(0).withVoice(1));
cursor.write(attachC = chord(f4, Pitch.Companion.pi(Pitch.Companion.getC(), 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.Companion.pi(Pitch.Companion.getG(), 4)));
attachC.addDirection(new Dynamic(DynamicValue.sfz));
cursor.write(chord(f4, Pitch.Companion.pi(Pitch.Companion.getA(), 4)));
// cursor = cursor.withScore(ScoreController.attachElement(cursor.getScore(), attachC, new Dynamic(DynamicsType.pp)));
cursor.write(chord(f4, Pitch.Companion.pi(Pitch.Companion.getG(), 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.Companion.pi(Pitch.Companion.getC(), 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.Score in project Zong by Xenoage.
the class MidiVelocityConverterTry method midiConverterTest.
public void midiConverterTest() {
Score score = createTestScore();
try {
SynthManager.init(false);
MidiScorePlayer.init();
MidiScorePlayer pl = midiScorePlayer();
pl.addPlaybackListener(new MidiScorePlayerTry());
pl.openScore(score);
pl.start();
try {
Thread.sleep(8000);
} catch (InterruptedException ex) {
}
SynthManager.close();
} catch (MidiUnavailableException e) {
}
/*
byte[] message = sequence.getTracks()[0].get(0).getMessage().getMessage();
//Assert.assertEquals(58, message[2]);
message = sequence.getTracks()[0].get(1).getMessage().getMessage();
Assert.assertEquals(116, message[2]);
//Message 2 is note-off event
message = sequence.getTracks()[0].get(3).getMessage().getMessage();
Assert.assertEquals(110, message[2]);
//Message 4 and 5 are note-off events
message = sequence.getTracks()[0].get(6).getMessage().getMessage();
Assert.assertEquals(110, message[2]);
//Message 7 is note-off event
message = sequence.getTracks()[0].get(8).getMessage().getMessage();
Assert.assertEquals(110, message[2]);
message = sequence.getTracks()[0].get(9).getMessage().getMessage();
Assert.assertEquals(116, message[2]);
//Message 10 is note-off event
message = sequence.getTracks()[0].get(11).getMessage().getMessage();
Assert.assertEquals(58, message[2]);
//Message 12 and 13 are note-off events
message = sequence.getTracks()[0].get(14).getMessage().getMessage();
Assert.assertEquals(58, message[2]);
//Message15 is note-off event
message = sequence.getTracks()[0].get(16).getMessage().getMessage();
Assert.assertEquals(102, message[2]);
message = sequence.getTracks()[0].get(17).getMessage().getMessage();
Assert.assertEquals(58, message[2]);
//Message 18 is note-off event
message = sequence.getTracks()[0].get(19).getMessage().getMessage();
Assert.assertEquals(58, message[2]);
//Message 20 is note-off event
message = sequence.getTracks()[0].get(21).getMessage().getMessage();
Assert.assertEquals(58, message[2]);
//Message 22, 23 and 24 are note-off events
*/
}
Aggregations