* Auto-Refresh: virtual modifier removed from slot (did not connect due to dubious reasons here with the virtual modifier)
* Code cleanup, unused functions removed
svn path=/trunk/kdenlive/; revision=5150
const QPen AbstractScopeWidget::penDark(QBrush(QColor(0, 0, 20, 250)), 1, Qt::SolidLine);
const QPen AbstractScopeWidget::penDarkDots(QBrush(QColor(0, 0, 20, 250)), 1, Qt::DotLine);
+const QString AbstractScopeWidget::directions[] = {"North", "Northeast", "East", "Southeast"};
+
AbstractScopeWidget::AbstractScopeWidget(bool trackMouse, QWidget *parent) :
QWidget(parent),
m_mousePos(0, 0),
m_semaphoreScope(1),
m_semaphoreBackground(1),
initialDimensionUpdateDone(false),
- m_requestForcedUpdate(false)
+ m_requestForcedUpdate(false),
+ m_rescaleMinDist(4),
+ m_rescaleVerticalThreshold(2.0f)
{
m_scopePalette = QPalette();
void AbstractScopeWidget::forceUpdate(bool doUpdate)
{
#ifdef DEBUG_ASW
- qDebug() << "Force update called in " << widgetName() << ". Arg: " << doUpdate;
+ qDebug() << "Forced update called in " << widgetName() << ". Arg: " << doUpdate;
#endif
if (!doUpdate) {
///// Events /////
-void AbstractScopeWidget::mouseReleaseEvent(QMouseEvent *event)
-{
- if (!m_aAutoRefresh->isChecked()) {
- m_requestForcedUpdate = true;
- }
- prodHUDThread();
- prodScopeThread();
- prodBackgroundThread();
- QWidget::mouseReleaseEvent(event);
-}
void AbstractScopeWidget::resizeEvent(QResizeEvent *event)
{
davinci.drawImage(m_scopeRect.topLeft(), m_imgHUD);
}
+void AbstractScopeWidget::mousePressEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton) {
+ // Rescaling mode starts
+ m_rescaleActive = true;
+ m_rescalePropertiesLocked = false;
+ m_rescaleFirstRescaleDone = false;
+ m_rescaleStartPoint = event->pos();
+ m_rescaleModifiers = event->modifiers();
+ }
+}
+void AbstractScopeWidget::mouseReleaseEvent(QMouseEvent *event)
+{
+ m_rescaleActive = false;
+ m_rescalePropertiesLocked = false;
+
+ if (!m_aAutoRefresh->isChecked()) {
+ m_requestForcedUpdate = true;
+ }
+ prodHUDThread();
+ prodScopeThread();
+ prodBackgroundThread();
+ QWidget::mouseReleaseEvent(event);
+}
void AbstractScopeWidget::mouseMoveEvent(QMouseEvent *event)
{
m_mousePos = event->pos();
m_mouseWithinWidget = true;
emit signalMousePositionChanged();
+
+ QPoint movement = event->pos()-m_rescaleStartPoint;
+
+ if (m_rescaleActive) {
+ if (m_rescalePropertiesLocked) {
+ // Direction is known, now adjust parameters
+
+ // Reset the starting point to make the next moveEvent relative to the current one
+ m_rescaleStartPoint = event->pos();
+
+
+ if (!m_rescaleFirstRescaleDone) {
+ // We have just learned the desired direction; Normalize the movement to one pixel
+ // to avoid a jump by m_rescaleMinDist
+
+ if (movement.x() != 0) {
+ movement.setX(movement.x() / abs(movement.x()));
+ }
+ if (movement.y() != 0) {
+ movement.setY(movement.y() / abs(movement.y()));
+ }
+
+ m_rescaleFirstRescaleDone = true;
+ }
+
+ handleMouseDrag(movement, m_rescaleDirection, m_rescaleModifiers);
+
+
+
+ } else {
+ // Detect the movement direction here.
+ // This algorithm relies on the aspect ratio of dy/dx (size and signum).
+ if (movement.manhattanLength() > m_rescaleMinDist) {
+ float diff = ((float) movement.y())/movement.x();
+
+ if (abs(diff) > m_rescaleVerticalThreshold || movement.x() == 0) {
+ m_rescaleDirection = North;
+ } else if (abs(diff) < 1/m_rescaleVerticalThreshold) {
+ m_rescaleDirection = East;
+ } else if (diff < 0) {
+ m_rescaleDirection = Northeast;
+ } else {
+ m_rescaleDirection = Southeast;
+ }
+#ifdef DEBUG_ASW
+ qDebug() << "Diff is " << diff << "; chose " << directions[m_rescaleDirection] << " as direction";
+#endif
+ m_rescalePropertiesLocked = true;
+ }
+ }
+ }
}
+
void AbstractScopeWidget::leaveEvent(QEvent *)
{
m_mouseWithinWidget = false;
void AbstractScopeWidget::slotHUDRenderingFinished(uint mseconds, uint oldFactor)
{
-// qDebug() << "HUD rendering has finished, waiting for termination in " << m_widgetName;
+#ifdef DEBUG_ASW
+ qDebug() << "HUD rendering has finished in " << mseconds << " ms, waiting for termination in " << m_widgetName;
+#endif
m_threadHUD.waitForFinished();
m_imgHUD = m_threadHUD.result();
// The signal can be received before the thread has really finished. So we
// need to wait until it has really finished before starting a new thread.
#ifdef DEBUG_ASW
- qDebug() << "Scope rendering has finished, waiting for termination in " << m_widgetName;
+ qDebug() << "Scope rendering has finished in " << mseconds << " ms, waiting for termination in " << m_widgetName;
#endif
m_threadScope.waitForFinished();
m_imgScope = m_threadScope.result();
void AbstractScopeWidget::slotBackgroundRenderingFinished(uint mseconds, uint oldFactor)
{
#ifdef DEBUG_ASW
- qDebug() << "Background rendering has finished, waiting for termination in " << m_widgetName;
+ qDebug() << "Background rendering has finished in " << mseconds << " ms, waiting for termination in " << m_widgetName;
#endif
m_threadBackground.waitForFinished();
m_imgBackground = m_threadBackground.result();
m_newBackgroundFrames.fetchAndAddRelaxed(1);
#ifdef DEBUG_ASW
- qDebug() << "Monitor incoming. New frames total HUD/Scope/Background: " << m_newHUDFrames
+ qDebug() << "Monitor incoming at " << widgetName() << ". New frames total HUD/Scope/Background: " << m_newHUDFrames
<< "/" << m_newScopeFrames << "/" << m_newBackgroundFrames;
#endif
}
}
-void AbstractScopeWidget::slotRenderZoneUpdated(QImage frame)
-{
- m_scopeImage = frame;
- slotRenderZoneUpdated();
-}
-
void AbstractScopeWidget::slotResetRealtimeFactor(bool realtimeChecked)
{
if (!realtimeChecked) {
void AbstractScopeWidget::slotAutoRefreshToggled(bool autoRefresh)
{
+#ifdef DEBUG_ASW
+ qDebug() << "Auto-refresh switched to " << autoRefresh << " in " << widgetName()
+ << " (Visible: " << isVisible() << "/" << this->visibleRegion().isEmpty() << ")";
+#endif
if (isVisible()) {
+ // Notify listeners whether we accept new frames now
emit requestAutoRefresh(autoRefresh);
}
// TODO only if depends on input
}
}
+void AbstractScopeWidget::handleMouseDrag(const QPoint, const RescaleDirection, const Qt::KeyboardModifiers) { }
+
#ifdef DEBUG_ASW
#undef DEBUG_ASW
public:
AbstractScopeWidget(bool trackMouse = false, QWidget *parent = 0);
virtual ~AbstractScopeWidget(); // Must be virtual because of inheritance, to avoid memory leaks
+
+
+ enum RescaleDirection { North, Northeast, East, Southeast };
+
+
QPalette m_scopePalette;
/** Initializes widget settings (reads configuration).
Has to be called in the implementing object. */
virtual void init();
- /** Does this scope have auto-refresh enabled */
+ /** Tell whether this scope has auto-refresh enabled. Required for determining whether
+ new data (e.g. an image frame) has to be delivered to this widget. */
bool autoRefreshEnabled();
///// Unimplemented /////
static const QPen penDark;
static const QPen penDarkDots;
+ static const QString directions[]; // Mainly for debug output
+
protected:
///// Variables /////
virtual uint calculateAccelFactorScope(uint oldMseconds, uint oldFactor);
virtual uint calculateAccelFactorBackground(uint oldMseconds, uint oldFactor);
+ /** The Abstract Scope will try to detect the movement direction when dragging on the widget with the mouse.
+ As soon as the direction is determined it will execute this method. Can be used e.g. for re-scaling content.
+ This is just a dummy function, re-implement to add functionality. */
+ virtual void handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
+
///// Reimplemented /////
- void mouseMoveEvent(QMouseEvent *);
+ void mouseMoveEvent(QMouseEvent *event);
+ void mousePressEvent(QMouseEvent *event);
+ void mouseReleaseEvent(QMouseEvent *event);
void leaveEvent(QEvent *);
- void mouseReleaseEvent(QMouseEvent *);
void paintEvent(QPaintEvent *);
void resizeEvent(QResizeEvent *);
void showEvent(QShowEvent *); // Called when the widget is activated via the Menu entry
void forceUpdateHUD();
void forceUpdateScope();
void forceUpdateBackground();
- virtual void slotAutoRefreshToggled(bool);
+ void slotAutoRefreshToggled(bool);
signals:
/** mseconds represent the time taken for the calculation,
void prodScopeThread();
void prodBackgroundThread();
+ ///// Movement detection /////
+ const int m_rescaleMinDist;
+ const float m_rescaleVerticalThreshold;
+
+ bool m_rescaleActive;
+ bool m_rescalePropertiesLocked;
+ bool m_rescaleFirstRescaleDone;
+ short m_rescaleScale;
+ Qt::KeyboardModifiers m_rescaleModifiers;
+ RescaleDirection m_rescaleDirection;
+ QPoint m_rescaleStartPoint;
+
+
protected slots:
void customContextMenuRequested(const QPoint &pos);
/** To be called when a new frame has been received.
The scope then decides whether and when it wants to recalculate the scope, depending
on whether it is currently visible and whether a calculation thread is already running. */
void slotRenderZoneUpdated();
- void slotRenderZoneUpdated(QImage);//TODO remove
/** The following slots are called when rendering of a component has finished. They e.g. update
the widget and decide whether to immediately restart the calculation thread. */
void slotHUDRenderingFinished(uint mseconds, uint accelerationFactor);
#define MAX_FREQ_VALUE 96000
#define MIN_FREQ_VALUE 1000
-const QString AudioSpectrum::directions[] = {"North", "Northeast", "East", "Southeast"};
-
AudioSpectrum::AudioSpectrum(QWidget *parent) :
AbstractAudioScopeWidget(false, parent),
- m_fftTools(),
- m_rescaleMinDist(8),
- m_rescaleVerticalThreshold(2.0f),
- m_rescaleActive(false),
- m_rescalePropertiesLocked(false),
- m_rescaleScale(1)
+ m_fftTools()
{
ui = new Ui::AudioSpectrum_UI;
ui->setupUi(this);
///// EVENTS /////
-void AudioSpectrum::mouseMoveEvent(QMouseEvent *event)
+void AudioSpectrum::handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers)
{
- QPoint movement = event->pos()-m_rescaleStartPoint;
-
- if (m_rescaleActive) {
- if (m_rescalePropertiesLocked) {
- // Direction is known, now adjust parameters
-
- // Reset the starting point to make the next moveEvent relative to the current one
- m_rescaleStartPoint = event->pos();
-
-
- if (!m_rescaleFirstRescaleDone) {
- // We have just learned the desired direction; Normalize the movement to one pixel
- // to avoid a jump by m_rescaleMinDist
-
- if (movement.x() != 0) {
- movement.setX(movement.x() / abs(movement.x()));
- }
- if (movement.y() != 0) {
- movement.setY(movement.y() / abs(movement.y()));
- }
-
- m_rescaleFirstRescaleDone = true;
- }
-
- if (m_rescaleClockDirection == AudioSpectrum::North) {
- // Nort-South direction: Adjust the dB scale
+ if (rescaleDirection == AudioSpectrum::North) {
+ // Nort-South direction: Adjust the dB scale
- if ((m_rescaleModifiers & Qt::ShiftModifier) == 0) {
+ if ((rescaleModifiers & Qt::ShiftModifier) == 0) {
- // By default adjust the min dB value
- m_dBmin += movement.y();
+ // By default adjust the min dB value
+ m_dBmin += movement.y();
- } else {
+ } else {
- // Adjust max dB value if Shift is pressed.
- m_dBmax += movement.y();
+ // Adjust max dB value if Shift is pressed.
+ m_dBmax += movement.y();
- }
+ }
- // Ensure the dB values lie in [-100, 0] (or rather [MIN_DB_VALUE, 0])
- // 0 is the upper bound, everything below -70 dB is most likely noise
+ // Ensure the dB values lie in [-100, 0] (or rather [MIN_DB_VALUE, 0])
+ // 0 is the upper bound, everything below -70 dB is most likely noise
+ if (m_dBmax > 0) {
+ m_dBmax = 0;
+ }
+ if (m_dBmin < MIN_DB_VALUE) {
+ m_dBmin = MIN_DB_VALUE;
+ }
+ // Ensure there is at least 6 dB between the minimum and the maximum value;
+ // lower values hardly make sense
+ if (m_dBmax - m_dBmin < 6) {
+ if ((rescaleModifiers & Qt::ShiftModifier) == 0) {
+ // min was adjusted; Try to adjust the max value to maintain the
+ // minimum dB difference of 6 dB
+ m_dBmax = m_dBmin + 6;
if (m_dBmax > 0) {
m_dBmax = 0;
+ m_dBmin = -6;
}
+ } else {
+ // max was adjusted, adjust min
+ m_dBmin = m_dBmax - 6;
if (m_dBmin < MIN_DB_VALUE) {
m_dBmin = MIN_DB_VALUE;
+ m_dBmax = MIN_DB_VALUE+6;
}
- // Ensure there is at least 6 dB between the minimum and the maximum value;
- // lower values hardly make sense
- if (m_dBmax - m_dBmin < 6) {
- if ((m_rescaleModifiers & Qt::ShiftModifier) == 0) {
- // min was adjusted; Try to adjust the max value to maintain the
- // minimum dB difference of 6 dB
- m_dBmax = m_dBmin + 6;
- if (m_dBmax > 0) {
- m_dBmax = 0;
- m_dBmin = -6;
- }
- } else {
- // max was adjusted, adjust min
- m_dBmin = m_dBmax - 6;
- if (m_dBmin < MIN_DB_VALUE) {
- m_dBmin = MIN_DB_VALUE;
- m_dBmax = MIN_DB_VALUE+6;
- }
- }
- }
-
- forceUpdateHUD();
- forceUpdateScope();
-
- } else if (m_rescaleClockDirection == AudioSpectrum::East) {
- // East-West direction: Adjust the maximum frequency
- m_freqMax -= 100*movement.x();
- if (m_freqMax < MIN_FREQ_VALUE) {
- m_freqMax = MIN_FREQ_VALUE;
- }
- if (m_freqMax > MAX_FREQ_VALUE) {
- m_freqMax = MAX_FREQ_VALUE;
- }
- m_customFreq = true;
-
- forceUpdateHUD();
- forceUpdateScope();
}
+ }
+ forceUpdateHUD();
+ forceUpdateScope();
- } else {
- // Detect the movement direction here.
- // This algorithm relies on the aspect ratio of dy/dx (size and signum).
- if (movement.manhattanLength() > m_rescaleMinDist) {
- float diff = ((float) movement.y())/movement.x();
-
- if (abs(diff) > m_rescaleVerticalThreshold || movement.x() == 0) {
- m_rescaleClockDirection = AudioSpectrum::North;
- } else if (abs(diff) < 1/m_rescaleVerticalThreshold) {
- m_rescaleClockDirection = AudioSpectrum::East;
- } else if (diff < 0) {
- m_rescaleClockDirection = AudioSpectrum::Northeast;
- } else {
- m_rescaleClockDirection = AudioSpectrum::Southeast;
- }
-#ifdef DEBUG_AUDIOSPEC
- qDebug() << "Diff is " << diff << "; chose " << directions[m_rescaleClockDirection] << " as direction";
-#endif
- m_rescalePropertiesLocked = true;
- }
+ } else if (rescaleDirection == AudioSpectrum::East) {
+ // East-West direction: Adjust the maximum frequency
+ m_freqMax -= 100*movement.x();
+ if (m_freqMax < MIN_FREQ_VALUE) {
+ m_freqMax = MIN_FREQ_VALUE;
}
- } else {
- AbstractAudioScopeWidget::mouseMoveEvent(event);
- }
-}
-
-void AudioSpectrum::mousePressEvent(QMouseEvent *event)
-{
- if (event->button() == Qt::LeftButton) {
- // Rescaling mode starts
- m_rescaleActive = true;
- m_rescalePropertiesLocked = false;
- m_rescaleFirstRescaleDone = false;
- m_rescaleStartPoint = event->pos();
- m_rescaleModifiers = event->modifiers();
+ if (m_freqMax > MAX_FREQ_VALUE) {
+ m_freqMax = MAX_FREQ_VALUE;
+ }
+ m_customFreq = true;
- } else {
- AbstractAudioScopeWidget::mousePressEvent(event);
+ forceUpdateHUD();
+ forceUpdateScope();
}
}
-void AudioSpectrum::mouseReleaseEvent(QMouseEvent *event)
-{
- m_rescaleActive = false;
- m_rescalePropertiesLocked = false;
-
- AbstractAudioScopeWidget::mouseReleaseEvent(event);
-}
-
-const QString AudioSpectrum::cfgSignature(const int size)
-{
- return QString("s%1").arg(size);
-}
-
#ifdef DEBUG_AUDIOSPEC
#undef DEBUG_AUDIOSPEC
// Implemented virtual methods
QString widgetName() const;
- static const QString directions[]; // Mainly for debug output
- enum RescaleDirection { North, Northeast, East, Southeast };
- enum RescaleDimension { Min_dB, Max_dB, Max_Hz };
-
protected:
///// Implemented methods /////
virtual void readConfig();
void writeConfig();
- void mouseMoveEvent(QMouseEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
+ virtual void handleMouseDrag(const QPoint movement, const RescaleDirection rescaleDirection, const Qt::KeyboardModifiers rescaleModifiers);
private:
Ui::AudioSpectrum_UI *ui;
bool m_customFreq;
- /** Returns a signature for a kiss_fft configuration
- used as a hash in the cache */
- static const QString cfgSignature(const int size);
-
-
- ///// Movement detection /////
- const int m_rescaleMinDist;
- const float m_rescaleVerticalThreshold;
-
- bool m_rescaleActive;
- bool m_rescalePropertiesLocked;
- bool m_rescaleFirstRescaleDone;
- short m_rescaleScale;
- Qt::KeyboardModifiers m_rescaleModifiers;
- AudioSpectrum::RescaleDirection m_rescaleClockDirection;
- QPoint m_rescaleStartPoint;
-
-
private slots:
void slotResetMaxFreq();
// Can be less as a pre-rendered image is kept in space.
#define SPECTROGRAM_HISTORY_SIZE 1000
-#define DEBUG_SPECTROGRAM
+//#define DEBUG_SPECTROGRAM
#ifdef DEBUG_SPECTROGRAM
#include <QDebug>
#endif
#include <stdlib.h>
+//#define DEBUG_MAINW
+#ifdef DEBUG_MAINW
+#include <QDebug>
+#endif
+
static const char version[] = VERSION;
static const int ID_TIMELINE_POS = 0;
}
}
}
+#ifdef DEBUG_MAINW
+ qDebug() << "Any scope accepting new frames? " << request;
+#endif
if (!request) {
m_projectMonitor->render->sendFrameForAnalysis = false;
}
}
}
if (!request) {
- if (!m_projectMonitor->effectSceneDisplayed())
+ if (!m_projectMonitor->effectSceneDisplayed()) {
m_projectMonitor->render->sendFrameForAnalysis = false;
+ }
m_clipMonitor->render->sendFrameForAnalysis = false;
} else {
m_projectMonitor->render->sendFrameForAnalysis = true;
#include "mainwindow.moc"
+#ifdef DEBUG_MAINW
+#undef DEBUG_MAINW
+#endif