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

📄 notationstaff.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/* -*- 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 "NotationStaff.h"#include "misc/Debug.h"#include <kapplication.h>#include <klocale.h>#include "misc/Strings.h"#include "document/ConfigGroups.h"#include "base/Composition.h"#include "base/Device.h"#include "base/Event.h"#include "base/Exception.h"#include "base/Instrument.h"#include "base/MidiDevice.h"#include "base/MidiTypes.h"#include "base/NotationQuantizer.h"#include "base/NotationTypes.h"#include "base/Profiler.h"#include "base/Segment.h"#include "base/Selection.h"#include "base/SnapGrid.h"#include "base/Staff.h"#include "base/Studio.h"#include "base/Track.h"#include "base/ViewElement.h"#include "document/RosegardenGUIDoc.h"#include "gui/editors/guitar/Chord.h"#include "gui/general/LinedStaff.h"#include "gui/general/PixmapFunctions.h"#include "gui/general/ProgressReporter.h"#include "gui/kdeext/QCanvasSimpleSprite.h"#include "NotationChord.h"#include "NotationElement.h"#include "NotationProperties.h"#include "NotationView.h"#include "NoteFontFactory.h"#include "NotePixmapFactory.h"#include "NotePixmapParameters.h"#include "NoteStyleFactory.h"#include <kconfig.h>#include <kmessagebox.h>#include <qcanvas.h>#include <qpainter.h>#include <qpoint.h>#include <qrect.h>namespace Rosegarden{NotationStaff::NotationStaff(QCanvas *canvas, Segment *segment,                             SnapGrid *snapGrid, int id,                             NotationView *view,                             std::string fontName, int resolution) :        ProgressReporter(0),        LinedStaff(canvas, segment, snapGrid, id, resolution,                   resolution / 16 + 1,  // line thickness                   LinearMode, 0, 0,  // pageMode, pageWidth and pageHeight set later                   0 // row spacing                  ),        m_notePixmapFactory(0),        m_graceNotePixmapFactory(0),        m_previewSprite(0),        m_staffName(0),        m_notationView(view),        m_legerLineCount(8),        m_barNumbersEvery(0),        m_colourQuantize(true),        m_showUnknowns(true),        m_showRanges(true),        m_showCollisions(true),        m_printPainter(0),        m_ready(false){    KConfig *config = kapp->config();    config->setGroup(NotationViewConfigGroup);    m_colourQuantize = config->readBoolEntry("colourquantize", false);    // Shouldn't change these  during the lifetime of the staff, really:    m_showUnknowns = config->readBoolEntry("showunknowns", false);    m_showRanges = config->readBoolEntry("showranges", true);    m_showCollisions = config->readBoolEntry("showcollisions", true);    m_keySigCancelMode = config->readNumEntry("keysigcancelmode", 1);    changeFont(fontName, resolution);}NotationStaff::~NotationStaff(){    deleteTimeSignatures();    delete m_notePixmapFactory;    delete m_graceNotePixmapFactory;}voidNotationStaff::changeFont(std::string fontName, int size){    setResolution(size);    delete m_notePixmapFactory;    m_notePixmapFactory = new NotePixmapFactory(fontName, size);    std::vector<int> sizes = NoteFontFactory::getScreenSizes(fontName);    int graceSize = size;    for (unsigned int i = 0; i < sizes.size(); ++i) {        if (sizes[i] == size || sizes[i] > size*3 / 4)            break;        graceSize = sizes[i];    }    delete m_graceNotePixmapFactory;    m_graceNotePixmapFactory = new NotePixmapFactory(fontName, graceSize);    setLineThickness(m_notePixmapFactory->getStaffLineThickness());}voidNotationStaff::insertTimeSignature(double layoutX,                                   const TimeSignature &timeSig){    if (timeSig.isHidden())        return ;    m_notePixmapFactory->setSelected(false);    QCanvasPixmap *pixmap = m_notePixmapFactory->makeTimeSigPixmap(timeSig);    QCanvasTimeSigSprite *sprite =        new QCanvasTimeSigSprite(layoutX, pixmap, m_canvas);    LinedStaffCoords sigCoords =        getCanvasCoordsForLayoutCoords(layoutX, getLayoutYForHeight(4));    sprite->move(sigCoords.first, (double)sigCoords.second);    sprite->show();    m_timeSigs.insert(sprite);}voidNotationStaff::deleteTimeSignatures(){    //    NOTATION_DEBUG << "NotationStaff::deleteTimeSignatures()" << endl;    for (SpriteSet::iterator i = m_timeSigs.begin();            i != m_timeSigs.end(); ++i) {        delete *i;    }    m_timeSigs.clear();}voidNotationStaff::insertRepeatedClefAndKey(double layoutX, int barNo){    bool needClef = false, needKey = false;    timeT t;    timeT barStart = getSegment().getComposition()->getBarStart(barNo);    Clef clef = getSegment().getClefAtTime(barStart, t);    if (t < barStart)        needClef = true;    ::Rosegarden::Key key = getSegment().getKeyAtTime(barStart, t);    if (t < barStart)        needKey = true;    double dx = m_notePixmapFactory->getBarMargin() / 2;    if (!m_notationView->isInPrintMode())        m_notePixmapFactory->setShaded(true);    if (needClef) {        int layoutY = getLayoutYForHeight(clef.getAxisHeight());        LinedStaffCoords coords =            getCanvasCoordsForLayoutCoords(layoutX + dx, layoutY);        QCanvasPixmap *pixmap = m_notePixmapFactory->makeClefPixmap(clef);        QCanvasNonElementSprite *sprite =            new QCanvasNonElementSprite(pixmap, m_canvas);        sprite->move(coords.first, coords.second);        sprite->show();        m_repeatedClefsAndKeys.insert(sprite);        dx += pixmap->width() + m_notePixmapFactory->getNoteBodyWidth() * 2 / 3;    }    if (needKey) {        int layoutY = getLayoutYForHeight(12);        LinedStaffCoords coords =            getCanvasCoordsForLayoutCoords(layoutX + dx, layoutY);        QCanvasPixmap *pixmap = m_notePixmapFactory->makeKeyPixmap(key, clef);        QCanvasNonElementSprite *sprite =            new QCanvasNonElementSprite(pixmap, m_canvas);        sprite->move(coords.first, coords.second);        sprite->show();        m_repeatedClefsAndKeys.insert(sprite);        dx += pixmap->width();    }    /* attempt to blot out things like slurs & ties that overrun this area: doesn't work             if (m_notationView->isInPrintMode() && (needClef || needKey)) {         	int layoutY = getLayoutYForHeight(14);    	int h = getLayoutYForHeight(-8) - layoutY;         	LinedStaffCoords coords =    	    getCanvasCoordsForLayoutCoords(layoutX, layoutY);            	QCanvasRectangle *rect = new QCanvasRectangle(coords.first, coords.second,    						      dx, h, m_canvas);    	rect->setPen(Qt::black);    	rect->setBrush(Qt::white);    	rect->setZ(1);    	rect->show();         	m_repeatedClefsAndKeys.insert(rect);        }    */    m_notePixmapFactory->setShaded(false);}voidNotationStaff::deleteRepeatedClefsAndKeys(){    for (ItemSet::iterator i = m_repeatedClefsAndKeys.begin();            i != m_repeatedClefsAndKeys.end(); ++i) {        delete *i;    }    m_repeatedClefsAndKeys.clear();}voidNotationStaff::drawStaffName(){    delete m_staffName;    m_staffNameText =        getSegment().getComposition()->        getTrackById(getSegment().getTrack())->getLabel();    QCanvasPixmap *map =        m_notePixmapFactory->makeTextPixmap        (Text(m_staffNameText, Text::StaffName));    m_staffName = new QCanvasStaffNameSprite(map, m_canvas);    int layoutY = getLayoutYForHeight(3);    LinedStaffCoords coords = getCanvasCoordsForLayoutCoords(0, layoutY);    m_staffName->move(getX() + getMargin() + m_notePixmapFactory->getNoteBodyWidth(),                      coords.second - map->height() / 2);    m_staffName->show();}boolNotationStaff::isStaffNameUpToDate(){    return (m_staffNameText ==            getSegment().getComposition()->            getTrackById(getSegment().getTrack())->getLabel());}voidNotationStaff::getClefAndKeyAtCanvasCoords(double cx, int cy,        Clef &clef,        ::Rosegarden::Key &key) const{    LinedStaffCoords layoutCoords = getLayoutCoordsForCanvasCoords(cx, cy);    int i;    for (i = 0; i < m_clefChanges.size(); ++i) {        if (m_clefChanges[i].first > layoutCoords.first)            break;        clef = m_clefChanges[i].second;    }    for (i = 0; i < m_keyChanges.size(); ++i) {        if (m_keyChanges[i].first > layoutCoords.first)            break;        key = m_keyChanges[i].second;    }}ViewElementList::iteratorNotationStaff::getClosestElementToLayoutX(double x,        Event *&clef,        Event *&key,        bool notesAndRestsOnly,        int proximityThreshold){    START_TIMING;    double minDist = 10e9, prevDist = 10e9;    NotationElementList *notes = getViewElementList();    NotationElementList::iterator it, result;    // TODO: this is grossly inefficient    for (it = notes->begin(); it != notes->end(); ++it) {        NotationElement *el = static_cast<NotationElement*>(*it);        bool before = ((*it)->getLayoutX() < x);        if (!el->isNote() && !el->isRest()) {            if (before) {                if ((*it)->event()->isa(Clef::EventType)) {                    clef = (*it)->event();                } else if ((*it)->event()->isa(::Rosegarden::Key::EventType)) {                    key = (*it)->event();                }            }            if (notesAndRestsOnly)                continue;        }        double dx = x - (*it)->getLayoutX();        if (dx < 0)            dx = -dx;        if (dx < minDist) {            minDist = dx;            result = it;        } else if (!before) {            break;        }        prevDist = dx;    }    if (proximityThreshold > 0 && minDist > proximityThreshold) {        NOTATION_DEBUG << "NotationStaff::getClosestElementToLayoutX() : element is too far away : "        << minDist << endl;        return notes->end();    }    NOTATION_DEBUG << "NotationStaff::getClosestElementToLayoutX: found element at layout " << (*result)->getLayoutX() << " - we're at layout " << x << endl;    PRINT_ELAPSED("NotationStaff::getClosestElementToLayoutX");    return result;}ViewElementList::iteratorNotationStaff::getElementUnderLayoutX(double x,                                      Event *&clef,                                      Event *&key){    NotationElementList *notes = getViewElementList();    NotationElementList::iterator it;    // TODO: this is grossly inefficient    for (it = notes->begin(); it != notes->end(); ++it) {        NotationElement* el = static_cast<NotationElement*>(*it);        bool before = ((*it)->getLayoutX() <= x);        if (!el->isNote() && !el->isRest()) {

⌨️ 快捷键说明

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