with Block::set_length_and_* functions, keep the speeds correct
With differently set speeds, these functions would mess with the timing in ways that would be confusing to the user. Now they act in a much more intuitive way and also prevent negative media times.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include <QUndoCommand>
|
||||
|
||||
#include "node/block/clip/clip.h"
|
||||
#include "node/output/track/track.h"
|
||||
#include "widget/slider/floatslider.h"
|
||||
#include "widget/slider/timeslider.h"
|
||||
|
||||
|
||||
@@ -97,7 +97,14 @@ void Block::set_length_and_media_out(const rational &length)
|
||||
return;
|
||||
}
|
||||
|
||||
set_media_out(media_out() + (length - this->length()));
|
||||
rational media_out_diff = length - this->length();
|
||||
|
||||
// Try to maintain the same speed (which is determined by the media in to out points)
|
||||
if (media_length() != this->length()) {
|
||||
media_out_diff = media_out_diff / this->length() * media_length();
|
||||
}
|
||||
|
||||
set_media_out(media_out() + media_out_diff);
|
||||
|
||||
set_length(length);
|
||||
}
|
||||
@@ -110,8 +117,15 @@ void Block::set_length_and_media_in(const rational &length)
|
||||
return;
|
||||
}
|
||||
|
||||
rational media_in_diff = this->length() - length;
|
||||
|
||||
// Try to maintain the same speed (which is determined by the media in to out points)
|
||||
if (media_length() != this->length()) {
|
||||
media_in_diff = media_in_diff / this->length() * media_length();
|
||||
}
|
||||
|
||||
// Calculate media_in adjustment
|
||||
set_media_in(media_in() + (this->length() - length));
|
||||
set_media_in(media_in() + media_in_diff);
|
||||
|
||||
// Set the length without setting media out
|
||||
set_length(length);
|
||||
|
||||
@@ -54,19 +54,15 @@ NodeValueTable AudioRenderWorker::RenderBlock(const TrackOutput *track, const Ti
|
||||
// Stretch samples here
|
||||
if (b->media_length() != b->length()) {
|
||||
QByteArray speed_adjusted_samples;
|
||||
double clip_speed = b->speed();
|
||||
int sample_count = audio_params_.bytes_to_samples(samples_from_this_block.size());
|
||||
|
||||
qDebug() << "Adjusting audio to speed" << clip_speed;
|
||||
double clip_speed = b->speed();
|
||||
|
||||
int sample_count = audio_params_.bytes_to_samples(samples_from_this_block.size());
|
||||
|
||||
for (double i=0;i<sample_count;i+=clip_speed) {
|
||||
int sample_index = qFloor(i);
|
||||
int byte_index = audio_params_.samples_to_bytes(sample_index);
|
||||
|
||||
if (byte_index >= samples_from_this_block.size() || (byte_index + audio_params_.samples_to_bytes(1)) > samples_from_this_block.size()) {
|
||||
qDebug() << "Tried to access" << byte_index << "-" << (byte_index + audio_params_.samples_to_bytes(1)) << "of" << samples_from_this_block.size();
|
||||
}
|
||||
|
||||
QByteArray sample_at_this_index = samples_from_this_block.mid(byte_index, audio_params_.samples_to_bytes(1));
|
||||
speed_adjusted_samples.append(sample_at_this_index);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user