Example #1
0
//---------------------------------------------------------------------------------------
void SelectionSet::get_start_end_note_rests(ImoNoteRest** ppStart,
                                            ImoNoteRest** ppEnd)
{
    ensure_set_is_valid();

    ImoNoteRest* pStart = NULL;
    ImoNoteRest* pEnd = NULL;

    ColStaffObjs* pCollection = get_staffobjs_collection();
    if (pCollection != NULL)
    {
        ColStaffObjsIterator it;
        for (it = pCollection->begin(); it != pCollection->end(); ++it)
        {
            ImoObj* pImo = (*it)->imo_object();
            if (pImo->is_note_rest())
            {
                if (!pStart)
                    pStart = static_cast<ImoNoteRest*>(pImo);
                else
                    pEnd = static_cast<ImoNoteRest*>(pImo);
            }
        }
    }

    if (ppStart)
        *ppStart = pStart;
    if (ppEnd)
        *ppEnd = pEnd;
}
Example #2
0
//---------------------------------------------------------------------------------------
bool SelectionValidator::is_valid_to_add_tuplet(SelectionSet* pSelection)
{
    //Checks if current selection is valid for adding a tuplet.
    //Conditions to be valid:
    //   1. All notes/rest in the seleccion are not in a tuplet, are consecutive, and are
    //      in the same voice.

    bool fValid = true;
    ImoNoteRest* pStart = NULL;
    int nNumNotes = 0;
    int nVoice;

    ColStaffObjs* pCollection = pSelection->get_staffobjs_collection();
    if (pCollection == NULL)
        return false;

    ColStaffObjsIterator it;
    for (it = pCollection->begin(); fValid && it != pCollection->end(); ++it)
    {
        ImoObj* pImo = (*it)->imo_object();
        if (pImo->is_note_rest())
        {
            nNumNotes++;
            ImoNoteRest* pNote = static_cast<ImoNoteRest*>(pImo);
            if (pNote->is_in_tuplet())
                return false;

            if (!pStart)
            {
                //This is the first note/rest
                pStart = pNote;
                nVoice = pStart->get_voice();
            }
            else
            {
                fValid &= nVoice == pNote->get_voice();
            }
        }
    }

    //check that more than one note
    fValid &= (nNumNotes > 1);

    return fValid;
}
Example #3
0
//---------------------------------------------------------------------------------------
list<ImoId> SelectionSet::filter_notes_rests()
{
    //note/rests are returned in order

    ensure_set_is_valid();

    list<ImoId> notes;
    ColStaffObjs* pCollection = get_staffobjs_collection();
    if (pCollection != NULL)
    {
        ColStaffObjsIterator it;
        for (it = pCollection->begin(); it != pCollection->end(); ++it)
        {
            ImoObj* pImo = (*it)->imo_object();
            if (pImo->is_note_rest())
                notes.push_back(pImo->get_id());
        }
    }
    return notes;
}
Example #4
0
//---------------------------------------------------------------------------------------
bool SelectionValidator::is_valid_for_join_beam(SelectionSet* pSelection)
{
    //Returns TRUE if current selection is valid either:
    // - to create a beamed group with the selected notes,
    // - to join two or more beamed groups
    // - or to add a note to a beamed group

    //Conditions to be valid:
    //   1. All notes/rest in the seleccion are consecutive, are in the same
    //      voice (unless in chord), and must be eighths or shorter ones.
    //   2. If not beamed, first note/rest must be a note
    //   3. If not beamed, last note/rest must be a note
    //   4. If beamed, all selected note/rest must not be in the same beam

    bool fValid = true;
    ImoNoteRest* pStart = NULL;

    int nNumNotes = 0;
    int nVoice;
    ImoNoteRest* pLast = NULL;
    bool fAllBeamed = true;     //assume that all are beamed in the same beam
    ImoBeam* pCurBeam = NULL;

    ColStaffObjs* pCollection = pSelection->get_staffobjs_collection();
    if (pCollection == NULL)
        return false;

    ColStaffObjsIterator it;
    for (it = pCollection->begin(); fValid && it != pCollection->end(); ++it)
    {
        ImoObj* pImo = (*it)->imo_object();
        if (pImo->is_note_rest())
        {
            nNumNotes++;
            if (!pStart)
            {
                //This is the first note/rest. If not beamed, it must be a note
                //shorter than quarter
                pStart = static_cast<ImoNoteRest*>(pImo);
                nVoice = pStart->get_voice();
                if (!pStart->is_beamed())
                {
                    fValid &= pStart->is_note();
                    fValid &= static_cast<ImoNote*>(pStart)->get_note_type() >= k_eighth;
                    fAllBeamed = false;
                }
                else
                    pCurBeam = pStart->get_beam();
            }
            else
            {
                // verify voice, and that it is an eighth or shorter
                pLast = static_cast<ImoNoteRest*>(pImo);
                fValid &= pLast->get_note_type() >= k_eighth;
                fValid &= nVoice == pLast->get_voice() ||
                          (pLast->is_note() && static_cast<ImoNote*>(pLast)->is_in_chord());

                //verify that if beamed, all selected note/rest must not be in the same beam
                fAllBeamed &= pLast->is_beamed();
                if (fValid && fAllBeamed)
                    fAllBeamed &= (pCurBeam == pLast->get_beam());
            }
        }
    }

    //verify last note/rest. If not beamed, it must be a note
    if (pLast && !pLast->is_beamed())
        fValid &= pLast->is_note();

    return fValid && !fAllBeamed && nNumNotes > 1;
}