Cleanup mixer and disconnect on hide

parent eb3c8212
...@@ -42,8 +42,8 @@ static inline double levelToDB(double level) ...@@ -42,8 +42,8 @@ static inline double levelToDB(double level)
MixerManager::MixerManager(QWidget *parent) MixerManager::MixerManager(QWidget *parent)
: QWidget(parent) : QWidget(parent)
, renderPosition(0) , m_masterMixer(nullptr)
, m_connectedWidgets(0) , m_connectedWidgets(false)
{ {
m_masterBox = new QHBoxLayout; m_masterBox = new QHBoxLayout;
m_box = new QHBoxLayout; m_box = new QHBoxLayout;
...@@ -62,6 +62,9 @@ void MixerManager::registerTrack(int tid, std::shared_ptr<Mlt::Tractor> service, ...@@ -62,6 +62,9 @@ void MixerManager::registerTrack(int tid, std::shared_ptr<Mlt::Tractor> service,
connect(mixer.get(), &MixerWidget::muteTrack, [&](int id, bool mute) { connect(mixer.get(), &MixerWidget::muteTrack, [&](int id, bool mute) {
m_model->setTrackProperty(id, "hide", mute ? QStringLiteral("1") : QStringLiteral("3")); m_model->setTrackProperty(id, "hide", mute ? QStringLiteral("1") : QStringLiteral("3"));
}); });
if (m_connectedWidgets) {
mixer->connectMixer(true);
}
connect(this, &MixerManager::updateLevels, mixer.get(), &MixerWidget::updateAudioLevel); connect(this, &MixerManager::updateLevels, mixer.get(), &MixerWidget::updateAudioLevel);
connect(mixer.get(), &MixerWidget::toggleSolo, [&](int trid, bool solo) { connect(mixer.get(), &MixerWidget::toggleSolo, [&](int trid, bool solo) {
if (!solo) { if (!solo) {
...@@ -121,7 +124,6 @@ void MixerManager::cleanup() ...@@ -121,7 +124,6 @@ void MixerManager::cleanup()
if (m_masterMixer) { if (m_masterMixer) {
m_masterMixer->clear(true); m_masterMixer->clear(true);
} }
m_connectedWidgets = 0;
} }
void MixerManager::setModel(std::shared_ptr<TimelineItemModel> model) void MixerManager::setModel(std::shared_ptr<TimelineItemModel> model)
...@@ -148,6 +150,9 @@ void MixerManager::setModel(std::shared_ptr<TimelineItemModel> model) ...@@ -148,6 +150,9 @@ void MixerManager::setModel(std::shared_ptr<TimelineItemModel> model)
connect(m_masterMixer.get(), &MixerWidget::muteTrack, [&](int /*id*/, bool mute) { connect(m_masterMixer.get(), &MixerWidget::muteTrack, [&](int /*id*/, bool mute) {
m_model->tractor()->set("hide", mute ? 3 : 1); m_model->tractor()->set("hide", mute ? 3 : 1);
}); });
if (m_connectedWidgets) {
m_masterMixer->connectMixer(true);
}
connect(this, &MixerManager::updateLevels, m_masterMixer.get(), &MixerWidget::updateAudioLevel); connect(this, &MixerManager::updateLevels, m_masterMixer.get(), &MixerWidget::updateAudioLevel);
m_masterBox->addWidget(m_masterMixer.get()); m_masterBox->addWidget(m_masterMixer.get());
} }
...@@ -158,3 +163,14 @@ void MixerManager::recordStateChanged(int tid, bool recording) ...@@ -158,3 +163,14 @@ void MixerManager::recordStateChanged(int tid, bool recording)
m_mixers[tid]->setRecordState(recording); m_mixers[tid]->setRecordState(recording);
} }
} }
void MixerManager::connectMixer(bool connect)
{
m_connectedWidgets = connect;
for (auto item : m_mixers) {
item.second->connectMixer(m_connectedWidgets);
}
if (m_masterMixer != nullptr) {
m_masterMixer->connectMixer(m_connectedWidgets);
}
}
...@@ -42,11 +42,13 @@ class MixerManager : public QWidget ...@@ -42,11 +42,13 @@ class MixerManager : public QWidget
public: public:
MixerManager(QWidget *parent); MixerManager(QWidget *parent);
/* @brief Shows the parameters of the given transition model */ /** @brief Shows the parameters of the given transition model */
void registerTrack(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag); void registerTrack(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag);
void deregisterTrack(int tid); void deregisterTrack(int tid);
void setModel(std::shared_ptr<TimelineItemModel> model); void setModel(std::shared_ptr<TimelineItemModel> model);
void cleanup(); void cleanup();
/** @brief Connect the mixer widgets to the correspondant filters */
void connectMixer(bool connect);
public slots: public slots:
void resetAudioValues(); void resetAudioValues();
...@@ -57,9 +59,6 @@ signals: ...@@ -57,9 +59,6 @@ signals:
void recordAudio(int tid); void recordAudio(int tid);
void purgeCache(); void purgeCache();
public:
int renderPosition;
protected: protected:
std::unordered_map<int, std::shared_ptr<MixerWidget>> m_mixers; std::unordered_map<int, std::shared_ptr<MixerWidget>> m_mixers;
std::shared_ptr<MixerWidget> m_masterMixer; std::shared_ptr<MixerWidget> m_masterMixer;
...@@ -70,7 +69,7 @@ private: ...@@ -70,7 +69,7 @@ private:
QHBoxLayout *m_box; QHBoxLayout *m_box;
QHBoxLayout *m_masterBox; QHBoxLayout *m_masterBox;
int m_lastFrame; int m_lastFrame;
int m_connectedWidgets; bool m_connectedWidgets;
QVector <int> m_soloMuted; QVector <int> m_soloMuted;
}; };
......
...@@ -328,7 +328,6 @@ void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackTag) ...@@ -328,7 +328,6 @@ void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackTag)
if (service->get_int("hide") > 1) { if (service->get_int("hide") > 1) {
setMute(true); setMute(true);
} }
m_listener = m_monitorFilter->listen("property-changed", this, (mlt_listener)property_changed);
} }
void MixerWidget::mousePressEvent(QMouseEvent *event) void MixerWidget::mousePressEvent(QMouseEvent *event)
...@@ -449,3 +448,15 @@ void MixerWidget::setRecordState(bool recording) ...@@ -449,3 +448,15 @@ void MixerWidget::setRecordState(bool recording)
} }
updateLabel(); updateLabel();
} }
void MixerWidget::connectMixer(bool connect)
{
if (connect) {
if (m_listener == nullptr) {
m_listener = m_monitorFilter->listen("property-changed", this, (mlt_listener)property_changed);
}
} else {
delete m_listener;
m_listener = nullptr;
}
}
...@@ -64,6 +64,8 @@ public: ...@@ -64,6 +64,8 @@ public:
/** @brief Uncheck the solo button /** @brief Uncheck the solo button
* */ * */
void unSolo(); void unSolo();
/** @brief Connect the mixer widgets to the correspondant filters */
void connectMixer(bool connect);
protected: protected:
void mousePressEvent(QMouseEvent *event) override; void mousePressEvent(QMouseEvent *event) override;
......
...@@ -244,7 +244,10 @@ void MainWindow::init() ...@@ -244,7 +244,10 @@ void MainWindow::init()
QAction *showMixer = new QAction(QIcon::fromTheme(QStringLiteral("adjustlevels")), i18n("Audio Mixer"), this); QAction *showMixer = new QAction(QIcon::fromTheme(QStringLiteral("adjustlevels")), i18n("Audio Mixer"), this);
showMixer->setCheckable(true); showMixer->setCheckable(true);
addAction(QStringLiteral("audiomixer_button"), showMixer); addAction(QStringLiteral("audiomixer_button"), showMixer);
connect(mixerDock, &QDockWidget::visibilityChanged, showMixer, &QAction::setChecked); connect(mixerDock, &QDockWidget::visibilityChanged, [&, showMixer](bool visible) {
pCore->mixer()->connectMixer(visible);
showMixer->setChecked(visible);
});
connect(showMixer, &QAction::triggered, [&, mixerDock]() { connect(showMixer, &QAction::triggered, [&, mixerDock]() {
if (mixerDock->isVisible()) { if (mixerDock->isVisible()) {
mixerDock->close(); mixerDock->close();
...@@ -1894,9 +1897,6 @@ void MainWindow::connectDocument() ...@@ -1894,9 +1897,6 @@ void MainWindow::connectDocument()
pCore->mixer()->updateLevels(frame.get_position()); pCore->mixer()->updateLevels(frame.get_position());
//QMetaObject::invokeMethod(this, "setAudioValues", Qt::QueuedConnection, Q_ARG(const QVector<int> &, levels)); //QMetaObject::invokeMethod(this, "setAudioValues", Qt::QueuedConnection, Q_ARG(const QVector<int> &, levels));
}); });
connect(pCore->monitorManager(), &MonitorManager::frameRendered, [&](int pos) {
pCore->mixer()->renderPosition = pos;
});
connect(pCore->mixer(), &MixerManager::purgeCache, m_projectMonitor, &Monitor::purgeCache); connect(pCore->mixer(), &MixerManager::purgeCache, m_projectMonitor, &Monitor::purgeCache);
// TODO REFAC: reconnect to new timeline // TODO REFAC: reconnect to new timeline
......
...@@ -1543,11 +1543,6 @@ void GLWidget::on_frame_show(mlt_consumer, void *self, mlt_frame frame_ptr) ...@@ -1543,11 +1543,6 @@ void GLWidget::on_frame_show(mlt_consumer, void *self, mlt_frame frame_ptr)
} }
} }
void GLWidget::on_frame_render(mlt_consumer, GLWidget *widget, mlt_frame frame_ptr)
{
widget->frameRendered(mlt_frame_get_position(frame_ptr));
}
void GLWidget::on_gl_nosync_frame_show(mlt_consumer, void *self, mlt_frame frame_ptr) void GLWidget::on_gl_nosync_frame_show(mlt_consumer, void *self, mlt_frame frame_ptr)
{ {
Mlt::Frame frame(frame_ptr); Mlt::Frame frame(frame_ptr);
......
...@@ -184,7 +184,6 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren ...@@ -184,7 +184,6 @@ Monitor::Monitor(Kdenlive::MonitorId id, MonitorManager *manager, QWidget *paren
connect(m_horizontalScroll, &QAbstractSlider::valueChanged, this, &Monitor::setOffsetX); connect(m_horizontalScroll, &QAbstractSlider::valueChanged, this, &Monitor::setOffsetX);
connect(m_verticalScroll, &QAbstractSlider::valueChanged, this, &Monitor::setOffsetY); connect(m_verticalScroll, &QAbstractSlider::valueChanged, this, &Monitor::setOffsetY);
connect(m_glMonitor, &GLWidget::frameDisplayed, this, &Monitor::onFrameDisplayed); connect(m_glMonitor, &GLWidget::frameDisplayed, this, &Monitor::onFrameDisplayed);
connect(m_glMonitor, &GLWidget::frameRendered, manager, &MonitorManager::frameRendered, Qt::DirectConnection);
connect(m_glMonitor, &GLWidget::mouseSeek, this, &Monitor::slotMouseSeek); connect(m_glMonitor, &GLWidget::mouseSeek, this, &Monitor::slotMouseSeek);
connect(m_glMonitor, &GLWidget::monitorPlay, this, &Monitor::slotPlay); connect(m_glMonitor, &GLWidget::monitorPlay, this, &Monitor::slotPlay);
connect(m_glMonitor, &GLWidget::startDrag, this, &Monitor::slotStartDrag); connect(m_glMonitor, &GLWidget::startDrag, this, &Monitor::slotStartDrag);
......
...@@ -147,8 +147,6 @@ signals: ...@@ -147,8 +147,6 @@ signals:
void updateOverlayInfos(int, int); void updateOverlayInfos(int, int);
/** @brief info is available for audio spectrum widget */ /** @brief info is available for audio spectrum widget */
void frameDisplayed(const SharedFrame &); void frameDisplayed(const SharedFrame &);
/** @brief A frame was processed in the consumer queue */
void frameRendered(int);
/** @brief Triggered when the project monitor is paused (used to reset stored audiomixer data */ /** @brief Triggered when the project monitor is paused (used to reset stored audiomixer data */
void pauseTriggered(); void pauseTriggered();
}; };
......
...@@ -126,7 +126,6 @@ void ProjectManager::newFile(bool showProjectSettings) ...@@ -126,7 +126,6 @@ void ProjectManager::newFile(bool showProjectSettings)
void ProjectManager::newFile(QString profileName, bool showProjectSettings) void ProjectManager::newFile(QString profileName, bool showProjectSettings)
{ {
// fix mantis#3160
QUrl startFile = QUrl::fromLocalFile(KdenliveSettings::defaultprojectfolder() + QStringLiteral("/_untitled.kdenlive")); QUrl startFile = QUrl::fromLocalFile(KdenliveSettings::defaultprojectfolder() + QStringLiteral("/_untitled.kdenlive"));
if (checkForBackupFile(startFile, true)) { if (checkForBackupFile(startFile, true)) {
return; return;
......
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