Add support for streams in the track list and use the logging system for GLib

This commit is contained in:
Zachary Hall 2024-04-14 10:19:46 -07:00
parent b35ddd11cb
commit 7ff0d40da3
4 changed files with 68 additions and 1 deletions

View file

@ -102,7 +102,15 @@ macro(prefix_all)
list(APPEND ${OUT_VAR} ${PREFIX}${ARG})
endforeach()
endmacro()
prefix_all(LIBRARY_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/ backend.cpp options.cpp playback.cpp util.cpp log.cpp dbus.cpp)
prefix_all(LIBRARY_SOURCES
${CMAKE_CURRENT_SOURCE_DIR}/
backend.cpp
options.cpp
playback.cpp
util.cpp
log.cpp
dbus.cpp
)
add_library(liblooper STATIC ${LIBRARY_SOURCES})
target_include_directories(liblooper PUBLIC ${INC})
target_link_libraries(liblooper PUBLIC SDL2::SDL2 ${SDL_MIXER_X_TARGET} PkgConfig::SoundTouch SDBusCpp::sdbus-c++ libvgmstream libvgmstream_shared)

View file

@ -2,17 +2,56 @@
#include "main_window.hpp"
#include <assets/assets.h>
#include <license.hpp>
#include <log.hpp>
std::string GtkBackend::get_id() {
return "gtk";
}
std::string GtkBackend::get_name() {
return "GTK frontend";
}
void g_log_handler(const gchar *domain, GLogLevelFlags flags, const gchar *message, gpointer userdata) {
bool fatal = flags & GLogLevelFlags::G_LOG_FLAG_FATAL;
bool recursion = flags & GLogLevelFlags::G_LOG_FLAG_RECURSION;
GLogLevelFlags level = (GLogLevelFlags)(flags & GLogLevelFlags::G_LOG_LEVEL_MASK);
/*
G_LOG_LEVEL_ERROR = 1 << 2,
G_LOG_LEVEL_CRITICAL = 1 << 3,
G_LOG_LEVEL_WARNING = 1 << 4,
G_LOG_LEVEL_MESSAGE = 1 << 5,
G_LOG_LEVEL_INFO = 1 << 6,
G_LOG_LEVEL_DEBUG = 1 << 7,
*/
LogStream *stream;
switch (level) {
case GLogLevelFlags::G_LOG_LEVEL_ERROR: {
stream = new LogStream({domain}, {ERROR});
} break;
case GLogLevelFlags::G_LOG_LEVEL_CRITICAL: {
stream = new LogStream({"CRITICAL", domain}, {stderr});
} break;
case GLogLevelFlags::G_LOG_LEVEL_WARNING: {
stream = new LogStream({domain}, {WARNING});
} break;
case GLogLevelFlags::G_LOG_LEVEL_INFO: {
stream = new LogStream({domain}, {INFO});
} break;
case GLogLevelFlags::G_LOG_LEVEL_DEBUG: {
stream = new LogStream({domain}, {DEBUG});
} break;
default: {
stream = new LogStream({domain}, {stderr});
} break;
}
stream->writeln(message);
delete stream;
}
int GtkBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
int ret = UIBackend::run(realArgs, argc, argv);
if (ret != 0) {
return ret;
}
g_log_set_default_handler(g_log_handler, nullptr);
g_log_writer
Glib::set_application_name("Looper");
auto app = Gtk::Application::create("com.complecwaft.Looper.GTK", Gio::Application::Flags::NON_UNIQUE);
char *gtk_frontend_css = (char*)malloc(gtk_frontend_css_size + 1);

View file

@ -84,6 +84,14 @@ std::vector<meta_t> MprisAPI::GetTracksMetadata(const std::vector<track_id_t> &T
std::vector<meta_t> output;
if (!dbus_api->IsStopped()) {
output.push_back(Metadata());
auto streams = dbus_api->playback->get_streams();
int i = 0;
for (auto stream : streams) {
std::map<std::string, sdbus::Variant> meta;
meta["mpris:trackid"] = std::format("{}{}", streamPrefix, i);
meta["xesam:title"] = stream;
i++;
}
}
return output;
}
@ -94,6 +102,11 @@ void MprisAPI::RemoveTrack(const track_id_t &TrackId) {
return;
}
void MprisAPI::GoTo(const track_id_t &TrackId) {
if (TrackId.starts_with(streamPrefix)) {
std::string stream = TrackId.substr(streamPrefix.length());
int streamIdx = std::stoi(stream);
dbus_api->PlayStream((uint32_t)streamIdx);
}
return;
}
std::vector<track_id_t> MprisAPI::Tracks() {
@ -102,6 +115,12 @@ std::vector<track_id_t> MprisAPI::Tracks() {
return output;
}
output.push_back(playing_track_id);
auto streams = dbus_api->playback->get_streams();
int i = 0;
for (auto stream : streams) {
output.push_back(std::format("{}{}", streamPrefix, i));
i++;
}
return output;
}
bool MprisAPI::CanEditTracks() {

View file

@ -13,6 +13,7 @@ class DBusAPI;
class MprisAPI : public sdbus::AdaptorInterfaces<org::mpris::MediaPlayer2_adaptor, org::mpris::MediaPlayer2::Player_adaptor, org::mpris::MediaPlayer2::TrackList_adaptor, sdbus::Properties_adaptor> {
friend class DBusAPI;
DBusAPI *dbus_api;
const std::string streamPrefix = "/com/complecwaft/looper/Streams/";
std::string curPlayingObjectPath;
sdbus::IConnection &connection;
const std::string mainInterface = "org.mpris.MediaPlayer2";