PasteConductorDataCommand::PasteConductorDataCommand(Composition *composition,
        Clipboard *clipboard,
        timeT t) :
        NamedCommand(tr("Paste Tempos and Time Signatures")),
        m_composition(composition),
        m_clipboard(new Clipboard(*clipboard)),
        m_t0(t)
{
    if(m_clipboard->hasNominalRange()) {
        timeT start, end;
        m_clipboard->getNominalRange(start, end);
        timeT range = end - start;

        // Get any tempo and timesig data that we're going to erase
        // in execute. 
        m_temposPre   = TempoSelection(*m_composition, t,
                                       t + range, false);
        m_timesigsPre = TimeSignatureSelection(*m_composition, t,
                                               t + range, false);
    }
}
Example #2
0
void
Clipboard::clearTimeSignatureSelection()
{
    m_timeSigSelection = TimeSignatureSelection();
    m_haveTimeSigSelection = false;
}
void
OpenOrCloseRangeCommand::execute()
{
    Profiler profiler("OpenOrCloseRangeCommand::execute()");
    timeT offset = m_endTime - m_beginTime;
    if (!m_opening)
        offset = -offset;

    if (m_opening) {
        if (offset + m_composition->getDuration() >
                m_composition->getEndMarker()) {
            m_composition->setEndMarker(m_composition->getBarEndForTime(
                m_composition->getDuration() + offset));
        }
    }

    if (!m_prepared) {

        timeT movingFrom = m_beginTime;
        if (!m_opening)
            movingFrom = m_endTime;

        for (Composition::iterator i = m_composition->begin();
                i != m_composition->end(); ++i) {

            if ((*i)->getStartTime() >= movingFrom) {
                m_moving.push_back(*i);
            }
        }

        m_timesigsPre = TimeSignatureSelection
                        (*m_composition, movingFrom,
                         m_composition->getEndMarker(),
                         false);

        m_temposPre = TempoSelection
                      (*m_composition, movingFrom,
                       m_composition->getEndMarker(),
                       false);

        m_markersPre = MarkerSelection
            (*m_composition, movingFrom,
             m_composition->getEndMarker());

        for (TimeSignatureSelection::timesigcontainer::const_iterator i =
                    m_timesigsPre.begin(); i != m_timesigsPre.end(); ++i) {

            timeT t = i->first;
            TimeSignature sig = i->second;
            m_timesigsPost.addTimeSignature(t + offset, sig);
        }

        for (TempoSelection::tempocontainer::const_iterator i =
                    m_temposPre.begin(); i != m_temposPre.end(); ++i) {

            timeT t = i->first;
            TempoSelection::tempochange change = i->second;
            m_temposPost.addTempo(t + offset, change.first, change.second);
        }

        for (MarkerSelection::Container::const_iterator i =
                    m_markersPre.begin(); i != m_markersPre.end(); ++i) {

            m_markersPost.addCopyAtOffset(offset, *i);
        }
        
        m_prepared = true;
    }

    // For each segment in the moving list
    for (std::vector<Segment *>::iterator i = m_moving.begin();
            i != m_moving.end(); ++i) {

// RG_DEBUG << "Moving segment on track " << (*i)->getTrack() << " from " << 
//     (*i)->getStartTime() << " to " << ((*i)->getStartTime() + offset) << 
//     " (current end time is " << (*i)->getEndTime() << ", end marker is " << 
//     (*i)->getEndMarkerTime() << ")" << endl;

        // Move the segment
        (*i)->setStartTime((*i)->getStartTime() + offset);
    }


    m_timesigsPre.RemoveFromComposition(m_composition);
    m_timesigsPost.AddToComposition(m_composition);
    m_temposPre.RemoveFromComposition(m_composition);
    m_temposPost.AddToComposition(m_composition);
    m_markersPre.RemoveFromComposition(m_composition);
    m_markersPost.AddToComposition(m_composition);

    // Preserve the loop range for undo
    m_loopBegin = m_composition->getLoopStart();
    m_loopEnd = m_composition->getLoopEnd();

    // If we are opening up a range, try to preserve the loop range.
    if (m_opening) {
        RosegardenDocument *doc = RosegardenMainWindow::self()->getDocument();

        // If the paste point is prior to the loop range
        if (m_beginTime <= m_loopBegin) {
            // Shift the loop range right.
            doc->setLoop(m_loopBegin + offset, m_loopEnd + offset);
        } else if (m_beginTime < m_loopEnd) {
            // The paste point is within the loop range
            
            // Just shift the end point to expand the loop range
            doc->setLoop(m_loopBegin, m_loopEnd + offset);
        } else {
            // The paste point is after the loop range, so leave it alone.
        }
    }

    // If we are closing the range, the loop range and the range to be removed
    // are the same.  We will leave the loop range alone in case the user wants
    // to Cut Range again (or Delete Range if that is ever added to the UI).
    m_hasExecuted = true;
}