From ec75b9e317baf249d67295300bc5308b7c33f4ac Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Tue, 31 Mar 2020 17:07:38 +0200 Subject: Fix GStreamer input, rework ICY-Text write --- src/utils.h | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) (limited to 'src/utils.h') diff --git a/src/utils.h b/src/utils.h index ca77a53..2f6b639 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,8 +1,9 @@ #pragma once -#include -#include -#include +#include +#include +#include +#include #define NUMOF(l) (sizeof(l) / sizeof(*l)) @@ -15,3 +16,41 @@ const char* level(int channel, int peak); size_t strlen_utf8(const char *s); +struct ICY_TEXT_t { + std::string artist; + std::string title; + std::string now_playing; + + operator bool() const { + return not (artist.empty() and title.empty() and now_playing.empty()); + } + + bool operator==(const ICY_TEXT_t& other) const { + return + artist == other.artist and + title == other.title and + now_playing == other.now_playing; + } + bool operator!=(const ICY_TEXT_t& other) const { + return !(*this == other); + } + void useArtistTitle(const std::string& artist, const std::string& title) { + this->artist = artist; + this->title = title; + now_playing = ""; + } + void useNowPlaying(const std::string& now_playing) { + artist = ""; + title = ""; + this->now_playing = now_playing; + } +}; + +/*! Write the corresponding text to a file readable by ODR-PadEnc, with optional + * DL+ information. The text is passed as a copy because we actually use the + * m_nowplaying variable which is also accessed in another thread, so better + * make a copy. + * + * \return false on failure + */ +bool write_icy_to_file(const ICY_TEXT_t text, const std::string& filename, bool dl_plus); -- cgit v1.2.3