Skip to content

Commit

Permalink
widget: playlist filter, mute and UI tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
BLumia committed Aug 14, 2024
1 parent 5256480 commit a69ef28
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 16 deletions.
62 changes: 51 additions & 11 deletions widget/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <QListView>
#include <QTime>
#include <QMessageBox>
#include <QSortFilterProxyModel>

#include <portaudio.h>
#include <libopenmpt/libopenmpt.hpp>
Expand All @@ -24,12 +25,14 @@ MainWindow::MainWindow(QWidget *parent)
, m_player(new Player(this))
, m_playlistManager(new PlaylistManager(this))
, m_instrumentsModel(new InstrumentsModel(m_player, this))
, m_playlistFilderModel(new QSortFilterProxyModel(this))
{
ui->setupUi(this);
ui->plainTextEdit->setFont(Util::defaultMonoFont());
ui->instrumentsListView->setFont(Util::defaultMonoFont());
ui->instrumentsListView->setModel(m_instrumentsModel);
ui->playlistView->setModel(m_playlistManager->model());
m_playlistFilderModel->setSourceModel(m_playlistManager->model());
ui->playlistView->setModel(m_playlistFilderModel);
setWindowIcon(QIcon(":/icons/dist/pineapple-tracker-player.svg"));

m_playlistManager->setAutoLoadFilterSuffixes({"*.xm", "*.it", "*.mod", "*.s3m", "*.mptm"});
Expand All @@ -43,8 +46,8 @@ MainWindow::MainWindow(QWidget *parent)
});

connect(m_player, &Player::fileLoaded, this, [this](){
ui->horizontalSlider->setMaximum(m_player->totalOrders() - 1);
ui->horizontalSlider->setValue(m_player->currentOrder());
ui->playbackSlider->setMaximum(m_player->totalOrders() - 1);
ui->playbackSlider->setValue(m_player->currentOrder());
ui->songTitle->setText(m_player->title());
const QString & artist = m_player->artist();
ui->label_4->setText(artist.isEmpty() ? m_player->tracker() : (m_player->artist() + " (" + m_player->tracker() + ")") );
Expand All @@ -58,8 +61,8 @@ MainWindow::MainWindow(QWidget *parent)
});

connect(m_player, &Player::currentOrderChanged, this, [this](){
QSignalBlocker sb(ui->horizontalSlider);
ui->horizontalSlider->setValue(m_player->currentOrder());
QSignalBlocker sb(ui->playbackSlider);
ui->playbackSlider->setValue(m_player->currentOrder());
});

connect(m_player, &Player::currentRowChanged, this, [this](){
Expand All @@ -70,13 +73,30 @@ MainWindow::MainWindow(QWidget *parent)
));
});

connect(ui->horizontalSlider, &QSlider::valueChanged, this, [this](int value){
m_player->seek(ui->horizontalSlider->value());
connect(m_player, &Player::gainChanged, this, [this](){
// only update the icon of the mute button here.
int32_t gain = m_player->gain();
QString iconText;
if (gain < ui->volumeSlider->minimum()) {
// muted
iconText = "audio-volume-muted";
} else if (gain <= -1000) {
iconText = "audio-volume-low";
} else if (gain <= 0) {
iconText = "audio-volume-medium";
} else {
iconText = "audio-volume-high";
}
ui->muteButton->setIcon(QIcon::fromTheme(iconText));
});

connect(ui->playbackSlider, &QSlider::valueChanged, this, [this](int value){
m_player->seek(ui->playbackSlider->value());
QToolTip::showText(QCursor::pos(), QString::number(value), nullptr);
});

connect(ui->horizontalSlider_2, &QSlider::sliderMoved, this, [this](int value){
m_player->setGain(ui->horizontalSlider_2->value());
connect(ui->volumeSlider, &QSlider::sliderMoved, this, [this](int value){
m_player->setGain(ui->volumeSlider->value());
QToolTip::showText(QCursor::pos(), QString("%1 dB").arg(value / 100.f), nullptr);
});

Expand Down Expand Up @@ -149,8 +169,9 @@ void MainWindow::on_playlistBtn_clicked()

void MainWindow::on_playlistView_activated(const QModelIndex &index)
{
m_playlistManager->setCurrentIndex(index);
playFiles({m_playlistManager->urlByIndex(index)});
QModelIndex sourceIndex(m_playlistFilderModel->mapToSource(index));
m_playlistManager->setCurrentIndex(sourceIndex);
playFiles({m_playlistManager->urlByIndex(sourceIndex)});
}


Expand Down Expand Up @@ -182,3 +203,22 @@ void MainWindow::on_actionAbout_triggered()
infoBox.exec();
}


void MainWindow::on_filterEdit_textChanged(const QString &arg1)
{
m_playlistFilderModel->setFilterFixedString(arg1);
}


void MainWindow::on_muteButton_clicked()
{
if (QGuiApplication::queryKeyboardModifiers().testFlag(Qt::ShiftModifier)) {
m_player->setGain(0);
ui->volumeSlider->setValue(0);
return;
}

bool isMuted = m_player->gain() < ui->volumeSlider->minimum();
m_player->setGain(isMuted ? ui->volumeSlider->value() : std::numeric_limits<std::int32_t>::min());
}

5 changes: 4 additions & 1 deletion widget/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
class QDragEnterEvent;
class QDropEvent;
class QSortFilterProxyModel;
QT_END_NAMESPACE

class Player;
Expand All @@ -30,12 +31,14 @@ private slots:
void on_messageBtn_clicked();
void on_playlistBtn_clicked();
void on_playlistView_activated(const QModelIndex &index);

void on_actionAbout_triggered();
void on_filterEdit_textChanged(const QString &arg1);
void on_muteButton_clicked();

private:
Ui::MainWindow *ui;
Player * m_player = nullptr;
PlaylistManager * m_playlistManager = nullptr;
InstrumentsModel * m_instrumentsModel = nullptr;
QSortFilterProxyModel * m_playlistFilderModel = nullptr;
};
55 changes: 51 additions & 4 deletions widget/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@
</widget>
</item>
<item>
<widget class="QSlider" name="horizontalSlider">
<widget class="QSlider" name="playbackSlider">
<property name="orientation">
<enum>Qt::Orientation::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0,0">
<item>
<widget class="QPushButton" name="playButton">
<property name="text">
Expand All @@ -62,15 +62,28 @@
</spacer>
</item>
<item>
<widget class="QSlider" name="horizontalSlider_2">
<widget class="QPushButton" name="muteButton">
<property name="text">
<string/>
</property>
<property name="icon">
<iconset theme="audio-volume-high"/>
</property>
<property name="flat">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QSlider" name="volumeSlider">
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
<property name="minimum">
<number>-1500</number>
<number>-2000</number>
</property>
<property name="maximum">
<number>1000</number>
Expand Down Expand Up @@ -109,29 +122,50 @@
<property name="text">
<string>Playlist</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QPushButton" name="messageBtn">
<property name="text">
<string>Message</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
<item>
<widget class="QPushButton" name="instrumentsBtn">
<property name="text">
<string>Instruments</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="flat">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup</string>
</attribute>
</widget>
</item>
</layout>
Expand Down Expand Up @@ -181,6 +215,16 @@
<item>
<widget class="QListView" name="playlistView"/>
</item>
<item>
<widget class="QLineEdit" name="filterEdit">
<property name="placeholderText">
<string>Type to filter by keyword</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="instrumentsPage">
Expand Down Expand Up @@ -252,4 +296,7 @@
</widget>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="buttonGroup"/>
</buttongroups>
</ui>

0 comments on commit a69ef28

Please sign in to comment.