Commit ace08d61 authored by Julius Künzel's avatar Julius Künzel
Browse files

Audiomixer: show track name


Signed-off-by: Julius Künzel's avatarJulius Künzel <jk.kdedev@smartlab.uber.space>
parent 94770e55
Pipeline #51360 canceled with stage
......@@ -67,13 +67,13 @@ MixerManager::MixerManager(QWidget *parent)
setLayout(m_box);
}
void MixerManager::registerTrack(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag)
void MixerManager::registerTrack(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag, const QString &trackName)
{
if (m_mixers.count(tid) > 0) {
// Track already registered
return;
}
std::shared_ptr<MixerWidget> mixer(new MixerWidget(tid, service, trackTag, this));
std::shared_ptr<MixerWidget> mixer(new MixerWidget(tid, service, trackTag, trackName, this));
connect(mixer.get(), &MixerWidget::muteTrack, this, [&](int id, bool mute) {
m_model->setTrackProperty(id, "hide", mute ? QStringLiteral("1") : QStringLiteral("3"));
});
......@@ -153,6 +153,14 @@ void MixerManager::setModel(std::shared_ptr<TimelineItemModel> model)
} else {
qDebug()<<"=== MODEL DATA CHANGED: MUTE DONE TRACK NOT FOUND!!!";
}
} else if (roles.contains(TimelineModel::NameRole)) {
int id = (int) topLeft.internalId();
if (m_mixers.count(id) > 0) {
qDebug()<<"=== MODEL DATA CHANGED: CHANGED";
m_mixers[id]->setTrackName(m_model->data(topLeft, TimelineModel::NameRole).toString());
} else {
qDebug()<<"=== MODEL DATA CHANGED: CHANGE NAME DONE TRACK NOT FOUND!!!";
}
}
});
......@@ -161,7 +169,7 @@ void MixerManager::setModel(std::shared_ptr<TimelineItemModel> model)
// delete previous master mixer
m_masterBox->removeWidget(m_masterMixer.get());
}
m_masterMixer.reset(new MixerWidget(-1, service, i18n("Master"), this));
m_masterMixer.reset(new MixerWidget(-1, service, i18n("Master"), QString(), this));
connect(m_masterMixer.get(), &MixerWidget::muteTrack, this, [&](int /*id*/, bool mute) {
m_model->tractor()->set("hide", mute ? 3 : 1);
});
......
......@@ -44,7 +44,7 @@ class MixerManager : public QWidget
public:
MixerManager(QWidget *parent);
/** @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, const QString &trackName);
void deregisterTrack(int tid);
void setModel(std::shared_ptr<TimelineItemModel> model);
void cleanup();
......
......@@ -44,6 +44,7 @@
#include <QMouseEvent>
#include <QStyle>
#include <QFontDatabase>
#include <KSqueezedTextLabel>
static inline double IEC_Scale(double dB)
{
......@@ -99,7 +100,7 @@ void MixerWidget::property_changed( mlt_service , MixerWidget *widget, char *nam
}
}
MixerWidget::MixerWidget(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag, MixerManager *parent)
MixerWidget::MixerWidget(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag, const QString &trackName, MixerManager *parent)
: QWidget(parent)
, m_manager(parent)
, m_tid(tid)
......@@ -115,11 +116,12 @@ MixerWidget::MixerWidget(int tid, std::shared_ptr<Mlt::Tractor> service, const Q
, m_lastVolume(0)
, m_listener(nullptr)
, m_recording(false)
, m_trackTag(trackTag)
{
buildUI(service.get(), trackTag);
buildUI(service.get(), trackName);
}
MixerWidget::MixerWidget(int tid, Mlt::Tractor *service, const QString &trackTag, MixerManager *parent)
MixerWidget::MixerWidget(int tid, Mlt::Tractor *service, const QString &trackTag, const QString &trackName, MixerManager *parent)
: QWidget(parent)
, m_manager(parent)
, m_tid(tid)
......@@ -135,8 +137,9 @@ MixerWidget::MixerWidget(int tid, Mlt::Tractor *service, const QString &trackTag
, m_lastVolume(0)
, m_listener(nullptr)
, m_recording(false)
, m_trackTag(trackTag)
{
buildUI(service, trackTag);
buildUI(service, trackName);
}
MixerWidget::~MixerWidget()
......@@ -146,7 +149,7 @@ MixerWidget::~MixerWidget()
}
}
void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackTag)
void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackName)
{
setFont(QFontDatabase::systemFont(QFontDatabase::SmallestReadableFont));
// Build audio meter widget
......@@ -243,10 +246,12 @@ void MixerWidget::buildUI(Mlt::Tractor *service, const QString &trackTag)
}
}
m_trackLabel = new QLabel(trackTag, this);
m_trackLabel = new KSqueezedTextLabel(this);
m_trackLabel->setAutoFillBackground(true);
m_trackLabel->setAlignment(Qt::AlignHCenter);
m_trackLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken);
m_trackLabel->setTextElideMode(Qt::ElideRight);
setTrackName(trackName);
m_muteAction = new KDualAction(i18n("Mute track"), i18n("Unmute track"), this);
m_muteAction->setActiveIcon(QIcon::fromTheme(QStringLiteral("kdenlive-hide-audio")));
m_muteAction->setInactiveIcon(QIcon::fromTheme(QStringLiteral("kdenlive-show-audio")));
......@@ -411,6 +416,15 @@ void MixerWidget::mousePressEvent(QMouseEvent *event)
}
}
void MixerWidget::setTrackName(const QString &name) {
// Show only tag on master or if name is empty
if (name.isEmpty() || m_tid == -1) {
m_trackLabel->setText(m_trackTag);
} else {
m_trackLabel->setText(QString("%1 - %2").arg(m_trackTag).arg(name));
}
}
void MixerWidget::setMute(bool mute)
{
m_muteAction->setActive(mute);
......
......@@ -39,6 +39,7 @@ class QDoubleSpinBox;
class QLabel;
class QToolButton;
class MixerManager;
class KSqueezedTextLabel;
namespace Mlt {
class Tractor;
......@@ -50,15 +51,16 @@ class MixerWidget : public QWidget
Q_OBJECT
public:
MixerWidget(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag, MixerManager *parent = nullptr);
MixerWidget(int tid, Mlt::Tractor *service, const QString &trackTag, MixerManager *parent = nullptr);
MixerWidget(int tid, std::shared_ptr<Mlt::Tractor> service, const QString &trackTag, const QString &trackName, MixerManager *parent = nullptr);
MixerWidget(int tid, Mlt::Tractor *service, const QString &trackTag, const QString &trackName, MixerManager *parent = nullptr);
virtual ~MixerWidget();
void buildUI(Mlt::Tractor *service, const QString &trackTag);
void buildUI(Mlt::Tractor *service, const QString &trackName);
/** @brief discard stored audio values and reset vu-meter to 0 if requested */
void reset();
/** @brief discard stored audio values */
void clear();
static void property_changed( mlt_service , MixerWidget *self, char *name );
void setTrackName(const QString &name);
void setMute(bool mute);
/** @brief Returns true if track is muted
* */
......@@ -101,12 +103,13 @@ private:
QToolButton *m_solo;
QToolButton *m_record;
QToolButton *m_collapse;
QLabel *m_trackLabel;
KSqueezedTextLabel *m_trackLabel;
QMutex m_storeMutex;
int m_lastVolume;
QVector <double>m_audioData;
Mlt::Event *m_listener;
bool m_recording;
const QString m_trackTag;
/** @Update track label to reflect state */
void updateLabel();
......
......@@ -679,7 +679,7 @@ void TimelineItemModel::buildTrackCompositing(bool rebuild)
transition->set_tracks(0, trackPos);
field->plant_transition(*transition.get(), 0, trackPos);
if (hasMixer) {
pCore->mixer()->registerTrack((*it)->getId(), (*it)->getTrackService(), getTrackTagById((*it)->getId()));
pCore->mixer()->registerTrack((*it)->getId(), (*it)->getTrackService(), getTrackTagById((*it)->getId()), (*it)->getProperty(QStringLiteral("kdenlive:track_name")).toString());
connect(pCore->mixer(), &MixerManager::showEffectStack, this, &TimelineItemModel::showTrackEffectStack);
}
}
......
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