]> git.sesse.net Git - kdenlive/blob - src/audioscopes/abstractaudioscopewidget.cpp
099a8e6e955b8b6565c3ebf8c49393dfe573884c
[kdenlive] / src / audioscopes / abstractaudioscopewidget.cpp
1 /***************************************************************************
2  *   Copyright (C) 2010 by Simon Andreas Eugster (simon.eu@gmail.com)      *
3  *   This file is part of kdenlive. See www.kdenlive.org.                  *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  ***************************************************************************/
10
11 #include "qtconcurrentrun.h"
12
13 #include "abstractaudioscopewidget.h"
14 #include "renderer.h"
15 #include "monitor.h"
16
17 #include <QFuture>
18 #include <QColor>
19 #include <QMenu>
20 #include <QMouseEvent>
21 #include <QPainter>
22
23 // Uncomment for debugging
24 //#define DEBUG_AASW
25
26 #ifdef DEBUG_AASW
27 #include <QDebug>
28 #endif
29
30 AbstractAudioScopeWidget::AbstractAudioScopeWidget(bool trackMouse, QWidget *parent) :
31         AbstractScopeWidget(trackMouse, parent),
32     m_freq(0),
33     m_nChannels(0),
34     m_nSamples(0),
35     m_audioFrame(),
36     m_newData(0)
37 {
38 }
39
40 void AbstractAudioScopeWidget::slotReceiveAudio(const QVector<int16_t> &sampleData, int freq, int num_channels, int num_samples)
41 {
42 #ifdef DEBUG_AASW
43     qDebug() << "Received audio for " << widgetName() << ".";
44 #endif
45     m_audioFrame = sampleData;
46     m_freq = freq;
47     m_nChannels = num_channels;
48     m_nSamples = num_samples;
49
50     m_newData.fetchAndAddAcquire(1);
51
52     AbstractScopeWidget::slotRenderZoneUpdated();
53 }
54
55 AbstractAudioScopeWidget::~AbstractAudioScopeWidget() {}
56
57 QImage AbstractAudioScopeWidget::renderScope(uint accelerationFactor)
58 {
59     int newData = m_newData.fetchAndStoreAcquire(0);
60
61     return renderAudioScope(accelerationFactor, m_audioFrame, m_freq, m_nChannels, m_nSamples, newData);
62 }
63
64 #ifdef DEBUG_AASW
65 #undef DEBUG_AASW
66 #endif