Search in sources :

Example 11 with Pitch

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

the class MidiToolsTest method getPitchFromNoteNumberTest.

@Test
public void getPitchFromNoteNumberTest() {
    for (int i : range(midi)) {
        Pitch p = MidiTools.getPitchFromNoteNumber(midi[i]);
        assertEquals(pitch[i], p);
    }
}
Also used : Pitch(com.xenoage.zong.core.music.Pitch) Test(org.junit.Test)

Example 12 with Pitch

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

the class StrategyTest method getScore.

@Override
public Score getScore() {
    // collect test material
    List<Example> examples = getAllExamples();
    // text style
    FormattedTextStyle style = Companion.getDefaultStyle().withFont(new FontInfo("Arial", 6f, FontStyle.normal));
    // one chord in each measure
    Score score = ScoreFactory.create1Staff();
    Cursor cursor = new Cursor(score, mp0, true);
    cursor.write(new TimeSignature(TimeType.Companion.getTime_3_4()));
    for (int i : range(examples)) {
        Example example = examples.get(i);
        cursor.setMp(atElement(0, i, 0, 0));
        // write key
        int fifths = ((TraditionalKey) example.getContext().getKey()).getFifths();
        cursor.write((ColumnElement) new TraditionalKey(fifths));
        // write example name (each 2nd example one line down for better reading)
        String text = (i % 2 == 1 ? "\n" : "") + example.getName();
        cursor.write((MeasureElement) new Words(styleText(text, style)));
        // write chord with all accidentals from context (or a rest)
        Map<Pitch, Integer> accs = example.getContext().getAccidentals();
        if (accs.size() > 0) {
            Pitch[] pitches = new Pitch[accs.size()];
            int accIndex = 0;
            for (Pitch acc : accs.keySet()) {
                pitches[accIndex] = Companion.pi(acc.getStep(), accs.get(acc), acc.getOctave());
                accIndex++;
            }
            Chord accsChords = ChordFactory.chord(pitches, Companion.get_1$4());
            cursor.write(accsChords);
        } else {
            cursor.write(new Rest(Companion.get_1$4()));
        }
        // write a rest
        cursor.write(new Rest(Companion.get_1$4()));
        // write the tested chord
        Chord testedChord = ChordFactory.chord(example.getPitches().toArray(new Pitch[0]), Companion.get_1$4());
        cursor.write(testedChord);
    }
    return score;
}
Also used : FormattedTextStyle(com.xenoage.zong.core.text.FormattedTextStyle) TraditionalKey(com.xenoage.zong.core.music.key.TraditionalKey) Cursor(com.xenoage.zong.io.selection.Cursor) TimeSignature(com.xenoage.zong.core.music.time.TimeSignature) Score(com.xenoage.zong.core.Score) Rest(com.xenoage.zong.core.music.rest.Rest) Example(material.accidentals.Example) Words(com.xenoage.zong.core.music.direction.Words) Pitch(com.xenoage.zong.core.music.Pitch) FontInfo(com.xenoage.utils.font.FontInfo) Chord(com.xenoage.zong.core.music.chord.Chord)

Example 13 with Pitch

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

the class Test01a method test.

@ToDo("the editiorial sharp (sharp in parenthesis) in the last measure is not supported yet")
@Test
public void test() {
    Pitch[] expectedPitches = getExpectedPitches();
    Staff staff = getFirstStaff();
    assertEquals(26, staff.getMeasures().size());
    int iPitch = 0;
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Measure measure = staff.getMeasures().get(iM);
        Voice voice = measure.getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Chord) {
                // check note and pitch
                Chord chord = (Chord) e;
                assertEquals(expectedPitches[iPitch++], chord.getNotes().get(0).getPitch());
            }
        }
    }
    assertEquals("not all notes found", expectedPitches.length, iPitch);
}
Also used : VoiceElement(com.xenoage.zong.core.music.VoiceElement) Staff(com.xenoage.zong.core.music.Staff) Pitch(com.xenoage.zong.core.music.Pitch) Measure(com.xenoage.zong.core.music.Measure) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) ToDo(musicxmltestsuite.tests.utils.ToDo) Test(org.junit.Test)

