From 22c184bf7548f413dc66229800f433108122662e Mon Sep 17 00:00:00 2001 From: Megamouse Date: Tue, 22 Apr 2025 22:57:31 +0200 Subject: [PATCH] cellMusic: improve logging --- Utilities/bin_patch.cpp | 2 +- rpcs3/Emu/Cell/Modules/cellMusic.cpp | 5 ++ .../Modules/cellMusicSelectionContext.cpp | 61 +++++++++++-------- rpcs3/rpcs3qt/qt_music_handler.cpp | 22 ++++++- 4 files changed, 59 insertions(+), 31 deletions(-) diff --git a/Utilities/bin_patch.cpp b/Utilities/bin_patch.cpp index 8d3fa1dee2..71106f30e1 100644 --- a/Utilities/bin_patch.cpp +++ b/Utilities/bin_patch.cpp @@ -1732,7 +1732,7 @@ void patch_engine::save_config(const patch_map& patches_map) fs::pending_file file(path); - if (!file.file || (file.file.write(out.c_str(), out.size()), !file.commit())) + if (!file.file || file.file.write(out.c_str(), out.size() < out.size() || !file.commit())) { patch_log.error("Failed to create patch config file %s (error=%s)", path, fs::g_tls_error); } diff --git a/rpcs3/Emu/Cell/Modules/cellMusic.cpp b/rpcs3/Emu/Cell/Modules/cellMusic.cpp index 157cf1906f..83937f7d16 100644 --- a/rpcs3/Emu/Cell/Modules/cellMusic.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMusic.cpp @@ -177,6 +177,11 @@ struct music_state return CELL_MUSIC_ERROR_NO_MORE_CONTENT; } + if (!fs::is_file(path)) + { + cellMusic.error("set_playback_command: File does not exist: '%s'", path); + } + switch (command) { case CELL_MUSIC_PB_CMD_FASTFORWARD: diff --git a/rpcs3/Emu/Cell/Modules/cellMusicSelectionContext.cpp b/rpcs3/Emu/Cell/Modules/cellMusicSelectionContext.cpp index 8de86380d8..e9360ebf6e 100644 --- a/rpcs3/Emu/Cell/Modules/cellMusicSelectionContext.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMusicSelectionContext.cpp @@ -77,7 +77,7 @@ std::string music_selection_context::get_yaml_path() const if (!fs::create_path(path)) { - cellMusicSelectionContext.fatal("Failed to create path: %s (%s)", path, fs::g_tls_error); + cellMusicSelectionContext.fatal("get_yaml_path: Failed to create path: %s (%s)", path, fs::g_tls_error); } return path + hash + ".yml"; @@ -101,13 +101,18 @@ void music_selection_context::set_playlist(const std::string& path) continue; } - playlist.push_back(dir_path + std::string(path + "/" + dir_entry.name).substr(vfs_dir_path.length())); + std::string track = dir_path + std::string(path + "/" + dir_entry.name).substr(vfs_dir_path.length()); + cellMusicSelectionContext.notice("set_playlist: Adding track to playlist: '%s'. (path: '%s', name: '%s')", track, path, dir_entry.name); + playlist.push_back(std::move(track)); } } else { content_type = CELL_SEARCH_CONTENTTYPE_MUSIC; - playlist.push_back(dir_path + path.substr(vfs_dir_path.length())); + + std::string track = dir_path + path.substr(vfs_dir_path.length()); + cellMusicSelectionContext.notice("set_playlist: Adding track to playlist: '%s'. (path: '%s')", track, path); + playlist.push_back(std::move(track)); } valid = true; @@ -118,7 +123,7 @@ void music_selection_context::create_playlist(const std::string& new_hash) hash = new_hash; const std::string yaml_path = get_yaml_path(); - cellMusicSelectionContext.notice("Saving music playlist file %s", yaml_path); + cellMusicSelectionContext.notice("create_playlist: Saving music playlist file %s", yaml_path); YAML::Emitter out; out << YAML::BeginMap; @@ -140,9 +145,9 @@ void music_selection_context::create_playlist(const std::string& new_hash) fs::pending_file file(yaml_path); - if (!file.file || (file.file.write(out.c_str(), out.size()), !file.commit())) + if (!file.file || file.file.write(out.c_str(), out.size() < out.size() || !file.commit())) { - cellMusicSelectionContext.error("Failed to create music playlist file %s (error=%s)", yaml_path, fs::g_tls_error); + cellMusicSelectionContext.error("create_playlist: Failed to create music playlist file '%s' (error=%s)", yaml_path, fs::g_tls_error); } } @@ -151,7 +156,7 @@ bool music_selection_context::load_playlist() playlist.clear(); const std::string path = get_yaml_path(); - cellMusicSelectionContext.notice("Loading music playlist file %s", path); + cellMusicSelectionContext.notice("load_playlist: Loading music playlist file '%s'", path); std::string content; { @@ -160,7 +165,7 @@ bool music_selection_context::load_playlist() if (!file) { - cellMusicSelectionContext.error("Failed to load music playlist file %s: %s", path, fs::g_tls_error); + cellMusicSelectionContext.error("load_playlist: Failed to load music playlist file '%s': %s", path, fs::g_tls_error); return false; } @@ -171,7 +176,7 @@ bool music_selection_context::load_playlist() if (!error.empty() || !root) { - cellMusicSelectionContext.error("Failed to load music playlist file %s:\n%s", path, error); + cellMusicSelectionContext.error("load_playlist: Failed to load music playlist file '%s':\n%s", path, error); return false; } @@ -180,54 +185,54 @@ bool music_selection_context::load_playlist() const std::string version = get_yaml_node_value(root["Version"], err); if (!err.empty()) { - cellMusicSelectionContext.error("No Version entry found. Error: '%s' (file: %s)", err, path); + cellMusicSelectionContext.error("load_playlist: No Version entry found. Error: '%s' (file: '%s')", err, path); return false; } if (version != target_version) { - cellMusicSelectionContext.error("Version '%s' does not match music playlist target '%s' (file: %s)", version, target_version, path); + cellMusicSelectionContext.error("load_playlist: Version '%s' does not match music playlist target '%s' (file: '%s')", version, target_version, path); return false; } const std::string file_type = get_yaml_node_value(root["FileType"], err); if (!err.empty()) { - cellMusicSelectionContext.error("No FileType entry found. Error: '%s' (file: %s)", err, path); + cellMusicSelectionContext.error("load_playlist: No FileType entry found. Error: '%s' (file: '%s')", err, path); return false; } if (file_type != target_file_type) { - cellMusicSelectionContext.error("FileType '%s' does not match music playlist target '%s' (file: %s)", file_type, target_file_type, path); + cellMusicSelectionContext.error("load_playlist: FileType '%s' does not match music playlist target '%s' (file: '%s')", file_type, target_file_type, path); return false; } content_type = static_cast(get_yaml_node_value(root["ContentType"], err)); if (!err.empty()) { - cellMusicSelectionContext.error("No ContentType entry found. Error: '%s' (file: %s)", err, path); + cellMusicSelectionContext.error("load_playlist: No ContentType entry found. Error: '%s' (file: '%s')", err, path); return false; } context_option = static_cast(get_yaml_node_value(root["ContextOption"], err)); if (!err.empty()) { - cellMusicSelectionContext.error("No ContextOption entry found. Error: '%s' (file: %s)", err, path); + cellMusicSelectionContext.error("load_playlist: No ContextOption entry found. Error: '%s' (file: '%s')", err, path); return false; } repeat_mode = static_cast(get_yaml_node_value(root["RepeatMode"], err)); if (!err.empty()) { - cellMusicSelectionContext.error("No RepeatMode entry found. Error: '%s' (file: %s)", err, path); + cellMusicSelectionContext.error("load_playlist: No RepeatMode entry found. Error: '%s' (file: '%s')", err, path); return false; } first_track = get_yaml_node_value(root["FirstTrack"], err); if (!err.empty()) { - cellMusicSelectionContext.error("No FirstTrack entry found. Error: '%s' (file: %s)", err, path); + cellMusicSelectionContext.error("load_playlist: No FirstTrack entry found. Error: '%s' (file: '%s')", err, path); return false; } @@ -235,15 +240,17 @@ bool music_selection_context::load_playlist() if (!track_node || track_node.Type() != YAML::NodeType::Sequence) { - cellMusicSelectionContext.error("No Tracks entry found or Tracks is not a Sequence. (file: %s)", path); + cellMusicSelectionContext.error("load_playlist: No Tracks entry found or Tracks is not a Sequence. (file: '%s')", path); return false; } for (usz i = 0; i < track_node.size(); i++) { + cellMusicSelectionContext.notice("load_playlist: Adding track to playlist: '%s'. (file: '%s')", track_node[i].Scalar(), path); playlist.push_back(track_node[i].Scalar()); } + cellMusicSelectionContext.notice("load_playlist: Loaded music playlist file '%s' (context: %s)", path, to_string()); valid = true; return true; } @@ -254,13 +261,13 @@ void music_selection_context::set_track(std::string_view track) if (playlist.empty()) { - cellMusicSelectionContext.error("No tracks to play... (requested path='%s')", track); + cellMusicSelectionContext.error("set_track: No tracks to play... (requested path='%s')", track); return; } for (usz i = 0; i < playlist.size(); i++) { - cellMusicSelectionContext.error("Comparing track '%s' vs '%s'", track, playlist[i]); + cellMusicSelectionContext.error("set_track: Comparing track '%s' vs '%s'", track, playlist[i]); if (track.ends_with(playlist[i])) { first_track = current_track = static_cast(i); @@ -268,14 +275,14 @@ void music_selection_context::set_track(std::string_view track) } } - cellMusicSelectionContext.error("Track '%s' not found...", track); + cellMusicSelectionContext.error("set_track: Track '%s' not found...", track); } u32 music_selection_context::step_track(bool next) { if (playlist.empty()) { - cellMusicSelectionContext.error("No tracks to play..."); + cellMusicSelectionContext.error("step_track: No tracks to play..."); current_track = umax; return umax; } @@ -290,7 +297,7 @@ u32 music_selection_context::step_track(bool next) if (++current_track >= playlist.size()) { // We are at the end of the playlist. - cellMusicSelectionContext.notice("No more tracks to play in playlist..."); + cellMusicSelectionContext.notice("step_track: No more tracks to play in playlist..."); current_track = umax; return umax; } @@ -301,7 +308,7 @@ u32 music_selection_context::step_track(bool next) if (current_track == 0) { // We are at the start of the playlist. - cellMusicSelectionContext.notice("No more tracks to play in playlist..."); + cellMusicSelectionContext.notice("step_track: No more tracks to play in playlist..."); current_track = umax; return umax; } @@ -339,13 +346,13 @@ u32 music_selection_context::step_track(bool next) case CELL_SEARCH_REPEATMODE_NOREPEAT1: { // We are done. We only wanted to decode a single track. - cellMusicSelectionContext.notice("No more tracks to play..."); + cellMusicSelectionContext.notice("step_track: No more tracks to play..."); current_track = umax; return umax; } default: { - fmt::throw_exception("Unknown repeat mode %d", static_cast(repeat_mode)); + fmt::throw_exception("step_track: Unknown repeat mode %d", static_cast(repeat_mode)); } } @@ -354,7 +361,7 @@ u32 music_selection_context::step_track(bool next) if (next ? current_track == 0 : current_track == (playlist.size() - 1)) { // We reached the first or last track again. Let's shuffle! - cellMusicSelectionContext.notice("Shuffling playlist..."); + cellMusicSelectionContext.notice("step_track: Shuffling playlist..."); auto engine = std::default_random_engine{}; std::shuffle(std::begin(playlist), std::end(playlist), engine); } diff --git a/rpcs3/rpcs3qt/qt_music_handler.cpp b/rpcs3/rpcs3qt/qt_music_handler.cpp index 21ce264b84..40224d05f2 100644 --- a/rpcs3/rpcs3qt/qt_music_handler.cpp +++ b/rpcs3/rpcs3qt/qt_music_handler.cpp @@ -2,6 +2,7 @@ #include "Emu/Cell/Modules/cellMusic.h" #include "Emu/System.h" #include "util/logs.hpp" +#include "Utilities/File.h" #include #include @@ -117,13 +118,18 @@ void qt_music_handler::play(const std::string& path) Emu.BlockingCallFromMainThread([&path, this]() { + if (!fs::is_file(path)) + { + music_log.error("play: File does not exist: '%s'", path); + } + if (m_path != path) { m_path = path; m_media_player->setSource(QUrl::fromLocalFile(QString::fromStdString(path))); } - music_log.notice("Playing music: %s", path); + music_log.notice("Playing music: '%s'", path); m_media_player->setPlaybackRate(1.0); m_media_player->play(); }); @@ -137,13 +143,18 @@ void qt_music_handler::fast_forward(const std::string& path) Emu.BlockingCallFromMainThread([&path, this]() { + if (!fs::is_file(path)) + { + music_log.error("fast_forward: File does not exist: '%s'", path); + } + if (m_path != path) { m_path = path; m_media_player->setSource(QUrl::fromLocalFile(QString::fromStdString(path))); } - music_log.notice("Fast-forwarding music..."); + music_log.notice("Fast-forwarding music: '%s'", path); m_media_player->setPlaybackRate(2.0); m_media_player->play(); }); @@ -157,13 +168,18 @@ void qt_music_handler::fast_reverse(const std::string& path) Emu.BlockingCallFromMainThread([&path, this]() { + if (!fs::is_file(path)) + { + music_log.error("fast_reverse: File does not exist: '%s'", path); + } + if (m_path != path) { m_path = path; m_media_player->setSource(QUrl::fromLocalFile(QString::fromStdString(path))); } - music_log.notice("Fast-reversing music..."); + music_log.notice("Fast-reversing music: '%s'", path); m_media_player->setPlaybackRate(-2.0); // NOTE: This doesn't work on the current Qt version m_media_player->play(); });