From: Simon A. Eugster Date: Fri, 17 Feb 2012 09:15:48 +0000 (+0100) Subject: Audio align now also handles resizes. X-Git-Url: https://git.sesse.net/?a=commitdiff_plain;h=d2e30a0fa75aa466d2bead42c6a2bfec01c83373;p=kdenlive Audio align now also handles resizes. --- diff --git a/TODO b/TODO index 01739df2..68fd6a03 100644 --- a/TODO +++ b/TODO @@ -10,6 +10,7 @@ Input proxy creation input method (register mimetype in file dialog, custom widget) effect support (a, v, av, special effects (freeze, speed)) + support for multi-channel sound (5.1, ...) => modules for avformat, qimage/gtk_image(?), generators (slideshow, color, f0r) diff --git a/src/customtrackview.cpp b/src/customtrackview.cpp index 9baf23b8..f45eabe2 100644 --- a/src/customtrackview.cpp +++ b/src/customtrackview.cpp @@ -4304,7 +4304,7 @@ bool CustomTrackView::moveClip(const ItemInfo &start, const ItemInfo &end, bool Mlt::Producer *prod = item->getProducer(end.track); qDebug() << "Moving item " << (long)item << " from .. to:"; - qDebug().maybeSpace() << item->info(); + qDebug() << item->info(); qDebug() << start; qDebug() << end; bool success = m_document->renderer()->mltMoveClip((int)(m_document->tracksCount() - start.track), (int)(m_document->tracksCount() - end.track), @@ -6006,7 +6006,7 @@ void CustomTrackView::alignAudio() } } if (!referenceOK) { - emit displayMessage(i18n("Audio alignment reference not yet set."), DefaultMessage); + emit displayMessage(i18n("Audio alignment reference not yet set."), InformationMessage); return; } @@ -6016,7 +6016,9 @@ void CustomTrackView::alignAudio() if (item->type() == AVWIDGET) { ClipItem *clip = static_cast(item); if (clip->clipType() == AV || clip->clipType() == AUDIO) { - AudioEnvelope *envelope = new AudioEnvelope(clip->getProducer(clip->track())); + AudioEnvelope *envelope = new AudioEnvelope(clip->getProducer(clip->track()), + clip->info().cropStart.frames(m_document->fps()), + clip->info().cropDuration.frames(m_document->fps())); int index = m_audioCorrelator->addChild(envelope); int shift = m_audioCorrelator->getShift(index); counter++; @@ -6032,16 +6034,39 @@ void CustomTrackView::alignAudio() qDebug() << "(eventually)"; qDebug() << "(maybe)"; + + QUndoCommand *moveCommand = new QUndoCommand(); + GenTime add(shift, m_document->fps()); ItemInfo start = clip->info(); + ItemInfo end = start; end.startPos = m_audioAlignmentReference->info().startPos + add; end.endPos = end.startPos + start.cropDuration; - QUndoCommand *moveCommand = new QUndoCommand(); + if ( end.startPos.seconds() < 0 ) { + // Clip would start before 0, so crop it first + qDebug() << "Need to crop clip. " << start; + + + GenTime cropBy = -end.startPos; + qDebug() << "end.startPos: " << end.startPos.toString() << ", cropBy: " << cropBy.toString(); + + ItemInfo resized = start; + resized.startPos += cropBy; + + resizeClip(start, resized); + new ResizeClipCommand(this, start, resized, false, false, moveCommand); + + start = clip->info(); + end.startPos += cropBy; + + qDebug() << "Clip cropped. " << start; + qDebug() << "Moving to: " << end; + } + moveCommand->setText(i18n("Auto-align clip")); new MoveClipCommand(this, start, end, true, moveCommand); -// moveClip(start, end, true); updateTrackDuration(clip->track(), moveCommand); m_commandStack->push(moveCommand); diff --git a/src/gentime.h b/src/gentime.h index e927eabb..8b735b44 100644 --- a/src/gentime.h +++ b/src/gentime.h @@ -59,12 +59,19 @@ public: /* * Operators. */ + + /// Unary minus + GenTime operator -() { + return GenTime(-m_time); + } + /// Addition GenTime & operator+=(GenTime op) { m_time += op.m_time; return *this; } + /// Subtraction GenTime & operator-=(GenTime op) { m_time -= op.m_time; return *this; @@ -115,7 +122,7 @@ public: } private: - /** Holds the time for this object. */ + /** Holds the time in seconds for this object. */ double m_time; /** A delta value that is used to get around floating point rounding issues. */ diff --git a/src/lib/audio/audioEnvelope.cpp b/src/lib/audio/audioEnvelope.cpp index 7849372d..aaad918c 100644 --- a/src/lib/audio/audioEnvelope.cpp +++ b/src/lib/audio/audioEnvelope.cpp @@ -16,14 +16,22 @@ #include #include -AudioEnvelope::AudioEnvelope(Mlt::Producer *producer) : +AudioEnvelope::AudioEnvelope(Mlt::Producer *producer, int offset, int length) : m_envelope(NULL), m_producer(producer), + m_offset(offset), + m_length(length), m_envelopeSize(producer->get_length()), m_envelopeStdDevCalculated(false), m_envelopeIsNormalized(false) { m_info = new AudioInfo(m_producer); + + Q_ASSERT(m_offset >= 0); + if (m_length > 0) { + Q_ASSERT(m_length+m_offset <= m_envelopeSize); + m_envelopeSize = m_length; + } } AudioEnvelope::~AudioEnvelope() @@ -71,7 +79,8 @@ void AudioEnvelope::loadEnvelope() QTime t; t.start(); - m_producer->seek(0); + int count = 0; + m_producer->seek(m_offset); m_producer->set_speed(1.0); // This is necessary, otherwise we don't get any new frames in the 2nd run. for (int i = 0; i < m_envelopeSize; i++) { @@ -92,10 +101,15 @@ void AudioEnvelope::loadEnvelope() m_envelopeMax = sum; } -// std::cout << position << "|" << m_producer->get_playtime() -// << "-" << m_producer->get_in() << "+" << m_producer->get_out() << " "; + std::cout << position << "|" << m_producer->get_playtime() + << "-" << m_producer->get_in() << "+" << m_producer->get_out() << " "; delete frame; + + count++; + if (m_length > 0 && count > m_length) { + break; + } } m_envelopeMean /= m_envelopeSize; std::cout << "Calculating the envelope (" << m_envelopeSize << " frames) took " diff --git a/src/lib/audio/audioEnvelope.h b/src/lib/audio/audioEnvelope.h index c0390334..7e12d724 100644 --- a/src/lib/audio/audioEnvelope.h +++ b/src/lib/audio/audioEnvelope.h @@ -26,7 +26,7 @@ class QImage; class AudioEnvelope { public: - AudioEnvelope(Mlt::Producer *producer); + AudioEnvelope(Mlt::Producer *producer, int offset = 0, int length = 0); ~AudioEnvelope(); /// Returns the envelope, calculates it if necessary. @@ -46,6 +46,9 @@ private: Mlt::Producer *m_producer; AudioInfo *m_info; + int m_offset; + int m_length; + int m_envelopeSize; int64_t m_envelopeMax; int64_t m_envelopeMean;