Skip to content

Commit

Permalink
finished the floating controlls for now, the audio backend will chang…
Browse files Browse the repository at this point in the history
…e later and the music player controller too
  • Loading branch information
Crylia committed Mar 28, 2024
1 parent 55eb496 commit baea46d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/Controller/MusicPlayer/MusicPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ bool MusicPlayer::IsPlaying( ) {
return audio.IsMusicPaused( );
}

bool MusicPlayer::IsActive( ) {
return audio.IsMusicPlaying( );
}

QPixmap MusicPlayer::GetAlbumArt( ) {
return audio.GetAlbumCover( );
}
Expand Down
2 changes: 2 additions & 0 deletions src/Controller/MusicPlayer/MusicPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ class MusicPlayer : public QObject {
this->shuffle = shuffle;
shuffleHandler( );
}
bool IsActive( );
bool GetShuffle( ) { return shuffle; }
void SetLoop(Loop loop) { this->loop = loop; }
Loop GetLoop( ) { return loop; }
u_short GetVolume( ) { return audio.GetVolume( ); }
void SetVolume(u_short volume) { audio.SetVolume(volume); }
int GetSongDuration( ) { return audio.GetMusicDuration( ); }

void AddSongToQueue(Song* song);
void RemoveSongFromQueue(Song* song);
Expand Down
34 changes: 33 additions & 1 deletion src/View/Modules/FloatingControls/FloatingControls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ FloatingControls::FloatingControls(QWidget* parent) :
color: #D7D7D7;
}
)");
connect(&musicPlayer, &MusicPlayer::SongChanged, this, &FloatingControls::setSongDur);
#pragma endregion
#pragma region Song Progress Bar
Expand Down Expand Up @@ -304,6 +305,27 @@ FloatingControls::FloatingControls(QWidget* parent) :
mainLayout->setSpacing(10);
this->setLayout(mainLayout);
m_progressUpdateTimer = new QTimer( );
connect(m_progressUpdateTimer, &QTimer::timeout, this, [this]( ) {
if (!musicPlayer.IsActive( )) {
m_songProgress->setValue(0);
m_songPos->setText("-:--");
return;
}
u_short sec = musicPlayer.GetSongProgression( );
m_songPos->setText(
QTime(
0,
sec / 60,
sec % 60
).toString("mm:ss"));
m_songProgress->setValue(sec);
});
m_progressUpdateTimer->start(1000);
}
FloatingControls::~FloatingControls( ) { }
Expand Down Expand Up @@ -412,7 +434,6 @@ void FloatingControls::playPause( ) {
}
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( )));
Expand All @@ -429,3 +450,14 @@ void FloatingControls::setTitle( ) {
m_albumArt->setPixmap(m_albumArt->pixmap( ).copy(targetRect).scaled(QSize(64, 64), Qt::KeepAspectRatio));
}
void FloatingControls::setSongDur( ) {
u_short sec = musicPlayer.GetSongDuration( );
m_songDur->setText(
QTime(
0,
sec / 60,
sec % 60
).toString("mm:ss"));
}
4 changes: 4 additions & 0 deletions src/View/Modules/FloatingControls/FloatingControls.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ class FloatingControls : public QFrame {
QSlider* m_songProgress;
QSlider* m_volumeSlider;

// Timer to update the song's duration and slider
QTimer* m_progressUpdateTimer;

bool fullscreen;

signals:
Expand All @@ -70,4 +73,5 @@ private slots:
void playPause( );

void setTitle( );
void setSongDur( );
};

0 comments on commit baea46d

Please sign in to comment.