File indexing completed on 2025-02-09 07:08:06
0001 /* 0002 * SPDX-FileCopyrightText: 2020 Jonah BrĂ¼chert <jbb@kaidan.im> 0003 * SPDX-FileCopyrightText: 2020-2021 Devin Lin <devin@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-3.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include <QAudioDecoder> 0011 #include <QAudioSource> 0012 #include <QMediaPlayer> 0013 #include <QMediaRecorder> 0014 #include <QObject> 0015 #include <QTimer> 0016 #include <QVariant> 0017 0018 #include <QDebug> 0019 0020 class AudioProber : public QAudioDecoder 0021 { 0022 Q_OBJECT 0023 Q_PROPERTY(QVariantList volumesList READ volumesList NOTIFY volumesListChanged) 0024 Q_PROPERTY(int animationIndex READ animationIndex NOTIFY animationIndexChanged) 0025 Q_PROPERTY(int maxVolumes READ maxVolumes WRITE setMaxVolumes NOTIFY maxVolumesChanged) 0026 0027 public: 0028 AudioProber(QObject *parent = nullptr); 0029 AudioProber(QObject *parent, QMediaRecorder *source); 0030 AudioProber(QObject *parent, QMediaPlayer *source); 0031 0032 void process(); 0033 void processVolumeBar(); 0034 0035 QVariantList volumesList() const; 0036 0037 int maxVolumes(); 0038 void setMaxVolumes(int m); 0039 0040 int animationIndex(); 0041 0042 void clearVolumesList(); 0043 0044 void start(); 0045 0046 private: 0047 void handleRecorderState(QMediaRecorder::RecorderState state); 0048 void handlePlayerState(QMediaPlayer::PlaybackState state); 0049 0050 int m_audioSum = 0; // 0051 int m_audioLen = 0; // used for calculating the value of one volume bar from many 0052 int m_animationIndex = 0; // which index rectangle is being expanded 0053 int m_maxVolumes = 100; // based on width of screen 0054 0055 QVariantList m_volumesList; 0056 0057 QTimer *volumeBarTimer; 0058 QMediaRecorder *m_recorderSource; 0059 QMediaPlayer *m_playerSource; 0060 QAudioSource *m_audioSource; 0061 QIODevice *m_audioIODevice; 0062 0063 Q_SIGNALS: 0064 void volumesListAdded(int volume); 0065 void volumesListChanged(); 0066 void animationIndexChanged(); 0067 void maxVolumesChanged(); 0068 void volumesListCleared(); 0069 };