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

📄 trackeditor.cpp

📁 LINUX下的混音软件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
                                InstrumentId id,                                int position){    Composition &comp = m_doc->getComposition();    AddTracksCommand* command = new AddTracksCommand(&comp, nbNewTracks, id,                                                     position);    addCommandToHistory(command);    slotReadjustCanvasSize();}void TrackEditor::slotDeleteTracks(std::vector<TrackId> tracks){    Composition &comp = m_doc->getComposition();    DeleteTracksCommand* command = new DeleteTracksCommand(&comp, tracks);    addCommandToHistory(command);}void TrackEditor::addSegment(int track, int time, unsigned int duration){    if (!m_doc)        return ; // sanity check    SegmentInsertCommand *command =        new SegmentInsertCommand(m_doc, track, time, duration);    addCommandToHistory(command);}void TrackEditor::slotSegmentOrderChanged(int section, int fromIdx, int toIdx){    RG_DEBUG << QString("TrackEditor::segmentOrderChanged(section : %1, from %2, to %3)")    .arg(section).arg(fromIdx).arg(toIdx) << endl;    //!!! how do we get here? need to involve a command    emit needUpdate();}voidTrackEditor::slotCanvasScrolled(int x, int y){    // update the pointer position if the user is dragging it from the loop ruler    if ((m_topStandardRuler && m_topStandardRuler->getLoopRuler() &&         m_topStandardRuler->getLoopRuler()->hasActiveMousePress() &&         !m_topStandardRuler->getLoopRuler()->getLoopingMode()) ||        (m_bottomStandardRuler && m_bottomStandardRuler->getLoopRuler() &&         m_bottomStandardRuler->getLoopRuler()->hasActiveMousePress() &&         !m_bottomStandardRuler->getLoopRuler()->getLoopingMode())) {        int mx = m_segmentCanvas->viewport()->mapFromGlobal(QCursor::pos()).x();        m_segmentCanvas->setPointerPos(x + mx);        // bad idea, creates a feedback loop        // 	timeT t = m_segmentCanvas->grid().getRulerScale()->getTimeForX(x + mx);        // 	slotSetPointerPosition(t);    }}voidTrackEditor::slotSetPointerPosition(timeT position){    SimpleRulerScale *ruler =        dynamic_cast<SimpleRulerScale*>(m_rulerScale);    if (!ruler)        return ;    double pos = m_segmentCanvas->grid().getRulerScale()->getXForTime(position);    int currentPointerPos = m_segmentCanvas->getPointerPos();    double distance = pos - currentPointerPos;    if (distance < 0.0)        distance = -distance;    if (distance >= 1.0) {        if (m_doc && m_doc->getSequenceManager() &&            (m_doc->getSequenceManager()->getTransportStatus() != STOPPED)) {                        if (m_playTracking) {                getSegmentCanvas()->slotScrollHoriz(int(double(position) / ruler->getUnitsPerPixel()));            }        } else if (!getSegmentCanvas()->isAutoScrolling()) {            int newpos = int(double(position) / ruler->getUnitsPerPixel());            //             RG_DEBUG << "TrackEditor::slotSetPointerPosition("            //                      << position            //                      << ") : calling canvas->slotScrollHoriz() "            //                      << newpos << endl;            getSegmentCanvas()->slotScrollHoriz(newpos);        }        m_segmentCanvas->setPointerPos(pos);    }}voidTrackEditor::slotPointerDraggedToPosition(timeT position){    int currentPointerPos = m_segmentCanvas->getPointerPos();    double newPosition;    if (handleAutoScroll(currentPointerPos, position, newPosition))        m_segmentCanvas->setPointerPos(int(newPosition));}voidTrackEditor::slotLoopDraggedToPosition(timeT position){    if (m_doc) {        int currentEndLoopPos = m_doc->getComposition().getLoopEnd();        double dummy;        handleAutoScroll(currentEndLoopPos, position, dummy);    }}bool TrackEditor::handleAutoScroll(int currentPosition, timeT newTimePosition, double &newPosition){    SimpleRulerScale *ruler =        dynamic_cast<SimpleRulerScale*>(m_rulerScale);    if (!ruler)        return false;    newPosition = m_segmentCanvas->grid().getRulerScale()->getXForTime(newTimePosition);    double distance = fabs(newPosition - currentPosition);    bool moveDetected = distance >= 1.0;    if (moveDetected) {        if (m_doc && m_doc->getSequenceManager() &&                (m_doc->getSequenceManager()->getTransportStatus() != STOPPED)) {            if (m_playTracking) {                getSegmentCanvas()->slotScrollHoriz(int(double(newTimePosition) / ruler->getUnitsPerPixel()));            }        } else {            int newpos = int(double(newTimePosition) / ruler->getUnitsPerPixel());            getSegmentCanvas()->slotScrollHorizSmallSteps(newpos);            getSegmentCanvas()->doAutoScroll();        }    }    return moveDetected;}voidTrackEditor::slotToggleTracking(){    m_playTracking = !m_playTracking;}voidTrackEditor::slotSetLoop(timeT start, timeT end){    getTopStandardRuler()->getLoopRuler()->slotSetLoopMarker(start, end);    getBottomStandardRuler()->getLoopRuler()->slotSetLoopMarker(start, end);}MultiViewCommandHistory*TrackEditor::getCommandHistory(){    return m_doc->getCommandHistory();}voidTrackEditor::addCommandToHistory(KCommand *command){    getCommandHistory()->addCommand(command);}voidTrackEditor::slotScrollToTrack(int track){    // Find the vertical track pos    int newY = track * getTrackCellHeight();    RG_DEBUG << "TrackEditor::scrollToTrack(" << track <<    ") scrolling to Y " << newY << endl;    // Scroll the segment view; it will scroll tracks by connected signals    //    slotVerticalScrollTrackButtons(newY);    m_segmentCanvas->slotScrollVertSmallSteps(newY);}voidTrackEditor::slotDeleteSelectedSegments(){    KMacroCommand *macro = new KMacroCommand("Delete Segments");    SegmentSelection segments =        m_segmentCanvas->getSelectedSegments();    if (segments.size() == 0)        return ;    SegmentSelection::iterator it;    // Clear the selection before erasing the Segments    // the selection points to    //    m_segmentCanvas->getModel()->clearSelected();    // Create the compound command    //    for (it = segments.begin(); it != segments.end(); it++) {        macro->addCommand(new SegmentEraseCommand(*it,                          &m_doc->getAudioFileManager()));    }    addCommandToHistory(macro);}voidTrackEditor::slotTurnRepeatingSegmentToRealCopies(){    RG_DEBUG << "TrackEditor::slotTurnRepeatingSegmentToRealCopies" << endl;    SegmentSelection segments =        m_segmentCanvas->getSelectedSegments();    if (segments.size() == 0)        return ;    QString text;    if (segments.size() == 1)        text = i18n("Turn Repeating Segment into Real Copies");    else        text = i18n("Turn Repeating Segments into Real Copies");    KMacroCommand *macro = new KMacroCommand(text);    SegmentSelection::iterator it = segments.begin();    for (; it != segments.end(); it++) {        if ((*it)->isRepeating()) {            macro->addCommand(new SegmentRepeatToCopyCommand(*it));        }    }    addCommandToHistory(macro);}voidTrackEditor::slotVerticalScrollTrackButtons(int y){    m_trackButtonScroll->setContentsPos(0, y);}void TrackEditor::dragEnterEvent(QDragEnterEvent *event){    event->accept(QUriDrag::canDecode(event) ||                  QTextDrag::canDecode(event));}void TrackEditor::dropEvent(QDropEvent* event){    QStrList uri;    QString text;    int heightAdjust = 0;    //int widthAdjust = 0;    // Adjust any drop event height position by visible rulers    //    if (m_topStandardRuler && m_topStandardRuler->isVisible())        heightAdjust += m_topStandardRuler->height();    if (m_tempoRuler && m_tempoRuler->isVisible())        heightAdjust += m_tempoRuler->height();    if (m_chordNameRuler && m_chordNameRuler->isVisible())        heightAdjust += m_chordNameRuler->height();    QPoint posInSegmentCanvas =        m_segmentCanvas->viewportToContents        (m_segmentCanvas->         viewport()->mapFrom(this, event->pos()));    int trackPos = m_segmentCanvas->grid().getYBin(posInSegmentCanvas.y());    timeT time =//        m_segmentCanvas->grid().getRulerScale()->//        getTimeForX(posInSegmentCanvas.x());        m_segmentCanvas->grid().snapX(posInSegmentCanvas.x());    if (QUriDrag::decode(event, uri)) {        RG_DEBUG << "TrackEditor::dropEvent() : got URI :"        << uri.first() << endl;        QString uriPath = uri.first();        if (uriPath.endsWith(".rg")) {            emit droppedDocument(uriPath);        } else {            QStrList uris;            QString uri;            if (QUriDrag::decode(event, uris)) uri = uris.first();//            QUriDrag::decodeLocalFiles(event, files);//            QString filePath = files.first();            RG_DEBUG << "TrackEditor::dropEvent() : got URI: "            << uri << endl;            RG_DEBUG << "TrackEditor::dropEvent() : dropping at track pos = "            << trackPos            << ", time = "            << time            << ", x = "            << event->pos().x()            << ", mapped x = "            << posInSegmentCanvas.x()            << endl;            Track* track = m_doc->getComposition().getTrackByPosition(trackPos);            if (track) {                QString audioText;                QTextOStream t(&audioText);                t << uri << "\n";                t << track->getId() << "\n";                t << time << "\n";                emit droppedNewAudio(audioText);            }        }    } else if (QTextDrag::decode(event, text)) {        RG_DEBUG << "TrackEditor::dropEvent() : got text info " << endl;        //<< text << endl;        if (text.endsWith(".rg")) {            emit droppedDocument(text);            //            // WARNING            //            // DO NOT PERFORM ANY OPERATIONS AFTER THAT            // EMITTING THIS SIGNAL TRIGGERS THE LOADING OF A NEW DOCUMENT            // AND AS A CONSEQUENCE THE DELETION OF THIS TrackEditor OBJECT            //        } else {            QTextIStream s(&text);            QString id;            AudioFileId audioFileId;            RealTime startTime, endTime;            // read the audio info checking for end of stream            s >> id;            s >> audioFileId;            s >> startTime.sec;            s >> startTime.nsec;            s >> endTime.sec;            s >> endTime.nsec;            if (id == "AudioFileManager") { // only create something if this is data from the right client                // Drop this audio segment if we have a valid track number                // (could also check for time limits too)                //                Track* track = m_doc->getComposition().getTrackByPosition(trackPos);                if (track) {                    RG_DEBUG << "TrackEditor::dropEvent() : dropping at track pos = "                    << trackPos                    << ", time = "                    << time                    << ", x = "                    << event->pos().x()                    << ", map = "                    << posInSegmentCanvas.x()                    << endl;                    QString audioText;                    QTextOStream t(&audioText);                    t << audioFileId << "\n";                    t << track->getId() << "\n";                    t << time << "\n"; // time on canvas                    t << startTime.sec << "\n";                    t << startTime.nsec << "\n";                    t << endTime.sec << "\n";                    t << endTime.nsec << "\n";                    emit droppedAudio(audioText);                }            } else {                KMessageBox::sorry(this, i18n("You can't drop files into Rosegarden from this client.  Try using Konqueror instead."));            }        }        // SEE WARNING ABOVE - DON'T DO ANYTHING, THIS OBJECT MAY NOT        // EXIST AT THIS POINT.    }}}#include "TrackEditor.moc"

⌨️ 快捷键说明

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