//======================================================================================= // PitchAssigner implementation //======================================================================================= void PitchAssigner::assign_pitch(ImoScore* pScore) { StaffObjsCursor cursor(pScore); ImoKeySignature* pKey = NULL; reset_accidentals(pKey); while(!cursor.is_end()) { ImoStaffObj* pSO = cursor.get_staffobj(); if (pSO->is_note()) { ImoNote* pNote = static_cast<ImoNote*>(pSO); compute_pitch(pNote); } else if (pSO->is_barline()) { reset_accidentals(pKey); } else if (pSO->is_key_signature()) { pKey = static_cast<ImoKeySignature*>( pSO ); reset_accidentals(pKey); } cursor.move_next(); } }
//--------------------------------------------------------------------------------------- void AutoClef::find_staves_needing_clef() { //An staff needs clef if it has pitched notes before finding a clef. //This method saves data for each staff in vectors m_fNeedsClef, m_pAt, //m_maxPitch, m_minPitch int staves = m_pCursor->get_num_staves(); int stavesWithNotes = 0; m_fNeedsClef.assign(staves, false); m_pAt.assign(staves, (ImoStaffObj*)nullptr); m_maxPitch.assign(staves, k_undefined_fpitch); m_minPitch.assign(staves, k_undefined_fpitch); m_numNotes.assign(staves, 0); vector<bool> fHasNotes; //true if staff i has pitched notes fHasNotes.assign(staves, false); while(!m_pCursor->is_end()) { ImoStaffObj* pSO = m_pCursor->get_staffobj(); int iStaff = m_pCursor->staff_index(); if (m_pAt[iStaff] == nullptr) m_pAt[iStaff] = pSO; if (pSO->is_note()) { ImoNote* pN = static_cast<ImoNote*>(pSO); if (!m_fNeedsClef[iStaff] && !fHasNotes[iStaff]) { if (pN->is_pitch_defined()) { int clefType = m_pCursor->get_applicable_clef_type(); if (clefType == k_clef_undefined) m_fNeedsClef[iStaff] = true; fHasNotes[iStaff] = true; } } if (m_fNeedsClef[iStaff]) { if (pN->is_pitch_defined()) { FPitch fp = pN->get_fpitch(); if (m_maxPitch[iStaff] == k_undefined_fpitch || m_maxPitch[iStaff] < fp) m_maxPitch[iStaff] = fp; if (m_minPitch[iStaff] == k_undefined_fpitch || m_minPitch[iStaff] > fp) m_minPitch[iStaff] = fp; ++m_numNotes[iStaff]; if (m_numNotes[iStaff] == 10) ++stavesWithNotes; if (stavesWithNotes == staves) break; } } } m_pCursor->move_next(); } }