Example #1
0
void Page::AdjustSylSpacingByVerse(PrepareProcessingListsParams &listsParams, Doc *doc)
{
    IntTree_t::iterator staves;
    IntTree_t::iterator layers;
    IntTree_t::iterator verses;

    if (listsParams.m_verseTree.child.empty()) return;

    std::vector<AttComparison *> filters;

    // Same for the lyrics, but Verse by Verse since Syl are TimeSpanningInterface elements for handling connectors
    for (staves = listsParams.m_verseTree.child.begin(); staves != listsParams.m_verseTree.child.end(); ++staves) {
        for (layers = staves->second.child.begin(); layers != staves->second.child.end(); ++layers) {
            for (verses = layers->second.child.begin(); verses != layers->second.child.end(); ++verses) {
                // Create ad comparison object for each type / @n
                AttCommonNComparison matchStaff(STAFF, staves->first);
                AttCommonNComparison matchLayer(LAYER, layers->first);
                AttCommonNComparison matchVerse(VERSE, verses->first);
                filters = { &matchStaff, &matchLayer, &matchVerse };

                // The first pass sets m_drawingFirstNote and m_drawingLastNote for each syl
                // m_drawingLastNote is set only if the syl has a forward connector
                AdjustSylSpacingParams adjustSylSpacingParams(doc);
                Functor adjustSylSpacing(&Object::AdjustSylSpacing);
                Functor adjustSylSpacingEnd(&Object::AdjustSylSpacingEnd);
                this->Process(&adjustSylSpacing, &adjustSylSpacingParams, &adjustSylSpacingEnd, &filters);
            }
        }
    }
}
Example #2
0
int Measure::AdjustXPos(FunctorParams *functorParams)
{
    AdjustXPosParams *params = dynamic_cast<AdjustXPosParams *>(functorParams);
    assert(params);

    params->m_minPos = 0;
    params->m_upcomingMinPos = VRV_UNSET;
    params->m_cumulatedXShift = 0;

    std::vector<int>::iterator iter;
    ArrayOfComparisons filters;
    for (iter = params->m_staffNs.begin(); iter != params->m_staffNs.end(); ++iter) {
        params->m_minPos = 0;
        params->m_upcomingMinPos = VRV_UNSET;
        params->m_cumulatedXShift = 0;
        params->m_staffN = (*iter);
        filters.clear();
        // Create ad comparison object for each type / @n
        std::vector<int> ns;
        // -1 for barline attributes that need to be taken into account each time
        ns.push_back(-1);
        ns.push_back(*iter);
        AttNIntegerComparisonAny matchStaff(ALIGNMENT_REFERENCE, ns);
        filters.push_back(&matchStaff);

        m_measureAligner.Process(params->m_functor, params, params->m_functorEnd, &filters);
    }

    // m_measureAligner.Process(params->m_functor, params, params->m_functorEnd);

    int minMeasureWidth
        = params->m_doc->GetOptions()->m_unit.GetValue() * params->m_doc->GetOptions()->m_measureMinWidth.GetValue();
    // First try to see if we have a double measure length element
    MeasureAlignerTypeComparison alignmentComparison(ALIGNMENT_FULLMEASURE2);
    Alignment *fullMeasure2
        = dynamic_cast<Alignment *>(m_measureAligner.FindChildByComparison(&alignmentComparison, 1));

    // With a double measure with element (mRpt2, multiRpt)
    if (fullMeasure2 != NULL) {
        minMeasureWidth *= 2;
    }
    // Nothing if the measure has at least one note or @metcon="false"
    else if ((this->FindChildByType(NOTE) != NULL) || (this->GetMetcon() == BOOLEAN_false)) {
        minMeasureWidth = 0;
    }

    int currentMeasureWidth = this->GetRightBarLineLeft() - this->GetLeftBarLineRight();
    if (currentMeasureWidth < minMeasureWidth) {
        ArrayOfAdjustmentTuples boundaries{ std::make_tuple(this->GetLeftBarLine()->GetAlignment(),
            this->GetRightBarLine()->GetAlignment(), minMeasureWidth - currentMeasureWidth) };
        m_measureAligner.AdjustProportionally(boundaries);
    }

    return FUNCTOR_SIBLINGS;
}
Example #3
0
int Measure::ConvertToCastOffMensural(FunctorParams *functorParams)
{
    ConvertToCastOffMensuralParams *params = dynamic_cast<ConvertToCastOffMensuralParams *>(functorParams);
    assert(params);

    // We are processing by staff/layer from the call below - we obviously do not want to loop...
    if (params->m_targetMeasure) {
        return FUNCTOR_CONTINUE;
    }

    bool convertToMeasured = params->m_doc->GetOptions()->m_mensuralToMeasure.GetValue();

    assert(params->m_targetSystem);
    assert(params->m_layerTree);

    // Create a temporary subsystem for receiving the measure segments
    System targetSubSystem;
    params->m_targetSubSystem = &targetSubSystem;

    // Create the first measure segment - problem: we are dropping the section element - we should create a score-based
    // MEI file instead
    Measure *measure = new Measure(convertToMeasured);
    if (convertToMeasured) {
        measure->SetN(StringFormat("%d", params->m_segmentTotal + 1));
    }
    params->m_targetSubSystem->AddChild(measure);

    ArrayOfComparisons filters;
    // Now we can process by layer and move their content to (measure) segments
    for (auto const &staves : params->m_layerTree->child) {
        for (auto const &layers : staves.second.child) {
            // Create ad comparison object for each type / @n
            AttNIntegerComparison matchStaff(STAFF, staves.first);
            AttNIntegerComparison matchLayer(LAYER, layers.first);
            filters = { &matchStaff, &matchLayer };

            params->m_segmentIdx = 1;
            params->m_targetMeasure = measure;

            Functor convertToCastOffMensural(&Object::ConvertToCastOffMensural);
            this->Process(&convertToCastOffMensural, params, NULL, &filters);
        }
    }

    params->m_targetMeasure = NULL;
    params->m_targetSubSystem = NULL;
    params->m_segmentTotal = targetSubSystem.GetChildCount();
    // Copy the measure segments to the final target segment
    params->m_targetSystem->MoveChildrenFrom(&targetSubSystem);

    return FUNCTOR_SIBLINGS;
}
Example #4
0
data_STEMDIRECTION Layer::GetDrawingStemDir(double time, double duration, Measure *measure, int staff)
{
    assert(measure);

    Functor findSpaceInAlignment(&Object::FindSpaceInReferenceAlignments);
    FindSpaceInAlignmentParams findSpaceInAlignmentParams(
        GetCurrentMeterSig(), GetCurrentMensur(), &findSpaceInAlignment);
    findSpaceInAlignmentParams.m_time = time;
    findSpaceInAlignmentParams.m_duration = duration;

    ArrayOfComparisons filters;
    AttNIntegerComparison matchStaff(ALIGNMENT_REFERENCE, staff);
    filters.push_back(&matchStaff);

    measure->m_measureAligner.Process(&findSpaceInAlignment, &findSpaceInAlignmentParams, NULL, &filters);

    if (findSpaceInAlignmentParams.m_success && (findSpaceInAlignmentParams.m_layerCount < 3)) {
        return STEMDIRECTION_NONE;
    }

    return m_drawingStemDir;
}
Example #5
0
int Measure::AdjustLayers(FunctorParams *functorParams)
{
    AdjustLayersParams *params = dynamic_cast<AdjustLayersParams *>(functorParams);
    assert(params);

    if (!m_hasAlignmentRefWithMultipleLayers) return FUNCTOR_SIBLINGS;

    std::vector<int>::iterator iter;
    ArrayOfComparisons filters;
    for (iter = params->m_staffNs.begin(); iter != params->m_staffNs.end(); ++iter) {
        filters.clear();
        // Create ad comparison object for each type / @n
        std::vector<int> ns;
        // -1 for barline attributes that need to be taken into account each time
        ns.push_back(-1);
        ns.push_back(*iter);
        AttNIntegerComparisonAny matchStaff(ALIGNMENT_REFERENCE, ns);
        filters.push_back(&matchStaff);

        m_measureAligner.Process(params->m_functor, params, NULL, &filters);
    }

    return FUNCTOR_SIBLINGS;
}
Example #6
0
float View::CalcInitialSlur(
    FloatingCurvePositioner *curve, Slur *slur, Staff *staff, int layerN, curvature_CURVEDIR curveDir, Point points[4])
{
    // For readability makes them p1 and p2
    Point p1 = points[0];
    Point p2 = points[3];

    /************** height **************/

    // the 'height' of the bezier
    int height;
    if (slur->HasBulge()) {
        height = m_doc->GetDrawingUnit(staff->m_drawingStaffSize) * slur->GetBulge();
    }
    else {
        int dist = abs(p2.x - p1.x);
        height = std::max(int(m_options->m_slurMinHeight.GetValue() * m_doc->GetDrawingUnit(staff->m_drawingStaffSize)),
            dist / m_options->m_slurHeightFactor.GetValue());
        height = std::min(
            int(m_options->m_slurMaxHeight.GetValue() * m_doc->GetDrawingUnit(staff->m_drawingStaffSize)), height);
    }

    // the height of the control points
    height = height * 4 / 3;

    /************** content **************/

    System *system = dynamic_cast<System *>(staff->GetFirstParent(SYSTEM));
    assert(system);
    FindSpannedLayerElementsParams findSpannedLayerElementsParams(slur, slur);
    findSpannedLayerElementsParams.m_minPos = p1.x;
    findSpannedLayerElementsParams.m_maxPos = p2.x;
    findSpannedLayerElementsParams.m_classIds
        = { ACCID, ARTIC_PART, ARTIC, CHORD, FLAG, NOTE, STEM, TIE, TUPLET_BRACKET, TUPLET_NUM };
    ArrayOfComparisons filters;
    // Create ad comparison object for each type / @n
    // For now we only look at one layer (assumed layer1 == layer2)
    AttNIntegerComparison matchStaff(STAFF, staff->GetN());
    AttNIntegerComparison matchLayer(LAYER, layerN);
    filters.push_back(&matchStaff);
    filters.push_back(&matchLayer);

    Functor findSpannedLayerElements(&Object::FindSpannedLayerElements);
    system->Process(&findSpannedLayerElements, &findSpannedLayerElementsParams, NULL, &filters);

    curve->ClearSpannedElements();
    for (auto &element : findSpannedLayerElementsParams.m_elements) {

        Point pRotated;
        Point pLeft;
        pLeft.x = element->GetSelfLeft();
        // if ((pLeft.x > p1->x) && (pLeft.x < p2->x)) {
        //    pLeft.y = (curveDir == curvature_CURVEDIR_above) ? element->GetSelfTop() : element->GetSelfBottom();
        //    spannedElements->push_back(spannedElement);
        //}
        Point pRight;
        pRight.x = element->GetSelfRight();
        // if ((pRight.x > p1->x) && (pRight.x < p2->x)) {
        //    pRight.y = (curveDir == curvature_CURVEDIR_above) ? element->GetSelfTop() : element->GetSelfBottom();
        //    spannedElements->push_back(spannedElement);
        //}
        if (((pLeft.x > p1.x) && (pLeft.x < p2.x)) || ((pRight.x > p1.x) && (pRight.x < p2.x))) {
            CurveSpannedElement *spannedElement = new CurveSpannedElement;
            spannedElement->m_boundingBox = element;
            curve->AddSpannedElement(spannedElement);
        }
    }

    for (auto &positioner : findSpannedLayerElementsParams.m_ties) {
        CurveSpannedElement *spannedElement = new CurveSpannedElement;
        spannedElement->m_boundingBox = positioner;
        curve->AddSpannedElement(spannedElement);
    }

    /************** angle **************/

    const ArrayOfCurveSpannedElements *spannedElements = curve->GetSpannedElements();
    float slurAngle = slur->GetAdjustedSlurAngle(m_doc, p1, p2, curveDir, (spannedElements->size() > 0));
    Point rotatedP2 = BoundingBox::CalcPositionAfterRotation(p2, -slurAngle, p1);

    /************** control points **************/

    Point rotatedC1, rotatedC2;
    slur->GetControlPoints(m_doc, p1, rotatedP2, rotatedC1, rotatedC2, curveDir, height, staff->m_drawingStaffSize);

    points[0] = p1;
    points[1] = BoundingBox::CalcPositionAfterRotation(rotatedC1, slurAngle, p1);
    points[2] = BoundingBox::CalcPositionAfterRotation(rotatedC2, slurAngle, p1);
    points[3] = BoundingBox::CalcPositionAfterRotation(rotatedP2, slurAngle, p1);

    return slurAngle;
}