Example 14 with Pitch

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

the class Test01b method test.

@Test
public void test() {
    Pitch[] expectedPitches = getExpectedPitches();
    int iPitch = 0;
    Staff staff = getFirstStaff();
    for (int iM = 0; iM < staff.getMeasures().size(); iM++) {
        Measure measure = staff.getMeasures().get(iM);
        Voice voice = measure.getVoice(0);
        for (VoiceElement e : voice.getElements()) {
            if (e instanceof Chord) {
                // check note and pitch
                Chord chord = (Chord) e;
                assertEquals(expectedPitches[iPitch++], chord.getNotes().get(0).getPitch());
            }
        }
    }
// TODO - ignore this test, since MusicXML input file has a bug (only a single measure),
// so currently only the first measure is tested
// assertEquals("not all notes found", expectedPitches.length, iPitch);
}
Also used : VoiceElement(com.xenoage.zong.core.music.VoiceElement) Staff(com.xenoage.zong.core.music.Staff) Pitch(com.xenoage.zong.core.music.Pitch) Measure(com.xenoage.zong.core.music.Measure) Voice(com.xenoage.zong.core.music.Voice) Chord(com.xenoage.zong.core.music.chord.Chord) Test(org.junit.Test)

Example 15 with Pitch

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

the class Test01b method test.

@Test
public void test() {
    Pitch[] expectedPitches = getExpectedPitches();
    MxlPart part = getFirstPart();
    int iPitch = 0;
    for (int iM = 0; iM < part.getMeasures().size(); iM++) {
        MxlMeasure measure = part.getMeasures().get(iM);
        for (MxlMusicDataContent data : measure.getMusicData().getContent()) {
            if (data.getMusicDataContentType() == MxlMusicDataContentType.Note) {
                // check note and pitch
                MxlFullNote note = ((MxlNote) data).getContent().getFullNote();
                MxlPitch pitch = (MxlPitch) (note.getContent());
                assertEquals("note " + iPitch, expectedPitches[iPitch++], pitch.getPitch());
            }
        }
    }
    assertEquals("not all notes found", expectedPitches.length, iPitch);
}
Also used : MxlMusicDataContent(com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent) MxlFullNote(com.xenoage.zong.musicxml.types.groups.MxlFullNote) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) MxlPitch(com.xenoage.zong.musicxml.types.MxlPitch) Pitch(com.xenoage.zong.core.music.Pitch) MxlPart(com.xenoage.zong.musicxml.types.partwise.MxlPart) MxlMeasure(com.xenoage.zong.musicxml.types.partwise.MxlMeasure) Test(org.junit.Test)

Aggregations

Pitch (com.xenoage.zong.core.music.Pitch)24 Chord (com.xenoage.zong.core.music.chord.Chord)12 Test (org.junit.Test)11 MP (com.xenoage.zong.core.position.MP)4 MxlPitch (com.xenoage.zong.musicxml.types.MxlPitch)4 MxlFullNote (com.xenoage.zong.musicxml.types.groups.MxlFullNote)4 Staff (com.xenoage.zong.core.music.Staff)3 Note (com.xenoage.zong.core.music.chord.Note)3 Rest (com.xenoage.zong.core.music.rest.Rest)3 Score (com.xenoage.zong.core.Score)2 Measure (com.xenoage.zong.core.music.Measure)2 Voice (com.xenoage.zong.core.music.Voice)2 VoiceElement (com.xenoage.zong.core.music.VoiceElement)2 Grace (com.xenoage.zong.core.music.chord.Grace)2 TimeSignature (com.xenoage.zong.core.music.time.TimeSignature)2 Cursor (com.xenoage.zong.io.selection.Cursor)2 MxlNote (com.xenoage.zong.musicxml.types.MxlNote)2 MxlCueNote (com.xenoage.zong.musicxml.types.choice.MxlCueNote)2 MxlGraceNote (com.xenoage.zong.musicxml.types.choice.MxlGraceNote)2 MxlMusicDataContent (com.xenoage.zong.musicxml.types.choice.MxlMusicDataContent)2