|
1 | 1 | /* |
2 | | - * Copyright (c) 2013-2025 Meltytech, LLC |
| 2 | + * Copyright (c) 2013-2026 Meltytech, LLC |
3 | 3 | * |
4 | 4 | * This program is free software: you can redistribute it and/or modify |
5 | 5 | * it under the terms of the GNU General Public License as published by |
@@ -45,6 +45,7 @@ static void deleteQVariantList(QVariantList *list) |
45 | 45 | AudioLevelsTask::AudioLevelsTask(Mlt::Producer &producer, QObject *object, const QModelIndex &index) |
46 | 46 | : QRunnable() |
47 | 47 | , m_object(object) |
| 48 | + , m_qmlProducer(object) |
48 | 49 | , m_isCanceled(false) |
49 | 50 | , m_isForce(false) |
50 | 51 | { |
@@ -79,7 +80,11 @@ void AudioLevelsTask::start(Mlt::Producer &producer, |
79 | 80 | if (*t == *task) { |
80 | 81 | // If so, then just add ourselves to be notified upon completion. |
81 | 82 | delete task; |
82 | | - task = 0; |
| 83 | + task = nullptr; |
| 84 | + if (index.isValid()) |
| 85 | + t->m_object = object; |
| 86 | + else |
| 87 | + t->m_qmlProducer = object; |
83 | 88 | t->m_producers << ProducerAndIndex(new Mlt::Producer(producer), index); |
84 | 89 | break; |
85 | 90 | } |
@@ -169,6 +174,22 @@ QString AudioLevelsTask::cacheKey() |
169 | 174 | return key; |
170 | 175 | } |
171 | 176 |
|
| 177 | +void AudioLevelsTask::notifyQObjects(const QPersistentModelIndex &index) |
| 178 | +{ |
| 179 | + if (index.isValid() && m_object) { |
| 180 | + // LOG_DEBUG() << "calling audioLevelsReady" << m_object << index; |
| 181 | + if (-1 != m_object->metaObject()->indexOfMethod("audioLevelsReady(QPersistentModelIndex)")) |
| 182 | + QMetaObject::invokeMethod(m_object, |
| 183 | + "audioLevelsReady", |
| 184 | + Q_ARG(const QPersistentModelIndex &, index)); |
| 185 | + } else if (m_qmlProducer) { |
| 186 | + // LOG_DEBUG() << "calling audioLevelsChanged" << m_qmlProducer; |
| 187 | + if (-1 != m_qmlProducer->metaObject()->indexOfSignal("audioLevelsChanged()")) { |
| 188 | + QMetaObject::invokeMethod(m_qmlProducer, "audioLevelsChanged"); |
| 189 | + } |
| 190 | + } |
| 191 | +} |
| 192 | + |
172 | 193 | void AudioLevelsTask::run() |
173 | 194 | { |
174 | 195 | // 2 channels interleaved of uchar values |
@@ -223,12 +244,7 @@ void AudioLevelsTask::run() |
223 | 244 | 0, |
224 | 245 | (mlt_destructor) deleteQVariantList); |
225 | 246 | p.first->unlock(); |
226 | | - if (-1 |
227 | | - != m_object->metaObject()->indexOfMethod( |
228 | | - "audioLevelsReady(QPersistentModelIndex)")) |
229 | | - QMetaObject::invokeMethod(m_object, |
230 | | - "audioLevelsReady", |
231 | | - Q_ARG(const QPersistentModelIndex &, p.second)); |
| 247 | + notifyQObjects(p.second); |
232 | 248 | } |
233 | 249 | } |
234 | 250 | } |
@@ -298,11 +314,7 @@ void AudioLevelsTask::run() |
298 | 314 | p.first->lock(); |
299 | 315 | p.first->set(kAudioLevelsProperty, levelsCopy, 0, (mlt_destructor) deleteQVariantList); |
300 | 316 | p.first->unlock(); |
301 | | - if (-1 |
302 | | - != m_object->metaObject()->indexOfMethod("audioLevelsReady(QPersistentModelIndex)")) |
303 | | - QMetaObject::invokeMethod(m_object, |
304 | | - "audioLevelsReady", |
305 | | - Q_ARG(const QPersistentModelIndex &, p.second)); |
| 317 | + notifyQObjects(p.second); |
306 | 318 | } |
307 | 319 | } |
308 | 320 | } |
0 commit comments