From 007b89b205cf10c36b2b3b33a797eba5b55a287f Mon Sep 17 00:00:00 2001 From: Thilo Graf Date: Sat, 13 Nov 2021 18:56:46 +0100 Subject: [PATCH] audioplayer: outsource for title data source handling into own methods Prepared to allow external access to an audio player instance. --- src/gui/audioplayer.cpp | 68 +++++++++++++++++++++++------------------ src/gui/audioplayer.h | 3 ++ 2 files changed, 42 insertions(+), 29 deletions(-) diff --git a/src/gui/audioplayer.cpp b/src/gui/audioplayer.cpp index 252a75862..d3fce525b 100644 --- a/src/gui/audioplayer.cpp +++ b/src/gui/audioplayer.cpp @@ -27,7 +27,7 @@ #include #endif -#include +#include "gui/audioplayer.h" #include #include @@ -1873,6 +1873,42 @@ void CAudioPlayerGui::paintCover() cover_object.paint(); } } +void CAudioPlayerGui::getCurrentCaption(std::string* text) +{ + if (m_inetmode) + { + *text = m_curr_audiofile.MetaData.album; + } + else + { + char sNr[20]; + sprintf(sNr, ": %2d", m_current + 1); + *text = g_Locale->getText(LOCALE_AUDIOPLAYER_PLAYING); + *text += sNr ; + } +} + +void CAudioPlayerGui::getCurrentTitleArtist(std::string* text) +{ + GetMetaData(m_curr_audiofile); + + if (m_curr_audiofile.MetaData.title.empty()) + *text = m_curr_audiofile.MetaData.artist; + else if (m_curr_audiofile.MetaData.artist.empty()) + *text = m_curr_audiofile.MetaData.title; + else if (g_settings.audioplayer_display == TITLE_ARTIST) + { + *text = m_curr_audiofile.MetaData.title; + *text += " - "; + *text += m_curr_audiofile.MetaData.artist; + } + else //if (g_settings.audioplayer_display == ARTIST_TITLE) + { + *text = m_curr_audiofile.MetaData.artist; + *text += " - "; + *text += m_curr_audiofile.MetaData.title; + } +} void CAudioPlayerGui::paintTitleBox() { @@ -1901,17 +1937,7 @@ void CAudioPlayerGui::paintTitleBox() // first line (Track number) std::string tmp; - if (m_inetmode) - { - tmp = m_curr_audiofile.MetaData.album; - } - else - { - char sNr[20]; - sprintf(sNr, ": %2d", m_current + 1); - tmp = g_Locale->getText(LOCALE_AUDIOPLAYER_PLAYING); - tmp += sNr ; - } + getCurrentCaption(&tmp); int w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp); int xstart = (m_width - w)/2; @@ -1920,24 +1946,8 @@ void CAudioPlayerGui::paintTitleBox() g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->RenderString(m_x + xstart, m_y + OFFSET_INNER_SMALL + 1*m_item_height, m_width - OFFSET_INNER_MID - xstart, tmp, COL_MENUHEAD_TEXT); //caption "current track" // second line (Artist/Title...) - GetMetaData(m_curr_audiofile); + getCurrentTitleArtist(&tmp); - if (m_curr_audiofile.MetaData.title.empty()) - tmp = m_curr_audiofile.MetaData.artist; - else if (m_curr_audiofile.MetaData.artist.empty()) - tmp = m_curr_audiofile.MetaData.title; - else if (g_settings.audioplayer_display == TITLE_ARTIST) - { - tmp = m_curr_audiofile.MetaData.title; - tmp += " - "; - tmp += m_curr_audiofile.MetaData.artist; - } - else //if (g_settings.audioplayer_display == ARTIST_TITLE) - { - tmp = m_curr_audiofile.MetaData.artist; - tmp += " - "; - tmp += m_curr_audiofile.MetaData.title; - } w = g_Font[SNeutrinoSettings::FONT_TYPE_MENU]->getRenderWidth(tmp); xstart = (m_width - w)/2; if (xstart < OFFSET_INNER_MID + m_cover_width) diff --git a/src/gui/audioplayer.h b/src/gui/audioplayer.h index 039cf1c71..7fa04706d 100644 --- a/src/gui/audioplayer.h +++ b/src/gui/audioplayer.h @@ -168,6 +168,9 @@ class CAudioPlayerGui : public CMenuTarget void showMetaData(); bool getNumericInput(neutrino_msg_t& msg, int& val); + void getCurrentCaption(std::string* text); + void getCurrentTitleArtist(std::string* text); + void addToPlaylist(CAudiofileExt &file); void removeFromPlaylist(long pos);