]> git.sesse.net Git - kdenlive/blob - src/scopes/audioscopes/abstractaudioscopewidget.cpp
Merging of scopes manager by Granjow (final merge)
[kdenlive] / src / scopes / 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 "abstractaudioscopewidget.h"
12 #include "renderer.h"
13 #include "monitor.h"
14
15 #include <QtConcurrentRun>
16 #include <QFuture>
17 #include <QColor>
18 #include <QMenu>
19 #include <QMouseEvent>
20 #include <QPainter>
21
22 // Uncomment for debugging
23 //#define DEBUG_AASW
24
25 #ifdef DEBUG_AASW
26 #include <QDebug>
27 #endif
28
29 AbstractAudioScopeWidget::AbstractAudioScopeWidget(bool trackMouse, QWidget *parent) :
30         AbstractScopeWidget(trackMouse, parent),
31     m_freq(0),
32     m_nChannels(0),
33     m_nSamples(0),
34     m_audioFrame(),
35     m_newData(0)
36 {
37 }
38
39 void AbstractAudioScopeWidget::slotReceiveAudio(QVector<int16_t> sampleData, int freq, int num_channels, int num_samples)
40 {
41 #ifdef DEBUG_AASW
42     qDebug() << "Received audio for " << widgetName() << ".";
43 #endif
44     m_audioFrame = sampleData;
45     m_freq = freq;
46     m_nChannels = num_channels;
47     m_nSamples = num_samples;
48
49     m_newData.fetchAndAddAcquire(1);
50
51     AbstractScopeWidget::slotRenderZoneUpdated();
52 }
53
54 AbstractAudioScopeWidget::~AbstractAudioScopeWidget() {}
55
56 QImage AbstractAudioScopeWidget::renderScope(uint accelerationFactor)
57 {
58     int newData = m_newData.fetchAndStoreAcquire(0);
59
60     return renderAudioScope(accelerationFactor, m_audioFrame, m_freq, m_nChannels, m_nSamples, newData);
61 }
62
63 #ifdef DEBUG_AASW
64 #undef DEBUG_AASW
65 #endif