From 2e1c017bce31757b19903d26cb5fba934778ccee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?N=C3=ADcolas=20F=2E=20R=2E=20A=2E=20Prado?= Date: Sun, 27 Feb 2022 20:18:28 -0500 Subject: [PATCH] SoundPlayer: Add start_new_file() to VisualizationWidget's API This adds a new start_new_file() function to VisualizationWidget which is called when the player starts a new file, passing the filename of the file. This allows VisualizationWidget subclasses to do any setup needed when a new file is started. --- .../Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp | 1 + .../Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h | 2 ++ Userland/Applications/SoundPlayer/VisualizationWidget.h | 1 + 3 files changed, 4 insertions(+) diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp index ca3e27b059..0add1963f4 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.cpp @@ -206,6 +206,7 @@ void SoundPlayerWidgetAdvancedView::time_elapsed(int seconds) void SoundPlayerWidgetAdvancedView::file_name_changed(StringView name) { + m_visualization->start_new_file(name); m_window.set_title(String::formatted("{} - Sound Player", name)); } diff --git a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h index c82ea44943..628d4a2f72 100644 --- a/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h +++ b/Userland/Applications/SoundPlayer/SoundPlayerWidgetAdvancedView.h @@ -32,6 +32,8 @@ public: auto new_visualization = T::construct(); m_player_view->insert_child_before(new_visualization, *static_cast(m_playback_progress_slider.ptr())); m_visualization = new_visualization; + if (!loaded_filename().is_empty()) + m_visualization->start_new_file(loaded_filename()); } virtual void play_state_changed(PlayState) override; diff --git a/Userland/Applications/SoundPlayer/VisualizationWidget.h b/Userland/Applications/SoundPlayer/VisualizationWidget.h index 03db2e6e46..da28b02a77 100644 --- a/Userland/Applications/SoundPlayer/VisualizationWidget.h +++ b/Userland/Applications/SoundPlayer/VisualizationWidget.h @@ -15,6 +15,7 @@ class VisualizationWidget : public GUI::Frame { public: virtual void set_buffer(RefPtr buffer) = 0; virtual void set_samplerate(int) { } + virtual void start_new_file(StringView) { } protected: VisualizationWidget() = default;