Did more work on the bindings between the audio and view
This commit is contained in:
@@ -3,10 +3,12 @@
|
|||||||
MusicPlayer::~MusicPlayer( ) { }
|
MusicPlayer::~MusicPlayer( ) { }
|
||||||
|
|
||||||
void MusicPlayer::PlaySong(Song* song) {
|
void MusicPlayer::PlaySong(Song* song) {
|
||||||
songHistory->push(songQueue->Top( ));
|
|
||||||
songQueue->SetTop(song);
|
songQueue->SetTop(song);
|
||||||
|
songHistory->push(songQueue->Top( ));
|
||||||
|
|
||||||
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
||||||
|
|
||||||
|
emit SongChanged( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicPlayer::NextSong( ) {
|
void MusicPlayer::NextSong( ) {
|
||||||
@@ -19,6 +21,7 @@ void MusicPlayer::NextSong( ) {
|
|||||||
songQueue->Next( );
|
songQueue->Next( );
|
||||||
|
|
||||||
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
||||||
|
emit SongChanged( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicPlayer::NextSong(Song* song, bool isPrioQueue) {
|
void MusicPlayer::NextSong(Song* song, bool isPrioQueue) {
|
||||||
@@ -31,6 +34,7 @@ void MusicPlayer::NextSong(Song* song, bool isPrioQueue) {
|
|||||||
songQueue->JumpToSong(song, isPrioQueue);
|
songQueue->JumpToSong(song, isPrioQueue);
|
||||||
|
|
||||||
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
||||||
|
emit SongChanged( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicPlayer::PreviousSong( ) {
|
void MusicPlayer::PreviousSong( ) {
|
||||||
@@ -41,6 +45,7 @@ void MusicPlayer::PreviousSong( ) {
|
|||||||
songHistory->pop( );
|
songHistory->pop( );
|
||||||
|
|
||||||
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
audio.PlaySong(songQueue->Top( )->GetPath( ));
|
||||||
|
emit SongChanged( );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MusicPlayer::SkipToTimestamp(unsigned const int& skipTo) {
|
void MusicPlayer::SkipToTimestamp(unsigned const int& skipTo) {
|
||||||
@@ -77,3 +82,27 @@ void MusicPlayer::shuffleHandler( ) {
|
|||||||
void MusicPlayer::setQueueLoop( ) {
|
void MusicPlayer::setQueueLoop( ) {
|
||||||
loop == All ? songQueue->LinkQueue(true) : songQueue->LinkQueue(false);
|
loop == All ? songQueue->LinkQueue(true) : songQueue->LinkQueue(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool MusicPlayer::IsPlaying( ) {
|
||||||
|
return audio.IsMusicPaused( );
|
||||||
|
}
|
||||||
|
|
||||||
|
QPixmap MusicPlayer::GetAlbumArt( ) {
|
||||||
|
return audio.GetAlbumCover( );
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Resumes or Plays the music depending on the current state, if no music is playing
|
||||||
|
* it returns false
|
||||||
|
*
|
||||||
|
* @return true Music is Playing
|
||||||
|
* @return false Music is Paused or nothing is playing
|
||||||
|
*/
|
||||||
|
bool MusicPlayer::PlayPause( ) {
|
||||||
|
if (!audio.IsMusicPlaying( )) return false;
|
||||||
|
|
||||||
|
audio.TogglePlayPause( );
|
||||||
|
|
||||||
|
emit SongChanged( );
|
||||||
|
return !audio.IsMusicPaused( );
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <QObject>
|
||||||
|
#include <QPixmap>
|
||||||
|
|
||||||
#include "../../core/audio/audio.h"
|
#include "../../core/audio/audio.h"
|
||||||
#include "../../core/SongHistory/SongHistory.hpp"
|
#include "../../core/SongHistory/SongHistory.hpp"
|
||||||
#include "../../core/SongQueue/SongQueue.h"
|
#include "../../core/SongQueue/SongQueue.h"
|
||||||
#include "../../core/song/song.h"
|
#include "../../core/song/song.h"
|
||||||
|
|
||||||
enum Loop {
|
class MusicPlayer : public QObject {
|
||||||
None,
|
Q_OBJECT
|
||||||
Once,
|
|
||||||
All
|
|
||||||
};
|
|
||||||
|
|
||||||
class MusicPlayer {
|
|
||||||
public:
|
public:
|
||||||
static MusicPlayer& getInstance( ) {
|
static MusicPlayer& getInstance( ) {
|
||||||
static MusicPlayer instance;
|
static MusicPlayer instance;
|
||||||
@@ -19,7 +17,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
MusicPlayer( ) : songQueue(new SongQueue( )) { }
|
MusicPlayer( ) : songQueue(new SongQueue( )), songHistory(new SongHistory<Song*>( )) { }
|
||||||
|
|
||||||
// 0 no shuffle, 1 shuffling
|
// 0 no shuffle, 1 shuffling
|
||||||
int shuffle = 0;
|
int shuffle = 0;
|
||||||
@@ -95,6 +93,18 @@ public:
|
|||||||
*/
|
*/
|
||||||
Song* GetCurrentlyPlaying( );
|
Song* GetCurrentlyPlaying( );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Will either play or pause a current song, if not song is active it returns false.
|
||||||
|
*
|
||||||
|
* @return true if currently playing
|
||||||
|
* @return false if paused or nothing playing
|
||||||
|
*/
|
||||||
|
bool PlayPause( );
|
||||||
|
|
||||||
|
bool IsPlaying( );
|
||||||
|
|
||||||
|
QPixmap GetAlbumArt( );
|
||||||
|
|
||||||
void SetShuffle(bool shuffle) {
|
void SetShuffle(bool shuffle) {
|
||||||
this->shuffle = shuffle;
|
this->shuffle = shuffle;
|
||||||
shuffleHandler( );
|
shuffleHandler( );
|
||||||
@@ -102,8 +112,13 @@ public:
|
|||||||
bool GetShuffle( ) { return shuffle; }
|
bool GetShuffle( ) { return shuffle; }
|
||||||
void SetLoop(Loop loop) { this->loop = loop; }
|
void SetLoop(Loop loop) { this->loop = loop; }
|
||||||
Loop GetLoop( ) { return loop; }
|
Loop GetLoop( ) { return loop; }
|
||||||
|
u_short GetVolume( ) { return audio.GetVolume( ); }
|
||||||
|
void SetVolume(u_short volume) { audio.SetVolume(volume); }
|
||||||
|
|
||||||
void AddSongToQueue(Song* song);
|
void AddSongToQueue(Song* song);
|
||||||
void RemoveSongFromQueue(Song* song);
|
void RemoveSongFromQueue(Song* song);
|
||||||
void MoveSongInQueue(Song* songToMove, Song* otherSong, bool beforeElseAfter);
|
void MoveSongInQueue(Song* songToMove, Song* otherSong, bool beforeElseAfter);
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void SongChanged( );
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,13 +2,6 @@
|
|||||||
|
|
||||||
#include "FloatingControls.h"
|
#include "FloatingControls.h"
|
||||||
|
|
||||||
|
|
||||||
enum Repeat : short {
|
|
||||||
ALL,
|
|
||||||
CURRENT,
|
|
||||||
NONE
|
|
||||||
};
|
|
||||||
|
|
||||||
static QPushButton* makeSongControlButton(QString name, QSize size = QSize(36, 36), QString color = "#D7D7D7") {
|
static QPushButton* makeSongControlButton(QString name, QSize size = QSize(36, 36), QString color = "#D7D7D7") {
|
||||||
QPushButton* button = new QPushButton( );
|
QPushButton* button = new QPushButton( );
|
||||||
button->setObjectName(name);
|
button->setObjectName(name);
|
||||||
@@ -31,8 +24,7 @@ static QPushButton* makeSongControlButton(QString name, QSize size = QSize(36, 3
|
|||||||
|
|
||||||
FloatingControls::FloatingControls(QWidget* parent) :
|
FloatingControls::FloatingControls(QWidget* parent) :
|
||||||
QFrame(parent),
|
QFrame(parent),
|
||||||
fullscreen(false),
|
fullscreen(false) {
|
||||||
songRepeat(NONE) {
|
|
||||||
|
|
||||||
#pragma region Frame setup
|
#pragma region Frame setup
|
||||||
this->setFixedHeight(100);
|
this->setFixedHeight(100);
|
||||||
@@ -102,6 +94,7 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
|||||||
color: #D7D7D7;
|
color: #D7D7D7;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
|
connect(&musicPlayer, &MusicPlayer::SongChanged, this, &FloatingControls::setTitle);
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
artistSongLayout->addWidget(m_artist);
|
artistSongLayout->addWidget(m_artist);
|
||||||
@@ -126,10 +119,24 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
|||||||
m_skipPrev = makeSongControlButton("prevSong", QSize(36, 36), "#D7D7D7");
|
m_skipPrev = makeSongControlButton("prevSong", QSize(36, 36), "#D7D7D7");
|
||||||
songControlsLayout->addWidget(m_skipPrev);
|
songControlsLayout->addWidget(m_skipPrev);
|
||||||
m_playPause = makeSongControlButton("play", QSize(36, 36), "#D7D7D7");
|
m_playPause = makeSongControlButton("play", QSize(36, 36), "#D7D7D7");
|
||||||
|
connect(m_playPause, &QPushButton::clicked, this, &FloatingControls::playPause);
|
||||||
songControlsLayout->addWidget(m_playPause);
|
songControlsLayout->addWidget(m_playPause);
|
||||||
m_skipNext = makeSongControlButton("nextSong", QSize(36, 36), "#D7D7D7");
|
m_skipNext = makeSongControlButton("nextSong", QSize(36, 36), "#D7D7D7");
|
||||||
songControlsLayout->addWidget(m_skipNext);
|
songControlsLayout->addWidget(m_skipNext);
|
||||||
m_loop = makeSongControlButton("songRepeat", QSize(36, 36), "#757575");
|
m_loop = makeSongControlButton("songRepeat", QSize(36, 36), "#757575");
|
||||||
|
connect(m_loop, &QPushButton::clicked, [this]( ) {
|
||||||
|
switch (musicPlayer.GetLoop( )) {
|
||||||
|
case None:
|
||||||
|
setLoop(All);
|
||||||
|
break;
|
||||||
|
case All:
|
||||||
|
setLoop(Once);
|
||||||
|
break;
|
||||||
|
case Once:
|
||||||
|
setLoop(None);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
});
|
||||||
songControlsLayout->addWidget(m_loop);
|
songControlsLayout->addWidget(m_loop);
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
@@ -207,9 +214,9 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
|||||||
m_volumeIcon = new QLabel( );
|
m_volumeIcon = new QLabel( );
|
||||||
m_volumeIcon->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
m_volumeIcon->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||||
m_volumeIcon->setObjectName("m_volumeIcon");
|
m_volumeIcon->setObjectName("m_volumeIcon");
|
||||||
m_volumeIcon->setPixmap(RenderSvg(":icons/volume-high.svg", 36, 36).scaled(QSize(24, 24), Qt::IgnoreAspectRatio));
|
m_volumeIcon->setPixmap(RenderSvg(":icons/volume-medium.svg", 24, 24));
|
||||||
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
colorize->setColor(QColor("#78AB70"));
|
colorize->setColor(QColor("#FFF59D"));
|
||||||
colorize->setStrength(1);
|
colorize->setStrength(1);
|
||||||
m_volumeIcon->setGraphicsEffect(colorize);
|
m_volumeIcon->setGraphicsEffect(colorize);
|
||||||
rightLayout->addWidget(m_volumeIcon);
|
rightLayout->addWidget(m_volumeIcon);
|
||||||
@@ -228,7 +235,7 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
|||||||
background: #414141;
|
background: #414141;
|
||||||
}
|
}
|
||||||
QSlider#m_volumeSlider::handle:horizontal{
|
QSlider#m_volumeSlider::handle:horizontal{
|
||||||
background: #78AB70;
|
background: #FFF59D;
|
||||||
border: 4px solid #414141;
|
border: 4px solid #414141;
|
||||||
width: 14px;
|
width: 14px;
|
||||||
height: 14px;
|
height: 14px;
|
||||||
@@ -237,12 +244,13 @@ FloatingControls::FloatingControls(QWidget* parent) :
|
|||||||
padding: -8px 0;
|
padding: -8px 0;
|
||||||
}
|
}
|
||||||
QSlider#m_volumeSlider::sub-page:horizontal{
|
QSlider#m_volumeSlider::sub-page:horizontal{
|
||||||
background: #78AB70;
|
background: #FFF59D;
|
||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
height: 8px;
|
height: 8px;
|
||||||
}
|
}
|
||||||
)");
|
)");
|
||||||
m_volumeSlider->setCursor(Qt::PointingHandCursor);
|
m_volumeSlider->setCursor(Qt::PointingHandCursor);
|
||||||
|
connect(m_volumeSlider, &QSlider::valueChanged, this, &FloatingControls::volumeChanged);
|
||||||
#pragma endregion
|
#pragma endregion
|
||||||
|
|
||||||
rightLayout->addWidget(m_volumeSlider);
|
rightLayout->addWidget(m_volumeSlider);
|
||||||
@@ -304,7 +312,120 @@ void FloatingControls::setShuffle(bool shuffle) {
|
|||||||
musicPlayer.SetShuffle(shuffle);
|
musicPlayer.SetShuffle(shuffle);
|
||||||
|
|
||||||
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
|
// Get the value to make sure it actually changed
|
||||||
musicPlayer.GetShuffle( ) ? colorize->setColor(QColor("#CE93D8")) : colorize->setColor(QColor("#757575"));
|
musicPlayer.GetShuffle( ) ? colorize->setColor(QColor("#CE93D8")) : colorize->setColor(QColor("#757575"));
|
||||||
colorize->setStrength(1);
|
colorize->setStrength(1);
|
||||||
m_shuffle->setGraphicsEffect(colorize);
|
m_shuffle->setGraphicsEffect(colorize);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FloatingControls::volumeChanged( ) {
|
||||||
|
int value = m_volumeSlider->value( );
|
||||||
|
musicPlayer.SetVolume(value);
|
||||||
|
|
||||||
|
// We know MIX_MAX_VOLUME is always 0-128 so no need to calculate anything
|
||||||
|
if (value == 0) {
|
||||||
|
m_volumeIcon->setPixmap(RenderSvg(":icons/volume-off.svg", 24, 24));
|
||||||
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
|
colorize->setColor(QColor("#FFF59D"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_volumeIcon->setGraphicsEffect(colorize);
|
||||||
|
}
|
||||||
|
else if (value > 0 && value < 42) {
|
||||||
|
m_volumeIcon->setPixmap(RenderSvg(":icons/volume-low.svg", 24, 24));
|
||||||
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
|
colorize->setColor(QColor("#FFF59D"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_volumeIcon->setGraphicsEffect(colorize);
|
||||||
|
}
|
||||||
|
else if (value >= 42 && value < 84) {
|
||||||
|
m_volumeIcon->setPixmap(RenderSvg(":icons/volume-medium.svg", 24, 24));
|
||||||
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
|
colorize->setColor(QColor("#FFF59D"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_volumeIcon->setGraphicsEffect(colorize);
|
||||||
|
}
|
||||||
|
else if (value >= 84 && value < 128) {
|
||||||
|
m_volumeIcon->setPixmap(RenderSvg(":icons/volume-high.svg", 24, 24));
|
||||||
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
|
colorize->setColor(QColor("#FFF59D"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_volumeIcon->setGraphicsEffect(colorize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FloatingControls::setLoop(Loop loop) {
|
||||||
|
musicPlayer.SetLoop(loop);
|
||||||
|
|
||||||
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
|
// Get the value to make sure it actually changed
|
||||||
|
switch (musicPlayer.GetLoop( )) {
|
||||||
|
case None:
|
||||||
|
m_loop->setIcon(RenderSvg(":icons/songRepeat.svg", 36, 36));
|
||||||
|
colorize->setColor(QColor("#757575"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_loop->setGraphicsEffect(colorize);
|
||||||
|
break;
|
||||||
|
case All:
|
||||||
|
m_loop->setIcon(RenderSvg(":icons/songRepeat.svg", 36, 36));
|
||||||
|
colorize->setColor(QColor("#CE93D8"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_loop->setGraphicsEffect(colorize);
|
||||||
|
break;
|
||||||
|
case Once:
|
||||||
|
m_loop->setIcon(RenderSvg(":icons/repeat-once.svg", 36, 36));
|
||||||
|
colorize->setColor(QColor("#CE93D8"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_loop->setGraphicsEffect(colorize);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FloatingControls::playPause( ) {
|
||||||
|
//! TESTING ONLY
|
||||||
|
musicPlayer.PlaySong(new Song(
|
||||||
|
"Check This Out",
|
||||||
|
"",
|
||||||
|
"2Complex",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"/home/crylia/Musik/Dubstep EDM Electro/2Complex - Check This Out.mp3",
|
||||||
|
0,
|
||||||
|
""
|
||||||
|
));
|
||||||
|
|
||||||
|
bool playing = musicPlayer.IsPlaying( );
|
||||||
|
|
||||||
|
QGraphicsColorizeEffect* colorize = new QGraphicsColorizeEffect( );
|
||||||
|
playing ?
|
||||||
|
m_playPause->setIcon(RenderSvg(":icons/play.svg", 36, 36)) :
|
||||||
|
m_playPause->setIcon(RenderSvg(":icons/pause.svg", 36, 36));
|
||||||
|
colorize->setColor(QColor("#D7D7D7"));
|
||||||
|
colorize->setStrength(1);
|
||||||
|
m_playPause->setGraphicsEffect(colorize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FloatingControls::setTitle( ) {
|
||||||
|
std::cout << musicPlayer.GetCurrentlyPlaying( )->GetTitle( ) << std::endl;
|
||||||
|
m_title->setText(QString::fromStdString(musicPlayer.GetCurrentlyPlaying( )->GetTitle( )));
|
||||||
|
m_artist->setText(QString::fromStdString(musicPlayer.GetCurrentlyPlaying( )->GetArtist( )));
|
||||||
|
|
||||||
|
m_albumArt->setPixmap(musicPlayer.GetAlbumArt( ));
|
||||||
|
QRect targetRect;
|
||||||
|
if (m_albumArt->pixmap( ).width( ) > m_albumArt->pixmap( ).height( )) {
|
||||||
|
int sideLength = m_albumArt->pixmap( ).height( );
|
||||||
|
targetRect = QRect((m_albumArt->pixmap( ).width( ) - sideLength) / 2, 0, sideLength, sideLength);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
int sideLength = m_albumArt->pixmap( ).width( );
|
||||||
|
targetRect = QRect(0, (m_albumArt->pixmap( ).height( ) - sideLength) / 2, sideLength, sideLength);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_albumArt->setPixmap(m_albumArt->pixmap( ).copy(targetRect).scaled(QSize(64, 64), Qt::KeepAspectRatio));
|
||||||
|
}
|
||||||
|
|||||||
@@ -59,8 +59,15 @@ private:
|
|||||||
QSlider* m_volumeSlider;
|
QSlider* m_volumeSlider;
|
||||||
|
|
||||||
bool fullscreen;
|
bool fullscreen;
|
||||||
Repeat songRepeat;
|
|
||||||
|
signals:
|
||||||
|
void SongChanged( );
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void setShuffle(bool shuffle);
|
void setShuffle(bool shuffle);
|
||||||
|
void setLoop(Loop loop);
|
||||||
|
void volumeChanged( );
|
||||||
|
void playPause( );
|
||||||
|
|
||||||
|
void setTitle( );
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ private:
|
|||||||
Node* next;
|
Node* next;
|
||||||
};
|
};
|
||||||
|
|
||||||
Node* topNode = nullptr;
|
Node* topNode;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SongHistory( ) { }
|
SongHistory( ) : topNode(nullptr) { }
|
||||||
~SongHistory( ) {
|
~SongHistory( ) {
|
||||||
while (!isEmpty( ))
|
while (!isEmpty( ))
|
||||||
pop( );
|
pop( );
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ Audio::~Audio( ) {
|
|||||||
void Audio::StartMusic( ) {
|
void Audio::StartMusic( ) {
|
||||||
if (Mix_PlayingMusic( ) == 0) {
|
if (Mix_PlayingMusic( ) == 0) {
|
||||||
//TODO: Get the loop status from the FloatingControls widget and replace the 1
|
//TODO: Get the loop status from the FloatingControls widget and replace the 1
|
||||||
Mix_PlayMusic(music, 1);
|
Mix_PlayMusic(music, this->loop);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +43,7 @@ void Audio::PlaySong(const std::string path) {
|
|||||||
SDL_Quit( );
|
SDL_Quit( );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Mix_PlayMusic(music, this->loop);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::PauseMusic( ) {
|
void Audio::PauseMusic( ) {
|
||||||
@@ -57,6 +58,17 @@ void Audio::ResumeMusic( ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Audio::TogglePlayPause( ) {
|
||||||
|
if (IsMusicPaused( ))
|
||||||
|
ResumeMusic( );
|
||||||
|
else
|
||||||
|
PauseMusic( );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Audio::IsMusicPaused( ) {
|
||||||
|
return (Mix_PausedMusic( ) == 1);
|
||||||
|
}
|
||||||
|
|
||||||
bool Audio::IsMusicPlaying( ) {
|
bool Audio::IsMusicPlaying( ) {
|
||||||
return (Mix_PlayingMusic( ) != 0);
|
return (Mix_PlayingMusic( ) != 0);
|
||||||
}
|
}
|
||||||
@@ -112,7 +124,7 @@ QPixmap Audio::GetAlbumCover( ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int Audio::GetVolume( ) {
|
int Audio::GetVolume( ) {
|
||||||
return Mix_GetMusicVolume(music);
|
return Mix_VolumeMusic(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Audio::SetVolume(int vol) {
|
void Audio::SetVolume(int vol) {
|
||||||
|
|||||||
@@ -12,6 +12,12 @@ extern "C" {
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
enum Loop {
|
||||||
|
None,
|
||||||
|
All,
|
||||||
|
Once
|
||||||
|
};
|
||||||
|
|
||||||
class Audio {
|
class Audio {
|
||||||
public:
|
public:
|
||||||
static Audio& getInstance( ) {
|
static Audio& getInstance( ) {
|
||||||
@@ -24,6 +30,7 @@ private:
|
|||||||
std::string path;
|
std::string path;
|
||||||
std::string artist;
|
std::string artist;
|
||||||
std::string album;
|
std::string album;
|
||||||
|
Loop loop;
|
||||||
|
|
||||||
Mix_Music* music;
|
Mix_Music* music;
|
||||||
|
|
||||||
@@ -50,7 +57,8 @@ public:
|
|||||||
void PauseMusic( );
|
void PauseMusic( );
|
||||||
void ResumeMusic( );
|
void ResumeMusic( );
|
||||||
bool IsMusicPlaying( );
|
bool IsMusicPlaying( );
|
||||||
|
void TogglePlayPause( );
|
||||||
|
bool IsMusicPaused( );
|
||||||
void SetVolume(int vol);
|
void SetVolume(int vol);
|
||||||
int GetVolume( );
|
int GetVolume( );
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -51,4 +51,8 @@ public:
|
|||||||
|
|
||||||
std::string GetPath( ) { return path; };
|
std::string GetPath( ) { return path; };
|
||||||
|
|
||||||
|
std::string GetTitle( ) { return title; }
|
||||||
|
std::string GetAlbum( ) { return album; }
|
||||||
|
std::string GetArtist( ) { return artist; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user