Search in sources :

Example 21 with Chord

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

the class VoiceTest method getElementTest.

@Test
public void getElementTest() {
    // our test example: (g: grace note)
    // Beats:       0        1     2           3     4
    // Elements     |g1|-----a-----|g2|g3|--b--|--c--|g4|
    // Checked:     x  x           x  x  x     x     x  x
    Rest n = null, a = new Rest(Companion.fr(2)), b = new Rest(Companion.fr(1)), c = new Rest(Companion.fr(1));
    Chord g1 = grace(1), g2 = grace(2), g3 = grace(3), g4 = grace(4);
    VoiceElement[] elementsPool = { a, b, c, g1, g2, g3, g4 };
    Voice voice = new Voice(ilist(g1, a, g2, g3, b, c, g4));
    // expected solutions
    int sideCount = FirstOrLast.values().length;
    int borderCount = StartOrStop.values().length;
    int inCount = Interval.values().length;
    VoiceElement[][][][] expected = new VoiceElement[sideCount][borderCount][inCount][];
    // first/start
    expected[o(First)][o(Start)][o(Before)] = new VoiceElement[] { n, g1, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Start)][o(BeforeOrAt)] = new VoiceElement[] { g1, g1, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Start)][o(At)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    expected[o(First)][o(Start)][o(AtOrAfter)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    expected[o(First)][o(Start)][o(After)] = new VoiceElement[] { a, g2, g3, b, c, g4, n, n };
    // first/stop
    expected[o(First)][o(Stop)][o(Before)] = new VoiceElement[] { n, n, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Stop)][o(BeforeOrAt)] = new VoiceElement[] { n, g1, g1, g1, g1, g1, g1, g1 };
    expected[o(First)][o(Stop)][o(At)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(First)][o(Stop)][o(AtOrAfter)] = new VoiceElement[] { g1, g1, a, g2, g3, b, c, g4 };
    expected[o(First)][o(Stop)][o(After)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    // last/start
    expected[o(Last)][o(Start)][o(Before)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(Last)][o(Start)][o(BeforeOrAt)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, g4 };
    expected[o(Last)][o(Start)][o(At)] = new VoiceElement[] { g1, a, g2, g3, b, c, g4, n };
    expected[o(Last)][o(Start)][o(AtOrAfter)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, g4, n };
    expected[o(Last)][o(Start)][o(After)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, n, n };
    // last/stop
    expected[o(Last)][o(Stop)][o(Before)] = new VoiceElement[] { n, n, g1, a, g2, g3, b, c };
    expected[o(Last)][o(Stop)][o(BeforeOrAt)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(Last)][o(Stop)][o(At)] = new VoiceElement[] { n, g1, a, g2, g3, b, c, g4 };
    expected[o(Last)][o(Stop)][o(AtOrAfter)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, g4, g4 };
    expected[o(Last)][o(Stop)][o(After)] = new VoiceElement[] { g4, g4, g4, g4, g4, g4, g4, n };
    // test
    for (int iSide = 0; iSide < sideCount; iSide++) {
        for (int iBorder = 0; iBorder < borderCount; iBorder++) {
            for (int iIn = 0; iIn < inCount; iIn++) {
                assertGetElement(voice, elementsPool, FirstOrLast.values()[iSide], StartOrStop.values()[iBorder], Interval.values()[iIn], expected[iSide][iBorder][iIn]);
            }
        }
    }
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 22 with Chord

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

the class VoiceTest method getElementAtTest.

@Test
public void getElementAtTest() {
    // our test example: (g: grace note)
    // Beats:       0        1     2           3     4
    // Elements     |g1|-----a-----|g2|g3|--b--|--c--|g4|
    // Checked:     x  x           x  x  x     x     x  x
    Rest a = new Rest(Companion.fr(2)), b = new Rest(Companion.fr(1)), c = new Rest(Companion.fr(1));
    Chord g1 = grace(1), g2 = grace(2), g3 = grace(3), g4 = grace(4);
    Voice voice = new Voice(ilist(g1, a, g2, g3, b, c, g4));
    // test
    assertEquals(a, voice.getElementAt(Companion.fr(0)));
    assertEquals(null, voice.getElementAt(Companion.fr(1)));
    assertEquals(b, voice.getElementAt(Companion.fr(2)));
    assertEquals(c, voice.getElementAt(Companion.fr(3)));
    assertEquals(g4, voice.getElementAt(Companion.fr(4)));
}
Also used : Rest(com.xenoage.zong.core.music.rest.Rest) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 23 with Chord

use of com.xenoage.zong.core.music.chord.Chord 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)

Example 24 with Chord

use of com.xenoage.zong.core.music.chord.Chord 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 25 with Chord

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

the class NotesNotatorTest method testSingleNoteF4.

/**
 * Tests a F4, 1/2. Stem: right, up. Width: 1x half.
 */
@Test
public void testSingleNoteF4() {
    Chord chord = chord(Companion.pi(3, 0, 4), Companion.fr(1, 2));
    NotesNotation notes = testee.compute(chord, StemDirection.Up, cw, context);
    assertEquals(n, notes.stemOffsetIs, Df);
    assertEquals(n, notes.widthIs, Df);
    NoteDisplacement note = notes.getNote(0);
    assertEquals(1, note.lp);
    assertEquals(0, note.xIs, Df);
    assertEquals(NoteSuspension.None, note.suspension);
}
Also used : NoteDisplacement(com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement) NotesNotation(com.xenoage.zong.musiclayout.notation.chord.NotesNotation) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Aggregations

Chord (com.xenoage.zong.core.music.chord.Chord)63 Test (org.junit.Test)34 MP (com.xenoage.zong.core.position.MP)16 Pitch (com.xenoage.zong.core.music.Pitch)12 Score (com.xenoage.zong.core.Score)11 Voice (com.xenoage.zong.core.music.Voice)10 NotesNotation (com.xenoage.zong.musiclayout.notation.chord.NotesNotation)10 VoiceElement (com.xenoage.zong.core.music.VoiceElement)8 Note (com.xenoage.zong.core.music.chord.Note)6 Rest (com.xenoage.zong.core.music.rest.Rest)6 ChordTest (musicxmltestsuite.tests.utils.ChordTest)6 Fraction (com.xenoage.utils.math.Fraction)5 Staff (com.xenoage.zong.core.music.Staff)4 Beam (com.xenoage.zong.core.music.beam.Beam)4 Grace (com.xenoage.zong.core.music.chord.Grace)4 StemDirection (com.xenoage.zong.core.music.chord.StemDirection)4 Dynamic (com.xenoage.zong.core.music.direction.Dynamic)4 SlurWaypoint (com.xenoage.zong.core.music.slur.SlurWaypoint)4 ChordNotation (com.xenoage.zong.musiclayout.notation.ChordNotation)4 NoteDisplacement (com.xenoage.zong.musiclayout.notation.chord.NoteDisplacement)4