summaryrefslogtreecommitdiff
path: root/Userland/Applications
diff options
context:
space:
mode:
authorCaoimhe <caoimhebyrne06@gmail.com>2023-03-19 16:36:51 +0000
committerLinus Groh <mail@linusgroh.de>2023-03-19 18:57:30 +0000
commit4c49e0f4a327f1b3ae4b228dbc8d78ebeaa999f6 (patch)
tree77916450f5336709aa41d857b7b884d77b0dd143 /Userland/Applications
parentdcc4868a3c6e3595f3f79f94c7e2f9afe4901abd (diff)
downloadserenity-4c49e0f4a327f1b3ae4b228dbc8d78ebeaa999f6.zip
SoundPlayer: Move `get_image_from_music_file` to the advanced view
Diffstat (limited to 'Userland/Applications')
-rw-r--r--Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp21
-rw-r--r--Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h5
-rw-r--r--Userland/Applications/SoundPlayer/main.cpp25
3 files changed, 30 insertions, 21 deletions
diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp
index 9fe0fc8aae..35216a5b7c 100644
--- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp
+++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp
@@ -6,9 +6,11 @@
*/
#include "SoundPlayerWidgetAdvancedView.h"
+#include "AlbumCoverVisualizationWidget.h"
#include "BarsVisualizationWidget.h"
#include "M3UParser.h"
#include "PlaybackManager.h"
+#include "SampleWidget.h"
#include <AK/DeprecatedString.h>
#include <AK/LexicalPath.h>
#include <AK/SIMD.h>
@@ -24,9 +26,10 @@
#include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h>
-SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window, Audio::ConnectionToServer& connection)
+SoundPlayerWidgetAdvancedView::SoundPlayerWidgetAdvancedView(GUI::Window& window, Audio::ConnectionToServer& connection, ImageDecoderClient::Client& image_decoder_client)
: Player(connection)
, m_window(window)
+ , m_image_decoder_client(image_decoder_client)
{
window.resize(455, 350);
window.set_resizable(true);
@@ -173,6 +176,22 @@ void SoundPlayerWidgetAdvancedView::set_playlist_visible(bool visible)
}
}
+RefPtr<Gfx::Bitmap> SoundPlayerWidgetAdvancedView::get_image_from_music_file()
+{
+ auto const& pictures = this->pictures();
+ if (pictures.is_empty())
+ return {};
+
+ // FIXME: We randomly select the first picture available for the track,
+ // We might want to hardcode or let the user set a preference.
+ auto decoded_image_or_error = m_image_decoder_client.decode_image(pictures[0].data);
+ if (!decoded_image_or_error.has_value())
+ return {};
+
+ auto const decoded_image = decoded_image_or_error.release_value();
+ return decoded_image.frames[0].bitmap;
+}
+
void SoundPlayerWidgetAdvancedView::play_state_changed(Player::PlayState state)
{
sync_previous_next_actions();
diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h
index eb00456f5b..51e335f1a3 100644
--- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h
+++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h
@@ -16,6 +16,7 @@
#include <LibGUI/Slider.h>
#include <LibGUI/Splitter.h>
#include <LibGUI/Widget.h>
+#include <LibImageDecoderClient/Client.h>
class SoundPlayerWidgetAdvancedView final : public GUI::Widget
, public Player {
@@ -24,6 +25,7 @@ class SoundPlayerWidgetAdvancedView final : public GUI::Widget
public:
void set_nonlinear_volume_slider(bool nonlinear);
void set_playlist_visible(bool visible);
+ RefPtr<Gfx::Bitmap> get_image_from_music_file();
template<typename T, typename... Args>
void set_visualization(Args... args)
@@ -53,13 +55,14 @@ protected:
void keydown_event(GUI::KeyEvent&) override;
private:
- SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ConnectionToServer&);
+ SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ConnectionToServer&, ImageDecoderClient::Client&);
void sync_previous_next_actions();
void drag_enter_event(GUI::DragEvent& event) override;
void drop_event(GUI::DropEvent& event) override;
GUI::Window& m_window;
+ ImageDecoderClient::Client& m_image_decoder_client;
RefPtr<GUI::HorizontalSplitter> m_splitter;
RefPtr<GUI::Widget> m_player_view;
diff --git a/Userland/Applications/SoundPlayer/main.cpp b/Userland/Applications/SoundPlayer/main.cpp
index 47200616a8..f717d1b5df 100644
--- a/Userland/Applications/SoundPlayer/main.cpp
+++ b/Userland/Applications/SoundPlayer/main.cpp
@@ -1,6 +1,6 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2021, the SerenityOS developers.
+ * Copyright (c) 2021-2023, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -48,7 +48,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
window->set_icon(app_icon.bitmap_for_size(16));
// start in advanced view by default
- Player* player = TRY(window->set_main_widget<SoundPlayerWidgetAdvancedView>(window, audio_client));
+ Player* player = TRY(window->set_main_widget<SoundPlayerWidgetAdvancedView>(window, audio_client, decoder_client));
if (!file_path.is_empty()) {
player->play_file_path(file_path);
@@ -134,23 +134,10 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
visualization_actions.add_action(samples);
auto album_cover_visualization = GUI::Action::create_checkable("&Album Cover", [&](auto&) {
- auto get_image_from_music_file = [&player, &decoder_client]() -> RefPtr<Gfx::Bitmap> {
- auto const& pictures = player->pictures();
-
- if (pictures.is_empty())
- return {};
-
- // FIXME: We randomly select the first picture available for the track,
- // We might want to hardcode or let the user set a preference.
- auto decoded_image_or_error = decoder_client->decode_image(pictures[0].data);
- if (!decoded_image_or_error.has_value())
- return {};
-
- auto const decoded_image = decoded_image_or_error.release_value();
- return decoded_image.frames[0].bitmap;
- };
-
- static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<AlbumCoverVisualizationWidget>(get_image_from_music_file);
+ auto* view = static_cast<SoundPlayerWidgetAdvancedView*>(player);
+ view->set_visualization<AlbumCoverVisualizationWidget>([&view]() {
+ return view->get_image_from_music_file();
+ });
});
TRY(visualization_menu->try_add_action(album_cover_visualization));
visualization_actions.add_action(album_cover_visualization);