예제 #1
0
CopyCommand::CopyCommand(EventSelection &selection,
                         Clipboard *clipboard) :
        NamedCommand(getGlobalName()),
        m_targetClipboard(clipboard)
{
    m_sourceClipboard = new Clipboard;
    m_savedClipboard = 0;
    std::string label = selection.getSegment().getLabel();
    m_sourceClipboard->newSegment(&selection)->setLabel(
            appendLabel(label, qstrtostr(tr("(excerpt)"))));
}
void
AudioSegmentInsertCommand::execute()
{
    if (!m_segment) {
        // Create and insert Segment
        //
        m_segment = new Segment(Segment::Audio);
        m_segment->setTrack(m_track);
        m_segment->setStartTime(m_startTime);
        m_segment->setAudioStartTime(m_audioStartTime);
        m_segment->setAudioEndTime(m_audioEndTime);
        m_segment->setAudioFileId(m_audioFileId);

        // Set color for audio segment (DMM)
        //
        m_segment->setColourIndex(GUIPalette::AudioDefaultIndex);

        // Calculate end time
        //
        RealTime startTime =
            m_composition->getElapsedRealTime(m_startTime);

        RealTime endTime =
            startTime + m_audioEndTime - m_audioStartTime;

        timeT endTimeT = m_composition->getElapsedTimeForRealTime(endTime);

        RG_DEBUG << "AudioSegmentInsertCommand::execute : start timeT "
        << m_startTime << ", startTime " << startTime << ", audioStartTime " << m_audioStartTime << ", audioEndTime " << m_audioEndTime << ", endTime " << endTime << ", end timeT " << endTimeT << endl;

        m_segment->setEndTime(endTimeT);

        if (endTimeT > m_composition->getEndMarker()) {
            m_composition->setEndMarker(m_composition->getBarEndForTime(endTimeT));
        }

        // Label by audio file name
        //
        AudioFile *aF =
            m_audioFileManager->getAudioFile(m_audioFileId);

        if (aF) {
            std::string label = aF->getLabel();
            m_segment->setLabel(appendLabel(label, qstrtostr(tr("(inserted)"))));
        } else {
            m_segment->setLabel(qstrtostr( tr("unknown audio file")) );
        }
        m_composition->addSegment(m_segment);
    } else {
        m_composition->addSegment(m_segment);
    }

    m_detached = false;
}
예제 #3
0
void
SegmentQuickCopyCommand::execute()
{
    if (!m_segment) {
        m_segment = m_segmentToCopy->clone(false);
        std::string label = m_segment->getLabel();
        m_segment->setLabel(appendLabel(label, qstrtostr(tr("(copied)"))));
    }
    m_composition->addSegment(m_segment);
    m_detached = false;
}
예제 #4
0
DataFieldWidget::DataFieldWidget(IDataForms *ADataForms, const IDataField &AField, bool AReadOnly, QWidget *AParent) : QWidget(AParent)
{
	FField = AField;
	FReadOnly = AReadOnly;
	FDataForms = ADataForms;
	FMediaWidget = NULL;

	setLayout(new QVBoxLayout(this));
	layout()->setMargin(0);

	if (FDataForms->isMediaValid(AField.media))
	{
		FMediaWidget = FDataForms->mediaWidget(AField.media,this);
		layout()->addWidget(FMediaWidget->instance());
	}

	QString label = !FField.label.isEmpty() ? FField.label : FField.desc;
	QString desc = !FField.desc.isEmpty() ? QString("<span>%1</span>").arg(Qt::escape(FField.desc)) : QString::null;
	if (!FReadOnly && FField.type == DATAFIELD_TYPE_BOOLEAN)
	{
		FCheckBox = new QCheckBox(this);
		FCheckBox->setText(label + (FField.required ? QString("*") : QString::null));
		FCheckBox->setToolTip(desc);
		FCheckBox->installEventFilter(this);
		connect(FCheckBox,SIGNAL(stateChanged(int)),SLOT(changed()));
		layout()->addWidget(FCheckBox);
	}
	else if (FField.type == DATAFIELD_TYPE_FIXED)
	{
		FLabel = new QLabel(this);
		FLabel->setWordWrap(true);
		FLabel->setTextFormat(Qt::PlainText);
		layout()->addWidget(FLabel);
	}
	else if (!FReadOnly && FField.type == DATAFIELD_TYPE_LISTSINGLE)
	{
		FComboBox = new QComboBox(this);
		appendLabel(label,FComboBox);
		foreach(const IDataOption &option, FField.options)
			FComboBox->addItem(option.label, option.value);
		if (FField.validate.method == DATAVALIDATE_METHOD_OPEN)
		{
			FComboBox->setEditable(true);
			FComboBox->setValidator(FDataForms->dataValidator(FField.validate,FComboBox));
			FLineEdit = FComboBox->lineEdit();
			connect(FLineEdit,SIGNAL(editTextChanged(const QString &)),SIGNAL(changed()));
		}
		FComboBox->setToolTip(desc);
		FComboBox->installEventFilter(this);
		connect(FComboBox,SIGNAL(currentIndexChanged(const QString &)),SIGNAL(changed()));
		layout()->addWidget(FComboBox);
	}
예제 #5
0
CopyCommand::CopyCommand(SegmentSelection &selection,
                         Clipboard *clipboard) :
        NamedCommand(getGlobalName()),
        m_targetClipboard(clipboard)
{
    m_sourceClipboard = new Clipboard;
    m_savedClipboard = 0;

    for (SegmentSelection::iterator i = selection.begin();
            i != selection.end(); ++i) {
        std::string label = (*i)->getLabel();
        m_sourceClipboard->newSegment(*i)->setLabel(
                appendLabel(label, qstrtostr(tr("(copied)"))));
    }
}
void
AudioSegmentSplitCommand::execute()
{
    if (!m_newSegment) {

        m_newSegment = new Segment(Segment::Audio);

        // Basics
        //
        m_newSegment->setAudioFileId(m_segment->getAudioFileId());
        m_newSegment->setTrack(m_segment->getTrack());

        // Get the RealTime split time
        //
        RealTime splitDiff =
            m_segment->getComposition()->getRealTimeDifference(
                m_segment->getStartTime(), m_splitTime);

        // Set audio start and end
        //
        m_newSegment->setAudioStartTime
        (m_segment->getAudioStartTime() + splitDiff);
        m_newSegment->setAudioEndTime(m_segment->getAudioEndTime());

        // Insert into composition before setting end time
        //
        m_segment->getComposition()->addSegment(m_newSegment);

        // Set start and end times
        //
        m_newSegment->setStartTime(m_splitTime);
        m_newSegment->setEndTime(m_segment->getEndTime());

        // Set original end time
        //
        //        m_previousEndAudioTime = m_segment->getAudioEndTime();
        //        m_segment->setAudioEndTime(m_newSegment->getAudioStartTime());

        RG_DEBUG << "AudioSegmentSplitCommand::execute: Set end audio of left segment to " << m_newSegment->getAudioStartTime() << endl;


        // Set labels
        //
        std::string label = m_segment->getLabel();
        m_segment->setLabel(appendLabel(label, qstrtostr(tr("(split)"))));
        m_newSegment->setLabel(m_segment->getLabel());

        // Set color
        //
        m_newSegment->setColourIndex(m_segment->getColourIndex());
    }

    // Resize left hand Segment
    //
    const timeT *emt = m_segment->getRawEndMarkerTime();
    if (emt) {
        m_previousEndMarkerTime = new timeT(*emt);
    } else {
        m_previousEndMarkerTime = 0;
    }

    RG_DEBUG << "AudioSegmentSplitCommand::execute: Setting end marker of left segment to " << m_splitTime << endl;

    m_segment->setEndMarkerTime(m_splitTime);

    if (!m_newSegment->getComposition()) {
        m_segment->getComposition()->addSegment(m_newSegment);
    }

    m_detached = false;

}
예제 #7
0
SegmentSplitCommand::SegmentVec
SegmentSplitCommand::
getNewSegments(Segment *segment, timeT splitTime, bool keepLabel)
{
    Segment * newSegmentA = segment->clone(false);
    Segment * newSegmentB = new Segment();

    newSegmentB->setTrack(segment->getTrack());
    newSegmentB->setStartTime(splitTime);

    // !!! Set Composition?
    
    Event *clefEvent = 0;
    Event *keyEvent = 0;

    // Copy the last occurrence of clef and key
    // from the left hand side of the split (nb. timesig events
    // don't appear in segments, only in composition)
    //
    Segment::iterator it = segment->findTime(splitTime);

    while (it != segment->begin()) {

        --it;

        if (!clefEvent && (*it)->isa(Clef::EventType)) {
            clefEvent = new Event(**it, splitTime);
        }

        if (!keyEvent && (*it)->isa(Key::EventType)) {
            keyEvent = new Event(**it, splitTime);
        }

        if (clefEvent && keyEvent)
            break;
    }

    // Insert relevant meta info if we've found some
    //
    if (clefEvent)
        newSegmentB->insert(clefEvent);

    if (keyEvent)
        newSegmentB->insert(keyEvent);

    // Copy through the Events
    //
    it = segment->findTime(splitTime);

    if (it != segment->end() && (*it)->getAbsoluteTime() > splitTime) {
        newSegmentB->fillWithRests((*it)->getAbsoluteTime());
    }

    while (it != segment->end()) {
        newSegmentB->insert(new Event(**it));
        ++it;
    }
    newSegmentB->setEndTime(segment->getEndTime());
    newSegmentB->setEndMarkerTime(segment->getEndMarkerTime());

    // Set labels
    //
    std::string label = segment->getLabel();
    newSegmentA->setLabel(label);
    newSegmentB->setLabel(label);
    if (!keepLabel) {
        newSegmentA->setLabel(appendLabel(label, qstrtostr(tr("(split)"))));
        newSegmentB->setLabel(appendLabel(label, qstrtostr(tr("(split)"))));
    }

    newSegmentB->setColourIndex(segment->getColourIndex());
    newSegmentB->setTranspose(segment->getTranspose());
    newSegmentB->setDelay(segment->getDelay());

    // Resize left hand Segment
    //
    std::vector<Event *> toErase, toInsert;
    for (Segment::iterator i = newSegmentA->findTime(splitTime);
         i != newSegmentA->end(); ++i) {
        if ((*i)->getAbsoluteTime() >= splitTime) break;
        if ((*i)->getAbsoluteTime() + (*i)->getDuration() > splitTime) {
            Event *e = new Event(**i, (*i)->getAbsoluteTime(),
                                 splitTime - (*i)->getAbsoluteTime());
            toErase.push_back(*i);
            toInsert.push_back(e);
        }
    }

    for (size_t i = 0; i < toErase.size(); ++i) {
        newSegmentA->eraseSingle(toErase[i]);
        delete toErase[i];
    }
    for (size_t i = 0; i < toInsert.size(); ++i) {
        newSegmentA->insert(toInsert[i]);
    }

    newSegmentA->setEndTime(splitTime);
    newSegmentA->setEndMarkerTime(splitTime);
    SegmentVec segmentVec;
    segmentVec.reserve(2);
    segmentVec.push_back(newSegmentA);
    segmentVec.push_back(newSegmentB);
    return segmentVec;
}
void
AudioSegmentRescaleCommand::execute()
{
    /* timeT startTime = m_segment->getStartTime(); */

    if (m_segment->getType() != Segment::Audio) {
        return;
    }

    bool failed = false;

    if (!m_newSegment) {

        m_newSegment = m_segment->clone(false);

        std::string label = m_newSegment->getLabel();
        m_newSegment->setLabel(appendLabel(label, qstrtostr(tr("(rescaled)"))));

        AudioFileId sourceFileId = m_segment->getAudioFileId();
        float absoluteRatio = m_ratio;

        std::cerr << "AudioSegmentRescaleCommand: segment file id " << sourceFileId << ", given ratio " << m_ratio << std::endl;

        if (m_segment->getStretchRatio() != 1.f &&
            m_segment->getStretchRatio() != 0.f) {
            sourceFileId = m_segment->getUnstretchedFileId();
            absoluteRatio *= m_segment->getStretchRatio();
            std::cerr << "AudioSegmentRescaleCommand: unstretched file id " << sourceFileId << ", prev ratio " << m_segment->getStretchRatio() << ", resulting ratio " << absoluteRatio << std::endl;
        }

        if (!m_timesGiven) {
            m_endMarkerTime = m_segment->getStartTime() +
                (m_segment->getEndMarkerTime() - m_segment->getStartTime()) * m_ratio;
        }

        try {
            m_fid = m_stretcher->getStretchedAudioFile(sourceFileId,
                                                       absoluteRatio);
            m_newSegment->setAudioFileId(m_fid);
            m_newSegment->setUnstretchedFileId(sourceFileId);
            m_newSegment->setStretchRatio(absoluteRatio);
            m_newSegment->setAudioStartTime(m_segment->getAudioStartTime() *
                                            m_ratio);
            if (m_timesGiven) {
                m_newSegment->setStartTime(m_startTime);
                m_newSegment->setAudioEndTime(m_segment->getAudioEndTime() *
                                              m_ratio);
                m_newSegment->setEndMarkerTime(m_endMarkerTime);
            } else {
                m_newSegment->setEndMarkerTime(m_endMarkerTime);
                m_newSegment->setAudioEndTime(m_segment->getAudioEndTime() *
                                              m_ratio);
            }
        } catch (SoundFile::BadSoundFileException e) {
            std::cerr << "AudioSegmentRescaleCommand: ERROR: BadSoundFileException: "
                      << e.getMessage() << std::endl;
            delete m_newSegment;
            m_newSegment = 0;
            m_fid = -1;
            failed = true;
        } catch (AudioFileManager::BadAudioPathException e) {
            std::cerr << "AudioSegmentRescaleCommand: ERROR: BadAudioPathException: "
                      << e.getMessage() << std::endl;
            delete m_newSegment;
            m_newSegment = 0;
            m_fid = -1;
            failed = true;
        } catch (AudioFileTimeStretcher::CancelledException e) {
            std::cerr << "AudioSegmentRescaleCommand: ERROR: Rescale cancelled" << std::endl;
            delete m_newSegment;
            m_newSegment = 0;
            m_fid = -1;
            failed = true;
        }
    }

    if (failed) return;

    m_segment->getComposition()->addSegment(m_newSegment);
    m_segment->getComposition()->detachSegment(m_segment);

//    m_newSegment->setEndMarkerTime
//    (startTime + rescale(m_segment->getEndMarkerTime() - startTime));

    m_detached = true;
}
void
SegmentAutoSplitCommand::execute()
{
    if (m_newSegments.empty()) {

        std::vector<AutoSplitPoint> splitPoints;

        Clef clef;
        Key key;
        timeT segmentStart = m_segment->getStartTime();
        timeT lastSoundTime = segmentStart;
        timeT lastSplitTime = segmentStart - 1;

        for (Segment::iterator i = m_segment->begin();
                m_segment->isBeforeEndMarker(i); ++i) {

            timeT myTime = (*i)->getAbsoluteTime();
            int barNo = m_composition->getBarNumber(myTime);

            if ((*i)->isa(Clef::EventType)) {
                clef = Clef(**i);
            } else if ((*i)->isa(Key::EventType)) {
                key = Key(**i);
            }

            if (myTime <= lastSplitTime)
                continue;

            bool newTimeSig = false;
            TimeSignature tsig =
                m_composition->getTimeSignatureInBar(barNo, newTimeSig);

            if (newTimeSig) {

                // If there's a new time sig in this bar and we haven't
                // already made a split in this bar, make one

                if (splitPoints.empty() ||
                        m_composition->getBarNumber
                        (splitPoints[splitPoints.size() - 1].time) < barNo) {

                    splitPoints.push_back(AutoSplitPoint(myTime, lastSoundTime,
                                                         clef, key));
                    lastSoundTime = lastSplitTime = myTime;
                }

            } else if ((*i)->isa(Note::EventRestType)) {

                // Otherwise never start a subsegment on a rest

                continue;

            } else {

                // When we meet a non-rest event, start a new split
                // if an entire bar has passed since the last non-rest event

                int lastSoundBarNo = m_composition->getBarNumber(lastSoundTime);

                if (lastSoundBarNo < barNo - 1 ||
                        (lastSoundBarNo == barNo - 1 &&
                         m_composition->getBarStartForTime(lastSoundTime) ==
                         lastSoundTime &&
                         lastSoundTime > segmentStart)) {

                    splitPoints.push_back
                    (AutoSplitPoint
                     (m_composition->getBarStartForTime(myTime), lastSoundTime,
                      clef, key));
                    lastSplitTime = myTime;
                }
            }

            lastSoundTime = std::max(lastSoundTime, myTime + (*i)->getDuration());
        }

        for (size_t split = 0; split <= splitPoints.size(); ++split) {

            Segment *newSegment = new Segment();
            newSegment->setTrack(m_segment->getTrack());
            std::string label = m_segment->getLabel();
            newSegment->setLabel(appendLabel(label, qstrtostr(tr("(part %1)").arg(split + 1))));
            newSegment->setColourIndex(m_segment->getColourIndex());

            timeT startTime = segmentStart;
            if (split > 0) {

                RG_DEBUG << "Auto-split point " << split - 1 << ": time "
                << splitPoints[split - 1].time << ", lastSoundTime "
                << splitPoints[split - 1].lastSoundTime << endl;

                startTime = splitPoints[split - 1].time;
                newSegment->insert(splitPoints[split - 1].clef.getAsEvent(startTime));
                newSegment->insert(splitPoints[split - 1].key.getAsEvent(startTime));
            }

            Segment::iterator i = m_segment->findTime(startTime);

            // A segment has to contain at least one note to be a worthy
            // candidate for adding back into the composition
            bool haveNotes = false;

            while (m_segment->isBeforeEndMarker(i)) {
                timeT t = (*i)->getAbsoluteTime();
                if (split < splitPoints.size() &&
                        t >= splitPoints[split].lastSoundTime)
                    break;
                if ((*i)->isa(Note::EventType))
                    haveNotes = true;
                newSegment->insert(new Event(**i));
                ++i;
            }

            if (haveNotes)
                m_newSegments.push_back(newSegment);
            else
                delete newSegment;
        }
    }

    m_composition->detachSegment(m_segment);
    for (size_t i = 0; i < m_newSegments.size(); ++i) {
        m_composition->addSegment(m_newSegments[i]);
    }
    m_detached = true;
}