⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linedstaff.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
    int testMd = 1000;    for (i = -1; i <= 1; ++i) {        int d = y - getCanvasYForHeight(ph + i, x, y);        if (d < 0)            d = -d;        if (d < md) {            md = d;            mi = i;        }        if (d < testMd) {            testMd = d;            testi = i;        }    }    if (mi > -2) {        //         RG_DEBUG << "LinedStaff::getHeightAtCanvasCoords: " << y        //                              << " -> " << (ph + mi) << " (mi is " << mi << ", distance "        //                              << md << ")" << endl;        //         if (mi == 0) {        //             RG_DEBUG << "GOOD APPROXIMATION" << endl;        //         } else {        //             RG_DEBUG << "BAD APPROXIMATION" << endl;        //         }        return ph + mi;    } else {        RG_DEBUG << "LinedStaff::getHeightAtCanvasCoords: heuristic got " << ph << ", nothing within range (closest was " << (ph + testi) << " which is " << testMd << " away)" << endl;        return 0;    }}QRectLinedStaff::getBarExtents(double x, int y) const{    int row = getRowForCanvasCoords(x, y);    for (int i = 1; i < m_barLines.size(); ++i) {        double layoutX = m_barLines[i]->getLayoutX();        int barRow = getRowForLayoutX(layoutX);        if (m_pageMode != LinearMode && (barRow < row))            continue;        BarLine *line = m_barLines[i];        if (line) {            if (line->x() <= x)                continue;            return QRect(int(m_barLines[i -1]->x()),                         getCanvasYForTopOfStaff(barRow),                         int(line->x() - m_barLines[i - 1]->x()),                         getHeightOfRow());        }    }    // failure    return QRect(int(getX() + getMargin()), getCanvasYForTopOfStaff(), 4, getHeightOfRow());}doubleLinedStaff::getCanvasXForLayoutX(double x) const{    switch (m_pageMode) {    case ContinuousPageMode:        return m_x + x - (m_pageWidth * getRowForLayoutX(x));    case MultiPageMode: {            int pageNo = getRowForLayoutX(x) / getRowsPerPage();            double cx = m_x + x - (m_pageWidth * getRowForLayoutX(x));            cx += m_margin + (m_margin * 2 + m_pageWidth) * pageNo;            return cx;        }    case LinearMode:    default:        return m_x + x;    }}LinedStaff::LinedStaffCoordsLinedStaff::getLayoutCoordsForCanvasCoords(double x, int y) const{    int row = getRowForCanvasCoords(x, y);    return LinedStaffCoords           ((row * m_pageWidth) + x - getCanvasXForLeftOfRow(row),            y - getCanvasYForTopOfStaff(row));}LinedStaff::LinedStaffCoordsLinedStaff::getCanvasCoordsForLayoutCoords(double x, int y) const{    int row = getRowForLayoutX(x);    return LinedStaffCoords           (getCanvasXForLayoutX(x), getCanvasYForTopLine(row) + y);}intLinedStaff::getRowForCanvasCoords(double x, int y) const{    switch (m_pageMode) {    case ContinuousPageMode:        return ((y - m_y) / m_rowSpacing);    case MultiPageMode: {            int px = int(x - m_x - m_margin);            int pw = int(m_margin * 2 + m_pageWidth);            if (px < pw)                y -= m_titleHeight;            return (getRowsPerPage() * (px / pw)) + ((y - m_y) / m_rowSpacing);        }    case LinearMode:    default:        return (int)((x - m_x) / m_pageWidth);    }}intLinedStaff::getCanvasYForTopOfStaff(int row) const{    switch (m_pageMode) {    case ContinuousPageMode:        if (row <= 0)            return m_y;        else            return m_y + (row * m_rowSpacing);    case MultiPageMode:        if (row <= 0)            return m_y + m_titleHeight;        else if (row < getRowsPerPage())            return m_y + ((row % getRowsPerPage()) * m_rowSpacing) + m_titleHeight;        else            return m_y + ((row % getRowsPerPage()) * m_rowSpacing);    case LinearMode:    default:        return m_y;    }}doubleLinedStaff::getCanvasXForLeftOfRow(int row) const{    switch (m_pageMode) {    case ContinuousPageMode:        return m_x;    case MultiPageMode:        return m_x + m_margin +               (m_margin*2 + m_pageWidth) * (row / getRowsPerPage());    case LinearMode:    default:        return m_x + (row * m_pageWidth);    }}voidLinedStaff::sizeStaff(HorizontalLayoutEngine &layout){    Profiler profiler("LinedStaff::sizeStaff", true);    deleteBars();    deleteRepeatedClefsAndKeys();    deleteTimeSignatures();    //    RG_DEBUG << "LinedStaff::sizeStaff" << endl;    int lastBar = layout.getLastVisibleBarOnStaff(*this);    double xleft = 0, xright = 0;    bool haveXLeft = false;    xright = layout.getBarPosition(lastBar) - 1;    TimeSignature currentTimeSignature;    for (int barNo = layout.getFirstVisibleBarOnStaff(*this);            barNo <= lastBar; ++barNo) {        double x = layout.getBarPosition(barNo);        if (!haveXLeft) {            xleft = x;            haveXLeft = true;        }        double timeSigX = 0;        TimeSignature timeSig;        bool isNew = layout.getTimeSignaturePosition(*this, barNo, timeSig, timeSigX);        if (isNew && barNo < lastBar) {            currentTimeSignature = timeSig;            insertTimeSignature(timeSigX, currentTimeSignature);        }        RG_DEBUG << "LinedStaff::sizeStaff: inserting bar at " << x << " on staff " << this << " (isNew " << isNew << ", timeSigX " << timeSigX << ")" << endl;        bool showBarNo =            (showBarNumbersEvery() > 0 &&             ((barNo + 1) % showBarNumbersEvery()) == 0);        insertBar(x,                  ((barNo == lastBar) ? 0 :                   (layout.getBarPosition(barNo + 1) - x)),                  layout.isBarCorrectOnStaff(*this, barNo - 1),                  currentTimeSignature,                  barNo,                  showBarNo);    }    m_startLayoutX = xleft;    m_endLayoutX = xright;    drawStaffName();    resizeStaffLines();}voidLinedStaff::deleteBars(){    for (BarLineList::iterator i = m_barLines.begin();            i != m_barLines.end(); ++i) {        (*i)->hide();        delete *i;    }    for (LineRecList::iterator i = m_beatLines.begin();            i != m_beatLines.end(); ++i) {        i->second->hide();        delete i->second;    }    for (LineRecList::iterator i = m_barConnectingLines.begin();            i != m_barConnectingLines.end(); ++i) {        i->second->hide();        delete i->second;    }    for (ItemList::iterator i = m_barNumbers.begin();            i != m_barNumbers.end(); ++i) {        (*i)->hide();        delete *i;    }    m_barLines.clear();    m_beatLines.clear();    m_barConnectingLines.clear();    m_barNumbers.clear();}voidLinedStaff::insertBar(double layoutX, double width, bool isCorrect,                      const TimeSignature &timeSig,                      int barNo, bool showBarNo){    //    RG_DEBUG << "insertBar: " << layoutX << ", " << width    //			 << ", " << isCorrect << endl;    int barThickness = m_lineThickness * 5 / 4;    // hack to ensure the bar line appears on the correct row in    // notation page layouts, with a conditional to prevent us from    // moving the bar and beat lines in the matrix    if (!showBeatLines()) {        if (width > 0.01) { // not final bar in staff            layoutX += 1;        } else {            layoutX -= 1;        }    }    int row = getRowForLayoutX(layoutX);    double x = getCanvasXForLayoutX(layoutX);    int y = getCanvasYForTopLine(row);    bool firstBarInRow = false, lastBarInRow = false;    if (m_pageMode != LinearMode &&            (getRowForLayoutX(layoutX) >             getRowForLayoutX(layoutX - getMargin() - 2)))        firstBarInRow = true;    if (m_pageMode != LinearMode &&            width > 0.01 &&  // width == 0 for final bar in staff            (getRowForLayoutX(layoutX) <             getRowForLayoutX(layoutX + width + getMargin() + 2)))        lastBarInRow = true;    BarStyle style = getBarStyle(barNo);    if (style == RepeatBothBar && firstBarInRow)        style = RepeatStartBar;    if (firstBarInRow)        insertRepeatedClefAndKey(layoutX, barNo);    // If we're supposed to be hiding bar lines, we do just that --    // create them as normal, then hide them.  We can't simply not    // create them because we rely on this to find bar extents for    // things like double-click selection in notation.    bool hidden = false;    if (style == PlainBar && timeSig.hasHiddenBars())        hidden = true;    double inset = 0.0;    if (style == RepeatStartBar || style == RepeatBothBar) {        inset = getBarInset(barNo, firstBarInRow);    }    BarLine *line = new BarLine(m_canvas, layoutX,                                getBarLineHeight(), barThickness, getLineSpacing(),                                (int)inset, style);    line->moveBy(x, y);    if (isCorrect) {        line->setPen(GUIPalette::getColour(GUIPalette::BarLine));        line->setBrush(GUIPalette::getColour(GUIPalette::BarLine));    } else {        line->setPen(GUIPalette::getColour(GUIPalette::BarLineIncorrect));        line->setBrush(GUIPalette::getColour(GUIPalette::BarLineIncorrect));    }    line->setZ( -1);    if (hidden)        line->hide();    else        line->show();    // The bar lines have to be in order of layout-x (there's no    // such interesting stipulation for beat or connecting lines)    BarLineList::iterator insertPoint = lower_bound                                        (m_barLines.begin(), m_barLines.end(), line, compareBars);    m_barLines.insert(insertPoint, line);    if (lastBarInRow) {        double xe = x + width - barThickness;        style = getBarStyle(barNo + 1);        if (style == RepeatBothBar)            style = RepeatEndBar;        BarLine *eline = new BarLine(m_canvas, layoutX,                                     getBarLineHeight(), barThickness, getLineSpacing(),                                     0, style);        eline->moveBy(xe, y);        eline->setPen(GUIPalette::getColour(GUIPalette::BarLine));        eline->setBrush(GUIPalette::getColour(GUIPalette::BarLine));        eline->setZ( -1);        if (hidden)            eline->hide();        else            eline->show();        BarLineList::iterator insertPoint = lower_bound                                            (m_barLines.begin(), m_barLines.end(), eline, compareBars);        m_barLines.insert(insertPoint, eline);    }    if (showBarNo) {        QFont font;        font.setPixelSize(m_resolution * 3 / 2);        QFontMetrics metrics(font);        QString text = QString("%1").arg(barNo + 1);        QCanvasItem *barNoText = new QCanvasText(text, font, m_canvas);        barNoText->setX(x);        barNoText->setY(y - metrics.height() - m_resolution * 2);        barNoText->setZ( -1);        if (hidden)            barNoText->hide();        else            barNoText->show();        m_barNumbers.push_back(barNoText);    }    QCanvasRectangle *rect = 0;    if (showBeatLines()) {        double gridLines; // number of grid lines per bar may be fractional        // If the snap time is zero we default to beat markers        //        if (m_snapGrid && m_snapGrid->getSnapTime(x))            gridLines = double(timeSig.getBarDuration()) /                        double(m_snapGrid->getSnapTime(x));        else            gridLines = timeSig.getBeatsPerBar();        double dx = width / gridLines;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -