Merge branch 'master' into rational_slider
This commit is contained in:
@@ -36,11 +36,12 @@ const int kMaximumSmoothness = 8;
|
||||
AudioMonitor::AudioMonitor(QWidget *parent) :
|
||||
QOpenGLWidget(parent),
|
||||
file_(nullptr),
|
||||
waveform_(nullptr),
|
||||
cached_channels_(0)
|
||||
{
|
||||
values_.resize(kMaximumSmoothness);
|
||||
|
||||
connect(AudioManager::instance(), &AudioManager::OutputDeviceStarted, this, &AudioMonitor::OutputDeviceSet);
|
||||
connect(AudioManager::instance(), &AudioManager::OutputWaveformStarted, this, &AudioMonitor::OutputAudioVisualWaveformSet);
|
||||
connect(AudioManager::instance(), &AudioManager::OutputPushed, this, &AudioMonitor::OutputPushed);
|
||||
connect(AudioManager::instance(), &AudioManager::AudioParamsChanged, this, &AudioMonitor::SetParams);
|
||||
connect(AudioManager::instance(), &AudioManager::Stopped, this, &AudioMonitor::Stop);
|
||||
@@ -84,6 +85,7 @@ void AudioMonitor::Stop()
|
||||
{
|
||||
delete file_;
|
||||
file_ = nullptr;
|
||||
waveform_ = nullptr;
|
||||
}
|
||||
|
||||
void AudioMonitor::OutputPushed(const QByteArray &d)
|
||||
@@ -97,6 +99,20 @@ void AudioMonitor::OutputPushed(const QByteArray &d)
|
||||
SetUpdateLoop(true);
|
||||
}
|
||||
|
||||
void AudioMonitor::OutputAudioVisualWaveformSet(const AudioVisualWaveform *waveform, const rational &start, int playback_speed)
|
||||
{
|
||||
Stop();
|
||||
|
||||
waveform_ = waveform;
|
||||
waveform_time_ = start;
|
||||
|
||||
playback_speed_ = playback_speed;
|
||||
|
||||
last_time_ = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
SetUpdateLoop(true);
|
||||
}
|
||||
|
||||
void AudioMonitor::SetUpdateLoop(bool e)
|
||||
{
|
||||
if (e) {
|
||||
@@ -211,8 +227,24 @@ void AudioMonitor::paintGL()
|
||||
|
||||
QVector<double> v(params_.channel_count(), 0);
|
||||
|
||||
if (file_) {
|
||||
UpdateValuesFromFile(v);
|
||||
if (file_ || waveform_) {
|
||||
// Determines how many milliseconds have passed since last update
|
||||
qint64 current_time = QDateTime::currentMSecsSinceEpoch();
|
||||
qint64 delta_time = current_time - last_time_;
|
||||
int abs_speed = qAbs(playback_speed_);
|
||||
|
||||
// Multiply by speed if the speed is not 1
|
||||
if (abs_speed != 1) {
|
||||
delta_time *= abs_speed;
|
||||
}
|
||||
|
||||
if (file_) {
|
||||
UpdateValuesFromFile(v, delta_time);
|
||||
} else if (waveform_) {
|
||||
UpdateValuesFromWaveform(v, delta_time);
|
||||
}
|
||||
|
||||
last_time_ = current_time;
|
||||
}
|
||||
|
||||
PushValue(v);
|
||||
@@ -254,7 +286,7 @@ void AudioMonitor::paintGL()
|
||||
}
|
||||
}
|
||||
|
||||
if (all_zeroes && !file_) {
|
||||
if (all_zeroes && !file_ && !waveform_) {
|
||||
// Optimize by disabling the update loop
|
||||
SetUpdateLoop(false);
|
||||
}
|
||||
@@ -266,20 +298,10 @@ void AudioMonitor::mousePressEvent(QMouseEvent *)
|
||||
update();
|
||||
}
|
||||
|
||||
void AudioMonitor::UpdateValuesFromFile(QVector<double>& v)
|
||||
void AudioMonitor::UpdateValuesFromFile(QVector<double>& v, qint64 delta_time)
|
||||
{
|
||||
// Determines how many milliseconds have passed since last update
|
||||
qint64 current_time = QDateTime::currentMSecsSinceEpoch();
|
||||
qint64 time_passed = current_time - last_time_;
|
||||
int abs_speed = qAbs(playback_speed_);
|
||||
|
||||
// Multiply by speed if the speed is not 1
|
||||
if (abs_speed != 1) {
|
||||
time_passed *= abs_speed;
|
||||
}
|
||||
|
||||
// Convert ms to float seconds and determine how many bytes that is
|
||||
qint64 bytes_to_read = params_.time_to_bytes(static_cast<double>(time_passed) * 0.001);
|
||||
qint64 bytes_to_read = params_.time_to_bytes(static_cast<double>(delta_time) * 0.001);
|
||||
|
||||
if (playback_speed_ < 0) {
|
||||
// If reversing, jump back by the amount of bytes we're going to read
|
||||
@@ -297,31 +319,35 @@ void AudioMonitor::UpdateValuesFromFile(QVector<double>& v)
|
||||
file_->seek(file_->pos() - bytes_to_read);
|
||||
}
|
||||
|
||||
// If speed is not 1, transform it here
|
||||
if (abs_speed != 1) {
|
||||
int sample_sz = params_.samples_to_bytes(1);
|
||||
int in_nb_samples = params_.bytes_to_samples(b.size());
|
||||
int out_nb_samples = in_nb_samples / abs_speed;
|
||||
QByteArray speed_adjusted(out_nb_samples * sample_sz, Qt::Uninitialized);
|
||||
BytesToSampleSummary(b, v);
|
||||
}
|
||||
|
||||
for (int i=0;i<out_nb_samples;i++) {
|
||||
memcpy(speed_adjusted.data() + i * sample_sz,
|
||||
b.constData() + i * abs_speed * sample_sz,
|
||||
sample_sz);
|
||||
void AudioMonitor::UpdateValuesFromWaveform(QVector<double> &v, qint64 delta_time)
|
||||
{
|
||||
// Delta time is provided in milliseconds, so we convert to seconds in rational
|
||||
rational length(delta_time, 1000);
|
||||
|
||||
AudioVisualWaveform::Sample sum = waveform_->GetSummaryFromTime(waveform_time_, length);
|
||||
|
||||
for (int i=0; i<sum.size(); i++) {
|
||||
float max = qMax(qAbs(sum.at(i).min), qAbs(sum.at(i).max));
|
||||
|
||||
int output_index = i%v.size();
|
||||
if (max > v.at(output_index)) {
|
||||
v[output_index] = max;
|
||||
}
|
||||
|
||||
b = speed_adjusted;
|
||||
}
|
||||
|
||||
BytesToSampleSummary(b, v);
|
||||
|
||||
last_time_ = current_time;
|
||||
waveform_time_ += length;
|
||||
}
|
||||
|
||||
void AudioMonitor::PushValue(const QVector<double> &v)
|
||||
{
|
||||
values_.removeFirst();
|
||||
values_.append(v);
|
||||
int lim = values_.size()-1;
|
||||
for (int i=0; i<lim; i++) {
|
||||
values_[i] = values_[i+1];
|
||||
}
|
||||
values_[lim] = v;
|
||||
}
|
||||
|
||||
void AudioMonitor::BytesToSampleSummary(const QByteArray &b, QVector<double> &v)
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <QOpenGLWidget>
|
||||
#include <QTimer>
|
||||
|
||||
#include "audio/audiovisualwaveform.h"
|
||||
#include "common/define.h"
|
||||
#include "render/audioparams.h"
|
||||
#include "render/audioplaybackcache.h"
|
||||
@@ -46,8 +47,9 @@ public slots:
|
||||
|
||||
void OutputPushed(const QByteArray& d);
|
||||
|
||||
void OutputAudioVisualWaveformSet(const AudioVisualWaveform *waveform, const rational& start, int playback_speed);
|
||||
|
||||
protected:
|
||||
//virtual void paintEvent(QPaintEvent* event) override;
|
||||
virtual void paintGL() override;
|
||||
|
||||
virtual void mousePressEvent(QMouseEvent* event) override;
|
||||
@@ -55,7 +57,9 @@ protected:
|
||||
private:
|
||||
void SetUpdateLoop(bool e);
|
||||
|
||||
void UpdateValuesFromFile(QVector<double> &v);
|
||||
void UpdateValuesFromFile(QVector<double> &v, qint64 delta_time);
|
||||
|
||||
void UpdateValuesFromWaveform(QVector<double> &v, qint64 delta_time);
|
||||
|
||||
void PushValue(const QVector<double>& v);
|
||||
|
||||
@@ -68,6 +72,9 @@ private:
|
||||
QIODevice* file_;
|
||||
qint64 last_time_;
|
||||
|
||||
const AudioVisualWaveform* waveform_;
|
||||
rational waveform_time_;
|
||||
|
||||
int playback_speed_;
|
||||
|
||||
QVector< QVector<double> > values_;
|
||||
|
||||
@@ -53,7 +53,7 @@ void NodeParamViewArrayWidget::UpdateCounter(const QString& input, int old_size,
|
||||
{
|
||||
Q_UNUSED(old_size)
|
||||
if (input == input_) {
|
||||
count_lbl_->setText(tr("%1 element(s)").arg(new_size));
|
||||
count_lbl_->setText(tr("%n element(s)", nullptr, new_size));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -381,7 +381,7 @@ void NodeParamViewItemBody::Retranslate()
|
||||
|
||||
if (ic.IsArray() && ic.element() >= 0) {
|
||||
// Make the label the array index
|
||||
i.value().main_label->setText(tr("%n:", nullptr, ic.element()));
|
||||
i.value().main_label->setText(tr("%1:").arg(ic.element()));
|
||||
} else {
|
||||
// Set to the input's name
|
||||
i.value().main_label->setText(tr("%1:").arg(ic.name()));
|
||||
|
||||
@@ -557,7 +557,7 @@ void NodeParamViewWidgetBridge::InputValueChanged(const NodeInput &input, const
|
||||
|
||||
void NodeParamViewWidgetBridge::PropertyChanged(const QString& input, const QString &key, const QVariant &value)
|
||||
{
|
||||
if (input != input_.input()) {
|
||||
if (input != input_.input() || (input_.IsArray() && input_.element() == -1)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -668,6 +668,13 @@ void NodeView::ShowContextMenu(const QPoint &pos)
|
||||
QAction* autopos = m.addAction(tr("Auto-Position"));
|
||||
connect(autopos, &QAction::triggered, this, &NodeView::AutoPositionDescendents);
|
||||
|
||||
ViewerOutput* viewer = dynamic_cast<ViewerOutput*>(selected.first()->GetNode());
|
||||
if (viewer) {
|
||||
m.addSeparator();
|
||||
QAction* open_in_viewer_action = m.addAction(tr("Open in Viewer"));
|
||||
connect(open_in_viewer_action, &QAction::triggered, this, &NodeView::OpenSelectedNodeInViewer);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
QAction* curved_action = m.addAction(tr("Smooth Edges"));
|
||||
@@ -756,6 +763,16 @@ void NodeView::ContextMenuFilterChanged(QAction *action)
|
||||
Q_UNUSED(action)
|
||||
}
|
||||
|
||||
void NodeView::OpenSelectedNodeInViewer()
|
||||
{
|
||||
QVector<Node*> selected = scene_.GetSelectedNodes();
|
||||
ViewerOutput* viewer = selected.isEmpty() ? nullptr : dynamic_cast<ViewerOutput*>(selected.first());
|
||||
|
||||
if (viewer) {
|
||||
Core::instance()->OpenNodeInViewer(viewer);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeView::AttachNodesToCursor(const QVector<Node *> &nodes)
|
||||
{
|
||||
QVector<NodeViewItem*> items(nodes.size());
|
||||
|
||||
@@ -194,6 +194,11 @@ private slots:
|
||||
*/
|
||||
void ContextMenuFilterChanged(QAction* action);
|
||||
|
||||
/**
|
||||
* @brief Opens the selected node in a Viewer
|
||||
*/
|
||||
void OpenSelectedNodeInViewer();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -95,8 +95,6 @@ ProjectExplorer::ProjectExplorer(QWidget *parent) :
|
||||
connect(tree_view_, &ProjectExplorerTreeView::customContextMenuRequested, this, &ProjectExplorer::ShowContextMenu);
|
||||
connect(list_view_, &ProjectExplorerListView::customContextMenuRequested, this, &ProjectExplorer::ShowContextMenu);
|
||||
connect(icon_view_, &ProjectExplorerIconView::customContextMenuRequested, this, &ProjectExplorer::ShowContextMenu);
|
||||
|
||||
connect(&model_, &ProjectViewModel::ItemRemoved, this, &ProjectExplorer::ItemRemoved);
|
||||
}
|
||||
|
||||
const ProjectToolbar::ViewType &ProjectExplorer::view_type() const
|
||||
|
||||
@@ -100,8 +100,6 @@ signals:
|
||||
*/
|
||||
void DoubleClickedItem(Node* item);
|
||||
|
||||
void ItemRemoved(Node* node);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief Get all the blocks that solely rely on an input node
|
||||
|
||||
@@ -39,6 +39,7 @@ SliderBase::SliderBase(Mode mode, QWidget *parent) :
|
||||
dragged_diff_(0),
|
||||
require_valid_input_(true),
|
||||
tristate_(false),
|
||||
format_plural_(false),
|
||||
drag_ladder_(nullptr),
|
||||
ladder_element_count_(0),
|
||||
dragged_(false)
|
||||
@@ -102,9 +103,10 @@ bool SliderBase::IsDragging() const
|
||||
return drag_ladder_;
|
||||
}
|
||||
|
||||
void SliderBase::SetFormat(const QString &s)
|
||||
void SliderBase::SetFormat(const QString &s, const bool plural)
|
||||
{
|
||||
custom_format_ = s;
|
||||
format_plural_ = plural;
|
||||
ForceLabelUpdate();
|
||||
}
|
||||
|
||||
@@ -114,6 +116,11 @@ void SliderBase::ClearFormat()
|
||||
ForceLabelUpdate();
|
||||
}
|
||||
|
||||
bool SliderBase::IsFormatPlural() const
|
||||
{
|
||||
return format_plural_;
|
||||
}
|
||||
|
||||
void SliderBase::ForceLabelUpdate()
|
||||
{
|
||||
UpdateLabel(Value());
|
||||
@@ -228,10 +235,17 @@ QString SliderBase::GetFormat() const
|
||||
}
|
||||
}
|
||||
|
||||
bool SliderBase::UsingLadders() const
|
||||
{
|
||||
return ladder_element_count_ > 0 && Config::Current()[QStringLiteral("UseSliderLadders")].toBool();
|
||||
}
|
||||
|
||||
void SliderBase::UpdateLabel(const QVariant &v)
|
||||
{
|
||||
if (tristate_) {
|
||||
label_->setText("---");
|
||||
} else if (format_plural_) {
|
||||
label_->setText(tr(GetFormat().toUtf8().constData(), nullptr, v.toInt()));
|
||||
} else {
|
||||
label_->setText(GetFormat().arg(ValueToString(v)));
|
||||
}
|
||||
@@ -322,7 +336,7 @@ void SliderBase::LadderDragged(int value, double multiplier)
|
||||
|
||||
drag_ladder_->SetValue(ValueToString(clamped_temp_dragged_value_));
|
||||
|
||||
if (!Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
|
||||
if (!UsingLadders()) {
|
||||
RepositionLadder();
|
||||
}
|
||||
|
||||
@@ -437,7 +451,7 @@ void SliderBase::ResetValue()
|
||||
void SliderBase::RepositionLadder()
|
||||
{
|
||||
if (drag_ladder_) {
|
||||
if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
|
||||
if (UsingLadders()) {
|
||||
drag_ladder_->move(QCursor::pos() - QPoint(drag_ladder_->width()/2, drag_ladder_->height()/2));
|
||||
} else {
|
||||
QPoint label_global_pos = label_->mapToGlobal(label_->pos());
|
||||
|
||||
@@ -61,9 +61,11 @@ public:
|
||||
|
||||
bool IsDragging() const;
|
||||
|
||||
void SetFormat(const QString& s);
|
||||
void SetFormat(const QString& s, const bool plural=false);
|
||||
void ClearFormat();
|
||||
|
||||
bool IsFormatPlural() const;
|
||||
|
||||
void SetLadderElementCount(int b)
|
||||
{
|
||||
ladder_element_count_ = b;
|
||||
@@ -102,6 +104,8 @@ private:
|
||||
|
||||
QString GetFormat() const;
|
||||
|
||||
bool UsingLadders() const;
|
||||
|
||||
SliderLabel* label_;
|
||||
|
||||
FocusableLineEdit* editor_;
|
||||
@@ -130,6 +134,8 @@ private:
|
||||
|
||||
QString custom_format_;
|
||||
|
||||
bool format_plural_;
|
||||
|
||||
SliderLadder* drag_ladder_;
|
||||
|
||||
int ladder_element_count_;
|
||||
|
||||
@@ -77,7 +77,7 @@ SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QString
|
||||
drag_timer_.setInterval(10);
|
||||
connect(&drag_timer_, &QTimer::timeout, this, &SliderLadder::TimerUpdate);
|
||||
|
||||
if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
|
||||
if (UsingLadders()) {
|
||||
drag_start_x_ = -1;
|
||||
} else {
|
||||
#if defined(Q_OS_MAC)
|
||||
@@ -95,7 +95,7 @@ SliderLadder::SliderLadder(double drag_multiplier, int nb_outer_values, QString
|
||||
|
||||
SliderLadder::~SliderLadder()
|
||||
{
|
||||
if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
|
||||
if (UsingLadders()) {
|
||||
|
||||
} else {
|
||||
#if defined(Q_OS_MAC)
|
||||
@@ -143,7 +143,7 @@ void SliderLadder::TimerUpdate()
|
||||
int ladder_right = this->x() + this->width() - 1;
|
||||
int now_pos = QCursor::pos().x();
|
||||
|
||||
if (Config::Current()[QStringLiteral("UseSliderLadders")].toBool()) {
|
||||
if (UsingLadders()) {
|
||||
|
||||
bool is_under_mouse = (now_pos >= ladder_left && now_pos <= ladder_right);
|
||||
|
||||
@@ -227,7 +227,12 @@ void SliderLadder::TimerUpdate()
|
||||
}
|
||||
}
|
||||
|
||||
SliderLadderElement::SliderLadderElement(const double &multiplier, QString width_hint, QWidget *parent) :
|
||||
bool SliderLadder::UsingLadders() const
|
||||
{
|
||||
return elements_.size() > 1;
|
||||
}
|
||||
|
||||
SliderLadderElement::SliderLadderElement(const double &multiplier, QString width_hint, QWidget *parent) :
|
||||
QWidget(parent),
|
||||
multiplier_(multiplier),
|
||||
highlighted_(false),
|
||||
|
||||
@@ -83,6 +83,8 @@ signals:
|
||||
void Released();
|
||||
|
||||
private:
|
||||
bool UsingLadders() const;
|
||||
|
||||
int drag_start_x_;
|
||||
int drag_start_y_;
|
||||
|
||||
|
||||
@@ -85,6 +85,7 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
|
||||
|
||||
// Disconnect length changed signal
|
||||
disconnect(viewer_node_, &ViewerOutput::LengthChanged, this, &TimeBasedWidget::UpdateMaximumScroll);
|
||||
disconnect(viewer_node_, &ViewerOutput::RemovedFromGraph, this, &TimeBasedWidget::ConnectedNodeRemovedFromGraph);
|
||||
|
||||
// Disconnect rate change signals if they were connected
|
||||
disconnect(viewer_node_, &ViewerOutput::FrameRateChanged, this, &TimeBasedWidget::AutoUpdateTimebase);
|
||||
@@ -109,6 +110,7 @@ void TimeBasedWidget::ConnectViewerNode(ViewerOutput *node)
|
||||
if (viewer_node_) {
|
||||
// Connect length changed signal
|
||||
connect(viewer_node_, &ViewerOutput::LengthChanged, this, &TimeBasedWidget::UpdateMaximumScroll);
|
||||
connect(viewer_node_, &ViewerOutput::RemovedFromGraph, this, &TimeBasedWidget::ConnectedNodeRemovedFromGraph);
|
||||
|
||||
// Connect ruler and scrollbar to timeline points
|
||||
ruler()->ConnectTimelinePoints(viewer_node_->GetTimelinePoints());
|
||||
@@ -216,6 +218,11 @@ void TimeBasedWidget::AutoUpdateTimebase()
|
||||
}
|
||||
}
|
||||
|
||||
void TimeBasedWidget::ConnectedNodeRemovedFromGraph()
|
||||
{
|
||||
ConnectViewerNode(nullptr);
|
||||
}
|
||||
|
||||
TimeRuler *TimeBasedWidget::ruler() const
|
||||
{
|
||||
return ruler_;
|
||||
@@ -281,29 +288,27 @@ void TimeBasedWidget::PassWheelEventsToScrollBar(QObject *object)
|
||||
|
||||
void TimeBasedWidget::SetTimestamp(int64_t timestamp)
|
||||
{
|
||||
if (GetTime() != timestamp) {
|
||||
if (UserIsDraggingPlayhead()) {
|
||||
// If the user is dragging the playhead, we will simply nudge over and not use autoscroll rules.
|
||||
QMetaObject::invokeMethod(this, "CatchUpScrollToPlayhead", Qt::QueuedConnection);
|
||||
} else {
|
||||
// Otherwise, assume we jumped to this out of nowhere and must now autoscroll
|
||||
switch (static_cast<AutoScroll::Method>(Config::Current()["Autoscroll"].toInt())) {
|
||||
case AutoScroll::kNone:
|
||||
// Do nothing
|
||||
break;
|
||||
case AutoScroll::kPage:
|
||||
QMetaObject::invokeMethod(this, "PageScrollToPlayhead", Qt::QueuedConnection);
|
||||
break;
|
||||
case AutoScroll::kSmooth:
|
||||
QMetaObject::invokeMethod(this, "CenterScrollOnPlayhead", Qt::QueuedConnection);
|
||||
break;
|
||||
}
|
||||
if (UserIsDraggingPlayhead()) {
|
||||
// If the user is dragging the playhead, we will simply nudge over and not use autoscroll rules.
|
||||
QMetaObject::invokeMethod(this, "CatchUpScrollToPlayhead", Qt::QueuedConnection);
|
||||
} else {
|
||||
// Otherwise, assume we jumped to this out of nowhere and must now autoscroll
|
||||
switch (static_cast<AutoScroll::Method>(Config::Current()["Autoscroll"].toInt())) {
|
||||
case AutoScroll::kNone:
|
||||
// Do nothing
|
||||
break;
|
||||
case AutoScroll::kPage:
|
||||
QMetaObject::invokeMethod(this, "PageScrollToPlayhead", Qt::QueuedConnection);
|
||||
break;
|
||||
case AutoScroll::kSmooth:
|
||||
QMetaObject::invokeMethod(this, "CenterScrollOnPlayhead", Qt::QueuedConnection);
|
||||
break;
|
||||
}
|
||||
|
||||
ruler_->SetTime(timestamp);
|
||||
|
||||
TimeChangedEvent(timestamp);
|
||||
}
|
||||
|
||||
ruler_->SetTime(timestamp);
|
||||
|
||||
TimeChangedEvent(timestamp);
|
||||
}
|
||||
|
||||
void TimeBasedWidget::SetTimebase(const rational &timebase)
|
||||
|
||||
@@ -230,6 +230,8 @@ private slots:
|
||||
|
||||
void AutoUpdateTimebase();
|
||||
|
||||
void ConnectedNodeRemovedFromGraph();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -50,8 +50,10 @@
|
||||
|
||||
namespace olive {
|
||||
|
||||
#define super TimeBasedWidget
|
||||
|
||||
TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
TimeBasedWidget(true, true, parent),
|
||||
super(true, true, parent),
|
||||
rubberband_(QRubberBand::Rectangle, this),
|
||||
active_tool_(nullptr),
|
||||
use_audio_time_units_(false)
|
||||
@@ -111,8 +113,6 @@ TimelineWidget::TimelineWidget(QWidget *parent) :
|
||||
connect(views_.first()->view()->horizontalScrollBar(), &QScrollBar::rangeChanged, scrollbar(), &QScrollBar::setRange);
|
||||
vert_layout->addWidget(scrollbar());
|
||||
|
||||
connect(ruler(), &TimeRuler::TimeChanged, this, &TimelineWidget::SetViewTimestamp);
|
||||
|
||||
foreach (TimelineAndTrackView* tview, views_) {
|
||||
TimelineView* view = tview->view();
|
||||
|
||||
@@ -187,7 +187,7 @@ void TimelineWidget::Clear()
|
||||
|
||||
void TimelineWidget::TimebaseChangedEvent(const rational &timebase)
|
||||
{
|
||||
TimeBasedWidget::TimebaseChangedEvent(timebase);
|
||||
super::TimebaseChangedEvent(timebase);
|
||||
|
||||
timecode_label_->SetTimebase(timebase);
|
||||
|
||||
@@ -198,7 +198,7 @@ void TimelineWidget::TimebaseChangedEvent(const rational &timebase)
|
||||
|
||||
void TimelineWidget::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
TimeBasedWidget::resizeEvent(event);
|
||||
super::resizeEvent(event);
|
||||
|
||||
// Update timecode label size
|
||||
UpdateTimecodeWidthFromSplitters(views_.first()->splitter());
|
||||
@@ -206,6 +206,8 @@ void TimelineWidget::resizeEvent(QResizeEvent *event)
|
||||
|
||||
void TimelineWidget::TimeChangedEvent(const int64_t& timestamp)
|
||||
{
|
||||
super::TimeChangedEvent(timestamp);
|
||||
|
||||
SetViewTimestamp(timestamp);
|
||||
|
||||
timecode_label_->SetValue(timestamp);
|
||||
@@ -213,7 +215,7 @@ void TimelineWidget::TimeChangedEvent(const int64_t& timestamp)
|
||||
|
||||
void TimelineWidget::ScaleChangedEvent(const double &scale)
|
||||
{
|
||||
TimeBasedWidget::ScaleChangedEvent(scale);
|
||||
super::ScaleChangedEvent(scale);
|
||||
|
||||
foreach (TimelineAndTrackView* view, views_) {
|
||||
view->view()->SetScale(scale);
|
||||
|
||||
@@ -180,9 +180,11 @@ void SeekableWidget::SeekToScreenPoint(int screen)
|
||||
}
|
||||
}
|
||||
|
||||
SetTime(timestamp);
|
||||
if (timestamp != GetTime()) {
|
||||
SetTime(timestamp);
|
||||
|
||||
emit TimeChanged(timestamp);
|
||||
emit TimeChanged(timestamp);
|
||||
}
|
||||
}
|
||||
|
||||
void SeekableWidget::DrawTimelinePoints(QPainter* p, int marker_bottom)
|
||||
|
||||
@@ -99,6 +99,8 @@ VideoParamEdit::VideoParamEdit(QWidget* parent) :
|
||||
|
||||
// FIXME: Replace with rational slider
|
||||
frame_rate_slider_ = new FloatSlider();
|
||||
frame_rate_slider_->SetMinimum(0);
|
||||
frame_rate_slider_->SetDecimalPlaces(2);
|
||||
connect(frame_rate_slider_, &FloatSlider::ValueChanged, this, &VideoParamEdit::Changed);
|
||||
layout->addWidget(frame_rate_slider_, row, 1);
|
||||
|
||||
@@ -211,6 +213,8 @@ VideoParamEdit::VideoParamEdit(QWidget* parent) :
|
||||
|
||||
void VideoParamEdit::SetParameterMask(uint64_t mask)
|
||||
{
|
||||
mask_ = mask;
|
||||
|
||||
width_lbl_->setVisible(mask & kWidthHeight);
|
||||
width_slider_->setVisible(mask & kWidthHeight);
|
||||
height_lbl_->setVisible(mask & kWidthHeight);
|
||||
@@ -220,7 +224,7 @@ void VideoParamEdit::SetParameterMask(uint64_t mask)
|
||||
depth_slider_->setVisible(mask & kDepth);
|
||||
|
||||
frame_rate_lbl_->setVisible(mask & kFrameRate);
|
||||
frame_rate_combobox_->setVisible((mask & kFrameRate) && (mask & ~kFrameRateIsArbitrary));
|
||||
frame_rate_combobox_->setVisible((mask & kFrameRate) && !(mask & kFrameRateIsArbitrary));
|
||||
frame_rate_slider_->setVisible((mask & kFrameRate) && (mask & kFrameRateIsArbitrary));
|
||||
|
||||
pixel_aspect_lbl_->setVisible(mask & kPixelAspect);
|
||||
|
||||
@@ -30,21 +30,38 @@
|
||||
|
||||
namespace olive {
|
||||
|
||||
#define super SeekableWidget
|
||||
|
||||
AudioWaveformView::AudioWaveformView(QWidget *parent) :
|
||||
SeekableWidget(parent),
|
||||
super(parent),
|
||||
playback_(nullptr)
|
||||
{
|
||||
setAutoFillBackground(true);
|
||||
setBackgroundRole(QPalette::Base);
|
||||
}
|
||||
|
||||
cached_waveform_.resize(QThread::idealThreadCount());
|
||||
AudioVisualWaveform GenerateWaveform(QIODevice* device, AudioParams params, TimeRange range)
|
||||
{
|
||||
device->open(QFile::ReadOnly);
|
||||
device->seek(params.time_to_bytes(range.in()));
|
||||
|
||||
SampleBufferPtr samples = SampleBuffer::CreateFromPackedData(params, device->read(params.time_to_bytes(range.length())));
|
||||
AudioVisualWaveform waveform;
|
||||
waveform.set_channel_count(params.channel_count());
|
||||
waveform.OverwriteSamples(samples, params.sample_rate());
|
||||
device->close();
|
||||
delete device;
|
||||
return waveform;
|
||||
}
|
||||
|
||||
void AudioWaveformView::SetViewer(AudioPlaybackCache *playback)
|
||||
{
|
||||
if (playback_) {
|
||||
disconnect(playback_, &AudioPlaybackCache::Validated, this, &AudioWaveformView::ForceUpdateOfRange);
|
||||
disconnect(playback_, &AudioPlaybackCache::ParametersChanged, this, &AudioWaveformView::BackendParamsChanged);
|
||||
pool_.clear();
|
||||
pool_.waitForDone();
|
||||
|
||||
disconnect(playback_, &AudioPlaybackCache::Validated, this, &AudioWaveformView::RenderRange);
|
||||
//disconnect(playback_, &AudioPlaybackCache::ParametersChanged, this, &AudioWaveformView::RenderRange);
|
||||
|
||||
SetTimebase(0);
|
||||
}
|
||||
@@ -52,18 +69,20 @@ void AudioWaveformView::SetViewer(AudioPlaybackCache *playback)
|
||||
playback_ = playback;
|
||||
|
||||
if (playback_) {
|
||||
connect(playback_, &AudioPlaybackCache::Validated, this, &AudioWaveformView::ForceUpdateOfRange);
|
||||
connect(playback_, &AudioPlaybackCache::ParametersChanged, this, &AudioWaveformView::BackendParamsChanged);
|
||||
connect(playback_, &AudioPlaybackCache::Validated, this, &AudioWaveformView::RenderRange);
|
||||
//connect(playback_, &AudioPlaybackCache::ParametersChanged, this, &AudioWaveformView::RenderRange);
|
||||
|
||||
SetTimebase(playback_->GetParameters().sample_rate_as_time_base());
|
||||
}
|
||||
|
||||
ForceUpdate();
|
||||
waveform_.set_channel_count(playback_->GetParameters().channel_count());
|
||||
|
||||
RenderRange(TimeRange(0, playback_->GetLength()));
|
||||
}
|
||||
}
|
||||
|
||||
void AudioWaveformView::paintEvent(QPaintEvent *event)
|
||||
{
|
||||
QWidget::paintEvent(event);
|
||||
super::paintEvent(event);
|
||||
|
||||
if (!playback_) {
|
||||
return;
|
||||
@@ -80,40 +99,9 @@ void AudioWaveformView::paintEvent(QPaintEvent *event)
|
||||
// Draw in/out points
|
||||
DrawTimelinePoints(&p);
|
||||
|
||||
CachedWaveformInfo wanted_info = {size(), GetScale(), GetScroll(), params};
|
||||
|
||||
for (int i=0; i<cached_waveform_.size(); i++) {
|
||||
ActiveCache& cache = cached_waveform_[i];
|
||||
|
||||
int slice_start = width()/cached_waveform_.size() * i;
|
||||
|
||||
if (cache.info == wanted_info) {
|
||||
|
||||
// Draw pixmap
|
||||
p.drawPixmap(slice_start, 0, cache.pixmap);
|
||||
|
||||
} else if (cache.caching_info != wanted_info) {
|
||||
|
||||
int slice_end = width()/cached_waveform_.size() * (i+1);
|
||||
|
||||
// Pixmap is obsolete, will need to draw again
|
||||
|
||||
// Delete any existing watcher so we don't receive the signal
|
||||
delete cache.watcher;
|
||||
|
||||
// Queue a new background cache operation
|
||||
cache.caching_info = wanted_info;
|
||||
cache.watcher = new QFutureWatcher<QPixmap>();
|
||||
connect(cache.watcher, &QFutureWatcher<QPixmap>::finished, this, &AudioWaveformView::BackgroundCacheFinished);
|
||||
cache.watcher->setFuture(QtConcurrent::run(this,
|
||||
&AudioWaveformView::DrawWaveform,
|
||||
playback_->CreatePlaybackDevice(),
|
||||
wanted_info,
|
||||
slice_start,
|
||||
slice_end));
|
||||
|
||||
}
|
||||
}
|
||||
// Draw waveform
|
||||
p.setPen(QColor(64, 255, 160)); // FIXME: Hardcoded color
|
||||
AudioVisualWaveform::DrawWaveform(&p, rect(), GetScale(), waveform_, SceneToTime(GetScroll()));
|
||||
|
||||
// Draw playhead
|
||||
p.setPen(PLAYHEAD_COLOR);
|
||||
@@ -122,117 +110,38 @@ void AudioWaveformView::paintEvent(QPaintEvent *event)
|
||||
p.drawLine(playhead_x, 0, playhead_x, height());
|
||||
}
|
||||
|
||||
QPixmap AudioWaveformView::DrawWaveform(QIODevice* fs, CachedWaveformInfo info, int slice_start, int slice_end) const
|
||||
void AudioWaveformView::RenderRange(const TimeRange &range)
|
||||
{
|
||||
QPixmap pixmap(slice_end - slice_start, info.size.height());
|
||||
pixmap.fill(Qt::transparent);
|
||||
// Floor to second increments
|
||||
int64_t start = qFloor(range.in().toDouble());
|
||||
int64_t end = qCeil(range.out().toDouble());
|
||||
|
||||
if (fs->open(QFile::ReadOnly)) {
|
||||
for (; start!=end; start++) {
|
||||
TimeRange this_range(start, start+1);
|
||||
|
||||
QPainter wave_painter(&pixmap);
|
||||
QFutureWatcher<AudioVisualWaveform>* watcher = new QFutureWatcher<AudioVisualWaveform>();
|
||||
connect(watcher, &QFutureWatcher<AudioVisualWaveform>::finished, this, &AudioWaveformView::BackgroundFinished);
|
||||
|
||||
// FIXME: Hardcoded color
|
||||
wave_painter.setPen(QColor(64, 255, 160));
|
||||
|
||||
int drew = 0;
|
||||
|
||||
fs->seek(info.params.samples_to_bytes(ScreenToUnitRounded(slice_start)));
|
||||
|
||||
for (int x=slice_start; x<slice_end && !fs->atEnd(); x++) {
|
||||
int samples_len = ScreenToUnitRounded(x+1) - ScreenToUnitRounded(x);
|
||||
int max_read_size = info.params.samples_to_bytes(samples_len);
|
||||
|
||||
QByteArray read_buffer = fs->read(max_read_size);
|
||||
|
||||
// Detect whether we've reached EOF and recalculate sample count if so
|
||||
if (read_buffer.size() < max_read_size) {
|
||||
samples_len = info.params.bytes_to_samples(read_buffer.size());
|
||||
}
|
||||
|
||||
QVector<AudioVisualWaveform::SamplePerChannel> samples = AudioVisualWaveform::SumSamples(reinterpret_cast<const float*>(read_buffer.constData()),
|
||||
samples_len,
|
||||
info.params.channel_count());
|
||||
|
||||
for (int i=0;i<info.params.channel_count();i++) {
|
||||
AudioVisualWaveform::DrawSample(&wave_painter, samples, x - slice_start, 0, info.size.height());
|
||||
|
||||
drew++;
|
||||
}
|
||||
}
|
||||
|
||||
fs->close();
|
||||
jobs_.insert(this_range, watcher);
|
||||
|
||||
watcher->setFuture(QtConcurrent::run(&pool_, GenerateWaveform, playback_->CreatePlaybackDevice(), playback_->GetParameters(), this_range));
|
||||
}
|
||||
|
||||
delete fs;
|
||||
|
||||
return pixmap;
|
||||
}
|
||||
|
||||
void AudioWaveformView::BackendParamsChanged()
|
||||
void AudioWaveformView::BackgroundFinished()
|
||||
{
|
||||
SetTimebase(playback_->GetParameters().sample_rate_as_time_base());
|
||||
}
|
||||
QFutureWatcher<AudioVisualWaveform>* watcher = static_cast<QFutureWatcher<AudioVisualWaveform>*>(sender());
|
||||
|
||||
void AudioWaveformView::ForceUpdate()
|
||||
{
|
||||
// Forces the cache to invalidate
|
||||
for (int i=0; i<cached_waveform_.size(); i++) {
|
||||
cached_waveform_[i].info.size = QSize();
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void AudioWaveformView::ForceUpdateOfRange(const TimeRange &range)
|
||||
{
|
||||
int in = TimeToScreen(range.in());
|
||||
int out = TimeToScreen(range.out());
|
||||
|
||||
// Don't need to redraw anything
|
||||
if (out < 0 || in >= width()) {
|
||||
return;
|
||||
}
|
||||
|
||||
int start_invalidate = qMax(0, in/cached_waveform_.size());
|
||||
int end_invalidate = qMin(cached_waveform_.size()-1, out/cached_waveform_.size());
|
||||
|
||||
for (int i=start_invalidate; i<=end_invalidate; i++) {
|
||||
// Invalidate these
|
||||
cached_waveform_[i].info.size = QSize();
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void AudioWaveformView::BackgroundCacheFinished()
|
||||
{
|
||||
// Retrieve sender
|
||||
QFutureWatcher<QPixmap>* watcher = static_cast<QFutureWatcher<QPixmap>*>(sender());
|
||||
|
||||
// Determine index
|
||||
int index = -1;
|
||||
for (int i=0; i<cached_waveform_.size(); i++) {
|
||||
if (cached_waveform_.at(i).watcher == watcher) {
|
||||
index = i;
|
||||
for (auto it=jobs_.begin(); it!=jobs_.end(); it++) {
|
||||
if (it.value() == watcher) {
|
||||
AudioVisualWaveform rendered = watcher->result();
|
||||
waveform_.OverwriteSums(rendered, it.key().in());
|
||||
jobs_.erase(it);
|
||||
update();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index > -1) {
|
||||
// Store generated pixmap
|
||||
cached_waveform_[index].info = cached_waveform_[index].caching_info;
|
||||
cached_waveform_[index].pixmap = watcher->result();
|
||||
cached_waveform_[index].watcher = nullptr;
|
||||
|
||||
// Reset size
|
||||
cached_waveform_[index].caching_info.size = QSize();
|
||||
|
||||
// Update with new pixmap
|
||||
update();
|
||||
}
|
||||
|
||||
// Clean up
|
||||
delete watcher;
|
||||
}
|
||||
|
||||
|
||||
@@ -41,51 +41,27 @@ public:
|
||||
|
||||
void SetViewer(AudioPlaybackCache *playback);
|
||||
|
||||
const AudioVisualWaveform* waveform() const
|
||||
{
|
||||
return &waveform_;
|
||||
}
|
||||
|
||||
protected:
|
||||
virtual void paintEvent(QPaintEvent* event) override;
|
||||
|
||||
private:
|
||||
struct CachedWaveformInfo {
|
||||
QSize size;
|
||||
double scale;
|
||||
int scroll;
|
||||
AudioParams params;
|
||||
void RenderRange(const TimeRange& range);
|
||||
|
||||
bool operator==(const CachedWaveformInfo& rhs) const
|
||||
{
|
||||
return size == rhs.size
|
||||
&& qFuzzyCompare(scale, rhs.scale)
|
||||
&& scroll == rhs.scroll
|
||||
&& params == rhs.params;
|
||||
}
|
||||
|
||||
bool operator!=(const CachedWaveformInfo& rhs) const
|
||||
{
|
||||
return !(*this == rhs);
|
||||
}
|
||||
};
|
||||
|
||||
struct ActiveCache {
|
||||
QPixmap pixmap;
|
||||
CachedWaveformInfo info;
|
||||
CachedWaveformInfo caching_info;
|
||||
QFutureWatcher<QPixmap>* watcher = nullptr;
|
||||
};
|
||||
|
||||
QPixmap DrawWaveform(QIODevice *fs, CachedWaveformInfo info, int slice_start, int slice_end) const;
|
||||
QThreadPool pool_;
|
||||
|
||||
AudioPlaybackCache *playback_;
|
||||
|
||||
QVector<ActiveCache> cached_waveform_;
|
||||
AudioVisualWaveform waveform_;
|
||||
|
||||
QHash<TimeRange, QFutureWatcher<AudioVisualWaveform>*> jobs_;
|
||||
|
||||
private slots:
|
||||
void BackendParamsChanged();
|
||||
|
||||
void ForceUpdate();
|
||||
|
||||
void ForceUpdateOfRange(const TimeRange& range);
|
||||
|
||||
void BackgroundCacheFinished();
|
||||
void BackgroundFinished();
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
|
||||
|
||||
display_widget_ = new ViewerDisplayWidget();
|
||||
display_widget_->setAcceptDrops(true);
|
||||
display_widget_->SetShowWidgetBackground(true);
|
||||
connect(display_widget_, &ViewerDisplayWidget::customContextMenuRequested, this, &ViewerWidget::ShowContextMenu);
|
||||
connect(display_widget_, &ViewerDisplayWidget::CursorColor, this, &ViewerWidget::CursorColor);
|
||||
connect(display_widget_, &ViewerDisplayWidget::ColorProcessorChanged, this, &ViewerWidget::ColorProcessorChanged);
|
||||
@@ -109,6 +110,11 @@ ViewerWidget::ViewerWidget(QWidget *parent) :
|
||||
connect(controls_, &PlaybackControls::TimeChanged, this, &ViewerWidget::SetTimeAndSignal);
|
||||
layout->addWidget(controls_);
|
||||
|
||||
// If audio is invalidated during playback, we wait some time before starting it again
|
||||
audio_restart_timer_.setInterval(250);
|
||||
audio_restart_timer_.setSingleShot(true);
|
||||
connect(&audio_restart_timer_, &QTimer::timeout, this, &ViewerWidget::StartAudioOutput);
|
||||
|
||||
// FIXME: Magic number
|
||||
SetScale(48.0);
|
||||
|
||||
@@ -185,6 +191,8 @@ void ViewerWidget::ConnectNodeEvent(ViewerOutput *n)
|
||||
connect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters);
|
||||
connect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange);
|
||||
connect(n->video_frame_cache(), &FrameHashCache::Shifted, this, &ViewerWidget::ViewerShiftedRange);
|
||||
connect(n->audio_playback_cache(), &AudioPlaybackCache::Invalidated, this, &ViewerWidget::AudioCacheInvalidated);
|
||||
connect(n->audio_playback_cache(), &AudioPlaybackCache::Validated, this, &ViewerWidget::AudioCacheValidated);
|
||||
connect(n, &ViewerOutput::TextureInputChanged, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
VideoParams vp = n->GetVideoParams();
|
||||
@@ -229,6 +237,8 @@ void ViewerWidget::DisconnectNodeEvent(ViewerOutput *n)
|
||||
disconnect(n, &ViewerOutput::AudioParamsChanged, this, &ViewerWidget::UpdateRendererAudioParameters);
|
||||
disconnect(n->video_frame_cache(), &FrameHashCache::Invalidated, this, &ViewerWidget::ViewerInvalidatedVideoRange);
|
||||
disconnect(n->video_frame_cache(), &FrameHashCache::Shifted, this, &ViewerWidget::ViewerShiftedRange);
|
||||
disconnect(n->audio_playback_cache(), &AudioPlaybackCache::Invalidated, this, &ViewerWidget::AudioCacheInvalidated);
|
||||
disconnect(n->audio_playback_cache(), &AudioPlaybackCache::Validated, this, &ViewerWidget::AudioCacheValidated);
|
||||
disconnect(n, &ViewerOutput::TextureInputChanged, this, &ViewerWidget::UpdateStack);
|
||||
|
||||
ruler()->SetPlaybackCache(nullptr);
|
||||
@@ -390,13 +400,27 @@ void ViewerWidget::DecodeCachedImage(RenderTicketPtr ticket, const QString &fn,
|
||||
bool ViewerWidget::ShouldForceWaveform() const
|
||||
{
|
||||
return GetConnectedNode()
|
||||
&& !GetConnectedNode()->IsInputConnected(ViewerOutput::kTextureInput)
|
||||
&& GetConnectedNode()->IsInputConnected(ViewerOutput::kSamplesInput);
|
||||
&& !GetConnectedNode()->GetConnectedTextureOutput().IsValid()
|
||||
&& GetConnectedNode()->GetConnectedSampleOutput().IsValid();
|
||||
}
|
||||
|
||||
void ViewerWidget::StartAudioOutput()
|
||||
{
|
||||
AudioPlaybackCache* audio_cache = GetConnectedNode()->audio_playback_cache();
|
||||
if (audio_cache->GetParameters().is_valid()) {
|
||||
AudioManager::instance()->SetOutputParams(audio_cache->GetParameters());
|
||||
AudioManager::instance()->StartOutput(audio_cache,
|
||||
audio_cache->GetParameters().time_to_bytes(GetTime()),
|
||||
playback_speed_);
|
||||
emit AudioManager::instance()->OutputWaveformStarted(waveform_view_->waveform(),
|
||||
GetTime(), playback_speed_);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::UpdateTextureFromNode(const rational& time)
|
||||
{
|
||||
bool frame_exists_at_time = FrameExistsAtTime(time);
|
||||
bool frame_might_be_still = GetConnectedNode() && GetConnectedNode()->GetConnectedTextureOutput().IsValid() && GetConnectedNode()->GetVideoLength().isNull();
|
||||
|
||||
// Check playback queue for a frame
|
||||
if (IsPlaying()) {
|
||||
@@ -433,24 +457,24 @@ void ViewerWidget::UpdateTextureFromNode(const rational& time)
|
||||
}
|
||||
|
||||
// Only show warning if frame actually exists
|
||||
if (frame_exists_at_time) {
|
||||
if (frame_exists_at_time && !frame_might_be_still) {
|
||||
qWarning() << "Playback queue failed to keep up";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!frame_exists_at_time) {
|
||||
if (frame_exists_at_time || frame_might_be_still) {
|
||||
// Frame was not in queue, will require rendering or decoding from cache
|
||||
RenderTicketWatcher* watcher = new RenderTicketWatcher();
|
||||
connect(watcher, &RenderTicketWatcher::Finished, this, &ViewerWidget::RendererGeneratedFrame);
|
||||
nonqueue_watchers_.append(watcher);
|
||||
watcher->SetTicket(GetFrame(time, true));
|
||||
} else {
|
||||
// There is definitely no frame here, we can immediately flip to showing nothing
|
||||
nonqueue_watchers_.clear();
|
||||
SetDisplayImage(nullptr, false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Frame was not in queue, will require rendering or decoding from cache
|
||||
RenderTicketWatcher* watcher = new RenderTicketWatcher();
|
||||
connect(watcher, &RenderTicketWatcher::Finished, this, &ViewerWidget::RendererGeneratedFrame);
|
||||
nonqueue_watchers_.append(watcher);
|
||||
watcher->SetTicket(GetFrame(time, true));
|
||||
}
|
||||
|
||||
void ViewerWidget::PlayInternal(int speed, bool in_to_out_only)
|
||||
@@ -527,6 +551,7 @@ void ViewerWidget::PauseInternal()
|
||||
|
||||
playback_queue_.clear();
|
||||
playback_backup_timer_.stop();
|
||||
audio_restart_timer_.stop();
|
||||
}
|
||||
|
||||
prequeuing_ = false;
|
||||
@@ -593,9 +618,7 @@ QString ViewerWidget::GetCachedFilenameFromTime(const rational &time)
|
||||
|
||||
bool ViewerWidget::FrameExistsAtTime(const rational &time)
|
||||
{
|
||||
return GetConnectedNode()
|
||||
&& ((time >= 0 && time < GetConnectedNode()->video_frame_cache()->GetLength())
|
||||
|| GetConnectedNode()->video_frame_cache()->GetLength().isNull());
|
||||
return GetConnectedNode() && time >= 0 && time < GetConnectedNode()->GetVideoLength();
|
||||
}
|
||||
|
||||
void ViewerWidget::SetDisplayImage(FramePtr frame, bool main_only)
|
||||
@@ -650,13 +673,7 @@ void ViewerWidget::FinishPlayPreprocess()
|
||||
{
|
||||
int64_t playback_start_time = ruler()->GetTime();
|
||||
|
||||
AudioPlaybackCache* audio_cache = GetConnectedNode()->audio_playback_cache();
|
||||
if (audio_cache->GetParameters().is_valid()) {
|
||||
AudioManager::instance()->SetOutputParams(audio_cache->GetParameters());
|
||||
AudioManager::instance()->StartOutput(audio_cache,
|
||||
audio_cache->GetParameters().time_to_bytes(GetTime()),
|
||||
playback_speed_);
|
||||
}
|
||||
StartAudioOutput();
|
||||
|
||||
playback_timer_.Start(playback_start_time, playback_speed_, timebase_dbl());
|
||||
display_widget_->ResetFPSTimer();
|
||||
@@ -1263,4 +1280,21 @@ void ViewerWidget::Dropped(QDropEvent *event)
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::AudioCacheInvalidated()
|
||||
{
|
||||
if (IsPlaying()) {
|
||||
AudioManager::instance()->StopOutput();
|
||||
}
|
||||
}
|
||||
|
||||
void ViewerWidget::AudioCacheValidated()
|
||||
{
|
||||
if (IsPlaying()) {
|
||||
// This timer will restart audio
|
||||
AudioManager::instance()->StopOutput();
|
||||
audio_restart_timer_.stop();
|
||||
audio_restart_timer_.start();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -245,6 +245,8 @@ private:
|
||||
|
||||
PreviewAutoCacher auto_cacher_;
|
||||
|
||||
QTimer audio_restart_timer_;
|
||||
|
||||
static QVector<ViewerWidget*> instances_;
|
||||
|
||||
private slots:
|
||||
@@ -292,6 +294,11 @@ private slots:
|
||||
|
||||
void Dropped(QDropEvent* event);
|
||||
|
||||
void AudioCacheInvalidated();
|
||||
void AudioCacheValidated();
|
||||
|
||||
void StartAudioOutput();
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,8 @@ ViewerDisplayWidget::ViewerDisplayWidget(QWidget *parent) :
|
||||
hand_dragging_(false),
|
||||
deinterlace_(false),
|
||||
show_fps_(false),
|
||||
frames_skipped_(0)
|
||||
frames_skipped_(0),
|
||||
show_widget_background_(false)
|
||||
{
|
||||
connect(Core::instance(), &Core::ToolChanged, this, &ViewerDisplayWidget::UpdateCursor);
|
||||
|
||||
@@ -301,7 +302,7 @@ void ViewerDisplayWidget::dropEvent(QDropEvent *event)
|
||||
void ViewerDisplayWidget::OnPaint()
|
||||
{
|
||||
// Clear background to empty
|
||||
QColor bg_color = palette().window().color();
|
||||
QColor bg_color = show_widget_background_ ? palette().window().color() : Qt::black;
|
||||
renderer()->ClearDestination(bg_color.redF(), bg_color.greenF(), bg_color.blueF());
|
||||
|
||||
// We only draw if we have a pipeline
|
||||
|
||||
@@ -71,6 +71,12 @@ public:
|
||||
void SetVideoParams(const VideoParams ¶ms);
|
||||
void SetTime(const rational& time);
|
||||
|
||||
void SetShowWidgetBackground(bool e)
|
||||
{
|
||||
show_widget_background_ = e;
|
||||
update();
|
||||
}
|
||||
|
||||
FramePtr last_loaded_buffer() const;
|
||||
|
||||
/**
|
||||
@@ -288,6 +294,8 @@ private:
|
||||
QVector<double> frame_rate_averages_;
|
||||
int frame_rate_average_count_;
|
||||
|
||||
bool show_widget_background_;
|
||||
|
||||
private slots:
|
||||
void EmitColorAtCursor(QMouseEvent* e);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user