1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 10:27:34 +00:00

SoundPlayer: Rename main widget to SoundPlayerWidget

This is the main widget, and is never replaced by something else, so
having "AdvancedView" in there is a bit confusing.
This commit is contained in:
Sam Atkins 2023-07-19 14:33:06 +01:00 committed by Sam Atkins
parent fae350be3f
commit d00f489cdc
4 changed files with 31 additions and 31 deletions

View file

@ -14,7 +14,7 @@ set(SOURCES
Playlist.cpp Playlist.cpp
PlaylistWidget.cpp PlaylistWidget.cpp
SampleWidget.cpp SampleWidget.cpp
SoundPlayerWidgetAdvancedView.cpp SoundPlayerWidget.cpp
main.cpp main.cpp
) )

View file

@ -5,7 +5,7 @@
* SPDX-License-Identifier: BSD-2-Clause * SPDX-License-Identifier: BSD-2-Clause
*/ */
#include "SoundPlayerWidgetAdvancedView.h" #include "SoundPlayerWidget.h"
#include "AlbumCoverVisualizationWidget.h" #include "AlbumCoverVisualizationWidget.h"
#include "BarsVisualizationWidget.h" #include "BarsVisualizationWidget.h"
#include "M3UParser.h" #include "M3UParser.h"
@ -28,7 +28,7 @@
#include <LibGUI/Window.h> #include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h> #include <LibGfx/Bitmap.h>
SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window, Audio::ConnectionToServer& connection, ImageDecoderClient::Client& image_decoder_client) SoundPlayerWidget::SoundPlayerWidget(GUI::Window& window, Audio::ConnectionToServer& connection, ImageDecoderClient::Client& image_decoder_client)
: Player(connection) : Player(connection)
, m_window(window) , m_window(window)
, m_image_decoder_client(image_decoder_client) , m_image_decoder_client(image_decoder_client)
@ -140,19 +140,19 @@ SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window
done_initializing(); done_initializing();
} }
void SoundPlayerWidgetAdvancedView::set_nonlinear_volume_slider(bool nonlinear) void SoundPlayerWidget::set_nonlinear_volume_slider(bool nonlinear)
{ {
m_nonlinear_volume_slider = nonlinear; m_nonlinear_volume_slider = nonlinear;
} }
void SoundPlayerWidgetAdvancedView::drag_enter_event(GUI::DragEvent& event) void SoundPlayerWidget::drag_enter_event(GUI::DragEvent& event)
{ {
auto const& mime_types = event.mime_types(); auto const& mime_types = event.mime_types();
if (mime_types.contains_slow("text/uri-list")) if (mime_types.contains_slow("text/uri-list"))
event.accept(); event.accept();
} }
void SoundPlayerWidgetAdvancedView::drop_event(GUI::DropEvent& event) void SoundPlayerWidget::drop_event(GUI::DropEvent& event)
{ {
event.accept(); event.accept();
@ -166,7 +166,7 @@ void SoundPlayerWidgetAdvancedView::drop_event(GUI::DropEvent& event)
} }
} }
void SoundPlayerWidgetAdvancedView::keydown_event(GUI::KeyEvent& event) void SoundPlayerWidget::keydown_event(GUI::KeyEvent& event)
{ {
if (event.key() == Key_Up) if (event.key() == Key_Up)
m_volume_slider->increase_slider_by_page_steps(1); m_volume_slider->increase_slider_by_page_steps(1);
@ -177,7 +177,7 @@ void SoundPlayerWidgetAdvancedView::keydown_event(GUI::KeyEvent& event)
GUI::Widget::keydown_event(event); GUI::Widget::keydown_event(event);
} }
void SoundPlayerWidgetAdvancedView::set_playlist_visible(bool visible) void SoundPlayerWidget::set_playlist_visible(bool visible)
{ {
if (!visible) { if (!visible) {
m_playlist_widget->remove_from_parent(); m_playlist_widget->remove_from_parent();
@ -187,7 +187,7 @@ void SoundPlayerWidgetAdvancedView::set_playlist_visible(bool visible)
} }
} }
RefPtr<Gfx::Bitmap> SoundPlayerWidgetAdvancedView::get_image_from_music_file() RefPtr<Gfx::Bitmap> SoundPlayerWidget::get_image_from_music_file()
{ {
auto const& pictures = this->pictures(); auto const& pictures = this->pictures();
if (pictures.is_empty()) if (pictures.is_empty())
@ -203,7 +203,7 @@ RefPtr<Gfx::Bitmap> SoundPlayerWidgetAdvancedView::get_image_from_music_file()
return decoded_image.frames[0].bitmap; return decoded_image.frames[0].bitmap;
} }
void SoundPlayerWidgetAdvancedView::play_state_changed(Player::PlayState state) void SoundPlayerWidget::play_state_changed(Player::PlayState state)
{ {
sync_previous_next_actions(); sync_previous_next_actions();
@ -220,34 +220,34 @@ void SoundPlayerWidgetAdvancedView::play_state_changed(Player::PlayState state)
} }
} }
void SoundPlayerWidgetAdvancedView::loop_mode_changed(Player::LoopMode) void SoundPlayerWidget::loop_mode_changed(Player::LoopMode)
{ {
} }
void SoundPlayerWidgetAdvancedView::mute_changed(bool muted) void SoundPlayerWidget::mute_changed(bool muted)
{ {
m_mute_action->set_text(muted ? "Unmute"sv : "Mute"sv); m_mute_action->set_text(muted ? "Unmute"sv : "Mute"sv);
m_mute_action->set_icon(muted ? m_muted_icon : m_volume_icon); m_mute_action->set_icon(muted ? m_muted_icon : m_volume_icon);
m_volume_slider->set_enabled(!muted); m_volume_slider->set_enabled(!muted);
} }
void SoundPlayerWidgetAdvancedView::sync_previous_next_actions() void SoundPlayerWidget::sync_previous_next_actions()
{ {
m_back_action->set_enabled(playlist().size() > 1 && !playlist().shuffling()); m_back_action->set_enabled(playlist().size() > 1 && !playlist().shuffling());
m_next_action->set_enabled(playlist().size() > 1); m_next_action->set_enabled(playlist().size() > 1);
} }
void SoundPlayerWidgetAdvancedView::shuffle_mode_changed(Player::ShuffleMode) void SoundPlayerWidget::shuffle_mode_changed(Player::ShuffleMode)
{ {
sync_previous_next_actions(); sync_previous_next_actions();
} }
void SoundPlayerWidgetAdvancedView::time_elapsed(int seconds) void SoundPlayerWidget::time_elapsed(int seconds)
{ {
m_timestamp_label->set_text(String::formatted("Elapsed: {}", human_readable_digital_time(seconds)).release_value_but_fixme_should_propagate_errors()); m_timestamp_label->set_text(String::formatted("Elapsed: {}", human_readable_digital_time(seconds)).release_value_but_fixme_should_propagate_errors());
} }
void SoundPlayerWidgetAdvancedView::file_name_changed(StringView name) void SoundPlayerWidget::file_name_changed(StringView name)
{ {
m_visualization->start_new_file(name); m_visualization->start_new_file(name);
DeprecatedString title = name; DeprecatedString title = name;
@ -263,13 +263,13 @@ void SoundPlayerWidgetAdvancedView::file_name_changed(StringView name)
m_window.set_title(DeprecatedString::formatted("{} — Sound Player", title)); m_window.set_title(DeprecatedString::formatted("{} — Sound Player", title));
} }
void SoundPlayerWidgetAdvancedView::total_samples_changed(int total_samples) void SoundPlayerWidget::total_samples_changed(int total_samples)
{ {
m_playback_progress_slider->set_max(total_samples); m_playback_progress_slider->set_max(total_samples);
m_playback_progress_slider->set_page_step(total_samples / 10); m_playback_progress_slider->set_page_step(total_samples / 10);
} }
void SoundPlayerWidgetAdvancedView::sound_buffer_played(FixedArray<Audio::Sample> const& buffer, int sample_rate, int samples_played) void SoundPlayerWidget::sound_buffer_played(FixedArray<Audio::Sample> const& buffer, int sample_rate, int samples_played)
{ {
m_visualization->set_buffer(buffer); m_visualization->set_buffer(buffer);
m_visualization->set_samplerate(sample_rate); m_visualization->set_samplerate(sample_rate);
@ -278,12 +278,12 @@ void SoundPlayerWidgetAdvancedView::sound_buffer_played(FixedArray<Audio::Sample
m_playback_progress_slider->set_value(samples_played, GUI::AllowCallback::No); m_playback_progress_slider->set_value(samples_played, GUI::AllowCallback::No);
} }
void SoundPlayerWidgetAdvancedView::volume_changed(double volume) void SoundPlayerWidget::volume_changed(double volume)
{ {
m_volume_label->set_text(String::formatted("{}%", static_cast<int>(volume * 100)).release_value_but_fixme_should_propagate_errors()); m_volume_label->set_text(String::formatted("{}%", static_cast<int>(volume * 100)).release_value_but_fixme_should_propagate_errors());
} }
void SoundPlayerWidgetAdvancedView::playlist_loaded(StringView path, bool loaded) void SoundPlayerWidget::playlist_loaded(StringView path, bool loaded)
{ {
if (!loaded) { if (!loaded) {
GUI::MessageBox::show(&m_window, DeprecatedString::formatted("Could not load playlist at \"{}\".", path), "Error opening playlist"sv, GUI::MessageBox::Type::Error); GUI::MessageBox::show(&m_window, DeprecatedString::formatted("Could not load playlist at \"{}\".", path), "Error opening playlist"sv, GUI::MessageBox::Type::Error);
@ -293,7 +293,7 @@ void SoundPlayerWidgetAdvancedView::playlist_loaded(StringView path, bool loaded
play_file_path(playlist().next()); play_file_path(playlist().next());
} }
void SoundPlayerWidgetAdvancedView::audio_load_error(StringView path, StringView error_string) void SoundPlayerWidget::audio_load_error(StringView path, StringView error_string)
{ {
GUI::MessageBox::show(&m_window, DeprecatedString::formatted("Failed to load audio file: {} ({})", path, error_string.is_null() ? "Unknown error"sv : error_string), GUI::MessageBox::show(&m_window, DeprecatedString::formatted("Failed to load audio file: {} ({})", path, error_string.is_null() ? "Unknown error"sv : error_string),
"Filetype error"sv, GUI::MessageBox::Type::Error); "Filetype error"sv, GUI::MessageBox::Type::Error);

View file

@ -18,9 +18,9 @@
#include <LibGUI/Widget.h> #include <LibGUI/Widget.h>
#include <LibImageDecoderClient/Client.h> #include <LibImageDecoderClient/Client.h>
class SoundPlayerWidgetAdvancedView final : public GUI::Widget class SoundPlayerWidget final : public GUI::Widget
, public Player { , public Player {
C_OBJECT(SoundPlayerWidgetAdvancedView) C_OBJECT(SoundPlayerWidget)
public: public:
void set_nonlinear_volume_slider(bool nonlinear); void set_nonlinear_volume_slider(bool nonlinear);
@ -55,7 +55,7 @@ protected:
void keydown_event(GUI::KeyEvent&) override; void keydown_event(GUI::KeyEvent&) override;
private: private:
SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ConnectionToServer&, ImageDecoderClient::Client&); SoundPlayerWidget(GUI::Window&, Audio::ConnectionToServer&, ImageDecoderClient::Client&);
void sync_previous_next_actions(); void sync_previous_next_actions();

View file

@ -9,7 +9,7 @@
#include "BarsVisualizationWidget.h" #include "BarsVisualizationWidget.h"
#include "Player.h" #include "Player.h"
#include "SampleWidget.h" #include "SampleWidget.h"
#include "SoundPlayerWidgetAdvancedView.h" #include "SoundPlayerWidget.h"
#include <LibAudio/ConnectionToServer.h> #include <LibAudio/ConnectionToServer.h>
#include <LibAudio/FlacLoader.h> #include <LibAudio/FlacLoader.h>
#include <LibConfig/Client.h> #include <LibConfig/Client.h>
@ -52,7 +52,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16)); window->set_icon(app_icon.bitmap_for_size(16));
// start in advanced view by default // start in advanced view by default
Player* player = TRY(window->set_main_widget<SoundPlayerWidgetAdvancedView>(window, audio_client, decoder_client)); Player* player = TRY(window->set_main_widget<SoundPlayerWidget>(window, audio_client, decoder_client));
if (!file_path.is_empty()) { if (!file_path.is_empty()) {
player->play_file_path(file_path); player->play_file_path(file_path);
@ -95,14 +95,14 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
playback_menu->add_action(loop_playlist); playback_menu->add_action(loop_playlist);
auto linear_volume_slider = GUI::Action::create_checkable("&Nonlinear Volume Slider", [&](auto& action) { auto linear_volume_slider = GUI::Action::create_checkable("&Nonlinear Volume Slider", [&](auto& action) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_nonlinear_volume_slider(action.is_checked()); static_cast<SoundPlayerWidget*>(player)->set_nonlinear_volume_slider(action.is_checked());
}); });
TRY(playback_menu->try_add_separator()); TRY(playback_menu->try_add_separator());
TRY(playback_menu->try_add_action(linear_volume_slider)); TRY(playback_menu->try_add_action(linear_volume_slider));
TRY(playback_menu->try_add_separator()); TRY(playback_menu->try_add_separator());
auto playlist_toggle = GUI::Action::create_checkable("&Show Playlist", [&](auto& action) { auto playlist_toggle = GUI::Action::create_checkable("&Show Playlist", [&](auto& action) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_playlist_visible(action.is_checked()); static_cast<SoundPlayerWidget*>(player)->set_playlist_visible(action.is_checked());
}); });
if (player->loop_mode() == Player::LoopMode::Playlist) { if (player->loop_mode() == Player::LoopMode::Playlist) {
playlist_toggle->set_checked(true); playlist_toggle->set_checked(true);
@ -129,21 +129,21 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
}; };
auto bars = GUI::Action::create_checkable("&Bars", [&](auto&) { auto bars = GUI::Action::create_checkable("&Bars", [&](auto&) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<BarsVisualizationWidget>(); static_cast<SoundPlayerWidget*>(player)->set_visualization<BarsVisualizationWidget>();
set_selected_visualization_in_config("bars"sv); set_selected_visualization_in_config("bars"sv);
}); });
TRY(visualization_menu->try_add_action(bars)); TRY(visualization_menu->try_add_action(bars));
visualization_actions.add_action(bars); visualization_actions.add_action(bars);
auto samples = GUI::Action::create_checkable("&Samples", [&](auto&) { auto samples = GUI::Action::create_checkable("&Samples", [&](auto&) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<SampleWidget>(); static_cast<SoundPlayerWidget*>(player)->set_visualization<SampleWidget>();
set_selected_visualization_in_config("samples"sv); set_selected_visualization_in_config("samples"sv);
}); });
TRY(visualization_menu->try_add_action(samples)); TRY(visualization_menu->try_add_action(samples));
visualization_actions.add_action(samples); visualization_actions.add_action(samples);
auto album_cover_visualization = GUI::Action::create_checkable("&Album Cover", [&](auto&) { auto album_cover_visualization = GUI::Action::create_checkable("&Album Cover", [&](auto&) {
auto* view = static_cast<SoundPlayerWidgetAdvancedView*>(player); auto* view = static_cast<SoundPlayerWidget*>(player);
view->set_visualization<AlbumCoverVisualizationWidget>([&view]() { view->set_visualization<AlbumCoverVisualizationWidget>([&view]() {
return view->get_image_from_music_file(); return view->get_image_from_music_file();
}); });