TEST_FIXTURE(MxlCompilerTestFixture, MxlCompilerFromFile_100) { //100 - compile raw xml file format Document doc(m_libraryScope); MxlCompiler compiler(m_libraryScope, &doc); string path = m_scores_path + "50000-hello-world.xml"; ImoObj* pRoot = compiler.compile_file(path); CHECK( compiler.get_file_locator() == path ); ImoDocument* pDoc = dynamic_cast<ImoDocument*>(pRoot); CHECK( pDoc && pDoc->get_version() == "0.0" ); CHECK( pDoc && pDoc->get_num_content_items() == 1 ); ImoScore* pScore = dynamic_cast<ImoScore*>( pDoc->get_content_item(0) ); CHECK( pScore != nullptr ); CHECK( pScore && pScore->get_num_instruments() == 1 ); CHECK( pScore && pScore->get_staffobjs_table() != nullptr ); ImoInstrument* pInstr = pScore->get_instrument(0); CHECK( pInstr != nullptr ); CHECK( pInstr && pInstr->get_num_staves() == 1 ); ImoMusicData* pMD = pInstr->get_musicdata(); CHECK( pMD != nullptr ); CHECK( pMD && pMD->get_num_items() == 5 ); ImoObj* pImo = pMD->get_first_child(); CHECK( pImo && pImo->is_clef() == true ); // cout << "Test: MxlCompilerFromFile_100" << endl; // cout << doc.to_string() << endl; if (pRoot && !pRoot->is_document()) delete pRoot; }
//--------------------------------------------------------------------------------------- void SystemLayouter::add_initial_line_joining_all_staves_in_system() { //do not draw if 'hide staff lines' option enabled ImoOptionInfo* pOpt = m_pScore->get_option("StaffLines.Hide"); bool fDrawStafflines = (pOpt == NULL || pOpt->get_bool_value() == false); if (!fDrawStafflines) return; //do not draw if empty score with one instrument with one staff if (m_pScore->get_num_instruments() == 1) { ImoInstrument* pInstr = m_pScore->get_instrument(0); if (pInstr->get_num_staves() == 1 && m_pScoreMeter->is_empty_score()) return; } //do not draw if so asked when score meter was created (//TODO: what is this for?) if (m_pScoreMeter->must_draw_left_barline()) { InstrumentEngraver* pInstrEngrv = m_pPartsEngraver->get_engraver_for(0); ImoObj* pCreator = m_pScore->get_instrument(0); LUnits xPos = pInstrEngrv->get_staves_left(); LUnits yTop = pInstrEngrv->get_staves_top_line(); int iInstr = m_pScoreMeter->num_instruments() - 1; pInstrEngrv = m_pPartsEngraver->get_engraver_for(iInstr); LUnits yBottom = pInstrEngrv->get_staves_bottom_line(); BarlineEngraver engrv(m_libraryScope, m_pScoreMeter); Color color = Color(0,0,0); //TODO staff lines color? GmoShape* pLine = engrv.create_system_barline_shape(pCreator, xPos, yTop, yBottom, color); m_pBoxSystem->add_shape(pLine, GmoShape::k_layer_staff); } }
//--------------------------------------------------------------------------------------- void SystemLayouter::add_instruments_info() { int maxInstr = m_pScore->get_num_instruments() - 1; for (int i = 0; i <= maxInstr; i++) { ImoInstrument* pInstr = m_pScore->get_instrument(i); m_pBoxSystem->add_num_staves_for_instrument(pInstr->get_num_staves()); } }
//--------------------------------------------------------------------------------------- void ScoreMeter::get_staff_spacing(ImoScore* pScore) { int instruments = pScore->get_num_instruments(); m_staffIndex.reserve(instruments); int staves = 0; for (int iInstr=0; iInstr < instruments; ++iInstr) { m_staffIndex[iInstr] = staves; ImoInstrument* pInstr = pScore->get_instrument(iInstr); int numStaves = pInstr->get_num_staves(); staves += numStaves; for (int iStaff=0; iStaff < numStaves; ++iStaff) m_lineSpace.push_back( pInstr->get_line_spacing_for_staff(iStaff) ); } m_numStaves = staves; }
//--------------------------------------------------------------------------------------- LUnits SystemLayouter::engrave_prolog(int iInstr) { LUnits uPrologWidth = 0.0f; //AWARE when this method is invoked the paper position is at the left marging, //at the start of the new system. LUnits xStartPos = m_pagePos.x; //Save x to align all clefs //iterate over the collection of staff objects to draw current clef and key signature ImoInstrument* pInstr = m_pScore->get_instrument(iInstr); GmoBoxSystem* pBox = get_box_system(); int numStaves = pInstr->get_num_staves(); InstrumentEngraver* pInstrEngrv = m_pPartsEngraver->get_engraver_for(iInstr); for (int iStaff=0; iStaff < numStaves; ++iStaff) { LUnits xPos = xStartPos; m_pagePos.y = pInstrEngrv->get_top_line_of_staff(iStaff); int iStaffIndex = m_pScoreMeter->staff_index(iInstr, iStaff); ColStaffObjsEntry* pClefEntry = m_pSpAlgorithm->get_prolog_clef(m_iFirstCol, iStaffIndex); ColStaffObjsEntry* pKeyEntry = m_pSpAlgorithm->get_prolog_key(m_iFirstCol, iStaffIndex); ImoClef* pClef = pClefEntry ? static_cast<ImoClef*>(pClefEntry->imo_object()) : NULL; int clefType = pClef ? pClef->get_clef_type() : k_clef_undefined; //add clef shape if (pClefEntry) { if (pClef && pClef->is_visible()) { xPos += m_pScoreMeter->tenths_to_logical(LOMSE_SPACE_BEFORE_PROLOG, iInstr, iStaff); m_pagePos.x = xPos; GmoShape* pShape = m_pShapesCreator->create_staffobj_shape(pClef, iInstr, iStaff, m_pagePos, clefType); pShape->assign_id_as_prolog_shape(m_iSystem, iStaff, numStaves); pBox->add_shape(pShape, GmoShape::k_layer_notes); xPos += pShape->get_width(); } } //add key signature shape if (pKeyEntry) { ImoKeySignature* pKey = dynamic_cast<ImoKeySignature*>( pKeyEntry->imo_object() ); if (pKey && pKey->is_visible()) { xPos += m_pScoreMeter->tenths_to_logical(LOMSE_PROLOG_GAP_BEORE_KEY, iInstr, iStaff); m_pagePos.x = xPos; GmoShape* pShape = m_pShapesCreator->create_staffobj_shape(pKey, iInstr, iStaff, m_pagePos, clefType); pShape->assign_id_as_prolog_shape(m_iSystem, iStaff, numStaves); pBox->add_shape(pShape, GmoShape::k_layer_notes); xPos += pShape->get_width(); } } xPos += m_pScoreMeter->tenths_to_logical(LOMSE_SPACE_AFTER_PROLOG, iInstr, iStaff); uPrologWidth = max(uPrologWidth, xPos - xStartPos); } m_pagePos.x = xStartPos; //restore cursor set_prolog_width(uPrologWidth); return uPrologWidth; }