Пример #1
0
Alignment* MeasureAligner::GetAlignmentAtTime( double time, AlignmentType type )
{
    int i;
    int idx = -1; // the index if we reach the end.
    Alignment *alignment = NULL;
    // First try to see if we already have something at the time position
    for (i = 0; i < GetAlignmentCount(); i++)
    {
        alignment = dynamic_cast<Alignment*>(m_children[i]);
        assert( alignment );
        
        double alignment_time = alignment->GetTime();
        if ( vrv::AreEqual( alignment_time, time ) ) {
            // we found a default alignment, but we are inserting a grace note (another layer)
            // we need the grace note to be inserted before so we stop here
            // this does not work when we have grace notes simultanously at different voices because
            // they will all have their own alignment. We need something more sophisticated that takes
            // care of the staff/layer number (or using the layer uuid?)
            if ( (alignment->GetType() == ALIGNMENT_DEFAULT) && (type == ALIGNMENT_GRACENOTE) ) {
                idx = i;
                break;
            }
            else if ( (alignment->GetType() == type) && (type != ALIGNMENT_GRACENOTE) ) {
                return alignment;
            }
            else if ( alignment->GetType() > type ) {
                idx = i;
                break;
            }
        }
        // nothing found, do not go any further but keep the index
        if (alignment->GetTime() > time) {
            idx = i;
            break;
        }
    }
    // nothing found
    if ( idx == -1 ) {
        // this is tricky! Because we want m_rightAlignment to always stay at the end,
        // we always to insert _before_ the last one - m_rightAlignment is added in Reset()
        idx = GetAlignmentCount() - 1;
    }
    Alignment *newAlignement = new Alignment( time, type );
    AddAlignment( newAlignement, idx );
    return newAlignement;
}
Пример #2
0
Alignment *MeasureAligner::GetAlignmentAtTime(double time, AlignmentType type)
{
    time = round(time * (pow(10, 10)) / pow(10, 10));
    int i;
    int idx = -1; // the index if we reach the end.
    Alignment *alignment = NULL;
    // First try to see if we already have something at the time position
    for (i = 0; i < GetAlignmentCount(); i++) {
        alignment = dynamic_cast<Alignment *>(m_children.at(i));
        assert(alignment);

        double alignment_time = alignment->GetTime();
        if (vrv::AreEqual(alignment_time, time)) {
            if (alignment->GetType() == type) {
                return alignment;
            }
            else if (alignment->GetType() > type) {
                idx = i;
                break;
            }
        }
        // nothing found, do not go any further but keep the index
        if (alignment->GetTime() > time) {
            idx = i;
            break;
        }
    }
    // nothing found
    if (idx == -1) {
        if ((type != ALIGNMENT_MEASURE_END) && (this->Is() != GRACE_ALIGNER)) {
            // This typically occurs when a tstamp event occurs after the last note of a measure
            int rightBarlineIdx = m_rightBarLineAlignment->GetIdx();
            assert(rightBarlineIdx != -1);
            idx = rightBarlineIdx - 1;
            this->SetMaxTime(time);
        }
        else {
            idx = GetAlignmentCount();
        }
    }
    Alignment *newAlignment = new Alignment(time, type);
    AddAlignment(newAlignment, idx);
    return newAlignment;
}