summaryrefslogtreecommitdiff
path: root/Userland/Applications/SoundPlayer/main.cpp
diff options
context:
space:
mode:
authorCesar Torres <shortanemoia@protonmail.com>2021-03-21 13:01:33 +0100
committerAndreas Kling <kling@serenityos.org>2021-03-27 10:20:55 +0100
commit7aa52978359c721cb283bab786a36943dc5b3e20 (patch)
treef5ef8cc2ae35d0957bea660d15c96c893bf20a45 /Userland/Applications/SoundPlayer/main.cpp
parent45e928bfb294e43cd54bb75567c8ce3bf0645662 (diff)
downloadserenity-7aa52978359c721cb283bab786a36943dc5b3e20.zip
SoundPlayer: Update the SoundPlayer interface
Also fix rebase conflict
Diffstat (limited to 'Userland/Applications/SoundPlayer/main.cpp')
-rw-r--r--Userland/Applications/SoundPlayer/main.cpp99
1 files changed, 86 insertions, 13 deletions
diff --git a/Userland/Applications/SoundPlayer/main.cpp b/Userland/Applications/SoundPlayer/main.cpp
index 7a1946e6fc..a41ec64bec 100644
--- a/Userland/Applications/SoundPlayer/main.cpp
+++ b/Userland/Applications/SoundPlayer/main.cpp
@@ -24,7 +24,10 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+#include "NoVisualizationWidget.h"
+#include "Player.h"
#include "SoundPlayerWidget.h"
+#include "SoundPlayerWidgetAdvancedView.h"
#include <LibAudio/ClientConnection.h>
#include <LibGUI/Action.h>
#include <LibGUI/Application.h>
@@ -52,6 +55,8 @@ int main(int argc, char** argv)
auto audio_client = Audio::ClientConnection::construct();
audio_client->handshake();
+ PlaybackManager playback_manager(audio_client);
+
if (pledge("stdio recvfd sendfd accept rpath thread", nullptr) < 0) {
perror("pledge");
return 1;
@@ -61,31 +66,55 @@ int main(int argc, char** argv)
auto window = GUI::Window::construct();
window->set_title("Sound Player");
- window->set_resizable(false);
- window->resize(350, 140);
window->set_icon(app_icon.bitmap_for_size(16));
auto menubar = GUI::MenuBar::construct();
- auto& app_menu = menubar->add_menu("File");
- auto& player = window->set_main_widget<SoundPlayerWidget>(window, audio_client);
+ auto& app_menu = menubar->add_menu("File");
+ // start in simple view by default
+ Player* player = &window->set_main_widget<SoundPlayerWidget>(window, audio_client, playback_manager);
if (argc > 1) {
String path = argv[1];
- player.open_file(path);
- player.manager().play();
+ player->open_file(path);
+ player->playback_manager().play();
}
- auto hide_scope = GUI::Action::create_checkable("Hide scope", { Mod_Ctrl, Key_H }, [&](auto& action) {
- player.hide_scope(action.is_checked());
- });
-
app_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
Optional<String> path = GUI::FilePicker::get_open_filepath(window, "Open sound file...");
if (path.has_value()) {
- player.open_file(path.value());
+ player->open_file(path.value());
}
}));
- app_menu.add_action(move(hide_scope));
+
+ RefPtr<GUI::Action> hide_scope;
+
+ auto advanced_view_check = GUI::Action::create_checkable("Advanced view", { Mod_Ctrl, Key_A }, [&](auto& action) {
+ window->close();
+ if (action.is_checked()) {
+ player = &window->set_main_widget<SoundPlayerWidgetAdvancedView>(window, audio_client, playback_manager);
+ hide_scope->set_checkable(false);
+ } else {
+ player = &window->set_main_widget<SoundPlayerWidget>(window, audio_client, playback_manager);
+ hide_scope->set_checkable(true);
+ }
+ window->show();
+ });
+ app_menu.add_action(advanced_view_check);
+
+ hide_scope = GUI::Action::create_checkable("Hide visualization (legacy view)", { Mod_Ctrl, Key_H }, [&](auto& action) {
+ if (!advanced_view_check->is_checked())
+ static_cast<SoundPlayerWidget*>(player)->hide_scope(action.is_checked());
+ });
+
+ auto linear_volume_slider = GUI::Action::create_checkable("Nonlinear volume slider", [&](auto& action) {
+ if (advanced_view_check->is_checked())
+ static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_nonlinear_volume_slider(action.is_checked());
+ });
+ app_menu.add_action(linear_volume_slider);
+
+ auto ptr_copy = hide_scope;
+
+ app_menu.add_action(ptr_copy.release_nonnull());
app_menu.add_separator();
app_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
app->quit();
@@ -94,11 +123,55 @@ int main(int argc, char** argv)
auto& playback_menu = menubar->add_menu("Playback");
auto loop = GUI::Action::create_checkable("Loop", { Mod_Ctrl, Key_R }, [&](auto& action) {
- player.manager().loop(action.is_checked());
+ player->playback_manager().loop(action.is_checked());
});
playback_menu.add_action(move(loop));
+ auto& visualization_menu = menubar->add_menu("Visualization");
+ Vector<NonnullRefPtr<GUI::Action>> visualization_checkmarks;
+ GUI::Action* checked_vis = nullptr;
+ auto uncheck_all_but = [&](GUI::Action& one) {for (auto& a : visualization_checkmarks) if (a != &one) a->set_checked(false); };
+
+ auto bars = GUI::Action::create_checkable("Bars", [&](auto& action) {
+ uncheck_all_but(action);
+ if (checked_vis == &action) {
+ action.set_checked(true);
+ return;
+ }
+ checked_vis = &action;
+ static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<BarsVisualizationWidget>();
+ });
+ bars->set_checked(true);
+
+ visualization_menu.add_action(bars);
+ visualization_checkmarks.append(bars);
+
+ auto samples = GUI::Action::create_checkable("Samples", [&](auto& action) {
+ uncheck_all_but(action);
+ if (checked_vis == &action) {
+ action.set_checked(true);
+ return;
+ }
+ checked_vis = &action;
+ static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<SampleWidget>();
+ });
+
+ visualization_menu.add_action(samples);
+ visualization_checkmarks.append(samples);
+
+ auto none = GUI::Action::create_checkable("None", [&](auto& action) {
+ uncheck_all_but(action);
+ if (checked_vis == &action) {
+ action.set_checked(true);
+ return;
+ }
+ static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<NoVisualizationWidget>();
+ });
+
+ visualization_menu.add_action(none);
+ visualization_checkmarks.append(none);
+
auto& help_menu = menubar->add_menu("Help");
help_menu.add_action(GUI::CommonActions::make_about_action("Sound Player", app_icon, window));