Logo Search packages:      
Sourcecode: kdenlive version File versions

void CustomTrackView::doSplitAudio ( const GenTime pos,
int  track,
EffectsList  effects,
bool  split 
)

Seperates the audio of a clip to a audio track.

Parameters:
posPosition of the clip to split
trackTrack of the clip
splitSplit or unsplit

Definition at line 5962 of file customtrackview.cpp.

References DocClipBase::audioProducer(), ClipItem::effectAt(), GenTime::frames(), Render::mltTrackDuration(), DocClipBase::producer(), and DocClipBase::videoProducer().

{
    ClipItem *clip = getClipItemAt(pos, track);
    if (clip == NULL) {
        kDebug() << "// Cannot find clip to split!!!";
        return;
    }
    if (split) {
        int start = pos.frames(m_document->fps());
        int freetrack = m_document->tracksCount() - track - 1;

        // do not split audio when we are on an audio track
        if (m_document->trackInfoAt(freetrack).type == AUDIOTRACK)
            return;

        for (; freetrack > 0; freetrack--) {
            //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
            if (m_document->trackInfoAt(freetrack - 1).type == AUDIOTRACK && !m_document->trackInfoAt(freetrack - 1).isLocked) {
                //kDebug() << "// CHK DOC TRK:" << freetrack << ", DUR:" << m_document->renderer()->mltTrackDuration(freetrack);
                if (m_document->renderer()->mltTrackDuration(freetrack) < start || m_document->renderer()->mltGetSpaceLength(pos, freetrack, false) >= clip->cropDuration().frames(m_document->fps())) {
                    //kDebug() << "FOUND SPACE ON TRK: " << freetrack;
                    break;
                }
            }
        }
        kDebug() << "GOT TRK: " << track;
        if (freetrack == 0) {
            emit displayMessage(i18n("No empty space to put clip audio"), ErrorMessage);
        } else {
            ItemInfo info = clip->info();
            info.track = m_document->tracksCount() - freetrack;
            addClip(clip->xml(), clip->clipProducer(), info, clip->effectList());
            scene()->clearSelection();
            clip->setSelected(true);
            ClipItem *audioClip = getClipItemAt(start, info.track);
            if (audioClip) {
                clip->setVideoOnly(true);
                if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - track, start, clip->baseClip()->videoProducer()) == false) {
                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, track), ErrorMessage);
                }
                if (m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, start, clip->baseClip()->audioProducer(info.track)) == false) {
                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", start, info.track), ErrorMessage);
                }
                audioClip->setSelected(true);
                audioClip->setAudioOnly(true);

                // keep video effects, move audio effects to audio clip
                int videoIx = 0;
                int audioIx = 0;
                for (int i = 0; i < effects.count(); ++i) {
                    if (effects.at(i).attribute("type") == "audio") {
                        deleteEffect(m_document->tracksCount() - track, pos, clip->effectAt(videoIx));
                        audioIx++;
                    } else {
                        deleteEffect(freetrack, pos, audioClip->effectAt(audioIx));
                        videoIx++;
                    }
                }

                groupSelectedItems(false, true);
            }
        }
    } else {
        // unsplit clip: remove audio part and change video part to normal clip
        if (clip->parentItem() == NULL || clip->parentItem()->type() != GROUPWIDGET) {
            kDebug() << "//CANNOT FIND CLP GRP";
            return;
        }
        AbstractGroupItem *grp = static_cast <AbstractGroupItem *>(clip->parentItem());
        QList<QGraphicsItem *> children = grp->childItems();
        if (children.count() != 2) {
            kDebug() << "//SOMETHING IS WRONG WITH CLP GRP";
            return;
        }
        for (int i = 0; i < children.count(); i++) {
            if (children.at(i) != clip) {
                ClipItem *clp = static_cast <ClipItem *>(children.at(i));
                ItemInfo info = clip->info();
                deleteClip(clp->info());
                clip->setVideoOnly(false);

                if (!m_document->renderer()->mltUpdateClipProducer(m_document->tracksCount() - info.track, info.startPos.frames(m_document->fps()), clip->baseClip()->producer(info.track))) {
                    emit displayMessage(i18n("Cannot update clip (time: %1, track: %2)", info.startPos.frames(m_document->fps()), info.track), ErrorMessage);
                }

                // re-add audio effects
                for (int i = 0; i < effects.count(); ++i) {
                    if (effects.at(i).attribute("type") == "audio") {
                        addEffect(m_document->tracksCount() - track, pos, effects.at(i));
                    }
                }

                break;
            }
        }
        clip->setFlag(QGraphicsItem::ItemIsMovable, true);
        m_document->clipManager()->removeGroup(grp);
        scene()->destroyItemGroup(grp);
    }
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index