Added speed slider. Minor improvements
This commit is contained in:
@@ -13,24 +13,4 @@ add_executable(soundboard
|
|||||||
soundboard.hpp
|
soundboard.hpp
|
||||||
)
|
)
|
||||||
|
|
||||||
target_precompile_headers(soundboard PRIVATE
|
|
||||||
<QApplication>
|
|
||||||
<QCheckBox>
|
|
||||||
<QComboBox>
|
|
||||||
<QDirIterator>
|
|
||||||
<QFileDialog>
|
|
||||||
<QHBoxLayout>
|
|
||||||
<QJsonArray>
|
|
||||||
<QJsonDocument>
|
|
||||||
<QJsonObject>
|
|
||||||
<QLabel>
|
|
||||||
<QListWidget>
|
|
||||||
<QProcess>
|
|
||||||
<QPushButton>
|
|
||||||
<QSlider>
|
|
||||||
<QString>
|
|
||||||
<QVBoxLayout>
|
|
||||||
<QWidget>
|
|
||||||
)
|
|
||||||
|
|
||||||
target_link_libraries(soundboard PRIVATE Qt6::Widgets)
|
target_link_libraries(soundboard PRIVATE Qt6::Widgets)
|
||||||
|
|||||||
@@ -140,7 +140,7 @@ void Player::play_file(const QString& file_path,
|
|||||||
args << "--vo=null" << "--no-video"
|
args << "--vo=null" << "--no-video"
|
||||||
<< "--audio-pitch-correction=no"
|
<< "--audio-pitch-correction=no"
|
||||||
<< "--audio-device=" + target
|
<< "--audio-device=" + target
|
||||||
<< "--speed=" + QString::number(speed, 'f', 1)
|
<< "--speed=" + QString::number(speed, 'f', 2)
|
||||||
<< file_path;
|
<< file_path;
|
||||||
|
|
||||||
auto process = std::make_unique<QProcess>();
|
auto process = std::make_unique<QProcess>();
|
||||||
|
|||||||
@@ -53,26 +53,53 @@ Soundboard::Soundboard(QWidget* parent/* = nullptr */) :
|
|||||||
|
|
||||||
main_layout->addLayout(top_layout);
|
main_layout->addLayout(top_layout);
|
||||||
|
|
||||||
|
// Volume slider
|
||||||
|
QHBoxLayout* volume_slider_layout = new QHBoxLayout();
|
||||||
|
|
||||||
|
m_volume_label = new QLabel("Volume: 80%");
|
||||||
|
m_volume_label->setFixedWidth(100);
|
||||||
|
volume_slider_layout->addWidget(m_volume_label);
|
||||||
|
|
||||||
m_volume_slider = new QSlider(Qt::Horizontal);
|
m_volume_slider = new QSlider(Qt::Horizontal);
|
||||||
m_volume_slider->setToolTip("Adjust the output volume");
|
m_volume_slider->setToolTip("Adjust the output volume");
|
||||||
m_volume_slider->setRange(0, 80);
|
m_volume_slider->setRange(0, 100);
|
||||||
m_volume_slider->setValue(80);
|
m_volume_slider->setValue(80);
|
||||||
m_volume_slider->setSingleStep(5);
|
m_volume_slider->setSingleStep(5);
|
||||||
main_layout->addWidget(m_volume_slider);
|
volume_slider_layout->addWidget(m_volume_slider);
|
||||||
connect(m_volume_slider, &QSlider::valueChanged, this, &Soundboard::set_volume);
|
connect(m_volume_slider, &QSlider::valueChanged, this, &Soundboard::set_volume);
|
||||||
|
|
||||||
|
main_layout->addLayout(volume_slider_layout);
|
||||||
|
|
||||||
|
// Speed slider
|
||||||
|
QHBoxLayout* speed_slider_layout = new QHBoxLayout();
|
||||||
|
|
||||||
|
m_speed_label = new QLabel("Speed: 100%");
|
||||||
|
m_speed_label->setFixedWidth(100);
|
||||||
|
speed_slider_layout->addWidget(m_speed_label);
|
||||||
|
|
||||||
|
m_speed_slider = new QSlider(Qt::Horizontal);
|
||||||
|
m_speed_slider->setToolTip("Adjust the audio speed");
|
||||||
|
m_speed_slider->setRange(0, 100);
|
||||||
|
m_speed_slider->setValue(100);
|
||||||
|
m_speed_slider->setSingleStep(5);
|
||||||
|
speed_slider_layout->addWidget(m_speed_slider);
|
||||||
|
connect(m_speed_slider, &QSlider::valueChanged, this, &Soundboard::set_speed);
|
||||||
|
|
||||||
|
main_layout->addLayout(speed_slider_layout);
|
||||||
|
|
||||||
// Middle
|
// Middle
|
||||||
m_sound_list = new QListWidget();
|
m_sound_list = new QListWidget();
|
||||||
m_sound_list->setSelectionMode(QAbstractItemView::SingleSelection);
|
m_sound_list->setSelectionMode(QAbstractItemView::SingleSelection);
|
||||||
main_layout->addWidget(m_sound_list);
|
main_layout->addWidget(m_sound_list);
|
||||||
connect(m_sound_list, &QListWidget::itemSelectionChanged, this, &Soundboard::play_sound);
|
connect(m_sound_list, &QListWidget::itemClicked, this, &Soundboard::play_sound);
|
||||||
|
|
||||||
// Bottom
|
// Bottom
|
||||||
QHBoxLayout* bottom_layout = new QHBoxLayout();
|
QHBoxLayout* bottom_layout = new QHBoxLayout();
|
||||||
|
|
||||||
m_stop_button = new QPushButton("Stop");
|
m_stop_button = new QPushButton("Stop");
|
||||||
m_stop_button->setToolTip("Stop all audio streams");
|
m_stop_button->setToolTip("Stop all audio streams");
|
||||||
bottom_layout->addWidget(m_stop_button);
|
m_stop_button->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
|
||||||
|
bottom_layout->addWidget(m_stop_button, 1);
|
||||||
connect(m_stop_button, &QPushButton::pressed, this, &Soundboard::stop_sounds);
|
connect(m_stop_button, &QPushButton::pressed, this, &Soundboard::stop_sounds);
|
||||||
|
|
||||||
m_monitor_toggle = new QCheckBox("Monitor");
|
m_monitor_toggle = new QCheckBox("Monitor");
|
||||||
@@ -194,7 +221,7 @@ void Soundboard::play_sound()
|
|||||||
QString sound = item->text();
|
QString sound = item->text();
|
||||||
QString full_path = QDir(m_audio_directory).filePath(sound);
|
QString full_path = QDir(m_audio_directory).filePath(sound);
|
||||||
|
|
||||||
m_player.play_file(full_path, m_sink->get_name());
|
m_player.play_file(full_path, m_sink->get_name(), m_speed);
|
||||||
std::cout << "[INFO] Playing: " << sound << std::endl;
|
std::cout << "[INFO] Playing: " << sound << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -211,7 +238,13 @@ void Soundboard::set_volume(int value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
Pipewire::set_volume(m_sink->get_name(), value);
|
Pipewire::set_volume(m_sink->get_name(), value);
|
||||||
std::cout << "[INFO] Set volume to " << value << '%' << std::endl;
|
m_volume_label->setText(QString("Volume: ") + QString::number(value) + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
void Soundboard::set_speed(int value)
|
||||||
|
{
|
||||||
|
m_speed = static_cast<float>(value) / 100.0f;
|
||||||
|
m_speed_label->setText(QString("Speed: ") + QString::number(value) + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Soundboard::toggle_monitor(Qt::CheckState state)
|
void Soundboard::toggle_monitor(Qt::CheckState state)
|
||||||
|
|||||||
@@ -24,7 +24,10 @@ private:
|
|||||||
QPushButton* m_refresh_button = nullptr;
|
QPushButton* m_refresh_button = nullptr;
|
||||||
QPushButton* m_folder_button = nullptr;
|
QPushButton* m_folder_button = nullptr;
|
||||||
QLabel* m_label = nullptr;
|
QLabel* m_label = nullptr;
|
||||||
|
QLabel* m_volume_label = nullptr;
|
||||||
QSlider* m_volume_slider = nullptr;
|
QSlider* m_volume_slider = nullptr;
|
||||||
|
QLabel* m_speed_label = nullptr;
|
||||||
|
QSlider* m_speed_slider = nullptr;
|
||||||
QListWidget* m_sound_list = nullptr;
|
QListWidget* m_sound_list = nullptr;
|
||||||
QPushButton* m_stop_button = nullptr;
|
QPushButton* m_stop_button = nullptr;
|
||||||
QCheckBox* m_monitor_toggle = nullptr;
|
QCheckBox* m_monitor_toggle = nullptr;
|
||||||
@@ -35,6 +38,7 @@ private:
|
|||||||
|
|
||||||
std::vector<Pipewire::Node> m_apps;
|
std::vector<Pipewire::Node> m_apps;
|
||||||
QString m_audio_directory;
|
QString m_audio_directory;
|
||||||
|
float m_speed = 1.0f;
|
||||||
|
|
||||||
void on_app_selected(int index);
|
void on_app_selected(int index);
|
||||||
void refresh_apps();
|
void refresh_apps();
|
||||||
@@ -42,5 +46,6 @@ private:
|
|||||||
void play_sound();
|
void play_sound();
|
||||||
void stop_sounds();
|
void stop_sounds();
|
||||||
void set_volume(int value);
|
void set_volume(int value);
|
||||||
|
void set_speed(int value);
|
||||||
void toggle_monitor(Qt::CheckState state);
|
void toggle_monitor(Qt::CheckState state);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user