Example #1
0
int Measure::SetDrawingXY( ArrayPtrVoid *params )
{
    // param 0: a pointer doc
    // param 1: a pointer to the current system
    // param 2: a pointer to the current measure
    // param 3: a pointer to the current staff (unused)
    // param 4: a pointer to the current layer (unused)
    // param 5: a pointer to the view (unused)
    // param 6: a bool indicating if we are processing layer elements or not
    Doc *doc = static_cast<Doc*>((*params).at(0));
    System **currentSystem = static_cast<System**>((*params).at(1));
    Measure **currentMeasure = static_cast<Measure**>((*params).at(2));
    bool *processLayerElements = static_cast<bool*>((*params).at(6));
    
    (*currentMeasure) = this;
    
    // Second pass where we do just process layer elements
    if ((*processLayerElements)) return FUNCTOR_CONTINUE;
    
    // Here we set the appropriate y value to be used for drawing
    // With Raw documents, we use m_drawingXRel that is calculated by the layout algorithm
    // With Transcription documents, we use the m_xAbs
    if ( this->m_xAbs == VRV_UNSET ) {
        assert( doc->GetType() == Raw );
        this->SetDrawingX( this->m_drawingXRel + (*currentSystem)->GetDrawingX() );
    }
    else
    {
        assert( doc->GetType() == Transcription );
        this->SetDrawingX( this->m_xAbs );
    }

    
    return FUNCTOR_CONTINUE;
}
Example #2
0
int LayerElement::SetDrawingXY( ArrayPtrVoid *params )
{
    // param 0: a pointer doc
    // param 1: a pointer to the current system (unused)
    // param 2: a pointer to the current measure
    // param 3: a pointer to the current staff
    // param 4: a pointer to the current layer
    // param 5: a pointer to the view
    // param 6: a bool indicating if we are processing layer elements or not
    Doc *doc = static_cast<Doc*>((*params).at(0));
    Measure **currentMeasure = static_cast<Measure**>((*params).at(2));
    Staff **currentStaff = static_cast<Staff**>((*params).at(3));
    Layer **currentLayer = static_cast<Layer**>((*params).at(4));
    View *view = static_cast<View*>((*params).at(5));
    bool *processLayerElements = static_cast<bool*>((*params).at(6));
    
    // First pass, only set the X position
    if ((*processLayerElements)==false) {
        // Here we set the appropriate x value to be used for drawing
        // With Raw documents, we use m_drawingXRel that is calculated by the layout algorithm
        // With Transcription documents, we use the m_xAbs
        if ( this->m_xAbs == VRV_UNSET ) {
            assert( doc->GetType() == Raw );
            this->SetDrawingX( this->GetXRel() + (*currentMeasure)->GetDrawingX() );
            // Grace notes, also take into account the GraceAlignment
            Note *note = dynamic_cast<Note*>(this);
            if (note && note->HasGraceAlignment() ) {
                this->SetDrawingX( this->GetDrawingX() - note->GetAlignment()->GetGraceAligner()->GetWidth()
                                  + note->GetGraceAlignment()->GetXRel() );
            }
        }
        else
        {
            assert( doc->GetType() == Transcription );
            this->SetDrawingX( this->m_xAbs );
        }
        return FUNCTOR_CONTINUE;
    }
    
    LayerElement *layerElementY = this;
    
    // Look for cross-staff situations
    // If we have one, make is available in m_crossStaff
    DurationInterface *durElement = dynamic_cast<DurationInterface*>(this);
    if ( durElement && durElement->HasStaff()) {
        AttCommonNComparison comparisonFirst( STAFF, durElement->GetStaff() );
        m_crossStaff = dynamic_cast<Staff*>((*currentMeasure)->FindChildByAttComparison(&comparisonFirst, 1));
        if (m_crossStaff) {
            if (m_crossStaff == (*currentStaff)) LogWarning("The cross staff reference '%d' for element '%s' seems to be identical to the parent staff", durElement->GetStaff(), this->GetUuid().c_str());
            // Now try to get the corresponding layer - for now look for the same layer @n
            int layerN = (*currentLayer)->GetN();
            // When we will have allowed @layer in <note>, we will have to do:
            // int layerN = durElement->HasLayer() ? durElement->GetLayer() : (*currentLayer)->GetN();
            AttCommonNComparison comparisonFirstLayer( LAYER, layerN );
            m_crossLayer = dynamic_cast<Layer*>(m_crossStaff->FindChildByAttComparison(&comparisonFirstLayer, 1));
            if (m_crossLayer) {
                // Now we need to yet the element at the same position in the cross-staff layer of getting the right clef
                layerElementY = m_crossLayer->GetAtPos( this->GetDrawingX() );
                
            } else {
                LogWarning("Could not get the layer with cross-staff reference '%d' for element '%s'", durElement->GetStaff(), this->GetUuid().c_str());
            }
        } else {
            LogWarning("Could not get the cross staff reference '%d' for element '%s'", durElement->GetStaff(), this->GetUuid().c_str());
        }
        // If we have a @layer we probably also want to change the layer element (for getting the right clef if different)
    } else {
        m_crossStaff = NULL;
        m_crossLayer = NULL;
    }
    
    Staff *staffY = m_crossStaff ? m_crossStaff : (*currentStaff);
    Layer *layerY = m_crossLayer ? m_crossLayer : (*currentLayer);
    
    // Here we set the appropriate Y value to be used for drawing
    if ( this->m_xAbs == VRV_UNSET ) {
        assert( doc->GetType() == Raw );
        this->SetDrawingY( staffY->GetDrawingY() );
    }
    else
    {
        assert( doc->GetType() == Transcription );
        this->SetDrawingY( staffY->GetDrawingY() );
    }
    
    // Finally, adjust Y for notes and rests
    if (this->Is() == NOTE)
    {
        Note *note = dynamic_cast<Note*>(this);
        assert( note );
        this->SetDrawingY( this->GetDrawingY() + view->CalculatePitchPosY( staffY, note->GetPname(), layerY->GetClefOffset( layerElementY ), note->GetOct() ) );
    }
    else if (this->Is() == REST) {
        Rest *rest = dynamic_cast<Rest*>(this);
        assert( rest );
        // Automatically calculate rest position, if so requested
        if (rest->GetPloc() == PITCHNAME_NONE) {
            this->SetDrawingY( this->GetDrawingY() + view->CalculateRestPosY( staffY, rest->GetActualDur()) );
        } else {
            this->SetDrawingY( this->GetDrawingY() + view->CalculatePitchPosY( staffY, rest->GetPloc(), layerY->GetClefOffset( layerElementY ), rest->GetOloc()) );
        }
    }
    
    return FUNCTOR_CONTINUE;
}