Cleanup and add audio waveform overlay in monitor on audio clips (and optionnaly for video too)

parent 0f329871
......@@ -316,7 +316,10 @@ void KeyframeHelper::paintEvent(QPaintEvent *e)
int KeyframeHelper::value() const
{
return m_position;
if (m_seekPosition == SEEK_INACTIVE) {
return m_position;
}
return m_seekPosition;
}
void KeyframeHelper::setValue(const int pos)
......
......@@ -35,12 +35,13 @@ inline int lerp( const int a, const int b, double t )
return a + (b - a) * t;
}
//TODO: port to new qml monitor edit
CornersWidget::CornersWidget(Monitor *monitor, const QDomElement& e, int minFrame, int maxFrame, const Timecode &tc, int activeKeyframe, QWidget* parent) :
KeyframeEdit(e, minFrame, maxFrame, tc, activeKeyframe, parent),
m_monitor(monitor),
m_pos(0)
{
MonitorEditWidget *edit = monitor->getEffectEdit();
MonitorEditWidget *edit = NULL; //monitor->getEffectEdit();
m_scene = edit->getScene();
m_scene->cleanup();
......@@ -66,8 +67,8 @@ CornersWidget::~CornersWidget()
m_scene->removeItem(m_item);
delete m_item;
if (m_monitor) {
MonitorEditWidget *edit = m_monitor->getEffectEdit();
edit->removeCustomControls();
/*MonitorEditWidget *edit = m_monitor->getEffectEdit();
edit->removeCustomControls();*/
}
}
......
......@@ -494,7 +494,7 @@ void GeometryWidget::slotAddKeyframe(int pos)
return;
Mlt::GeometryItem item;
if (pos == -1)
pos = m_timePos->getValue();
pos = m_timeline->value(); // m_timePos->getValue();
item.frame(pos);
QRect rect = m_monitor->effectRect().normalized();
item.x(rect.x());
......
......@@ -636,7 +636,12 @@
<label>Show overlay info on monitor (in / out points, markers,...).</label>
<default>true</default>
</entry>
<entry name="displayAudioOverlay" type="Bool">
<label>Show audio overlay info on monitor.</label>
<default>false</default>
</entry>
<entry name="showOnMonitorScene" type="Bool">
<label>Show on monitor adjustable effect parameter (geometry, ..).</label>
<default>true</default>
......
......@@ -20,38 +20,21 @@
#include "abstractmonitor.h"
#include "monitormanager.h"
#include "glwidget.h"
#include "kdenlivesettings.h"
#include <QDebug>
#include <QDesktopWidget>
#include <QVBoxLayout>
#include <QMouseEvent>
AbstractMonitor::AbstractMonitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *parent):
QWidget(parent),
videoSurface(NULL),
m_id(id),
m_monitorManager(manager)
{
//videoBox = new VideoContainer(this);
}
AbstractMonitor::~AbstractMonitor()
{
//delete videoSurface;
}
void AbstractMonitor::createVideoSurface()
{
/*QVBoxLayout *lay = new QVBoxLayout;
lay->setContentsMargins(0, 0, 0, 0);
videoSurface = new VideoSurface;
lay->addWidget(videoSurface);
videoBox->setLayout(lay);*/
}
bool AbstractMonitor::isActive() const
......
......@@ -84,10 +84,7 @@ public:
virtual ~AbstractMonitor();
virtual AbstractRender *abstractRender() = 0;
bool isActive() const;
VideoSurface *videoSurface;
void createVideoSurface();
public slots:
virtual void stop() = 0;
virtual void start() = 0;
......
......@@ -65,6 +65,7 @@ GLWidget::GLWidget(bool accel, QObject *parent)
, m_offset(QPoint(0, 0))
, m_consumer(0)
, m_producer(0)
, m_audioWaveDisplayed(false)
{
qDebug() << "begin";
m_texture[0] = m_texture[1] = m_texture[2] = 0;
......@@ -511,9 +512,27 @@ static void onThreadStopped(mlt_properties owner, GLWidget* self)
self->stopGlsl();
}
void GLWidget::slotSwitchAudioOverlay(bool enable)
{
KdenliveSettings::setDisplayAudioOverlay(enable);
if (m_audioWaveDisplayed && enable == false) {
if (m_producer && m_producer->get_int("video_index") != -1) {
// We have a video producer, disable filter
removeAudioOverlay();
}
}
if (enable && !m_audioWaveDisplayed) {
createAudioOverlay(m_producer->get_int("video_index") == -1);
}
}
int GLWidget::setProducer(Mlt::Producer* producer, bool isMulti)
{
int error = 0;//Controller::setProducer(producer, isMulti);
/*if (m_producer) {
delete m_producer;
m_producer = NULL;
}*/
m_producer = producer;
if (!error && producer) {
error = reconfigure(isMulti);
......@@ -522,9 +541,86 @@ int GLWidget::setProducer(Mlt::Producer* producer, bool isMulti)
resizeGL(width(), height());
}
}
if (m_producer->get_int("video_index") == -1 && !KdenliveSettings::gpu_accel()) {
// This is an audio only clip, attach visualization filter. Currently, the filter crashes MLT when Movit accel is used
if (!m_audioWaveDisplayed) {
createAudioOverlay(true);
}
else {
adjustAudioOverlay(true);
}
}
else if (m_audioWaveDisplayed) {
// This is not an audio clip, hide wave
if (KdenliveSettings::displayAudioOverlay()) {
adjustAudioOverlay(m_producer->get_int("video_index") == -1);
}
else {
removeAudioOverlay();
}
}
return error;
}
void GLWidget::createAudioOverlay(bool isAudio)
{
Mlt::Filter f(*pCore->binController()->profile(), "audiowaveform");
if (f.is_valid()) {
//f.set("show_channel", 1);
f.set("color.1", "0xffff0099");
f.set("fill", 1);
if (isAudio) {
// Fill screen
f.set("rect", "0,0,100%,100%");
} else {
// Overlay on lower part of the screen
f.set("rect", "0,80%,100%,20%");
}
m_consumer->attach(f);
m_audioWaveDisplayed = true;
}
}
void GLWidget::removeAudioOverlay()
{
Mlt::Service sourceService(m_consumer->get_service());
// move all effects to the correct producer
int ct = 0;
Mlt::Filter *filter = sourceService.filter(ct);
while (filter) {
QString srv = filter->get("mlt_service");
if (srv == "audiowaveform") {
sourceService.detach(*filter);
delete filter;
break;
} else ct++;
filter = sourceService.filter(ct);
}
m_audioWaveDisplayed = false;
}
void GLWidget::adjustAudioOverlay(bool isAudio)
{
Mlt::Service sourceService(m_consumer->get_service());
// move all effects to the correct producer
int ct = 0;
Mlt::Filter *filter = sourceService.filter(ct);
while (filter) {
QString srv = filter->get("mlt_service");
if (srv == "audiowaveform") {
if (isAudio) {
filter->set("rect", "0,0,100%,100%");
}
else {
filter->set("rect", "0,80%,100%,20%");
}
break;
} else ct++;
filter = sourceService.filter(ct);
}
}
int GLWidget::reconfigure(bool isMulti)
{
int error = 0;
......
......@@ -89,6 +89,7 @@ public slots:
void setOffsetY(int y);
void setBlankScene();
void slotShowEffectScene(bool show);
void slotSwitchAudioOverlay(bool enable);
//void setCurrentFilter(QmlFilter* filter, QmlMetadata* meta);
signals:
......@@ -133,8 +134,11 @@ private:
int m_textureLocation[3];
float m_zoom;
QPoint m_offset;
bool m_audioWaveDisplayed;
static void on_frame_show(mlt_consumer, void* self, mlt_frame frame);
void createAudioOverlay(bool isAudio);
void removeAudioOverlay();
void adjustAudioOverlay(bool isAudio);
private slots:
void initializeGL();
......
......@@ -21,8 +21,6 @@
#include "monitor.h"
#include "monitorscene.h"
#include "monitoreditwidget.h"
#include "videosurface.h"
#include "glwidget.h"
#include "smallruler.h"
#include "mltcontroller/clipcontroller.h"
......@@ -61,12 +59,12 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
, m_dragStarted(false)
, m_loopClipAction(NULL)
, m_contextMenu(NULL)
, m_effectWidget(NULL)
, m_selectedClip(NULL)
, m_loopClipTransition(true)
, m_editMarker(NULL)
, m_glMonitor(NULL)
, m_rootItem(NULL)
, m_showEffectScene(false)
{
QVBoxLayout *layout = new QVBoxLayout;
layout->setContentsMargins(0, 0, 0, 0);
......@@ -206,7 +204,7 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
QAction *visibilityAction = new QAction(QIcon::fromTheme("video-display"), i18n("Show/Hide edit mode"), this);
visibilityAction->setCheckable(true);
visibilityAction->setChecked(KdenliveSettings::showOnMonitorScene());
connect(visibilityAction, SIGNAL(triggered(bool)), m_glMonitor, SLOT(slotShowEffectScene(bool)));
connect(visibilityAction, SIGNAL(triggered(bool)), this, SLOT(slotEnableEffectScene(bool)));
//visibilityAction->setVisible(false);
m_toolbar->addAction(visibilityAction);
/*m_effectWidget = new MonitorEditWidget(render, m_glWidget);
......@@ -231,8 +229,6 @@ Monitor::~Monitor()
delete m_ruler;
delete m_timePos;
delete m_overlay;
if (m_effectWidget)
delete m_effectWidget;
delete render;
}
......@@ -288,9 +284,15 @@ void Monitor::setupMenu(QMenu *goMenu, QAction *playZone, QAction *loopZone, QMe
dropFrames->setCheckable(true);
dropFrames->setChecked(true);
connect(dropFrames, SIGNAL(toggled(bool)), this, SLOT(slotSwitchDropFrames(bool)));
QAction *overlayAudio = m_contextMenu->addAction(QIcon(), i18n("Overlay audio waveform"));
overlayAudio->setCheckable(true);
connect(overlayAudio, SIGNAL(toggled(bool)), m_glMonitor, SLOT(slotSwitchAudioOverlay(bool)));
overlayAudio->setChecked(KdenliveSettings::displayAudioOverlay());
m_configMenu->addAction(showTips);
m_configMenu->addAction(dropFrames);
m_configMenu->addAction(overlayAudio);
}
void Monitor::slotGoToMarker(QAction *action)
......@@ -453,7 +455,7 @@ void Monitor::mousePressEvent(QMouseEvent * event)
m_dragStarted = true;
m_DragStartPosition = event->pos();
}
} else if (m_contextMenu && (!m_effectWidget || !m_effectWidget->isVisible())) {
} else if (m_contextMenu) {
m_contextMenu->popup(event->globalPos());
}
}
......@@ -527,7 +529,7 @@ void Monitor::slotSwitchFullScreen()
void Monitor::mouseReleaseEvent(QMouseEvent * event)
{
if (m_dragStarted && event->button() != Qt::RightButton) {
if (m_glMonitor->geometry().contains(event->pos()) && (!m_effectWidget || !m_effectWidget->isVisible())) {
if (m_glMonitor->geometry().contains(event->pos())) {
if (isActive()) slotPlay();
else slotActivateMonitor();
} //else event->ignore(); //QWidget::mouseReleaseEvent(event);
......@@ -1060,8 +1062,6 @@ void Monitor::resetProfile(const QString &profile)
render->resetProfile(profile);
}
m_rootItem->setProperty("framesize", QRect(0, 0, m_glMonitor->profileSize().width(), m_glMonitor->profileSize().height()));
if (m_effectWidget)
m_effectWidget->resetProfile(render);
}
void Monitor::saveSceneList(const QString &path, const QDomElement &info)
......@@ -1147,56 +1147,18 @@ void Monitor::slotSetSelectedClip(Transition* item)
}
void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
void Monitor::slotEnableEffectScene(bool enable)
{
m_glMonitor->slotShowEffectScene(show);
return;
if (m_id == Kdenlive::ProjectMonitor) {
if (!m_effectWidget->getVisibilityAction()->isChecked())
show = false;
if (m_effectWidget->isVisible() == show)
return;
setUpdatesEnabled(false);
if (show) {
if (videoSurface) {
videoSurface->setVisible(false);
// Preview is handeled internally through the Render::showFrame method
render->disablePreview(true);
#ifdef USE_OPENGL
} else {
m_glWidget->setVisible(false);
#endif
}
m_effectWidget->setVisible(true);
m_effectWidget->getScene()->slotZoomFit();
emit requestFrameForAnalysis(true);
} else {
m_effectWidget->setVisible(false);
emit requestFrameForAnalysis(false);
if (videoSurface) {
videoSurface->setVisible(true);
// Preview is handeled internally through the Render::showFrame method
render->disablePreview(false);
#ifdef USE_OPENGL
} else {
m_glWidget->setVisible(true);
#endif
}
}
if (!manuallyTriggered)
m_effectWidget->showVisibilityButton(show);
setUpdatesEnabled(true);
//TODO:
//videoBox->setEnabled(show);
//render->doRefresh();
KdenliveSettings::setShowOnMonitorScene(enable);
if (m_showEffectScene) {
slotShowEffectScene(true);
}
}
MonitorEditWidget* Monitor::getEffectEdit()
void Monitor::slotShowEffectScene(bool show, bool manuallyTriggered)
{
return m_effectWidget;
m_showEffectScene = show;
m_glMonitor->slotShowEffectScene(show && KdenliveSettings::showOnMonitorScene());
}
void Monitor::setUpEffectGeometry(QRect r)
......
......@@ -40,7 +40,6 @@ class ClipController;
class AbstractClipItem;
class Transition;
class ClipItem;
class MonitorEditWidget;
class Monitor;
class MonitorManager;
class QSlider;
......@@ -86,7 +85,6 @@ public:
void updateMarkers();
ClipController *currentController() const;
void setMarkers(const QList <CommentedTime> &markers);
MonitorEditWidget *getEffectEdit();
void reloadProducer(const QString &id);
QFrame *m_volumePopup;
/** @brief Reimplemented from QWidget, updates the palette colors. */
......@@ -140,13 +138,13 @@ private:
QMenu *m_playMenu;
QMenu *m_markerMenu;
QPoint m_DragStartPosition;
MonitorEditWidget *m_effectWidget;
/** Selected clip/transition in timeline. Used for looping it. */
AbstractClipItem *m_selectedClip;
/** true if selected clip is transition, false = selected clip is clip.
* Necessary because sometimes we get two signals, e.g. we get a clip and we get selected transition = NULL. */
bool m_loopClipTransition;
QWidget *m_glWidget;
bool m_showEffectScene;
GenTime getSnapForPos(bool previous);
Qt::WindowFlags m_baseFlags;
......@@ -178,6 +176,7 @@ private slots:
void onFrameDisplayed(const SharedFrame& frame);
void slotStartDrag();
void setZoom();
void slotEnableEffectScene(bool enable);
public slots:
void slotOpenFile(const QString &);
......
......@@ -26,7 +26,6 @@
#include "capture/mltdevicecapture.h"
#include "capture/managecapturesdialog.h"
#include "dialogs/profilesdialog.h"
#include "videosurface.h"
#include "glwidget.h"
#include <config-kdenlive.h>
......@@ -64,7 +63,6 @@ RecMonitor::RecMonitor(Kdenlive::MonitorId name, MonitorManager *manager, QWidge
l->setContentsMargins(0, 0, 0, 0);
l->setSpacing(0);
video_frame->setLayout(l);
createVideoSurface();
QToolBar *toolbar = new QToolBar(this);
QHBoxLayout *hlayout = new QHBoxLayout;
......@@ -145,20 +143,9 @@ RecMonitor::RecMonitor(Kdenlive::MonitorId name, MonitorManager *manager, QWidge
connect(m_captureProcess, &QProcess::stateChanged, this, &RecMonitor::slotProcessStatus);
connect(m_captureProcess, &QProcess::readyReadStandardError, this, &RecMonitor::slotReadProcessInfo);
QString videoDriver = KdenliveSettings::videodrivername();
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
env.insert("SDL_WINDOWID", QString::number(videoSurface->winId()));
if (!videoDriver.isEmpty()) {
if (videoDriver == "x11_noaccel") {
env.insert("SDL_VIDEO_YUV_HWACCEL", "0");
env.insert("SDL_VIDEODRIVER", "x11");
} else env.insert("SDL_VIDEODRIVER", videoDriver);
}
m_displayProcess->setProcessEnvironment(env);
qputenv("SDL_VIDEO_ALLOW_SCREENSAVER", "1");
//qDebug() << "/////// BUILDING MONITOR, ID: " << videoSurface->winId();
m_infoMessage = new KMessageWidget;
QVBoxLayout *s = static_cast <QVBoxLayout *> (layout());
s->insertWidget(1, m_infoMessage);
......@@ -1041,7 +1028,6 @@ void RecMonitor::buildMltDevice(const QString &path)
m_captureDevice->sendFrameForAnalysis = m_analyse;
m_monitorManager->updateScopeSource();
}
videoSurface->show();
}
void RecMonitor::slotChangeRecordingPreview(bool enable)
......
......@@ -42,6 +42,7 @@ void tracking_finished(mlt_service *owner, RotoWidget *self, char *data)
self->setSpline(QByteArray(data));
}
//TODO: port to new qml monitor edit
RotoWidget::RotoWidget(const QByteArray &data, Monitor *monitor, const ItemInfo &info, const Timecode &t, QWidget* parent) :
QWidget(parent),
m_monitor(monitor),
......@@ -53,7 +54,7 @@ RotoWidget::RotoWidget(const QByteArray &data, Monitor *monitor, const ItemInfo
m_keyframeWidget = new SimpleKeyframeWidget(t, m_out - m_in, this);
l->addWidget(m_keyframeWidget);
MonitorEditWidget *edit = monitor->getEffectEdit();
MonitorEditWidget *edit = NULL; //monitor->getEffectEdit();
m_scene = edit->getScene();
m_scene->cleanup();
......@@ -82,8 +83,8 @@ RotoWidget::~RotoWidget()
delete m_item;
if (m_monitor) {
MonitorEditWidget *edit = m_monitor->getEffectEdit();
edit->removeCustomControls();
/*MonitorEditWidget *edit = m_monitor->getEffectEdit();
edit->removeCustomControls();*/
m_monitor->slotShowEffectScene(false);
}
}
......
......@@ -1216,10 +1216,9 @@ int Render::setProducer(Mlt::Producer *producer, int position, bool isActive)
if (position != -1) producer->seek(position);
m_fps = producer->get_fps();
int volume = KdenliveSettings::volume();
/*
if (producer->get_int("_audioclip") == 1) {
// This is an audio only clip, create fake multitrack to apply audiowave filter
Mlt::Tractor *tractor = new Mlt::Tractor();
/*Mlt::Tractor *tractor = new Mlt::Tractor();
Mlt::Producer *color= new Mlt::Producer(*m_mltProfile, "color:red");
color->set_in_and_out(0, producer->get_out());
tractor->set_track(*producer, 0);
......@@ -1242,17 +1241,17 @@ int Render::setProducer(Mlt::Producer *producer, int position, bool isActive)
delete result;
tractor->track(0)->attach(*filter);
delete filter;
producer = &(tractor->parent());
}
producer = &(tractor->parent());*/
producer->set("meta.volume", (double)volume / 100);
if (m_mltProducer) {
//producer->set("meta.volume", (double)volume / 100);
/*if (m_mltProducer) {
m_mltProducer->set_speed(0);
delete m_mltProducer;
m_mltProducer = NULL;
}
*/
}*/
blockSignals(false);
m_mltProducer = producer;
m_mltProducer->set_speed(0);
......
......@@ -94,7 +94,6 @@ StopmotionMonitor::StopmotionMonitor(MonitorManager *manager, QWidget *parent) :
AbstractMonitor(Kdenlive::StopMotionMonitor, manager, parent),
m_captureDevice(NULL)
{
createVideoSurface();
}
StopmotionMonitor::~StopmotionMonitor()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment