Refactor clip monitor audio thumbnails to use same data as timeline thumbnail.

We now just need to also use this data to generate the bin thumbnail and memory usage should get back to normal
Related to #102
parent b205949e
Pipeline #28908 passed with stage
in 31 minutes and 3 seconds
......@@ -179,7 +179,7 @@ public:
/** @brief Returns the number of audio channels. */
int audioChannels() const;
/** @brief get data analysis value. */
/** @brief get data analysis value. */
QStringList updatedAnalysisData(const QString &name, const QString &data, int offset);
QMap<QString, QString> analysisData(bool withPrefix = false);
/** @brief Returns the list of this clip's subclip's ids. */
......
......@@ -1028,6 +1028,7 @@ void KdenliveSettingsDialog::updateSettings()
KdenliveSettings::setThumbColor1(m_configColors.kcfg_thumbColor1->color());
KdenliveSettings::setThumbColor2(m_configColors.kcfg_thumbColor2->color());
emit pCore->window()->getMainTimeline()->controller()->colorsChanged();
emit pCore->getMonitor(Kdenlive::ClipMonitor)->refreshAudioThumbs();
}
if (m_configSdl.kcfg_volume->value() != KdenliveSettings::volume()) {
......@@ -1042,6 +1043,7 @@ void KdenliveSettingsDialog::updateSettings()
if (m_configTimeline.kcfg_displayallchannels->isChecked() != KdenliveSettings::displayallchannels()) {
KdenliveSettings::setDisplayallchannels(m_configTimeline.kcfg_displayallchannels->isChecked());
emit audioThumbFormatChanged();
emit pCore->getMonitor(Kdenlive::ClipMonitor)->refreshAudioThumbs();
}
if (m_modified) {
......
......@@ -68,6 +68,7 @@ AudioStreamInfo::AudioStreamInfo(const std::shared_ptr<Mlt::Producer> &producer,
streamIndex++;
}
m_audioStreams.insert(ix, channelDescription);
m_audioChannels.insert(ix, chan);
}
}
QString active = producer->get("kdenlive:active_streams");
......@@ -115,6 +116,22 @@ QMap <int, QString> AudioStreamInfo::streams() const
return m_audioStreams;
}
QList <int> AudioStreamInfo::streamChannels() const
{
if (m_activeStreams.size() == 1 && m_activeStreams.contains(INT_MAX)) {
return m_audioChannels.values();
}
QList <int> activeChannels;
QMapIterator<int, QString> i(m_audioStreams);
while (i.hasNext()) {
i.next();
if (m_activeStreams.contains(i.key())) {
activeChannels << m_audioChannels.value(i.key());
}
}
return activeChannels;
}
QMap <int, QString> AudioStreamInfo::activeStreams() const
{
QMap <int, QString> active;
......
......@@ -28,7 +28,11 @@ public:
int samplingRate() const;
int channels() const;
/** @brief returns a list of audio stream index > stream description */
QMap <int, QString> streams() const;
/** @brief returns a list of audio stream index > channels per stream */
QList <int> streamChannels() const;
/** @brief returns a list of enabled audio stream indexes > stream description */
QMap <int, QString> activeStreams() const;
int bitrate() const;
const QString &samplingFormat() const;
......@@ -43,6 +47,7 @@ public:
private:
int m_audioStreamIndex;
QMap <int, QString> m_audioStreams;
QMap <int, int> m_audioChannels;
QList <int> m_activeStreams;
int m_ffmpegAudioIndex;
int m_samplingRate;
......
......@@ -78,7 +78,6 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
//TODO: is it a good option ?
QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts, true);
#if defined(Q_OS_WIN)
KSharedConfigPtr configWin = KSharedConfig::openConfig("kdenliverc");
......
......@@ -2611,6 +2611,9 @@ void MainWindow::slotSeparateAudioChannel()
{
KdenliveSettings::setDisplayallchannels(!KdenliveSettings::displayallchannels());
emit getCurrentTimeline()->controller()->audioThumbFormatChanged();
if (m_clipMonitor) {
emit m_clipMonitor->refreshAudioThumbs();
}
}
void MainWindow::slotInsertTrack()
......
......@@ -1044,6 +1044,14 @@ QMap <int, QString> ClipController::audioStreams() const
return {};
}
QList <int> ClipController::activeStreamChannels() const
{
if (!audioInfo()) {
return QList <int>();
}
return audioInfo()->streamChannels();
}
QMap <int, QString> ClipController::activeStreams() const
{
if (m_audioInfo) {
......
......@@ -218,6 +218,8 @@ public:
/** @brief Returns the list of all audio streams indexes for this clip */
QMap <int, QString> audioStreams() const;
/** @brief Returns the number of channels per audio stream. */
QList <int> activeStreamChannels() const;
/** @brief Returns the list of active audio streams indexes for this clip */
QMap <int, QString> activeStreams() const;
/** @brief Returns the count of audio streams for this clip */
......
......@@ -1189,6 +1189,12 @@ void Monitor::slotSeek(int pos)
emit m_monitorManager->cleanMixer();
}
void Monitor::refreshAudioThumbs()
{
emit m_glMonitor->getControllerProxy()->audioThumbFormatChanged();
emit m_glMonitor->getControllerProxy()->colorsChanged();
}
void Monitor::checkOverlay(int pos)
{
if (m_qmlManager->sceneType() != MonitorSceneDefault) {
......@@ -1570,11 +1576,21 @@ void Monitor::slotOpenClip(const std::shared_ptr<ProjectClip> &controller, int i
m_playAction->setActive(false);
}
m_audioMeterWidget->audioChannels = controller->audioInfo() ? controller->audioInfo()->channels() : 0;
if (!m_controller->hasVideo() || KdenliveSettings::displayClipMonitorInfo() & 0x10) {
m_glMonitor->getControllerProxy()->setAudioThumb(m_audioMeterWidget->audioChannels == 0 ? QList<QUrl>() : ThumbnailCache::get()->getAudioThumbPath(m_controller->clipId()));
}
m_controller->getMarkerModel()->registerSnapModel(m_snaps);
m_glMonitor->getControllerProxy()->setClipProperties(controller->clipId().toInt(), controller->clipType(), controller->hasAudioAndVideo(), controller->clipName());
if (!m_controller->hasVideo() || KdenliveSettings::displayClipMonitorInfo() & 0x10) {
qDebug()<<"=======\n\nSETTING AUDIO DATA IN MON\n\n=========";
if (m_audioMeterWidget->audioChannels == 0) {
m_glMonitor->getControllerProxy()->setAudioThumb();
} else {
QList<int> streamIndexes = m_controller->activeStreams().keys();
if (streamIndexes.count() == 1 && streamIndexes.at(0) == INT_MAX) {
// Display all streams
streamIndexes = m_controller->audioStreams().keys();
}
m_glMonitor->getControllerProxy()->setAudioThumb(streamIndexes, m_controller->activeStreamChannels());
}
}
m_glMonitor->setProducer(m_controller->originalProducer(), isActive(), in);
} else {
qDebug()<<"*************** CONTROLLER NOT READY";
......@@ -2208,7 +2224,15 @@ void Monitor::slotEditInlineMarker()
void Monitor::prepareAudioThumb()
{
if (m_controller) {
m_glMonitor->getControllerProxy()->setAudioThumb(ThumbnailCache::get()->getAudioThumbPath(m_controller->clipId()));
m_glMonitor->getControllerProxy()->setAudioThumb();
if (!m_controller->audioStreams().isEmpty()) {
QList<int> streamIndexes = m_controller->activeStreams().keys();
if (streamIndexes.count() == 1 && streamIndexes.at(0) == INT_MAX) {
// Display all streams
streamIndexes = m_controller->audioStreams().keys();
}
m_glMonitor->getControllerProxy()->setAudioThumb(streamIndexes, m_controller->activeStreamChannels());
}
}
}
......
......@@ -160,6 +160,8 @@ public:
/** @brief Returns true if monitor is currently fullscreen */
bool monitorIsFullScreen() const;
void reloadActiveStream();
/** @brief Trigger a refresh of audio thumbs colors */
void refreshAudioThumbs();
protected:
......
......@@ -338,9 +338,10 @@ void MonitorProxy::setClipProperties(int clipId, ClipType::ProducerType type, bo
emit clipNameChanged();
}
void MonitorProxy::setAudioThumb(const QList <QUrl> thumbPath)
void MonitorProxy::setAudioThumb(const QList <int> streamIndexes, QList <int> channels)
{
m_audioThumb = thumbPath;
m_audioChannels = channels;
m_audioStreams = streamIndexes;
emit audioThumbChanged();
}
......@@ -356,3 +357,18 @@ QPoint MonitorProxy::profile()
QSize s = pCore->getCurrentFrameSize();
return QPoint(s.width(), s.height());
}
QColor MonitorProxy::thumbColor1() const
{
return KdenliveSettings::thumbColor1();
}
QColor MonitorProxy::thumbColor2() const
{
return KdenliveSettings::thumbColor2();
}
bool MonitorProxy::audioThumbFormat() const
{
return KdenliveSettings::displayallchannels();
}
......@@ -44,8 +44,12 @@ class MonitorProxy : public QObject
Q_PROPERTY(int zoneOut READ zoneOut WRITE setZoneOut NOTIFY zoneChanged)
Q_PROPERTY(int rulerHeight READ rulerHeight WRITE setRulerHeight NOTIFY rulerHeightChanged)
Q_PROPERTY(QString markerComment READ markerComment NOTIFY markerCommentChanged)
Q_PROPERTY(QList <QUrl> audioThumb MEMBER m_audioThumb NOTIFY audioThumbChanged)
Q_PROPERTY(QList <int> audioStreams MEMBER m_audioStreams NOTIFY audioThumbChanged)
Q_PROPERTY(QList <int> audioChannels MEMBER m_audioChannels NOTIFY audioThumbChanged)
Q_PROPERTY(int overlayType READ overlayType WRITE setOverlayType NOTIFY overlayTypeChanged)
Q_PROPERTY(QColor thumbColor1 READ thumbColor1 NOTIFY colorsChanged)
Q_PROPERTY(QColor thumbColor2 READ thumbColor2 NOTIFY colorsChanged)
Q_PROPERTY(bool audioThumbFormat READ audioThumbFormat NOTIFY audioThumbFormatChanged)
/** @brief: Returns true if current clip in monitor has Audio and Video
* */
Q_PROPERTY(bool clipHasAV MEMBER m_hasAV NOTIFY clipHasAVChanged)
......@@ -72,6 +76,9 @@ public:
int getPosition() const;
Q_INVOKABLE bool setPosition(int pos);
Q_INVOKABLE void seek(int delta, uint modifiers);
Q_INVOKABLE QColor thumbColor1() const;
Q_INVOKABLE QColor thumbColor2() const;
Q_INVOKABLE bool audioThumbFormat() const;
void positionFromConsumer(int pos, bool playing);
void setMarkerComment(const QString &comment);
int zoneIn() const;
......@@ -92,7 +99,7 @@ public:
Q_INVOKABLE double fps() const;
QPoint profile();
void setClipProperties(int clipId, ClipType::ProducerType type, bool hasAV, const QString clipName);
void setAudioThumb(const QList <QUrl> thumbPath = QList <QUrl>());
void setAudioThumb(const QList <int> streamIndexes = QList <int>(), QList <int> channels = QList <int>());
void setAudioStream(const QString &name);
void setRulerHeight(int height);
......@@ -119,6 +126,8 @@ signals:
void clipTypeChanged();
void clipIdChanged();
void audioThumbChanged();
void colorsChanged();
void audioThumbFormatChanged();
void profileChanged();
private:
......@@ -127,7 +136,8 @@ private:
int m_zoneIn;
int m_zoneOut;
bool m_hasAV;
QList <QUrl> m_audioThumb;
QList <int> m_audioStreams;
QList <int> m_audioChannels;
QString m_markerComment;
QString m_clipName;
QString m_clipStream;
......
......@@ -44,6 +44,8 @@ Item {
property double frameSize: 10
property double timeScale: 1
property int overlayType: controller.overlayType
property color thumbColor1: controller.thumbColor1
property color thumbColor2: controller.thumbColor2
property color overlayColor: 'cyan'
property bool isClipMonitor: true
property int dragType: 0
......@@ -253,33 +255,35 @@ Item {
}
Repeater {
id: streamThumb
model: controller.audioThumb.length
model: controller.audioStreams.length
onCountChanged: {
thumbTimer.start()
}
property double streamHeight: parent.height / streamThumb.count
property double streamHeight: audioThumb.height / streamThumb.count
Item {
anchors.fill: parent
Image {
anchors.left: parent.left
anchors.right: parent.right
TimelineWaveform {
width: audioThumb.width
height: streamThumb.streamHeight
y: model.index * height
source: controller.audioThumb[model.index]
transform: [
Translate { x: (-audioThumb.width * root.zoomStart)},
Scale {xScale: 1/root.zoomFactor}
]
asynchronous: true
cache: false
smooth: false
channels: controller.audioChannels[model.index]
binId: controller.clipId
audioStream: controller.audioStreams[model.index] //clipRoot.audioStream
isFirstChunk: false
showItem: audioThumb.visible
format: controller.audioThumbFormat
drawInPoint: 0
drawOutPoint: audioThumb.width
waveInPoint: (root.duration - 1) * root.zoomStart * channels
waveOutPointWithUpdate: (root.duration - 1) * (root.zoomStart + root.zoomFactor) * channels
fillColor1: root.thumbColor1
fillColor2: root.thumbColor2
}
Rectangle {
width: parent.width
y: (model.index + 1) * streamThumb.streamHeight
height: 1
visible: streamThumb.count > 1 && model.index < streamThumb.count - 1
color: 'black'
color: 'yellow'
}
}
}
......
......@@ -86,6 +86,7 @@ class TimelineWaveform : public QQuickPaintedItem
Q_PROPERTY(int channels MEMBER m_channels NOTIFY audioChannelsChanged)
Q_PROPERTY(QString binId MEMBER m_binId NOTIFY levelsChanged)
Q_PROPERTY(int waveOutPoint MEMBER m_outPoint)
Q_PROPERTY(int waveOutPointWithUpdate MEMBER m_outPoint NOTIFY propertyChanged)
Q_PROPERTY(int audioStream MEMBER m_stream)
Q_PROPERTY(bool format MEMBER m_format NOTIFY propertyChanged)
Q_PROPERTY(bool showItem READ showItem WRITE setShowItem NOTIFY showItemChanged)
......
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