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

📄 linedstaff.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: *//*    Rosegarden    A MIDI and audio sequencer and musical notation editor.     This program is Copyright 2000-2007        Guillaume Laurent   <glaurent@telegraph-road.org>,        Chris Cannam        <cannam@all-day-breakfast.com>,        Richard Bown        <richard.bown@ferventsoftware.com>     The moral rights of Guillaume Laurent, Chris Cannam, and Richard    Bown to claim authorship of this work have been asserted.     Other copyrights also apply to some parts of this work.  Please    see the AUTHORS file and individual file headers for details.     This program is free software; you can redistribute it and/or    modify it under the terms of the GNU General Public License as    published by the Free Software Foundation; either version 2 of the    License, or (at your option) any later version.  See the file    COPYING included with this distribution for more information.*/#include "LinedStaff.h"#include "misc/Debug.h"#include "base/Event.h"#include "base/LayoutEngine.h"#include "base/NotationTypes.h"#include "base/Profiler.h"#include "base/Segment.h"#include "base/SnapGrid.h"#include "base/Staff.h"#include "base/ViewElement.h"#include "GUIPalette.h"#include "BarLine.h"#include <qcanvas.h>#include <qcolor.h>#include <qfont.h>#include <qfontmetrics.h>#include <qpen.h>#include <qrect.h>#include <qstring.h>#include <algorithm>namespace Rosegarden{// width of pointer//const int pointerWidth = 3;LinedStaff::LinedStaff(QCanvas *canvas, Segment *segment,                       SnapGrid *snapGrid, int id,                       int resolution, int lineThickness) :    Staff(*segment),    m_canvas(canvas),    m_snapGrid(snapGrid),    m_id(id),    m_x(0.0),    m_y(0),    m_margin(0.0),    m_titleHeight(0),    m_resolution(resolution),    m_lineThickness(lineThickness),    m_pageMode(LinearMode),    m_pageWidth(2000.0),  // fairly arbitrary, but we need something non-zero    m_rowsPerPage(0),    m_rowSpacing(0),    m_connectingLineLength(0),    m_startLayoutX(0),    m_endLayoutX(0),    m_current(false),    m_pointer(new QCanvasLine(canvas)),    m_insertCursor(new QCanvasLine(canvas)),    m_insertCursorTime(segment->getStartTime()),    m_insertCursorTimeValid(false){    initCursors();}LinedStaff::LinedStaff(QCanvas *canvas, Segment *segment,                       SnapGrid *snapGrid,                       int id, int resolution, int lineThickness,                       double pageWidth, int rowsPerPage, int rowSpacing) :    Staff(*segment),    m_canvas(canvas),    m_snapGrid(snapGrid),    m_id(id),    m_x(0.0),    m_y(0),    m_margin(0.0),    m_titleHeight(0),    m_resolution(resolution),    m_lineThickness(lineThickness),    m_pageMode(rowsPerPage ? MultiPageMode : ContinuousPageMode),    m_pageWidth(pageWidth),    m_rowsPerPage(rowsPerPage),    m_rowSpacing(rowSpacing),    m_connectingLineLength(0),    m_startLayoutX(0),    m_endLayoutX(0),    m_current(false),    m_pointer(new QCanvasLine(canvas)),    m_insertCursor(new QCanvasLine(canvas)),    m_insertCursorTime(segment->getStartTime()),    m_insertCursorTimeValid(false){    initCursors();}LinedStaff::LinedStaff(QCanvas *canvas, Segment *segment,                       SnapGrid *snapGrid,                       int id, int resolution, int lineThickness,                       PageMode pageMode, double pageWidth, int rowsPerPage,                       int rowSpacing) :    Staff(*segment),    m_canvas(canvas),    m_snapGrid(snapGrid),    m_id(id),    m_x(0.0),    m_y(0),    m_margin(0.0),    m_titleHeight(0),    m_resolution(resolution),    m_lineThickness(lineThickness),    m_pageMode(pageMode),    m_pageWidth(pageWidth),    m_rowsPerPage(rowsPerPage),    m_rowSpacing(rowSpacing),    m_connectingLineLength(0),    m_startLayoutX(0),    m_endLayoutX(0),    m_current(false),    m_pointer(new QCanvasLine(canvas)),    m_insertCursor(new QCanvasLine(canvas)),    m_insertCursorTime(segment->getStartTime()),    m_insertCursorTimeValid(false){    initCursors();}LinedStaff::~LinedStaff(){    /*!!! No, the canvas items are all deleted by the canvas on destruction.             deleteBars();        for (int i = 0; i < (int)m_staffLines.size(); ++i) clearStaffLineRow(i);    */}voidLinedStaff::initCursors(){    QPen pen(GUIPalette::getColour(GUIPalette::Pointer));    pen.setWidth(pointerWidth);    m_pointer->setPen(pen);    m_pointer->setBrush(GUIPalette::getColour(GUIPalette::Pointer));    pen.setColor(GUIPalette::getColour(GUIPalette::InsertCursor));    m_insertCursor->setPen(pen);    m_insertCursor->setBrush(GUIPalette::getColour(GUIPalette::InsertCursor));}voidLinedStaff::setResolution(int resolution){    m_resolution = resolution;}voidLinedStaff::setLineThickness(int lineThickness){    m_lineThickness = lineThickness;}voidLinedStaff::setPageMode(PageMode pageMode){    m_pageMode = pageMode;}voidLinedStaff::setPageWidth(double pageWidth){    m_pageWidth = pageWidth;}voidLinedStaff::setRowsPerPage(int rowsPerPage){    m_rowsPerPage = rowsPerPage;}voidLinedStaff::setRowSpacing(int rowSpacing){    m_rowSpacing = rowSpacing;}voidLinedStaff::setConnectingLineLength(int connectingLineLength){    m_connectingLineLength = connectingLineLength;}intLinedStaff::getId() const{    return m_id;}voidLinedStaff::setX(double x){    m_x = x;}doubleLinedStaff::getX() const{    return m_x;}voidLinedStaff::setY(int y){    m_y = y;}intLinedStaff::getY() const{    return m_y;}voidLinedStaff::setMargin(double margin){    m_margin = margin;}doubleLinedStaff::getMargin() const{    if (m_pageMode != MultiPageMode)        return 0;    return m_margin;}voidLinedStaff::setTitleHeight(int titleHeight){    m_titleHeight = titleHeight;}intLinedStaff::getTitleHeight() const{    return m_titleHeight;}doubleLinedStaff::getTotalWidth() const{    switch (m_pageMode) {    case ContinuousPageMode:        return getCanvasXForRightOfRow(getRowForLayoutX(m_endLayoutX)) - m_x;    case MultiPageMode:        return getCanvasXForRightOfRow(getRowForLayoutX(m_endLayoutX)) + m_margin - m_x;    case LinearMode:    default:        return getCanvasXForLayoutX(m_endLayoutX) - m_x;    }}intLinedStaff::getTotalHeight() const{    switch (m_pageMode) {    case ContinuousPageMode:        return getCanvasYForTopOfStaff(getRowForLayoutX(m_endLayoutX)) +               getHeightOfRow() - m_y;    case MultiPageMode:        return getCanvasYForTopOfStaff(m_rowsPerPage - 1) +               getHeightOfRow() - m_y;    case LinearMode:    default:        return getCanvasYForTopOfStaff(0) + getHeightOfRow() - m_y;    }}intLinedStaff::getHeightOfRow() const{    return getTopLineOffset() + getLegerLineCount() * getLineSpacing()           + getBarLineHeight() + m_lineThickness;}boolLinedStaff::containsCanvasCoords(double x, int y) const{    switch (m_pageMode) {    case ContinuousPageMode:        for (int row = getRowForLayoutX(m_startLayoutX);                row <= getRowForLayoutX(m_endLayoutX); ++row) {            if (y >= getCanvasYForTopOfStaff(row) &&                    y < getCanvasYForTopOfStaff(row) + getHeightOfRow()) {                return true;            }        }        return false;    case MultiPageMode:        for (int row = getRowForLayoutX(m_startLayoutX);                row <= getRowForLayoutX(m_endLayoutX); ++row) {            if (y >= getCanvasYForTopOfStaff(row) &&                    y < getCanvasYForTopOfStaff(row) + getHeightOfRow() &&                    x >= getCanvasXForLeftOfRow(row) &&                    x <= getCanvasXForRightOfRow(row)) {                return true;            }        }        return false;    case LinearMode:    default:        return (y >= getCanvasYForTopOfStaff() &&                y < getCanvasYForTopOfStaff() + getHeightOfRow());    }}intLinedStaff::getCanvasYForHeight(int h, double baseX, int baseY) const{    int y;    //    NOTATION_DEBUG << "LinedStaff::getCanvasYForHeight(" << h << "," << baseY    //		   << ")" << endl;    if (baseX < 0)        baseX = getX() + getMargin();    if (baseY >= 0) {        y = getCanvasYForTopLine(getRowForCanvasCoords(baseX, baseY));    } else {        y = getCanvasYForTopLine();    }    y += getLayoutYForHeight(h);    return y;}intLinedStaff::getLayoutYForHeight(int h) const{    int y = ((getTopLineHeight() - h) * getLineSpacing()) / getHeightPerLine();    if (h < getTopLineHeight() && (h % getHeightPerLine() != 0))        ++y;    return y;}intLinedStaff::getHeightAtCanvasCoords(double x, int y) const{    //!!! the lazy route: approximate, then get the right value    // by calling getCanvasYForHeight a few times... ugh    //    RG_DEBUG << "\nNotationStaff::heightOfYCoord: y = " << y    //                         << ", getTopLineOffset() = " << getTopLineOffset()    //                         << ", getLineSpacing() = " << m_npf->getLineSpacing()    //                         << endl;    if (x < 0)        x = getX() + getMargin();    int row = getRowForCanvasCoords(x, y);    int ph = (y - getCanvasYForTopLine(row)) * getHeightPerLine() /             getLineSpacing();    ph = getTopLineHeight() - ph;    int i;    int mi = -2;    int md = getLineSpacing() * 2;    int testi = -2;

⌨️ 快捷键说明

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