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),
}
}
if (!referenceOK) {
- emit displayMessage(i18n("Audio alignment reference not yet set."), DefaultMessage);
+ emit displayMessage(i18n("Audio alignment reference not yet set."), InformationMessage);
return;
}
if (item->type() == AVWIDGET) {
ClipItem *clip = static_cast<ClipItem*>(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++;
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);
#include <cmath>
#include <iostream>
-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()
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++) {
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 "