Files
SubWave/src/gui/NowPlayingPanel.cpp
T
rattatwinko 7297ae5f6b add: Audio Info in NowPlayingPanel.cpp ; Includes: Samplerate, bits/sample, and codec
change: opengl dll for windows now is not included, cause it is too large
refactor: Spectrogram colors for bars are now in a Header (GradientPresetHeader.h), with accompaning methods
2026-07-02 16:35:04 +02:00

136 lines
4.0 KiB
C++

#include "NowPlayingPanel.h"
#include "CoverArtWidget.h"
#include "engine/MusicLibrary.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QFont>
NowPlayingPanel::NowPlayingPanel(QWidget *parent)
: QGroupBox("Now Playing", parent)
, m_cover(new CoverArtWidget)
{
buildLayout();
connect(m_btnPlay, &QPushButton::clicked, this, &NowPlayingPanel::playPauseClicked);
connect(m_btnPrev, &QPushButton::clicked, this, &NowPlayingPanel::prevClicked);
connect(m_btnNext, &QPushButton::clicked, this, &NowPlayingPanel::nextClicked);
connect(m_seekBar, &QSlider::sliderPressed, this, [this]{ m_seekDragging = true; });
connect(m_seekBar, &QSlider::sliderReleased, this, [this]{
m_seekDragging = false;
emit seekRequested(m_seekBar->value() / 1000.0);
});
connect(m_volSlider, &QSlider::valueChanged, this, &NowPlayingPanel::volumeChanged);
}
void NowPlayingPanel::buildLayout()
{
m_cover->setFixedSize(130, 130);
QFont boldF = m_lblTitle->font();
boldF.setBold(true);
boldF.setPointSizeF(11);
m_lblTitle->setFont(boldF);
m_seekBar->setRange(0, 1000);
m_seekBar->setValue(0);
m_volSlider->setRange(0, 100);
m_volSlider->setValue(80);
m_volSlider->setFixedWidth(90);
auto *seekRow = new QHBoxLayout;
seekRow->addWidget(m_seekBar);
seekRow->addWidget(m_lblTime);
auto *btns = new QHBoxLayout;
btns->setSpacing(3);
btns->addWidget(m_btnPrev);
btns->addWidget(m_btnPlay);
btns->addWidget(m_btnNext);
btns->addSpacing(8);
btns->addWidget(m_chkShuffle);
btns->addWidget(m_chkRepeat);
auto *transport = new QHBoxLayout;
transport->addLayout(btns);
transport->addStretch();
transport->addWidget(new QLabel("Volume:"));
transport->addWidget(m_volSlider);
auto *metaRow = new QHBoxLayout;
metaRow->setSpacing(8);
metaRow->addWidget(new QLabel("Sample rate:"));
metaRow->addWidget(m_lblSampleRate);
metaRow->addWidget(new QLabel("Bits/Sample:"));
metaRow->addWidget(m_lblBitsPerSample);
metaRow->addWidget(new QLabel("Codec:"));
metaRow->addWidget(m_lblCodec);
metaRow->addStretch();
auto *right = new QVBoxLayout;
right->setSpacing(4);
right->addWidget(m_lblTitle);
right->addWidget(m_lblArtist);
right->addWidget(m_lblAlbum);
right->addLayout(metaRow);
right->addLayout(seekRow);
right->addLayout(transport);
auto *hlay = new QHBoxLayout(this);
hlay->addWidget(m_cover);
hlay->addLayout(right, 1);
}
void NowPlayingPanel::clearAudioInfo()
{
m_lblSampleRate->setText("-");
m_lblBitsPerSample->setText("-");
m_lblCodec->setText("-");
}
void NowPlayingPanel::updateTrack(const engine::Track *t)
{
if (!t) {
clearAudioInfo();
return;
}
m_cover->setTrack(t);
m_lblTitle->setText(t->displayTitle());
m_lblArtist->setText(t->artist);
m_lblAlbum->setText(t->album +
(t->year > 0 ? " (" + QString::number(t->year) + ")" : ""));
clearAudioInfo();
m_seekBar->setValue(0);
m_btnPlay->setText("Pause");
}
void NowPlayingPanel::updatePosition(qint64 posFrames, qint64 totalFrames, float sampleRate)
{
auto fmt = [](qint64 s) {
return QString("%1:%2").arg(s / 60).arg(s % 60, 2, 10, QChar('0'));
};
qint64 posSec = (sampleRate > 0) ? qint64(posFrames / sampleRate) : 0;
qint64 totSec = (sampleRate > 0 && totalFrames > 0)
? qint64(totalFrames / sampleRate) : 0;
m_lblTime->setText(fmt(posSec) + " / " + fmt(totSec));
if (!m_seekDragging && totalFrames > 0)
m_seekBar->setValue(int(posFrames * 1000 / totalFrames));
}
void NowPlayingPanel::updateAudioInfo(int sampleRate, int bitsPerSample, const QString &codec)
{
m_lblSampleRate->setText(sampleRate > 0 ? QString("%1 Hz").arg(sampleRate) : "-");
m_lblBitsPerSample->setText(bitsPerSample > 0 ? QString("%1").arg(bitsPerSample) : "-");
m_lblCodec->setText(!codec.isEmpty() ? codec : "-");
}
void NowPlayingPanel::setPlaybackActive(bool playing)
{
m_btnPlay->setText(playing ? "Pause" : "Play");
}