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

📄 matrixmover.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* -*- 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 "MatrixMover.h"#include "base/BaseProperties.h"#include <klocale.h>#include <kstddirs.h>#include "base/Event.h"#include "base/Segment.h"#include "base/Selection.h"#include "base/SnapGrid.h"#include "base/ViewElement.h"#include "commands/matrix/MatrixModifyCommand.h"#include "commands/matrix/MatrixInsertionCommand.h"#include "commands/notation/NormalizeRestsCommand.h"#include "gui/general/EditTool.h"#include "gui/general/RosegardenCanvasView.h"#include "MatrixElement.h"#include "MatrixStaff.h"#include "MatrixTool.h"#include "MatrixView.h"#include "MatrixVLayout.h"#include <kaction.h>#include <kglobal.h>#include <qiconset.h>#include <qpoint.h>#include <qstring.h>#include "misc/Debug.h"namespace Rosegarden{MatrixMover::MatrixMover(MatrixView* parent) :    MatrixTool("MatrixMover", parent),    m_currentElement(0),    m_currentStaff(0),    m_lastPlayedPitch(-1){    QString pixmapDir = KGlobal::dirs()->findResource("appdata", "pixmaps/");    QCanvasPixmap pixmap(pixmapDir + "/toolbar/select.xpm");    QIconSet icon = QIconSet(pixmap);    new KAction(i18n("Switch to Select Tool"), icon, 0, this,                SLOT(slotSelectSelected()), actionCollection(),                "select");    new KAction(i18n("Switch to Draw Tool"), "pencil", 0, this,                SLOT(slotDrawSelected()), actionCollection(),                "draw");    new KAction(i18n("Switch to Erase Tool"), "eraser", 0, this,                SLOT(slotEraseSelected()), actionCollection(),                "erase");    pixmap.load(pixmapDir + "/toolbar/resize.xpm");    icon = QIconSet(pixmap);    new KAction(i18n("Switch to Resize Tool"), icon, 0, this,                SLOT(slotResizeSelected()), actionCollection(),                "resize");    createMenu("matrixmover.rc");}void MatrixMover::handleEventRemoved(Event *event){    if (m_currentElement && m_currentElement->event() == event) {        m_currentElement = 0;    }}void MatrixMover::handleLeftButtonPress(timeT time,                                        int pitch,                                        int staffNo,                                        QMouseEvent* e,                                        ViewElement* el){    MATRIX_DEBUG << "MatrixMover::handleLeftButtonPress() : time = " << time << ", el = " << el << endl;    if (!el) return;    m_quickCopy = (e->state() & Qt::ControlButton);    if (!m_duplicateElements.empty()) {        for (size_t i = 0; i < m_duplicateElements.size(); ++i) {            delete m_duplicateElements[i]->event();            delete m_duplicateElements[i];        }        m_duplicateElements.clear();    }    m_currentElement = dynamic_cast<MatrixElement*>(el);    m_currentStaff = m_mParentView->getStaff(staffNo);    if (m_currentElement) {        // Add this element and allow movement        //        EventSelection* selection = m_mParentView->getCurrentSelection();        if (selection) {            EventSelection *newSelection;            if ((e->state() & Qt::ShiftButton) ||                    selection->contains(m_currentElement->event()))                newSelection = new EventSelection(*selection);            else                newSelection = new EventSelection(m_currentStaff->getSegment());            newSelection->addEvent(m_currentElement->event());            m_mParentView->setCurrentSelection(newSelection, true, true);            m_mParentView->canvas()->update();            selection = newSelection;        } else {            m_mParentView->setSingleSelectedEvent(m_currentStaff->getSegment(),                                                  m_currentElement->event(),                                                  true);            m_mParentView->canvas()->update();        }        long velocity = m_mParentView->getCurrentVelocity();        m_currentElement->event()->get<Int>(BaseProperties::VELOCITY, velocity);        m_mParentView->playNote(m_currentStaff->getSegment(), pitch, velocity);        m_lastPlayedPitch = pitch;        if (m_quickCopy && selection) {            for (EventSelection::eventcontainer::iterator i =                     selection->getSegmentEvents().begin();                 i != selection->getSegmentEvents().end(); ++i) {                MatrixElement *element = m_currentStaff->getElement(*i);                if (!element) continue;                MatrixElement *duplicate = new MatrixElement                    (new Event(**i), m_mParentView->isDrumMode());                duplicate->setLayoutY(element->getLayoutY());                duplicate->setLayoutX(element->getLayoutX());                duplicate->setWidth(element->getWidth());                duplicate->setHeight(element->getHeight());                duplicate->setCanvasZ(-1);                m_currentStaff->positionElement(duplicate);                m_duplicateElements.push_back(duplicate);            }        }    }        m_clickX = m_mParentView->inverseMapPoint(e->pos()).x();}timeTMatrixMover::getDragTime(QMouseEvent *e, timeT candidate){    int x = m_mParentView->inverseMapPoint(e->pos()).x();    int xdiff = x - m_clickX;    const SnapGrid &grid = getSnapGrid();    const RulerScale &scale = *grid.getRulerScale();        timeT eventTime = m_currentElement->getViewAbsoluteTime();    int eventX = scale.getXForTime(eventTime);    timeT preSnapTarget = scale.getTimeForX(eventX + xdiff);        candidate = grid.snapTime(preSnapTarget, SnapGrid::SnapEither);        if (xdiff == 0 ||        (abs(eventTime - preSnapTarget) < abs(candidate - preSnapTarget))) {        candidate = eventTime;    }    return candidate;}int MatrixMover::handleMouseMove(timeT newTime,                                 int newPitch,                                 QMouseEvent *e){    MATRIX_DEBUG << "MatrixMover::handleMouseMove() time = "    << newTime << endl;    if (e) {        setBasicContextHelp(e->state() & Qt::ControlButton);    }    if (!m_currentElement || !m_currentStaff)        return RosegardenCanvasView::NoFollow;    if (getSnapGrid().getSnapSetting() != SnapGrid::NoSnap) {        setContextHelp(i18n("Hold Shift to avoid snapping to beat grid"));    } else {        clearContextHelp();    }    if (e) newTime = getDragTime(e, newTime);    emit hoveredOverNoteChanged(newPitch, true, newTime);    using BaseProperties::PITCH;    int diffPitch = 0;    if (m_currentElement->event()->has(PITCH)) {        diffPitch = newPitch - m_currentElement->event()->get<Int>(PITCH);    }    int diffY =        int(((m_currentStaff->getLayoutYForHeight(newPitch) -              m_currentStaff->getElementHeight() / 2) -             m_currentElement->getLayoutY()));    EventSelection* selection = m_mParentView->getCurrentSelection();    EventSelection::eventcontainer::iterator it =        selection->getSegmentEvents().begin();    MatrixElement *element = 0;    int maxY = m_currentStaff->getCanvasYForHeight(0);    for (; it != selection->getSegmentEvents().end(); it++) {        element = m_currentStaff->getElement(*it);

⌨️ 快捷键说明

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