Skip to content

Commit

Permalink
Disabling Clip caching and fixing a bug with waveform()
Browse files Browse the repository at this point in the history
  • Loading branch information
jonoomph committed Feb 18, 2021
1 parent 3daa5bd commit 66eb3d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 32 deletions.
37 changes: 19 additions & 18 deletions src/Clip.cpp
Expand Up @@ -412,7 +412,9 @@ std::shared_ptr<Frame> Clip::GetFrame(std::shared_ptr<openshot::Frame> backgroun
apply_keyframes(original_frame, background_frame->GetImage());

// Cache frame
cache.Add(original_frame);
// TODO: disable clip cache temporarily for testing
// with this enabled, black frames appear when seeking to previous frames
//cache.Add(original_frame);

// Return processed 'frame'
return original_frame;
Expand Down Expand Up @@ -1123,6 +1125,22 @@ void Clip::apply_keyframes(std::shared_ptr<Frame> frame, std::shared_ptr<QImage>
// Get image from clip
std::shared_ptr<QImage> source_image = frame->GetImage();

/* REPLACE IMAGE WITH WAVEFORM IMAGE (IF NEEDED) */
if (Waveform())
{
// Debug output
ZmqLogger::Instance()->AppendDebugMethod("Clip::get_transform (Generate Waveform Image)", "frame->number", frame->number, "Waveform()", Waveform());

// Get the color of the waveform
int red = wave_color.red.GetInt(frame->number);
int green = wave_color.green.GetInt(frame->number);
int blue = wave_color.blue.GetInt(frame->number);
int alpha = wave_color.alpha.GetInt(frame->number);

// Generate Waveform Dynamically (the size of the timeline)
source_image = frame->GetWaveform(background_canvas->width(), background_canvas->height(), red, green, blue, alpha);
}

// Size of final image
int width = background_canvas->width();
int height = background_canvas->height();
Expand Down Expand Up @@ -1185,23 +1203,6 @@ QTransform Clip::get_transform(std::shared_ptr<Frame> frame, int width, int heig
// Get image from clip
std::shared_ptr<QImage> source_image = frame->GetImage();

/* REPLACE IMAGE WITH WAVEFORM IMAGE (IF NEEDED) */
if (Waveform())
{
// Debug output
ZmqLogger::Instance()->AppendDebugMethod("Clip::get_transform (Generate Waveform Image)", "frame->number", frame->number, "Waveform()", Waveform());

// Get the color of the waveform
int red = wave_color.red.GetInt(frame->number);
int green = wave_color.green.GetInt(frame->number);
int blue = wave_color.blue.GetInt(frame->number);
int alpha = wave_color.alpha.GetInt(frame->number);

// Generate Waveform Dynamically (the size of the timeline)
source_image = frame->GetWaveform(width, height, red, green, blue, alpha);
frame->AddImage(std::shared_ptr<QImage>(source_image));
}

/* ALPHA & OPACITY */
if (alpha.GetValue(frame->number) != 1.0)
{
Expand Down
23 changes: 9 additions & 14 deletions src/Frame.cpp
Expand Up @@ -189,18 +189,18 @@ std::shared_ptr<QImage> Frame::GetWaveform(int width, int height, int Red, int G
int total_width = 0;

// Loop through each audio channel
int Y = 100;
float Y = 100.0;
for (int channel = 0; channel < audio->getNumChannels(); channel++)
{
int X = 0;
float X = 0.0;

// Get audio for this channel
const float *samples = audio->getReadPointer(channel);

for (int sample = 0; sample < GetAudioSamplesCount(); sample++, X++)
{
// Sample value (scaled to -100 to 100)
float value = samples[sample] * 100;
float value = samples[sample] * 100.0;

// Append a line segment for each sample
if (value != 0.0) {
Expand All @@ -216,7 +216,7 @@ std::shared_ptr<QImage> Frame::GetWaveform(int width, int height, int Red, int G
}

// Add Channel Label Coordinate
labels.push_back(QPointF(5, Y - 5));
labels.push_back(QPointF(5.0, Y - 5.0));

// Increment Y
Y += (200 + height_padding);
Expand All @@ -232,21 +232,16 @@ std::shared_ptr<QImage> Frame::GetWaveform(int width, int height, int Red, int G
QPainter painter(wave_image.get());

// Set pen color
painter.setPen(QColor(Red, Green, Blue, Alpha));
QPen pen;
pen.setColor(QColor(Red, Green, Blue, Alpha));
pen.setWidthF(1.0);
pen.setStyle(Qt::NoPen);
painter.setPen(pen);

// Draw the waveform
painter.drawLines(lines);
painter.end();

// Loop through the channels labels (and draw the text)
// TODO: Configure Fonts in Qt5 correctly, so the drawText method does not crash
// painter.setFont(QFont(QString("Arial"), 16, 1, false));
// for (int channel = 0; channel < labels.size(); channel++) {
// stringstream label;
// label << "Channel " << channel;
// painter.drawText(labels.at(channel), QString::fromStdString(label.str()));
// }

// Resize Image (if requested)
if (width != total_width || height != total_height) {
QImage scaled_wave_image = wave_image->scaled(width, height, Qt::IgnoreAspectRatio, Qt::FastTransformation);
Expand Down

0 comments on commit 66eb3d5

Please sign in to comment.