File indexing completed on 2024-05-12 05:39:48
0001 /*************************************************************************** 0002 * Copyright (C) 2021 by Renaud Guezennec * 0003 * http://www.rolisteam.org/contact * 0004 * * 0005 * This software is free software; you can redistribute it and/or modify * 0006 * it under the terms of the GNU General Public License as published by * 0007 * the Free Software Foundation; either version 2 of the License, or * 0008 * (at your option) any later version. * 0009 * * 0010 * This program is distributed in the hope that it will be useful, * 0011 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 0012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 0013 * GNU General Public License for more details. * 0014 * * 0015 * You should have received a copy of the GNU General Public License * 0016 * along with this program; if not, write to the * 0017 * Free Software Foundation, Inc., * 0018 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 0019 ***************************************************************************/ 0020 #ifndef AUDIOPLAYERCONTROLLER_H 0021 #define AUDIOPLAYERCONTROLLER_H 0022 0023 #include "model/musicmodel.h" 0024 #include <QAudioOutput> 0025 #include <QMediaPlayer> 0026 #include <QModelIndexList> 0027 #include <QObject> 0028 #include <QPointer> 0029 #include <core_global.h> 0030 #include <memory> 0031 0032 class PreferencesManager; 0033 class CORE_EXPORT AudioPlayerController : public QObject 0034 { 0035 Q_OBJECT 0036 Q_PROPERTY(int id READ id CONSTANT) 0037 Q_PROPERTY(PlayingMode mode READ mode NOTIFY modeChanged) 0038 Q_PROPERTY(State state READ state NOTIFY stateChanged) 0039 Q_PROPERTY(MusicModel* model READ model CONSTANT) 0040 Q_PROPERTY(uint volume READ volume NOTIFY volumeChanged) 0041 Q_PROPERTY(bool localIsGm READ localIsGm WRITE setLocalIsGm NOTIFY localIsGmChanged) 0042 Q_PROPERTY(QString error READ error NOTIFY errorChanged) 0043 Q_PROPERTY(bool visible READ visible WRITE setVisible NOTIFY visibleChanged) 0044 Q_PROPERTY(bool muted READ muted NOTIFY mutedChanged) 0045 Q_PROPERTY(QString text READ text NOTIFY textChanged) 0046 Q_PROPERTY(quint64 time READ time NOTIFY timeChanged) 0047 public: 0048 enum PlayingMode 0049 { 0050 LOOP, 0051 UNIQUE, 0052 NEXT, 0053 SHUFFLE 0054 }; 0055 Q_ENUM(PlayingMode) 0056 enum State 0057 { 0058 StoppedState, 0059 PlayingState, 0060 PausedState, 0061 ErrorState 0062 }; 0063 Q_ENUM(State) 0064 explicit AudioPlayerController(int id, const QString& key, PreferencesManager* pref, QObject* parent= nullptr); 0065 virtual ~AudioPlayerController(); 0066 0067 int id() const; 0068 PlayingMode mode() const; 0069 MusicModel* model() const; 0070 QString error() const; 0071 bool visible() const; 0072 bool muted() const; 0073 quint64 time() const; 0074 State state() const; 0075 QString text() const; 0076 uint volume() const; 0077 bool localIsGm() const; 0078 QStringList directoriesList() const; 0079 0080 public slots: 0081 void setMedia(const QModelIndex& index); 0082 void play(); 0083 void stop(); 0084 void pause(); 0085 void next(); 0086 void setPlayingMode(AudioPlayerController::PlayingMode mode); 0087 void loadPlayList(const QString& path); 0088 void setVolume(uint volume); 0089 void exportList(const QString& path); 0090 void mute(); 0091 void clear(); 0092 void removeSong(const QModelIndexList& index); 0093 void addSong(const QList<QUrl>& path); 0094 void setLocalIsGm(bool b); 0095 void setVisible(bool b); 0096 void setTime(quint64 time); 0097 void addMusicModel(); 0098 0099 // networkfunction 0100 void nwNewSong(const QString& string, qint64 time); 0101 0102 signals: 0103 void modeChanged(); 0104 void volumeChanged(int); 0105 void localIsGmChanged(); 0106 void errorChanged(const QString& error); 0107 void visibleChanged(bool b); 0108 void mutedChanged(); 0109 void textChanged(); 0110 void stateChanged(AudioPlayerController::State state); 0111 void timeChanged(qint64); 0112 void durationChanged(qint64 dura); 0113 void startPlayingSong(QString name, qint64 time); 0114 0115 private: 0116 int m_id; 0117 PlayingMode m_mode= NEXT; 0118 std::unique_ptr<MusicModel> m_model; 0119 PreferencesManager* m_pref= nullptr; 0120 QMediaPlayer m_player; 0121 QAudioOutput m_audioOutput; 0122 QString m_text; 0123 bool m_localIsGM= false; 0124 bool m_visible= true; 0125 QString m_prefkey; 0126 // int m_volume{0}; 0127 }; 0128 0129 #endif // AUDIOPLAYERCONTROLLER_H