Search in sources :

Example 31 with Score

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));
}
Also used : Score(com.xenoage.zong.core.Score) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Test(org.junit.Test)

Example 32 with Score

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;
}
Also used : Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Cursor(com.xenoage.zong.io.selection.Cursor)

Example 33 with 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();
}
Also used : Score(com.xenoage.zong.core.Score) MidiScorePlayer(com.xenoage.zong.desktop.io.midi.out.MidiScorePlayer)

Example 34 with Score

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();
}
Also used : Score(com.xenoage.zong.core.Score) Dynamic(com.xenoage.zong.core.music.direction.Dynamic) Part(com.xenoage.zong.core.music.Part) Instrument(com.xenoage.zong.core.instrument.Instrument) PartAdd(com.xenoage.zong.commands.core.music.PartAdd) Clef(com.xenoage.zong.core.music.clef.Clef) Fraction(com.xenoage.utils.math.Fraction) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) Chord(com.xenoage.zong.core.music.chord.Chord) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature)

Example 35 with Score

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
		*/
}
Also used : MidiUnavailableException(javax.sound.midi.MidiUnavailableException) Score(com.xenoage.zong.core.Score) MidiScorePlayer(com.xenoage.zong.desktop.io.midi.out.MidiScorePlayer)

Aggregations

Score (com.xenoage.zong.core.Score)99 Test (org.junit.Test)62 Rest (com.xenoage.zong.core.music.rest.Rest)22 MP (com.xenoage.zong.core.position.MP)19 Voice (com.xenoage.zong.core.music.Voice)15 Cursor (com.xenoage.zong.io.selection.Cursor)15 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)14 Chord (com.xenoage.zong.core.music.chord.Chord)11 StavesList (com.xenoage.zong.core.music.StavesList)9 MusicXmlScoreFileInputTest (com.xenoage.zong.io.musicxml.in.MusicXmlScoreFileInputTest)9 Part (com.xenoage.zong.core.music.Part)8 ColumnHeader (com.xenoage.zong.core.header.ColumnHeader)7 lombok.val (lombok.val)7 TraditionalKey (com.xenoage.zong.core.music.key.TraditionalKey)6 Direction (com.xenoage.zong.core.music.direction.Direction)5 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)5 Size2f (com.xenoage.utils.math.geom.Size2f)4 PartAdd (com.xenoage.zong.commands.core.music.PartAdd)4 ScoreFormat (com.xenoage.zong.core.format.ScoreFormat)4 ScoreHeader (com.xenoage.zong.core.header.ScoreHeader)4