raDIYo 0.4
swplayercontrol.cpp
1/***************************************************************************
2
3 source::worx raDIYo
4 Copyright © 2020-2022 c.holzheuer
5 c.holzheuer@sourceworx.org
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12***************************************************************************/
13
14
15#include <QDebug>
16#include <QPainter>
17
18#include <swplayercontrol.h>
19
20
21SWPlayerControl::SWPlayerControl( SWRaDIYoMainWidget* parent )
22: SWAbstractControl( parent )
23{
24 setupUi( this );
25 _audioProbe.setSource( &_player );
26
27 connect( &_audioProbe, SIGNAL( audioBufferProbed(QAudioBuffer) ), this, SLOT(onAudioProbed(QAudioBuffer) ) );
28 connect( &_FFTCalc, SIGNAL( spectrumReady(SWDoubleVec) ), this, SLOT( onSpectrumReady(SWDoubleVec) ) );
29
30
31 const auto deviceInfos = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput);
32 for (const QAudioDeviceInfo &deviceInfo : deviceInfos)
33 qDebug() << "Device name: " << deviceInfo.deviceName();
34 const QAudioDeviceInfo& defDev = QAudioDeviceInfo::defaultOutputDevice();
35 qDebug() << "Default Device name: " << defDev.deviceName();
36
37}
38
39SWPlayerControl::~SWPlayerControl()
40{
41
42}
43
44void SWPlayerControl::loadSettings()
45{
46
47}
48
49void SWPlayerControl::saveSettings()
50{
51
52}
53
54void SWPlayerControl::onDialClicked()
55{
56 qDebug() << "player onClick";
57
58}
59
60
61void SWPlayerControl::onDialValueChanged( int value )
62{
63 // ??
64 _volume = value;
65 _player.setVolume( _volume );
66
67}
68
69
70void SWPlayerControl::onAudioProbed( QAudioBuffer audiobuffer )
71{
72
73 _FFTCalc.collectFrames( audiobuffer );
74
75}
76
77
78void SWPlayerControl::onSpectrumReady( const SWDoubleVec& spectrum )
79{
80
81 // hier verteilen wir das gesamtspectrum
82 // auf die xx balken des Displays
83 int numbins = _spectrumWidget->numBars();
84 //int numvals = spectrum.size();
85 int numvals = spectrum.size() / 4 * 2;
86 //int numvals = spectrum.size() / 3 * 2;
87 int divider = numvals / numbins;
88 QVector<int> bins( numbins );
89 SWDoubleVec vals( numbins );
90
91 for( int i=0; i<numvals; ++i )
92 {
93 bins[ i/divider ]++;
94 vals[ i/divider ] += spectrum[i];
95 // oder max: bar.value = qMax(bar.value, e.amplitude);
96 }
97 // durchschnitt bilden
98 for( int i=0; i<numbins; ++i )
99 {
100 if( bins[i] )
101 vals[ i ] /= bins[i];
102 }
103 _spectrumWidget->onValueListChanged( vals );
104
105}
106
107
113void SWPlayerControl::startPlaying( const QString& urlText )
114{
115
116 QUrl url( urlText );
117 qDebug() << "SWPlayerControl::startPlaying: local" << urlText << " local: " << url.toLocalFile();
118 _player.stop();
119 _player.setMedia( url );
120 _player.setVolume( _volume );
121 _player.play();
122}
123
124
125void SWPlayerControl::stopPlaying()
126{
127
128 qDebug() << "SWPlayerControl::stopPlaying: ";
129
130 _player.stop();
131 _spectrumWidget->clearValueList();
132}
133
134
135
void collectFrames(QAudioBuffer &audiobuffer)
Track::getPeakValue.
Definition: swfftcalc.cpp:120
void startPlaying(const QString &urlText)
SWPlayerControl::startPlaying: Erwartet eine ordentliche URL als String.