Add support for streams in the track list and use the logging system for GLib
This commit is contained in:
parent
b35ddd11cb
commit
7ff0d40da3
4 changed files with 68 additions and 1 deletions
|
@ -102,7 +102,15 @@ macro(prefix_all)
|
||||||
list(APPEND ${OUT_VAR} ${PREFIX}${ARG})
|
list(APPEND ${OUT_VAR} ${PREFIX}${ARG})
|
||||||
endforeach()
|
endforeach()
|
||||||
endmacro()
|
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})
|
add_library(liblooper STATIC ${LIBRARY_SOURCES})
|
||||||
target_include_directories(liblooper PUBLIC ${INC})
|
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)
|
target_link_libraries(liblooper PUBLIC SDL2::SDL2 ${SDL_MIXER_X_TARGET} PkgConfig::SoundTouch SDBusCpp::sdbus-c++ libvgmstream libvgmstream_shared)
|
||||||
|
|
|
@ -2,17 +2,56 @@
|
||||||
#include "main_window.hpp"
|
#include "main_window.hpp"
|
||||||
#include <assets/assets.h>
|
#include <assets/assets.h>
|
||||||
#include <license.hpp>
|
#include <license.hpp>
|
||||||
|
#include <log.hpp>
|
||||||
std::string GtkBackend::get_id() {
|
std::string GtkBackend::get_id() {
|
||||||
return "gtk";
|
return "gtk";
|
||||||
}
|
}
|
||||||
std::string GtkBackend::get_name() {
|
std::string GtkBackend::get_name() {
|
||||||
return "GTK frontend";
|
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 GtkBackend::run(std::vector<std::string> realArgs, int argc, char **argv) {
|
||||||
int ret = UIBackend::run(realArgs, argc, argv);
|
int ret = UIBackend::run(realArgs, argc, argv);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
g_log_set_default_handler(g_log_handler, nullptr);
|
||||||
|
g_log_writer
|
||||||
Glib::set_application_name("Looper");
|
Glib::set_application_name("Looper");
|
||||||
auto app = Gtk::Application::create("com.complecwaft.Looper.GTK", Gio::Application::Flags::NON_UNIQUE);
|
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);
|
char *gtk_frontend_css = (char*)malloc(gtk_frontend_css_size + 1);
|
||||||
|
|
19
dbus.cpp
19
dbus.cpp
|
@ -84,6 +84,14 @@ std::vector<meta_t> MprisAPI::GetTracksMetadata(const std::vector<track_id_t> &T
|
||||||
std::vector<meta_t> output;
|
std::vector<meta_t> output;
|
||||||
if (!dbus_api->IsStopped()) {
|
if (!dbus_api->IsStopped()) {
|
||||||
output.push_back(Metadata());
|
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;
|
return output;
|
||||||
}
|
}
|
||||||
|
@ -94,6 +102,11 @@ void MprisAPI::RemoveTrack(const track_id_t &TrackId) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
void MprisAPI::GoTo(const track_id_t &TrackId) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
std::vector<track_id_t> MprisAPI::Tracks() {
|
std::vector<track_id_t> MprisAPI::Tracks() {
|
||||||
|
@ -102,6 +115,12 @@ std::vector<track_id_t> MprisAPI::Tracks() {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
output.push_back(playing_track_id);
|
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;
|
return output;
|
||||||
}
|
}
|
||||||
bool MprisAPI::CanEditTracks() {
|
bool MprisAPI::CanEditTracks() {
|
||||||
|
|
1
dbus.hpp
1
dbus.hpp
|
@ -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> {
|
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;
|
friend class DBusAPI;
|
||||||
DBusAPI *dbus_api;
|
DBusAPI *dbus_api;
|
||||||
|
const std::string streamPrefix = "/com/complecwaft/looper/Streams/";
|
||||||
std::string curPlayingObjectPath;
|
std::string curPlayingObjectPath;
|
||||||
sdbus::IConnection &connection;
|
sdbus::IConnection &connection;
|
||||||
const std::string mainInterface = "org.mpris.MediaPlayer2";
|
const std::string mainInterface = "org.mpris.MediaPlayer2";
|
||||||
|
|
Loading…
Reference in a new issue