summaryrefslogtreecommitdiff
path: root/Userland/Applications/SoundPlayer
diff options
context:
space:
mode:
Diffstat (limited to 'Userland/Applications/SoundPlayer')
-rw-r--r--Userland/Applications/SoundPlayer/CMakeLists.txt2
-rw-r--r--Userland/Applications/SoundPlayer/main.cpp74
2 files changed, 36 insertions, 40 deletions
diff --git a/Userland/Applications/SoundPlayer/CMakeLists.txt b/Userland/Applications/SoundPlayer/CMakeLists.txt
index 26f5e31c1f..e2d0e6f0bb 100644
--- a/Userland/Applications/SoundPlayer/CMakeLists.txt
+++ b/Userland/Applications/SoundPlayer/CMakeLists.txt
@@ -19,4 +19,4 @@ set(SOURCES
)
serenity_app(SoundPlayer ICON app-sound-player)
-target_link_libraries(SoundPlayer LibAudio LibDSP LibGUI)
+target_link_libraries(SoundPlayer LibAudio LibDSP LibGUI LibMain)
diff --git a/Userland/Applications/SoundPlayer/main.cpp b/Userland/Applications/SoundPlayer/main.cpp
index 9d9e68e1a9..3b0c6b17b1 100644
--- a/Userland/Applications/SoundPlayer/main.cpp
+++ b/Userland/Applications/SoundPlayer/main.cpp
@@ -11,6 +11,7 @@
#include "SampleWidget.h"
#include "SoundPlayerWidgetAdvancedView.h"
#include <LibAudio/ClientConnection.h>
+#include <LibCore/System.h>
#include <LibGUI/Action.h>
#include <LibGUI/ActionGroup.h>
#include <LibGUI/Application.h>
@@ -19,84 +20,79 @@
#include <LibGUI/Menubar.h>
#include <LibGUI/Window.h>
#include <LibGfx/CharacterBitmap.h>
+#include <LibMain/Main.h>
#include <stdio.h>
-int main(int argc, char** argv)
+ErrorOr<int> serenity_main(Main::Arguments arguments)
{
- if (pledge("stdio recvfd sendfd rpath thread unix", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio recvfd sendfd rpath thread unix"));
- auto app = GUI::Application::construct(argc, argv);
- auto audio_client = Audio::ClientConnection::construct();
+ auto app = TRY(GUI::Application::try_create(arguments));
+ auto audio_client = TRY(Audio::ClientConnection::try_create());
- if (pledge("stdio recvfd sendfd rpath thread", nullptr) < 0) {
- perror("pledge");
- return 1;
- }
+ TRY(Core::System::pledge("stdio recvfd sendfd rpath thread"));
auto app_icon = GUI::Icon::default_icon("app-sound-player");
- auto window = GUI::Window::construct();
+ auto window = TRY(GUI::Window::try_create());
window->set_title("Sound Player");
window->set_icon(app_icon.bitmap_for_size(16));
- String path = argv[1];
// start in advanced view by default
- Player* player = &window->set_main_widget<SoundPlayerWidgetAdvancedView>(window, audio_client);
- if (argc > 1) {
+ Player* player = TRY(window->try_set_main_widget<SoundPlayerWidgetAdvancedView>(window, audio_client));
+ if (arguments.argc > 1) {
+ StringView path = arguments.strings[1];
player->play_file_path(path);
}
- auto& file_menu = window->add_menu("&File");
- file_menu.add_action(GUI::CommonActions::make_open_action([&](auto&) {
+ auto file_menu = TRY(window->try_add_menu("&File"));
+ TRY(file_menu->try_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->play_file_path(path.value());
}
- }));
+ })));
- file_menu.add_separator();
- file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) {
+ TRY(file_menu->try_add_separator());
+ TRY(file_menu->try_add_action(GUI::CommonActions::make_quit_action([&](auto&) {
app->quit();
- }));
+ })));
- auto& playback_menu = window->add_menu("&Playback");
+ auto playback_menu = TRY(window->try_add_menu("&Playback"));
GUI::ActionGroup loop_actions;
loop_actions.set_exclusive(true);
- auto loop_none = GUI::Action::create_checkable("&No Loop", [&](auto&) {
+ auto loop_none = TRY(GUI::Action::try_create("&No Loop", [&](auto&) {
player->set_loop_mode(Player::LoopMode::None);
- });
+ }));
loop_none->set_checked(true);
loop_actions.add_action(loop_none);
- playback_menu.add_action(loop_none);
+ TRY(playback_menu->try_add_action(loop_none));
auto loop_file = GUI::Action::create_checkable("Loop &File", { Mod_Ctrl, Key_F }, [&](auto&) {
player->set_loop_mode(Player::LoopMode::File);
});
loop_actions.add_action(loop_file);
- playback_menu.add_action(loop_file);
+ TRY(playback_menu->try_add_action(loop_file));
auto loop_playlist = GUI::Action::create_checkable("Loop &Playlist", { Mod_Ctrl, Key_P }, [&](auto&) {
player->set_loop_mode(Player::LoopMode::Playlist);
});
loop_actions.add_action(loop_playlist);
- 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) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_nonlinear_volume_slider(action.is_checked());
});
- playback_menu.add_separator();
- playback_menu.add_action(linear_volume_slider);
- playback_menu.add_separator();
+ TRY(playback_menu->try_add_separator());
+ TRY(playback_menu->try_add_action(linear_volume_slider));
+ TRY(playback_menu->try_add_separator());
auto playlist_toggle = GUI::Action::create_checkable("&Show Playlist", [&](auto& action) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_playlist_visible(action.is_checked());
});
- if (path.ends_with(".m3u") || path.ends_with(".m3u8"))
+ if (player->loop_mode() == Player::LoopMode::Playlist)
playlist_toggle->set_checked(true);
- playback_menu.add_action(playlist_toggle);
+ TRY(playback_menu->try_add_action(playlist_toggle));
auto shuffle_mode = GUI::Action::create_checkable("S&huffle Playlist", [&](auto& action) {
if (action.is_checked())
@@ -104,9 +100,9 @@ int main(int argc, char** argv)
else
player->set_shuffle_mode(Player::ShuffleMode::None);
});
- playback_menu.add_action(shuffle_mode);
+ TRY(playback_menu->try_add_action(shuffle_mode));
- auto& visualization_menu = window->add_menu("&Visualization");
+ auto visualization_menu = TRY(window->try_add_menu("&Visualization"));
GUI::ActionGroup visualization_actions;
visualization_actions.set_exclusive(true);
@@ -114,23 +110,23 @@ int main(int argc, char** argv)
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<BarsVisualizationWidget>();
});
bars->set_checked(true);
- visualization_menu.add_action(bars);
+ TRY(visualization_menu->try_add_action(bars));
visualization_actions.add_action(bars);
auto samples = GUI::Action::create_checkable("&Samples", [&](auto&) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<SampleWidget>();
});
- visualization_menu.add_action(samples);
+ TRY(visualization_menu->try_add_action(samples));
visualization_actions.add_action(samples);
auto none = GUI::Action::create_checkable("&None", [&](auto&) {
static_cast<SoundPlayerWidgetAdvancedView*>(player)->set_visualization<NoVisualizationWidget>();
});
- visualization_menu.add_action(none);
+ TRY(visualization_menu->try_add_action(none));
visualization_actions.add_action(none);
- auto& help_menu = window->add_menu("&Help");
- help_menu.add_action(GUI::CommonActions::make_about_action("Sound Player", app_icon, window));
+ auto help_menu = TRY(window->try_add_menu("&Help"));
+ TRY(help_menu->try_add_action(GUI::CommonActions::make_about_action("Sound Player", app_icon, window)));
window->show();
return app->exec();