Merge branch 'libmpdclient2'
Conflicts: src/browser.cpp src/ncmpcpp.cpp
This commit is contained in:
18
configure.in
18
configure.in
@@ -55,6 +55,24 @@ dnl ================================
|
|||||||
AC_CHECK_HEADERS([dirent.h regex.h], , AC_MSG_ERROR(vital headers missing))
|
AC_CHECK_HEADERS([dirent.h regex.h], , AC_MSG_ERROR(vital headers missing))
|
||||||
AC_CHECK_HEADERS([langinfo.h], , AC_MSG_WARN(locale detection disabled))
|
AC_CHECK_HEADERS([langinfo.h], , AC_MSG_WARN(locale detection disabled))
|
||||||
|
|
||||||
|
dnl ==============================
|
||||||
|
dnl = checking for libmpdclient2 =
|
||||||
|
dnl ==============================
|
||||||
|
PKG_CHECK_MODULES([libmpdclient], [libmpdclient >= 2.0], [
|
||||||
|
AC_SUBST(libmpdclient_LIBS)
|
||||||
|
AC_SUBST(libmpdclient_CFLAGS)
|
||||||
|
CPPFLAGS="$CPPFLAGS $libmpdclient_CFLAGS"
|
||||||
|
AC_CHECK_HEADERS([mpd/client.h],
|
||||||
|
LDFLAGS="$LDFLAGS $libmpdclient_LIBS"
|
||||||
|
,
|
||||||
|
AC_MSG_ERROR([missing mpd/client.h header])
|
||||||
|
)
|
||||||
|
],
|
||||||
|
if test "$fftw" = "yes" ; then
|
||||||
|
AC_MSG_ERROR([libmpdclient2 is required!])
|
||||||
|
fi
|
||||||
|
)
|
||||||
|
|
||||||
dnl ======================
|
dnl ======================
|
||||||
dnl = checking for iconv =
|
dnl = checking for iconv =
|
||||||
dnl ======================
|
dnl ======================
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
bin_PROGRAMS = ncmpcpp
|
bin_PROGRAMS = ncmpcpp
|
||||||
ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp conv.cpp display.cpp \
|
ncmpcpp_SOURCES = browser.cpp charset.cpp clock.cpp conv.cpp display.cpp \
|
||||||
error.cpp help.cpp helpers.cpp info.cpp libmpdclient.c lyrics.cpp \
|
error.cpp help.cpp helpers.cpp info.cpp lyrics.cpp media_library.cpp menu.cpp \
|
||||||
media_library.cpp menu.cpp misc.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp \
|
misc.cpp mpdpp.cpp ncmpcpp.cpp outputs.cpp playlist.cpp playlist_editor.cpp \
|
||||||
playlist_editor.cpp scrollpad.cpp search_engine.cpp settings.cpp song.cpp status.cpp \
|
scrollpad.cpp search_engine.cpp settings.cpp song.cpp status.cpp tag_editor.cpp \
|
||||||
str_pool.c tag_editor.cpp tiny_tag_editor.cpp visualizer.cpp window.cpp
|
tiny_tag_editor.cpp visualizer.cpp window.cpp
|
||||||
|
|
||||||
# set the include path found by configure
|
# set the include path found by configure
|
||||||
INCLUDES= $(all_includes)
|
INCLUDES= $(all_includes)
|
||||||
|
|||||||
@@ -431,13 +431,12 @@ void Browser::GetLocalDirectory(ItemList &v, const std::string &directory, bool
|
|||||||
else if (hasSupportedExtension(file->d_name))
|
else if (hasSupportedExtension(file->d_name))
|
||||||
{
|
{
|
||||||
new_item.type = itSong;
|
new_item.type = itSong;
|
||||||
mpd_Song *s = mpd_newSong();
|
mpd_pair file_pair = { "file", full_path.c_str() };
|
||||||
s->file = str_pool_get(full_path.c_str());
|
new_item.song = new Song(mpd_song_begin(&file_pair));
|
||||||
# ifdef HAVE_TAGLIB_H
|
# ifdef HAVE_TAGLIB_H
|
||||||
if (!recursively)
|
if (!recursively)
|
||||||
TagEditor::ReadTags(s);
|
TagEditor::ReadTags(*new_item.song);
|
||||||
# endif // HAVE_TAGLIB_H
|
# endif // HAVE_TAGLIB_H
|
||||||
new_item.song = new Song(s);
|
|
||||||
v.push_back(new_item);
|
v.push_back(new_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,6 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
#include "str_pool.h"
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@@ -55,7 +54,7 @@ namespace
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void charset_convert(const char *from, const char *to, const char *&inbuf, size_t len = 0)
|
void charset_convert(const char *from, const char *to, const char *&inbuf, bool delete_old, size_t len = 0)
|
||||||
{
|
{
|
||||||
if (!inbuf || !from || !to)
|
if (!inbuf || !from || !to)
|
||||||
return;
|
return;
|
||||||
@@ -81,9 +80,9 @@ namespace
|
|||||||
}
|
}
|
||||||
iconv_close(cd);
|
iconv_close(cd);
|
||||||
*outbuf = 0;
|
*outbuf = 0;
|
||||||
str_pool_put(instart);
|
if (delete_old)
|
||||||
inbuf = str_pool_get(outstart);
|
delete [] instart;
|
||||||
delete [] outstart;
|
inbuf = outstart;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,10 +90,10 @@ void utf_to_locale(std::string &s)
|
|||||||
{
|
{
|
||||||
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
const char *tmp = str_pool_get(s.c_str());
|
const char *tmp = strdup(s.c_str());
|
||||||
charset_convert("utf-8", Config.system_encoding.c_str(), tmp, s.length());
|
charset_convert("utf-8", Config.system_encoding.c_str(), tmp, 1, s.length());
|
||||||
s = tmp;
|
s = tmp;
|
||||||
str_pool_put(tmp);
|
delete [] tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string utf_to_locale_cpy(const std::string &s)
|
std::string utf_to_locale_cpy(const std::string &s)
|
||||||
@@ -108,10 +107,10 @@ void locale_to_utf(std::string &s)
|
|||||||
{
|
{
|
||||||
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (s.empty() || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
const char *tmp = str_pool_get(s.c_str());
|
const char *tmp = strdup(s.c_str());
|
||||||
charset_convert(Config.system_encoding.c_str(), "utf-8", tmp, s.length());
|
charset_convert(Config.system_encoding.c_str(), "utf-8", tmp, 1, s.length());
|
||||||
s = tmp;
|
s = tmp;
|
||||||
str_pool_put(tmp);
|
delete [] tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string locale_to_utf_cpy(const std::string &s)
|
std::string locale_to_utf_cpy(const std::string &s)
|
||||||
@@ -121,18 +120,18 @@ std::string locale_to_utf_cpy(const std::string &s)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void str_pool_utf_to_locale(const char *&s)
|
void utf_to_locale(const char *&s, bool delete_old)
|
||||||
{
|
{
|
||||||
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
charset_convert("utf-8", Config.system_encoding.c_str(), s);
|
charset_convert("utf-8", Config.system_encoding.c_str(), s, delete_old);
|
||||||
}
|
}
|
||||||
|
|
||||||
void str_pool_locale_to_utf(const char *&s)
|
void locale_to_utf(const char *&s, bool delete_old)
|
||||||
{
|
{
|
||||||
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
if (!s || Config.system_encoding.empty() || !has_non_ascii_chars(s))
|
||||||
return;
|
return;
|
||||||
charset_convert(Config.system_encoding.c_str(), "utf-8", s);
|
charset_convert(Config.system_encoding.c_str(), "utf-8", s, delete_old);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // HAVE_ICONV_H
|
#endif // HAVE_ICONV_H
|
||||||
|
|||||||
@@ -35,8 +35,8 @@ void locale_to_utf(std::string &);
|
|||||||
std::string utf_to_locale_cpy(const std::string &s);
|
std::string utf_to_locale_cpy(const std::string &s);
|
||||||
std::string locale_to_utf_cpy(const std::string &s);
|
std::string locale_to_utf_cpy(const std::string &s);
|
||||||
|
|
||||||
void str_pool_utf_to_locale(const char *&);
|
void utf_to_locale(const char *&, bool);
|
||||||
void str_pool_locale_to_utf(const char *&);
|
void locale_to_utf(const char *&, bool);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
@@ -46,9 +46,6 @@ void str_pool_locale_to_utf(const char *&);
|
|||||||
#define utf_to_locale_cpy(x) (x)
|
#define utf_to_locale_cpy(x) (x)
|
||||||
#define locale_to_utf_cpy(x) (x)
|
#define locale_to_utf_cpy(x) (x)
|
||||||
|
|
||||||
#define str_pool_utf_to_locale(x);
|
|
||||||
#define str_pool_locale_to_utf(x);
|
|
||||||
|
|
||||||
#endif // HAVE_ICONV_H
|
#endif // HAVE_ICONV_H
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
62
src/conv.cpp
62
src/conv.cpp
@@ -45,32 +45,30 @@ std::string IntoStr(int l)
|
|||||||
return ss.str();
|
return ss.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string IntoStr(mpd_TagItems tag) // this is only for left column's title in media library
|
std::string IntoStr(mpd_tag_type tag) // this is only for left column's title in media library
|
||||||
{
|
{
|
||||||
switch (tag)
|
switch (tag)
|
||||||
{
|
{
|
||||||
case MPD_TAG_ITEM_ARTIST:
|
case MPD_TAG_ARTIST:
|
||||||
return "Artist";
|
return "Artist";
|
||||||
case MPD_TAG_ITEM_ALBUM:
|
case MPD_TAG_ALBUM:
|
||||||
return "Album";
|
return "Album";
|
||||||
case MPD_TAG_ITEM_TITLE:
|
case MPD_TAG_TITLE:
|
||||||
return "Title";
|
return "Title";
|
||||||
case MPD_TAG_ITEM_TRACK:
|
case MPD_TAG_TRACK:
|
||||||
return "Track";
|
return "Track";
|
||||||
case MPD_TAG_ITEM_GENRE:
|
case MPD_TAG_GENRE:
|
||||||
return "Genre";
|
return "Genre";
|
||||||
case MPD_TAG_ITEM_DATE:
|
case MPD_TAG_DATE:
|
||||||
return "Year";
|
return "Year";
|
||||||
case MPD_TAG_ITEM_COMPOSER:
|
case MPD_TAG_COMPOSER:
|
||||||
return "Composer";
|
return "Composer";
|
||||||
case MPD_TAG_ITEM_PERFORMER:
|
case MPD_TAG_PERFORMER:
|
||||||
return "Performer";
|
return "Performer";
|
||||||
case MPD_TAG_ITEM_COMMENT:
|
case MPD_TAG_COMMENT:
|
||||||
return "Comment";
|
return "Comment";
|
||||||
case MPD_TAG_ITEM_DISC:
|
case MPD_TAG_DISC:
|
||||||
return "Disc";
|
return "Disc";
|
||||||
case MPD_TAG_ITEM_FILENAME:
|
|
||||||
return "Filename";
|
|
||||||
default:
|
default:
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
@@ -126,52 +124,50 @@ NCurses::Color IntoColor(const std::string &color)
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
mpd_TagItems IntoTagItem(char c)
|
mpd_tag_type IntoTagItem(char c)
|
||||||
{
|
{
|
||||||
switch (c)
|
switch (c)
|
||||||
{
|
{
|
||||||
case 'a':
|
case 'a':
|
||||||
return MPD_TAG_ITEM_ARTIST;
|
return MPD_TAG_ARTIST;
|
||||||
case 'y':
|
case 'y':
|
||||||
return MPD_TAG_ITEM_DATE;
|
return MPD_TAG_DATE;
|
||||||
case 'g':
|
case 'g':
|
||||||
return MPD_TAG_ITEM_GENRE;
|
return MPD_TAG_GENRE;
|
||||||
case 'c':
|
case 'c':
|
||||||
return MPD_TAG_ITEM_COMPOSER;
|
return MPD_TAG_COMPOSER;
|
||||||
case 'p':
|
case 'p':
|
||||||
return MPD_TAG_ITEM_PERFORMER;
|
return MPD_TAG_PERFORMER;
|
||||||
default:
|
default:
|
||||||
return MPD_TAG_ITEM_ARTIST;
|
return MPD_TAG_ARTIST;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_TAGLIB_H
|
#ifdef HAVE_TAGLIB_H
|
||||||
MPD::Song::SetFunction IntoSetFunction(mpd_TagItems tag)
|
MPD::Song::SetFunction IntoSetFunction(mpd_tag_type tag)
|
||||||
{
|
{
|
||||||
switch (tag)
|
switch (tag)
|
||||||
{
|
{
|
||||||
case MPD_TAG_ITEM_ARTIST:
|
case MPD_TAG_ARTIST:
|
||||||
return &MPD::Song::SetArtist;
|
return &MPD::Song::SetArtist;
|
||||||
case MPD_TAG_ITEM_ALBUM:
|
case MPD_TAG_ALBUM:
|
||||||
return &MPD::Song::SetAlbum;
|
return &MPD::Song::SetAlbum;
|
||||||
case MPD_TAG_ITEM_TITLE:
|
case MPD_TAG_TITLE:
|
||||||
return &MPD::Song::SetTitle;
|
return &MPD::Song::SetTitle;
|
||||||
case MPD_TAG_ITEM_TRACK:
|
case MPD_TAG_TRACK:
|
||||||
return &MPD::Song::SetTrack;
|
return &MPD::Song::SetTrack;
|
||||||
case MPD_TAG_ITEM_GENRE:
|
case MPD_TAG_GENRE:
|
||||||
return &MPD::Song::SetGenre;
|
return &MPD::Song::SetGenre;
|
||||||
case MPD_TAG_ITEM_DATE:
|
case MPD_TAG_DATE:
|
||||||
return &MPD::Song::SetDate;
|
return &MPD::Song::SetDate;
|
||||||
case MPD_TAG_ITEM_COMPOSER:
|
case MPD_TAG_COMPOSER:
|
||||||
return &MPD::Song::SetComposer;
|
return &MPD::Song::SetComposer;
|
||||||
case MPD_TAG_ITEM_PERFORMER:
|
case MPD_TAG_PERFORMER:
|
||||||
return &MPD::Song::SetPerformer;
|
return &MPD::Song::SetPerformer;
|
||||||
case MPD_TAG_ITEM_COMMENT:
|
case MPD_TAG_COMMENT:
|
||||||
return &MPD::Song::SetComment;
|
return &MPD::Song::SetComment;
|
||||||
case MPD_TAG_ITEM_DISC:
|
case MPD_TAG_DISC:
|
||||||
return &MPD::Song::SetDisc;
|
return &MPD::Song::SetDisc;
|
||||||
case MPD_TAG_ITEM_FILENAME:
|
|
||||||
return &MPD::Song::SetNewName;
|
|
||||||
default:
|
default:
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,16 +38,16 @@ long StrToLong(const std::string &);
|
|||||||
|
|
||||||
std::string IntoStr(int);
|
std::string IntoStr(int);
|
||||||
|
|
||||||
std::string IntoStr(mpd_TagItems);
|
std::string IntoStr(mpd_tag_type);
|
||||||
|
|
||||||
std::string IntoStr(NCurses::Color);
|
std::string IntoStr(NCurses::Color);
|
||||||
|
|
||||||
NCurses::Color IntoColor(const std::string &);
|
NCurses::Color IntoColor(const std::string &);
|
||||||
|
|
||||||
mpd_TagItems IntoTagItem(char);
|
mpd_tag_type IntoTagItem(char);
|
||||||
|
|
||||||
#ifdef HAVE_TAGLIB_H
|
#ifdef HAVE_TAGLIB_H
|
||||||
MPD::Song::SetFunction IntoSetFunction(mpd_TagItems);
|
MPD::Song::SetFunction IntoSetFunction(mpd_tag_type);
|
||||||
#endif // HAVE_TAGLIB_H
|
#endif // HAVE_TAGLIB_H
|
||||||
|
|
||||||
void EscapeUnallowedChars(std::string &);
|
void EscapeUnallowedChars(std::string &);
|
||||||
|
|||||||
@@ -169,24 +169,12 @@ void ParseArgv(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
else if (!strcmp(argv[i], "pause"))
|
else if (!strcmp(argv[i], "pause"))
|
||||||
{
|
{
|
||||||
Mpd.Execute("pause \"1\"\n");
|
Mpd.Pause(1);
|
||||||
quit = 1;
|
quit = 1;
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[i], "toggle"))
|
else if (!strcmp(argv[i], "toggle"))
|
||||||
{
|
{
|
||||||
Mpd.UpdateStatus();
|
Mpd.Toggle();
|
||||||
switch (Mpd.GetState())
|
|
||||||
{
|
|
||||||
case psPause:
|
|
||||||
case psPlay:
|
|
||||||
Mpd.Pause();
|
|
||||||
break;
|
|
||||||
case psStop:
|
|
||||||
Mpd.Play();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
quit = 1;
|
quit = 1;
|
||||||
}
|
}
|
||||||
else if (!strcmp(argv[i], "stop"))
|
else if (!strcmp(argv[i], "stop"))
|
||||||
|
|||||||
2102
src/libmpdclient.c
2102
src/libmpdclient.c
File diff suppressed because it is too large
Load Diff
@@ -1,689 +0,0 @@
|
|||||||
/* libmpdclient
|
|
||||||
(c)2003-2006 by Warren Dukes (warren.dukes@gmail.com)
|
|
||||||
This project's homepage is: http://www.musicpd.org
|
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions
|
|
||||||
are met:
|
|
||||||
|
|
||||||
- Redistributions of source code must retain the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
- Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
- Neither the name of the Music Player Daemon nor the names of its
|
|
||||||
contributors may be used to endorse or promote products derived from
|
|
||||||
this software without specific prior written permission.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
||||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
||||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
||||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
|
||||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
||||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
||||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
|
||||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
||||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
||||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
||||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef LIBMPDCLIENT_H
|
|
||||||
#define LIBMPDCLIENT_H
|
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
# define __W32API_USE_DLLIMPORT__ 1
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "str_pool.h"
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#define MPD_BUFFER_MAX_LENGTH 50000
|
|
||||||
#define MPD_ERRORSTR_MAX_LENGTH 1000
|
|
||||||
#define MPD_WELCOME_MESSAGE "OK MPD "
|
|
||||||
|
|
||||||
#define MPD_ERROR_TIMEOUT 10 /* timeout trying to talk to mpd */
|
|
||||||
#define MPD_ERROR_SYSTEM 11 /* system error */
|
|
||||||
#define MPD_ERROR_UNKHOST 12 /* unknown host */
|
|
||||||
#define MPD_ERROR_CONNPORT 13 /* problems connecting to port on host */
|
|
||||||
#define MPD_ERROR_NOTMPD 14 /* mpd not running on port at host */
|
|
||||||
#define MPD_ERROR_NORESPONSE 15 /* no response on attempting to connect */
|
|
||||||
#define MPD_ERROR_SENDING 16 /* error sending command */
|
|
||||||
#define MPD_ERROR_CONNCLOSED 17 /* connection closed by mpd */
|
|
||||||
#define MPD_ERROR_ACK 18 /* ACK returned! */
|
|
||||||
#define MPD_ERROR_BUFFEROVERRUN 19 /* Buffer was overrun! */
|
|
||||||
|
|
||||||
#define MPD_ACK_ERROR_UNK -1
|
|
||||||
#define MPD_ERROR_AT_UNK -1
|
|
||||||
|
|
||||||
#define MPD_ACK_ERROR_NOT_LIST 1
|
|
||||||
#define MPD_ACK_ERROR_ARG 2
|
|
||||||
#define MPD_ACK_ERROR_PASSWORD 3
|
|
||||||
#define MPD_ACK_ERROR_PERMISSION 4
|
|
||||||
#define MPD_ACK_ERROR_UNKNOWN_CMD 5
|
|
||||||
|
|
||||||
#define MPD_ACK_ERROR_NO_EXIST 50
|
|
||||||
#define MPD_ACK_ERROR_PLAYLIST_MAX 51
|
|
||||||
#define MPD_ACK_ERROR_SYSTEM 52
|
|
||||||
#define MPD_ACK_ERROR_PLAYLIST_LOAD 53
|
|
||||||
#define MPD_ACK_ERROR_UPDATE_ALREADY 54
|
|
||||||
#define MPD_ACK_ERROR_PLAYER_SYNC 55
|
|
||||||
#define MPD_ACK_ERROR_EXIST 56
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef enum mpd_TagItems
|
|
||||||
{
|
|
||||||
MPD_TAG_ITEM_ARTIST,
|
|
||||||
MPD_TAG_ITEM_ALBUM,
|
|
||||||
MPD_TAG_ITEM_TITLE,
|
|
||||||
MPD_TAG_ITEM_TRACK,
|
|
||||||
MPD_TAG_ITEM_NAME,
|
|
||||||
MPD_TAG_ITEM_GENRE,
|
|
||||||
MPD_TAG_ITEM_DATE,
|
|
||||||
MPD_TAG_ITEM_COMPOSER,
|
|
||||||
MPD_TAG_ITEM_PERFORMER,
|
|
||||||
MPD_TAG_ITEM_COMMENT,
|
|
||||||
MPD_TAG_ITEM_DISC,
|
|
||||||
MPD_TAG_ITEM_FILENAME,
|
|
||||||
MPD_TAG_ITEM_ANY,
|
|
||||||
MPD_TAG_NUM_OF_ITEM_TYPES
|
|
||||||
} mpd_TagItems;
|
|
||||||
|
|
||||||
extern char * mpdTagItemKeys[MPD_TAG_NUM_OF_ITEM_TYPES];
|
|
||||||
|
|
||||||
/* internal stuff don't touch this struct */
|
|
||||||
typedef struct _mpd_ReturnElement {
|
|
||||||
const char * name;
|
|
||||||
const char * value;
|
|
||||||
} mpd_ReturnElement;
|
|
||||||
|
|
||||||
/* mpd_Connection
|
|
||||||
* holds info about connection to mpd
|
|
||||||
* use error, and errorStr to detect errors
|
|
||||||
*/
|
|
||||||
typedef struct _mpd_Connection {
|
|
||||||
/* use this to check the version of mpd */
|
|
||||||
int version[3];
|
|
||||||
/* IMPORTANT, you want to get the error messages from here */
|
|
||||||
char errorStr[MPD_ERRORSTR_MAX_LENGTH+1];
|
|
||||||
int errorCode;
|
|
||||||
int errorAt;
|
|
||||||
/* this will be set to MPD_ERROR_* if there is an error, 0 if not */
|
|
||||||
int error;
|
|
||||||
/* DON'T TOUCH any of the rest of this stuff */
|
|
||||||
int sock;
|
|
||||||
char buffer[MPD_BUFFER_MAX_LENGTH+1];
|
|
||||||
int buflen;
|
|
||||||
int bufstart;
|
|
||||||
int doneProcessing;
|
|
||||||
int listOks;
|
|
||||||
int doneListOk;
|
|
||||||
int commandList;
|
|
||||||
mpd_ReturnElement * returnElement;
|
|
||||||
struct timeval timeout;
|
|
||||||
char *request;
|
|
||||||
} mpd_Connection;
|
|
||||||
|
|
||||||
/* mpd_newConnection
|
|
||||||
* use this to open a new connection
|
|
||||||
* you should use mpd_closeConnection, when your done with the connection,
|
|
||||||
* even if an error has occurred
|
|
||||||
* _timeout_ is the connection timeout period in seconds
|
|
||||||
*/
|
|
||||||
mpd_Connection * mpd_newConnection(const char * host, int port, float timeout);
|
|
||||||
|
|
||||||
void mpd_setConnectionTimeout(mpd_Connection * connection, float timeout);
|
|
||||||
|
|
||||||
/* mpd_closeConnection
|
|
||||||
* use this to close a connection and free'ing subsequent memory
|
|
||||||
*/
|
|
||||||
void mpd_closeConnection(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* mpd_clearError
|
|
||||||
* clears error
|
|
||||||
*/
|
|
||||||
void mpd_clearError(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* added by unK, make this extern as I want to use it */
|
|
||||||
void mpd_executeCommand(mpd_Connection * connection, const char * command);
|
|
||||||
|
|
||||||
/* STATUS STUFF */
|
|
||||||
|
|
||||||
/* use these with status.state to determine what state the player is in */
|
|
||||||
#define MPD_STATUS_STATE_UNKNOWN 0
|
|
||||||
#define MPD_STATUS_STATE_STOP 1
|
|
||||||
#define MPD_STATUS_STATE_PLAY 2
|
|
||||||
#define MPD_STATUS_STATE_PAUSE 3
|
|
||||||
|
|
||||||
/* us this with status.volume to determine if mpd has volume support */
|
|
||||||
#define MPD_STATUS_NO_VOLUME -1
|
|
||||||
|
|
||||||
/* mpd_Status
|
|
||||||
* holds info return from status command
|
|
||||||
*/
|
|
||||||
typedef struct mpd_Status {
|
|
||||||
/* 0-100, or MPD_STATUS_NO_VOLUME when there is no volume support */
|
|
||||||
int volume;
|
|
||||||
/* 1 if repeat is on, 0 otherwise */
|
|
||||||
int repeat;
|
|
||||||
/* 1 if random is on, 0 otherwise */
|
|
||||||
int random;
|
|
||||||
/* 1 if single mode is on, 0 otherwise */
|
|
||||||
int single;
|
|
||||||
/* 1 if consume mode is on, 0 otherwise */
|
|
||||||
int consume;
|
|
||||||
/* playlist length */
|
|
||||||
int playlistLength;
|
|
||||||
/* playlist, use this to determine when the playlist has changed */
|
|
||||||
long long playlist;
|
|
||||||
/* use with MPD_STATUS_STATE_* to determine state of player */
|
|
||||||
int state;
|
|
||||||
/* crossfade setting in seconds */
|
|
||||||
int crossfade;
|
|
||||||
/* if a song is currently selected (always the case when state is
|
|
||||||
* PLAY or PAUSE), this is the position of the currently
|
|
||||||
* playing song in the playlist, beginning with 0
|
|
||||||
*/
|
|
||||||
int song;
|
|
||||||
/* Song ID of the currently selected song */
|
|
||||||
int songid;
|
|
||||||
/* time in seconds that have elapsed in the currently playing/paused
|
|
||||||
* song
|
|
||||||
*/
|
|
||||||
int elapsedTime;
|
|
||||||
/* length in seconds of the currently playing/paused song */
|
|
||||||
int totalTime;
|
|
||||||
/* current bit rate in kbs */
|
|
||||||
int bitRate;
|
|
||||||
/* audio sample rate */
|
|
||||||
unsigned int sampleRate;
|
|
||||||
/* audio bits */
|
|
||||||
int bits;
|
|
||||||
/* audio channels */
|
|
||||||
int channels;
|
|
||||||
/* 1 if mpd is updating, 0 otherwise */
|
|
||||||
int updatingDb;
|
|
||||||
/* error */
|
|
||||||
char * error;
|
|
||||||
} mpd_Status;
|
|
||||||
|
|
||||||
void mpd_sendStatusCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* mpd_getStatus
|
|
||||||
* returns status info, be sure to free it with mpd_freeStatus()
|
|
||||||
* call this after mpd_sendStatusCommand()
|
|
||||||
*/
|
|
||||||
mpd_Status * mpd_getStatus(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* mpd_freeStatus
|
|
||||||
* free's status info malloc'd and returned by mpd_getStatus
|
|
||||||
*/
|
|
||||||
void mpd_freeStatus(mpd_Status * status);
|
|
||||||
|
|
||||||
typedef struct _mpd_Stats {
|
|
||||||
int numberOfArtists;
|
|
||||||
int numberOfAlbums;
|
|
||||||
int numberOfSongs;
|
|
||||||
unsigned long uptime;
|
|
||||||
unsigned long dbUpdateTime;
|
|
||||||
unsigned long playTime;
|
|
||||||
unsigned long dbPlayTime;
|
|
||||||
} mpd_Stats;
|
|
||||||
|
|
||||||
typedef struct _mpd_SearchStats {
|
|
||||||
int numberOfSongs;
|
|
||||||
unsigned long playTime;
|
|
||||||
} mpd_SearchStats;
|
|
||||||
|
|
||||||
void mpd_sendStatsCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
mpd_Stats * mpd_getStats(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_freeStats(mpd_Stats * stats);
|
|
||||||
|
|
||||||
mpd_SearchStats * mpd_getSearchStats(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_freeSearchStats(mpd_SearchStats * stats);
|
|
||||||
|
|
||||||
/* SONG STUFF */
|
|
||||||
|
|
||||||
#define MPD_SONG_NO_TIME -1
|
|
||||||
#define MPD_SONG_NO_NUM -1
|
|
||||||
#define MPD_SONG_NO_ID -1
|
|
||||||
|
|
||||||
/* mpd_Song
|
|
||||||
* for storing song info returned by mpd
|
|
||||||
*/
|
|
||||||
typedef struct _mpd_Song {
|
|
||||||
/* filename of song */
|
|
||||||
const char * file;
|
|
||||||
/* artist, maybe NULL if there is no tag */
|
|
||||||
const char * artist;
|
|
||||||
/* title, maybe NULL if there is no tag */
|
|
||||||
const char * title;
|
|
||||||
/* album, maybe NULL if there is no tag */
|
|
||||||
const char * album;
|
|
||||||
/* track, maybe NULL if there is no tag */
|
|
||||||
const char * track;
|
|
||||||
/* name, maybe NULL if there is no tag; it's the name of the current
|
|
||||||
* song, f.e. the icyName of the stream */
|
|
||||||
const char * name;
|
|
||||||
/* date */
|
|
||||||
const char *date;
|
|
||||||
|
|
||||||
/* added by qball */
|
|
||||||
/* Genre */
|
|
||||||
const char *genre;
|
|
||||||
/* Composer */
|
|
||||||
const char *composer;
|
|
||||||
/* Performer */
|
|
||||||
const char *performer;
|
|
||||||
/* Disc */
|
|
||||||
const char *disc;
|
|
||||||
/* Comment */
|
|
||||||
const char *comment;
|
|
||||||
|
|
||||||
/* length of song in seconds, check that it is not MPD_SONG_NO_TIME */
|
|
||||||
int time;
|
|
||||||
/* if plchanges/playlistinfo/playlistid used, is the position of the
|
|
||||||
* song in the playlist */
|
|
||||||
int pos;
|
|
||||||
/* song id for a song in the playlist */
|
|
||||||
int id;
|
|
||||||
} mpd_Song;
|
|
||||||
|
|
||||||
/* mpd_newSong
|
|
||||||
* use to allocate memory for a new mpd_Song
|
|
||||||
* file, artist, etc all initialized to NULL
|
|
||||||
* if your going to assign values to file, artist, etc
|
|
||||||
* be sure to malloc or strdup the memory
|
|
||||||
* use mpd_freeSong to free the memory for the mpd_Song, it will also
|
|
||||||
* free memory for file, artist, etc, so don't do it yourself
|
|
||||||
*/
|
|
||||||
mpd_Song * mpd_newSong(void);
|
|
||||||
|
|
||||||
/* mpd_freeSong
|
|
||||||
* use to free memory allocated by mpd_newSong
|
|
||||||
* also it will free memory pointed to by file, artist, etc, so be careful
|
|
||||||
*/
|
|
||||||
void mpd_freeSong(mpd_Song * song);
|
|
||||||
|
|
||||||
/* mpd_songDup
|
|
||||||
* works like strDup, but for a mpd_Song
|
|
||||||
*/
|
|
||||||
mpd_Song * mpd_songDup(mpd_Song * song);
|
|
||||||
|
|
||||||
/* DIRECTORY STUFF */
|
|
||||||
|
|
||||||
/* mpd_Directory
|
|
||||||
* used to store info fro directory (right now that just the path)
|
|
||||||
*/
|
|
||||||
typedef struct _mpd_Directory {
|
|
||||||
const char * path;
|
|
||||||
} mpd_Directory;
|
|
||||||
|
|
||||||
/* mpd_newDirectory
|
|
||||||
* allocates memory for a new directory
|
|
||||||
* use mpd_freeDirectory to free this memory
|
|
||||||
*/
|
|
||||||
mpd_Directory * mpd_newDirectory(void);
|
|
||||||
|
|
||||||
/* mpd_freeDirectory
|
|
||||||
* used to free memory allocated with mpd_newDirectory, and it frees
|
|
||||||
* path of mpd_Directory, so be careful
|
|
||||||
*/
|
|
||||||
void mpd_freeDirectory(mpd_Directory * directory);
|
|
||||||
|
|
||||||
/* mpd_directoryDup
|
|
||||||
* works like strdup, but for mpd_Directory
|
|
||||||
*/
|
|
||||||
mpd_Directory * mpd_directoryDup(mpd_Directory * directory);
|
|
||||||
|
|
||||||
/* PLAYLISTFILE STUFF */
|
|
||||||
|
|
||||||
/* mpd_PlaylistFile
|
|
||||||
* stores info about playlist file returned by lsinfo
|
|
||||||
*/
|
|
||||||
typedef struct _mpd_PlaylistFile {
|
|
||||||
const char * path;
|
|
||||||
} mpd_PlaylistFile;
|
|
||||||
|
|
||||||
/* mpd_newPlaylistFile
|
|
||||||
* allocates memory for new mpd_PlaylistFile, path is set to NULL
|
|
||||||
* free this memory with mpd_freePlaylistFile
|
|
||||||
*/
|
|
||||||
mpd_PlaylistFile * mpd_newPlaylistFile(void);
|
|
||||||
|
|
||||||
/* mpd_freePlaylist
|
|
||||||
* free memory allocated for freePlaylistFile, will also free
|
|
||||||
* path, so be careful
|
|
||||||
*/
|
|
||||||
void mpd_freePlaylistFile(mpd_PlaylistFile * playlist);
|
|
||||||
|
|
||||||
/* mpd_playlistFileDup
|
|
||||||
* works like strdup, but for mpd_PlaylistFile
|
|
||||||
*/
|
|
||||||
mpd_PlaylistFile * mpd_playlistFileDup(mpd_PlaylistFile * playlist);
|
|
||||||
|
|
||||||
/* INFO ENTITY STUFF */
|
|
||||||
|
|
||||||
/* the type of entity returned from one of the commands that generates info
|
|
||||||
* use in conjunction with mpd_InfoEntity.type
|
|
||||||
*/
|
|
||||||
#define MPD_INFO_ENTITY_TYPE_DIRECTORY 0
|
|
||||||
#define MPD_INFO_ENTITY_TYPE_SONG 1
|
|
||||||
#define MPD_INFO_ENTITY_TYPE_PLAYLISTFILE 2
|
|
||||||
|
|
||||||
/* mpd_InfoEntity
|
|
||||||
* stores info on stuff returned info commands
|
|
||||||
*/
|
|
||||||
typedef struct mpd_InfoEntity {
|
|
||||||
/* the type of entity, use with MPD_INFO_ENTITY_TYPE_* to determine
|
|
||||||
* what this entity is (song, directory, etc...)
|
|
||||||
*/
|
|
||||||
int type;
|
|
||||||
/* the actual data you want, mpd_Song, mpd_Directory, etc */
|
|
||||||
union {
|
|
||||||
mpd_Directory * directory;
|
|
||||||
mpd_Song * song;
|
|
||||||
mpd_PlaylistFile * playlistFile;
|
|
||||||
} info;
|
|
||||||
} mpd_InfoEntity;
|
|
||||||
|
|
||||||
mpd_InfoEntity * mpd_newInfoEntity(void);
|
|
||||||
|
|
||||||
void mpd_freeInfoEntity(mpd_InfoEntity * entity);
|
|
||||||
|
|
||||||
/* INFO COMMANDS AND STUFF */
|
|
||||||
|
|
||||||
/* use this function to loop over after calling Info/Listall functions */
|
|
||||||
mpd_InfoEntity * mpd_getNextInfoEntity(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* fetches the currently seeletect song (the song referenced by status->song
|
|
||||||
* and status->songid*/
|
|
||||||
void mpd_sendCurrentSongCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* songNum of -1, means to display the whole list */
|
|
||||||
void mpd_sendPlaylistInfoCommand(mpd_Connection * connection, int songNum);
|
|
||||||
|
|
||||||
/* songId of -1, means to display the whole list */
|
|
||||||
void mpd_sendPlaylistIdCommand(mpd_Connection * connection, int songId);
|
|
||||||
|
|
||||||
/* use this to get the changes in the playlist since version _playlist_ */
|
|
||||||
void mpd_sendPlChangesCommand(mpd_Connection * connection, long long playlist);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection: A valid and connected mpd_Connection.
|
|
||||||
* @param playlist: The playlist version you want the diff with.
|
|
||||||
* A more bandwidth efficient version of the mpd_sendPlChangesCommand.
|
|
||||||
* It only returns the pos+id of the changes song.
|
|
||||||
*/
|
|
||||||
void mpd_sendPlChangesPosIdCommand(mpd_Connection * connection, long long playlist);
|
|
||||||
|
|
||||||
/* recursivel fetches all songs/dir/playlists in "dir* (no metadata is
|
|
||||||
* returned) */
|
|
||||||
void mpd_sendListallCommand(mpd_Connection * connection, const char * dir);
|
|
||||||
|
|
||||||
/* same as sendListallCommand, but also metadata is returned */
|
|
||||||
void mpd_sendListallInfoCommand(mpd_Connection * connection, const char * dir);
|
|
||||||
|
|
||||||
/* non-recursive version of ListallInfo */
|
|
||||||
void mpd_sendLsInfoCommand(mpd_Connection * connection, const char * dir);
|
|
||||||
|
|
||||||
#define MPD_TABLE_ARTIST MPD_TAG_ITEM_ARTIST
|
|
||||||
#define MPD_TABLE_ALBUM MPD_TAG_ITEM_ALBUM
|
|
||||||
#define MPD_TABLE_TITLE MPD_TAG_ITEM_TITLE
|
|
||||||
#define MPD_TABLE_TRACK MPD_TAG_ITEM_TRACK
|
|
||||||
#define MPD_TABLE_GENRE MPD_TAG_ITEM_GENRE
|
|
||||||
#define MPD_TABLE_DATE MPD_TAG_ITEM_DATE
|
|
||||||
#define MPD_TABLE_COMPOSER MPD_TAG_ITEM_COMPOSER
|
|
||||||
#define MPD_TABLE_PERFORMER MPD_TAG_ITEM_PERFORMER
|
|
||||||
#define MPD_TABLE_COMMENT MPD_TAG_ITEM_COMMENT
|
|
||||||
#define MPD_TABLE_DISC MPD_TAG_ITEM_DISC
|
|
||||||
#define MPD_TABLE_FILENAME MPD_TAG_ITEM_FILENAME
|
|
||||||
|
|
||||||
void mpd_sendSearchCommand(mpd_Connection * connection, int table,
|
|
||||||
const char * str);
|
|
||||||
|
|
||||||
void mpd_sendFindCommand(mpd_Connection * connection, int table,
|
|
||||||
const char * str);
|
|
||||||
|
|
||||||
/* LIST TAG COMMANDS */
|
|
||||||
|
|
||||||
/* use this function fetch next artist entry, be sure to free the returned
|
|
||||||
* string. NULL means there are no more. Best used with sendListArtists
|
|
||||||
*/
|
|
||||||
char * mpd_getNextArtist(mpd_Connection * connection);
|
|
||||||
|
|
||||||
char * mpd_getNextAlbum(mpd_Connection * connection);
|
|
||||||
|
|
||||||
char * mpd_getNextTag(mpd_Connection *connection, int type);
|
|
||||||
|
|
||||||
/* list artist or albums by artist, arg1 should be set to the artist if
|
|
||||||
* listing albums by a artist, otherwise NULL for listing all artists or albums
|
|
||||||
*/
|
|
||||||
void mpd_sendListCommand(mpd_Connection * connection, int table,
|
|
||||||
const char * arg1);
|
|
||||||
|
|
||||||
/* SIMPLE COMMANDS */
|
|
||||||
|
|
||||||
void mpd_sendAddCommand(mpd_Connection * connection, const char * file);
|
|
||||||
|
|
||||||
int mpd_sendAddIdCommand(mpd_Connection *connection, const char *file);
|
|
||||||
|
|
||||||
void mpd_sendDeleteCommand(mpd_Connection * connection, int songNum);
|
|
||||||
|
|
||||||
void mpd_sendDeleteIdCommand(mpd_Connection * connection, int songNum);
|
|
||||||
|
|
||||||
void mpd_sendSaveCommand(mpd_Connection * connection, const char * name);
|
|
||||||
|
|
||||||
void mpd_sendLoadCommand(mpd_Connection * connection, const char * name);
|
|
||||||
|
|
||||||
void mpd_sendRmCommand(mpd_Connection * connection, const char * name);
|
|
||||||
|
|
||||||
void mpd_sendRenameCommand(mpd_Connection *connection, const char *from,
|
|
||||||
const char *to);
|
|
||||||
|
|
||||||
void mpd_sendShuffleCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendClearCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* use this to start playing at the beginning, useful when in random mode */
|
|
||||||
#define MPD_PLAY_AT_BEGINNING -1
|
|
||||||
|
|
||||||
void mpd_sendPlayCommand(mpd_Connection * connection, int songNum);
|
|
||||||
|
|
||||||
void mpd_sendPlayIdCommand(mpd_Connection * connection, int songNum);
|
|
||||||
|
|
||||||
void mpd_sendStopCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendPauseCommand(mpd_Connection * connection, int pauseMode);
|
|
||||||
|
|
||||||
void mpd_sendNextCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendPrevCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendMoveCommand(mpd_Connection * connection, int from, int to);
|
|
||||||
|
|
||||||
void mpd_sendMoveIdCommand(mpd_Connection * connection, int from, int to);
|
|
||||||
|
|
||||||
void mpd_sendSwapCommand(mpd_Connection * connection, int song1, int song2);
|
|
||||||
|
|
||||||
void mpd_sendSwapIdCommand(mpd_Connection * connection, int song1, int song2);
|
|
||||||
|
|
||||||
void mpd_sendSeekCommand(mpd_Connection * connection, int song, int time);
|
|
||||||
|
|
||||||
void mpd_sendSeekIdCommand(mpd_Connection * connection, int song, int time);
|
|
||||||
|
|
||||||
void mpd_sendRepeatCommand(mpd_Connection * connection, int repeatMode);
|
|
||||||
|
|
||||||
void mpd_sendRandomCommand(mpd_Connection * connection, int randomMode);
|
|
||||||
|
|
||||||
void mpd_sendSingleCommand(mpd_Connection * connection, int singleMode);
|
|
||||||
|
|
||||||
void mpd_sendConsumeCommand(mpd_Connection * connection, int consumeMode);
|
|
||||||
|
|
||||||
void mpd_sendSetvolCommand(mpd_Connection * connection, int volumeChange);
|
|
||||||
|
|
||||||
/* WARNING: don't use volume command, its depreacted */
|
|
||||||
void mpd_sendVolumeCommand(mpd_Connection * connection, int volumeChange);
|
|
||||||
|
|
||||||
void mpd_sendCrossfadeCommand(mpd_Connection * connection, int seconds);
|
|
||||||
|
|
||||||
void mpd_sendUpdateCommand(mpd_Connection * connection, const char * path);
|
|
||||||
|
|
||||||
/* returns the update job id, call this after a update command*/
|
|
||||||
int mpd_getUpdateId(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendPasswordCommand(mpd_Connection * connection, const char * pass);
|
|
||||||
|
|
||||||
/* after executing a command, when your done with it to get its status
|
|
||||||
* (you want to check connection->error for an error)
|
|
||||||
*/
|
|
||||||
void mpd_finishCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* command list stuff, use this to do things like add files very quickly */
|
|
||||||
void mpd_sendCommandListBegin(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendCommandListOkBegin(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendCommandListEnd(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/* advance to the next listOk
|
|
||||||
* returns 0 if advanced to the next list_OK,
|
|
||||||
* returns -1 if it advanced to an OK or ACK */
|
|
||||||
int mpd_nextListOkCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
typedef struct _mpd_OutputEntity {
|
|
||||||
int id;
|
|
||||||
char * name;
|
|
||||||
int enabled;
|
|
||||||
} mpd_OutputEntity;
|
|
||||||
|
|
||||||
void mpd_sendOutputsCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
mpd_OutputEntity * mpd_getNextOutput(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendEnableOutputCommand(mpd_Connection * connection, int outputId);
|
|
||||||
|
|
||||||
void mpd_sendDisableOutputCommand(mpd_Connection * connection, int outputId);
|
|
||||||
|
|
||||||
void mpd_freeOutputElement(mpd_OutputEntity * output);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a #mpd_Connection
|
|
||||||
*
|
|
||||||
* Queries mpd for the allowed commands
|
|
||||||
*/
|
|
||||||
void mpd_sendCommandsCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a #mpd_Connection
|
|
||||||
*
|
|
||||||
* Queries mpd for the not allowed commands
|
|
||||||
*/
|
|
||||||
void mpd_sendNotCommandsCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a #mpd_Connection
|
|
||||||
*
|
|
||||||
* returns the next supported command.
|
|
||||||
*
|
|
||||||
* @returns a string, needs to be free'ed
|
|
||||||
*/
|
|
||||||
char *mpd_getNextCommand(mpd_Connection *connection);
|
|
||||||
|
|
||||||
void mpd_sendUrlHandlersCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
char *mpd_getNextHandler(mpd_Connection * connection);
|
|
||||||
|
|
||||||
void mpd_sendTagTypesCommand(mpd_Connection * connection);
|
|
||||||
|
|
||||||
char *mpd_getNextTagType(mpd_Connection * connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a MpdConnection
|
|
||||||
* @param path the path to the playlist.
|
|
||||||
*
|
|
||||||
* List the content, with full metadata, of a stored playlist.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void mpd_sendListPlaylistInfoCommand(mpd_Connection *connection, const char *path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a MpdConnection
|
|
||||||
* @param path the path to the playlist.
|
|
||||||
*
|
|
||||||
* List the content of a stored playlist.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
void mpd_sendListPlaylistCommand(mpd_Connection *connection, char *path);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a #mpd_Connection
|
|
||||||
* @param exact if to match exact
|
|
||||||
*
|
|
||||||
* starts a search, use mpd_addConstraintSearch to add
|
|
||||||
* a constraint to the search, and mpd_commitSearch to do the actual search
|
|
||||||
*/
|
|
||||||
void mpd_startSearch(mpd_Connection *connection, int exact);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a #mpd_Connection
|
|
||||||
* @param type
|
|
||||||
* @param name
|
|
||||||
*/
|
|
||||||
void mpd_addConstraintSearch(mpd_Connection *connection, int type, const char *name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a #mpd_Connection
|
|
||||||
*/
|
|
||||||
void mpd_commitSearch(mpd_Connection *connection);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param connection a #mpd_Connection
|
|
||||||
* @param type The type to search for
|
|
||||||
*
|
|
||||||
* starts a search for fields... f.e. get a list of artists would be:
|
|
||||||
* @code
|
|
||||||
* mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
|
|
||||||
* mpd_commitSearch(connection);
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* or get a list of artist in genre "jazz" would be:
|
|
||||||
* @code
|
|
||||||
* mpd_startFieldSearch(connection, MPD_TAG_ITEM_ARTIST);
|
|
||||||
* mpd_addConstraintSearch(connection, MPD_TAG_ITEM_GENRE, "jazz")
|
|
||||||
* mpd_commitSearch(connection);
|
|
||||||
* @endcode
|
|
||||||
*
|
|
||||||
* mpd_startSearch will return a list of songs (and you need mpd_getNextInfoEntity)
|
|
||||||
* this one will return a list of only one field (the one specified with type) and you need
|
|
||||||
* mpd_getNextTag to get the results
|
|
||||||
*/
|
|
||||||
void mpd_startFieldSearch(mpd_Connection *connection, int type);
|
|
||||||
|
|
||||||
void mpd_startPlaylistSearch(mpd_Connection *connection, int exact);
|
|
||||||
|
|
||||||
void mpd_startStatsSearch(mpd_Connection *connection);
|
|
||||||
|
|
||||||
void mpd_sendPlaylistClearCommand(mpd_Connection *connection, const char *path);
|
|
||||||
|
|
||||||
void mpd_sendPlaylistAddCommand(mpd_Connection *connection,
|
|
||||||
const char *playlist, const char *path);
|
|
||||||
|
|
||||||
void mpd_sendPlaylistMoveCommand(mpd_Connection *connection,
|
|
||||||
const char *playlist, int from, int to);
|
|
||||||
|
|
||||||
void mpd_sendPlaylistDeleteCommand(mpd_Connection *connection,
|
|
||||||
const char *playlist, int pos);
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -185,11 +185,11 @@ void MediaLibrary::Update()
|
|||||||
Albums->Reset();
|
Albums->Reset();
|
||||||
TagList list;
|
TagList list;
|
||||||
locale_to_utf(Artists->Current());
|
locale_to_utf(Artists->Current());
|
||||||
if (Config.media_lib_primary_tag == MPD_TAG_ITEM_ARTIST)
|
if (Config.media_lib_primary_tag == MPD_TAG_ARTIST)
|
||||||
Mpd.GetAlbums(Artists->Current(), list);
|
Mpd.GetAlbums(Artists->Current(), list);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Mpd.StartFieldSearch(MPD_TAG_ITEM_ALBUM);
|
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearch(list);
|
||||||
}
|
}
|
||||||
@@ -197,21 +197,22 @@ void MediaLibrary::Update()
|
|||||||
// <mpd-0.14 doesn't support searching for empty tag
|
// <mpd-0.14 doesn't support searching for empty tag
|
||||||
if (Mpd.Version() > 13)
|
if (Mpd.Version() > 13)
|
||||||
{
|
{
|
||||||
TagList noalbum_list;
|
SongList noalbum_list;
|
||||||
Mpd.StartFieldSearch(MPD_TAG_ITEM_FILENAME);
|
Mpd.StartSearch(1);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||||
Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, "");
|
Mpd.AddSearch(MPD_TAG_ALBUM, "");
|
||||||
Mpd.CommitSearch(noalbum_list);
|
Mpd.CommitSearch(noalbum_list);
|
||||||
if (!noalbum_list.empty())
|
if (!noalbum_list.empty())
|
||||||
Albums->AddOption(std::make_pair("<no album>", SearchConstraints("", "")));
|
Albums->AddOption(std::make_pair("<no album>", SearchConstraints("", "")));
|
||||||
|
FreeSongList(noalbum_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (TagList::const_iterator it = list.begin(); it != list.end(); ++it)
|
for (TagList::const_iterator it = list.begin(); it != list.end(); ++it)
|
||||||
{
|
{
|
||||||
TagList l;
|
TagList l;
|
||||||
Mpd.StartFieldSearch(MPD_TAG_ITEM_DATE);
|
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
Mpd.AddSearch(Config.media_lib_primary_tag, Artists->Current());
|
||||||
Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, *it);
|
Mpd.AddSearch(MPD_TAG_ALBUM, *it);
|
||||||
Mpd.CommitSearch(l);
|
Mpd.CommitSearch(l);
|
||||||
if (l.empty())
|
if (l.empty())
|
||||||
{
|
{
|
||||||
@@ -237,17 +238,17 @@ void MediaLibrary::Update()
|
|||||||
for (TagList::const_iterator i = artists.begin(); i != artists.end(); ++i)
|
for (TagList::const_iterator i = artists.begin(); i != artists.end(); ++i)
|
||||||
{
|
{
|
||||||
TagList albums;
|
TagList albums;
|
||||||
Mpd.StartFieldSearch(MPD_TAG_ITEM_ALBUM);
|
Mpd.StartFieldSearch(MPD_TAG_ALBUM);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
||||||
Mpd.CommitSearch(albums);
|
Mpd.CommitSearch(albums);
|
||||||
for (TagList::const_iterator j = albums.begin(); j != albums.end(); ++j)
|
for (TagList::const_iterator j = albums.begin(); j != albums.end(); ++j)
|
||||||
{
|
{
|
||||||
if (Config.media_lib_primary_tag != MPD_TAG_ITEM_DATE)
|
if (Config.media_lib_primary_tag != MPD_TAG_DATE)
|
||||||
{
|
{
|
||||||
TagList years;
|
TagList years;
|
||||||
Mpd.StartFieldSearch(MPD_TAG_ITEM_DATE);
|
Mpd.StartFieldSearch(MPD_TAG_DATE);
|
||||||
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
Mpd.AddSearch(Config.media_lib_primary_tag, *i);
|
||||||
Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, *j);
|
Mpd.AddSearch(MPD_TAG_ALBUM, *j);
|
||||||
Mpd.CommitSearch(years);
|
Mpd.CommitSearch(years);
|
||||||
if (!years.empty())
|
if (!years.empty())
|
||||||
{
|
{
|
||||||
@@ -292,9 +293,9 @@ void MediaLibrary::Update()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, Albums->Current().second.Album);
|
Mpd.AddSearch(MPD_TAG_ALBUM, Albums->Current().second.Album);
|
||||||
if (!Albums->Current().second.Album.empty()) // for <no album>
|
if (!Albums->Current().second.Album.empty()) // for <no album>
|
||||||
Mpd.AddSearch(MPD_TAG_ITEM_DATE, Albums->Current().second.Year);
|
Mpd.AddSearch(MPD_TAG_DATE, Albums->Current().second.Year);
|
||||||
}
|
}
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearch(list);
|
||||||
|
|
||||||
|
|||||||
651
src/mpdpp.cpp
651
src/mpdpp.cpp
File diff suppressed because it is too large
Load Diff
71
src/mpdpp.h
71
src/mpdpp.h
@@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "libmpdclient.h"
|
#include <mpd/client.h>
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
namespace MPD
|
namespace MPD
|
||||||
@@ -96,47 +96,46 @@ namespace MPD
|
|||||||
void SetPort(int port) { itsPort = port; }
|
void SetPort(int port) { itsPort = port; }
|
||||||
void SetTimeout(int timeout) { itsTimeout = timeout; }
|
void SetTimeout(int timeout) { itsTimeout = timeout; }
|
||||||
void SetPassword(const std::string &password) { itsPassword = password; }
|
void SetPassword(const std::string &password) { itsPassword = password; }
|
||||||
void SendPassword() const;
|
bool SendPassword() const;
|
||||||
|
|
||||||
void SetStatusUpdater(StatusUpdater, void *);
|
void SetStatusUpdater(StatusUpdater, void *);
|
||||||
void SetErrorHandler(ErrorHandler, void *);
|
void SetErrorHandler(ErrorHandler, void *);
|
||||||
void UpdateStatus();
|
void UpdateStatus();
|
||||||
void UpdateDirectory(const std::string &);
|
bool UpdateDirectory(const std::string &);
|
||||||
|
|
||||||
void Execute(const std::string &) const;
|
|
||||||
|
|
||||||
void Play() const;
|
void Play() const;
|
||||||
void Play(int) const;
|
void Play(int) const;
|
||||||
void PlayID(int) const;
|
void PlayID(int) const;
|
||||||
void Pause() const;
|
void Pause(bool) const;
|
||||||
|
void Toggle() const;
|
||||||
void Stop() const;
|
void Stop() const;
|
||||||
void Next() const;
|
void Next() const;
|
||||||
void Prev() const;
|
void Prev() const;
|
||||||
void Move(int, int) const;
|
void Move(unsigned, unsigned) const;
|
||||||
void Swap(int, int) const;
|
void Swap(unsigned, unsigned) const;
|
||||||
void Seek(int) const;
|
void Seek(unsigned) const;
|
||||||
void Shuffle() const;
|
void Shuffle() const;
|
||||||
void ClearPlaylist() const;
|
void ClearPlaylist() const;
|
||||||
|
|
||||||
bool isPlaying() const { return GetState() > psStop; }
|
bool isPlaying() const { return GetState() > psStop; }
|
||||||
|
|
||||||
PlayerState GetState() const { return isConnected && itsCurrentStatus ? PlayerState(itsCurrentStatus->state) : psUnknown; }
|
PlayerState GetState() const{ return itsCurrentStatus ? PlayerState(mpd_status_get_state(itsCurrentStatus)) : psUnknown; }
|
||||||
bool GetRepeat() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->repeat : 0; }
|
bool GetRepeat() const { return itsCurrentStatus ? mpd_status_get_repeat(itsCurrentStatus) : 0; }
|
||||||
bool GetRandom() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->random : 0; }
|
bool GetRandom() const { return itsCurrentStatus ? mpd_status_get_random(itsCurrentStatus) : 0; }
|
||||||
bool GetSingle() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->single : 0; }
|
bool GetSingle() const { return itsCurrentStatus ? mpd_status_get_single(itsCurrentStatus) : 0; }
|
||||||
bool GetConsume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->consume : 0; }
|
bool GetConsume() const { return itsCurrentStatus ? mpd_status_get_consume(itsCurrentStatus) : 0; }
|
||||||
bool GetDBIsUpdating() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->updatingDb : 0; }
|
bool GetDBIsUpdating() const { return itsCurrentStatus ? mpd_status_get_update_id(itsCurrentStatus) : 0; }
|
||||||
int GetVolume() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->volume : -1; }
|
int GetVolume() const { return itsCurrentStatus ? mpd_status_get_volume(itsCurrentStatus) : -1; }
|
||||||
int GetCrossfade() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->crossfade : -1; }
|
unsigned GetCrossfade() const { return itsCurrentStatus ? mpd_status_get_crossfade(itsCurrentStatus) : 0; }
|
||||||
long long GetPlaylistID() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlist : -1; }
|
unsigned GetPlaylistID() const { return itsCurrentStatus ? mpd_status_get_queue_version(itsCurrentStatus) : 0; }
|
||||||
long long GetOldPlaylistID() const { return isConnected && itsOldStatus ? itsOldStatus->playlist : -1; }
|
unsigned GetOldPlaylistID() const { return itsOldStatus ? mpd_status_get_queue_version(itsOldStatus) : 0; }
|
||||||
int GetElapsedTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->elapsedTime : -1; }
|
unsigned GetElapsedTime() const { return itsCurrentStatus ? mpd_status_get_elapsed_time(itsCurrentStatus) : 0; }
|
||||||
int GetTotalTime() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->totalTime : 0; }
|
int GetTotalTime() const { return itsCurrentStatus ? mpd_status_get_total_time(itsCurrentStatus) : 0; }
|
||||||
unsigned GetBitrate() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->bitRate : 0; }
|
unsigned GetBitrate() const { return itsCurrentStatus ? mpd_status_get_kbit_rate(itsCurrentStatus) : 0; }
|
||||||
|
|
||||||
size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength; }
|
size_t GetMaxPlaylistLength() const { return itsMaxPlaylistLength; }
|
||||||
size_t GetPlaylistLength() const { return isConnected && itsCurrentStatus ? itsCurrentStatus->playlistLength : 0; }
|
size_t GetPlaylistLength() const { return itsCurrentStatus ? mpd_status_get_queue_length(itsCurrentStatus) : 0; }
|
||||||
void GetPlaylistChanges(long long, SongList &) const;
|
void GetPlaylistChanges(unsigned, SongList &) const;
|
||||||
|
|
||||||
const std::string & GetErrorMessage() const { return itsErrorMessage; }
|
const std::string & GetErrorMessage() const { return itsErrorMessage; }
|
||||||
int GetErrorCode() const { return itsErrorCode; }
|
int GetErrorCode() const { return itsErrorCode; }
|
||||||
@@ -150,16 +149,16 @@ namespace MPD
|
|||||||
void SetRandom(bool) const;
|
void SetRandom(bool) const;
|
||||||
void SetSingle(bool) const;
|
void SetSingle(bool) const;
|
||||||
void SetConsume(bool) const;
|
void SetConsume(bool) const;
|
||||||
void SetCrossfade(int) const;
|
void SetCrossfade(unsigned) const;
|
||||||
void SetVolume(int);
|
void SetVolume(unsigned);
|
||||||
|
|
||||||
int AddSong(const std::string &); // returns id of added song
|
int AddSong(const std::string &); // returns id of added song
|
||||||
int AddSong(const Song &); // returns id of added song
|
int AddSong(const Song &); // returns id of added song
|
||||||
bool AddRandomSongs(size_t);
|
bool AddRandomSongs(size_t);
|
||||||
void Add(const std::string &path) const;
|
void Add(const std::string &path) const;
|
||||||
void Delete(int) const;
|
void Delete(unsigned) const;
|
||||||
void DeleteID(int) const;
|
void DeleteID(unsigned) const;
|
||||||
void Delete(const std::string &, int) const;
|
void Delete(const std::string &, unsigned) const;
|
||||||
void StartCommandsList();
|
void StartCommandsList();
|
||||||
bool CommitCommandsList();
|
bool CommitCommandsList();
|
||||||
|
|
||||||
@@ -172,13 +171,13 @@ namespace MPD
|
|||||||
void Rename(const std::string &, const std::string &) const;
|
void Rename(const std::string &, const std::string &) const;
|
||||||
|
|
||||||
void StartSearch(bool) const;
|
void StartSearch(bool) const;
|
||||||
void StartFieldSearch(mpd_TagItems);
|
void StartFieldSearch(mpd_tag_type);
|
||||||
void AddSearch(mpd_TagItems, const std::string &) const;
|
void AddSearch(mpd_tag_type, const std::string &) const;
|
||||||
void CommitSearch(SongList &) const;
|
void CommitSearch(SongList &) const;
|
||||||
void CommitSearch(TagList &) const;
|
void CommitSearch(TagList &) const;
|
||||||
|
|
||||||
void GetPlaylists(TagList &) const;
|
void GetPlaylists(TagList &) const;
|
||||||
void GetList(TagList &, mpd_TagItems) const;
|
void GetList(TagList &, mpd_tag_type) const;
|
||||||
void GetAlbums(const std::string &, TagList &) const;
|
void GetAlbums(const std::string &, TagList &) const;
|
||||||
void GetDirectory(const std::string &, ItemList &) const;
|
void GetDirectory(const std::string &, ItemList &) const;
|
||||||
void GetDirectoryRecursive(const std::string &, SongList &) const;
|
void GetDirectoryRecursive(const std::string &, SongList &) const;
|
||||||
@@ -192,7 +191,7 @@ namespace MPD
|
|||||||
private:
|
private:
|
||||||
int CheckForErrors();
|
int CheckForErrors();
|
||||||
|
|
||||||
mpd_Connection *itsConnection;
|
mpd_connection *itsConnection;
|
||||||
bool isConnected;
|
bool isConnected;
|
||||||
bool isCommandsListEnabled;
|
bool isCommandsListEnabled;
|
||||||
|
|
||||||
@@ -205,8 +204,8 @@ namespace MPD
|
|||||||
int itsTimeout;
|
int itsTimeout;
|
||||||
std::string itsPassword;
|
std::string itsPassword;
|
||||||
|
|
||||||
mpd_Status *itsCurrentStatus;
|
mpd_status *itsCurrentStatus;
|
||||||
mpd_Status *itsOldStatus;
|
mpd_status *itsOldStatus;
|
||||||
|
|
||||||
StatusChanges itsChanges;
|
StatusChanges itsChanges;
|
||||||
|
|
||||||
@@ -215,7 +214,7 @@ namespace MPD
|
|||||||
ErrorHandler itsErrorHandler;
|
ErrorHandler itsErrorHandler;
|
||||||
void *itsErrorHandlerUserdata;
|
void *itsErrorHandlerUserdata;
|
||||||
|
|
||||||
mpd_TagItems itsSearchedField;
|
mpd_tag_type itsSearchedField;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
#include <clocale>
|
#include <clocale>
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
@@ -394,7 +395,7 @@ int main(int argc, char *argv[])
|
|||||||
&& mouse_event.y == (Config.new_design ? 1 : LINES-1) && mouse_event.x < 9
|
&& mouse_event.y == (Config.new_design ? 1 : LINES-1) && mouse_event.x < 9
|
||||||
) // playing/paused
|
) // playing/paused
|
||||||
{
|
{
|
||||||
Mpd.Pause();
|
Mpd.Toggle();
|
||||||
UpdateStatusImmediately = 1;
|
UpdateStatusImmediately = 1;
|
||||||
}
|
}
|
||||||
else if ((mouse_event.bstate & BUTTON2_PRESSED || mouse_event.bstate & BUTTON4_PRESSED)
|
else if ((mouse_event.bstate & BUTTON2_PRESSED || mouse_event.bstate & BUTTON4_PRESSED)
|
||||||
@@ -574,13 +575,13 @@ int main(int argc, char *argv[])
|
|||||||
Playlist::BlockUpdate = 1;
|
Playlist::BlockUpdate = 1;
|
||||||
myPlaylist->UpdateTimer();
|
myPlaylist->UpdateTimer();
|
||||||
// needed for keeping proper position of now playing song.
|
// needed for keeping proper position of now playing song.
|
||||||
if (myPlaylist->NowPlaying > myPlaylist->CurrentSong()->GetPosition()-del_counter)
|
if (myPlaylist->NowPlaying > int(myPlaylist->CurrentSong()->GetPosition())-del_counter)
|
||||||
myPlaylist->NowPlaying--;
|
--myPlaylist->NowPlaying;
|
||||||
Mpd.DeleteID(myPlaylist->CurrentSong()->GetID());
|
Mpd.DeleteID(myPlaylist->CurrentSong()->GetID());
|
||||||
myPlaylist->Items->DeleteOption(id);
|
myPlaylist->Items->DeleteOption(id);
|
||||||
myPlaylist->Items->Refresh();
|
myPlaylist->Items->Refresh();
|
||||||
myPlaylist->Items->ReadKey(input);
|
myPlaylist->Items->ReadKey(input);
|
||||||
del_counter++;
|
++del_counter;
|
||||||
}
|
}
|
||||||
myPlaylist->FixPositions(myPlaylist->Items->Choice());
|
myPlaylist->FixPositions(myPlaylist->Items->Choice());
|
||||||
myPlaylist->Items->SetTimeout(ncmpcpp_window_timeout);
|
myPlaylist->Items->SetTimeout(ncmpcpp_window_timeout);
|
||||||
@@ -722,7 +723,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
else if (Keypressed(input, Key.Pause))
|
else if (Keypressed(input, Key.Pause))
|
||||||
{
|
{
|
||||||
Mpd.Pause();
|
Mpd.Toggle();
|
||||||
UpdateStatusImmediately = 1;
|
UpdateStatusImmediately = 1;
|
||||||
}
|
}
|
||||||
else if (Keypressed(input, Key.SavePlaylist))
|
else if (Keypressed(input, Key.SavePlaylist))
|
||||||
@@ -1806,7 +1807,7 @@ int main(int argc, char *argv[])
|
|||||||
}
|
}
|
||||||
while (input != 'a' && input != 'y' && input != 'g' && input != 'c' && input != 'p');
|
while (input != 'a' && input != 'y' && input != 'g' && input != 'c' && input != 'p');
|
||||||
UnlockStatusbar();
|
UnlockStatusbar();
|
||||||
mpd_TagItems new_tagitem = IntoTagItem(input);
|
mpd_tag_type new_tagitem = IntoTagItem(input);
|
||||||
if (new_tagitem != Config.media_lib_primary_tag)
|
if (new_tagitem != Config.media_lib_primary_tag)
|
||||||
{
|
{
|
||||||
Config.media_lib_primary_tag = new_tagitem;
|
Config.media_lib_primary_tag = new_tagitem;
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ void Playlist::EnterPressed()
|
|||||||
{
|
{
|
||||||
for (size_t i = 0; i < playlist.size(); ++i)
|
for (size_t i = 0; i < playlist.size(); ++i)
|
||||||
{
|
{
|
||||||
if (playlist[i]->GetPosition() > int(i))
|
if (playlist[i]->GetPosition() > i)
|
||||||
{
|
{
|
||||||
Mpd.Swap(playlist[i]->GetPosition(), i);
|
Mpd.Swap(playlist[i]->GetPosition(), i);
|
||||||
std::swap(cmp[playlist[i]->GetPosition()], cmp[i]);
|
std::swap(cmp[playlist[i]->GetPosition()], cmp[i]);
|
||||||
|
|||||||
@@ -279,7 +279,7 @@ void DefaultConfiguration(ncmpcpp_config &conf)
|
|||||||
conf.active_column_color = clRed;
|
conf.active_column_color = clRed;
|
||||||
conf.window_border = brGreen;
|
conf.window_border = brGreen;
|
||||||
conf.active_window_border = brRed;
|
conf.active_window_border = brRed;
|
||||||
conf.media_lib_primary_tag = MPD_TAG_ITEM_ARTIST;
|
conf.media_lib_primary_tag = MPD_TAG_ARTIST;
|
||||||
conf.colors_enabled = true;
|
conf.colors_enabled = true;
|
||||||
conf.fancy_scrolling = true;
|
conf.fancy_scrolling = true;
|
||||||
conf.playlist_show_remaining_time = false;
|
conf.playlist_show_remaining_time = false;
|
||||||
|
|||||||
@@ -24,8 +24,9 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include <mpd/client.h>
|
||||||
|
|
||||||
#include "home.h"
|
#include "home.h"
|
||||||
#include "libmpdclient.h"
|
|
||||||
#include "ncmpcpp.h"
|
#include "ncmpcpp.h"
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -170,7 +171,7 @@ struct ncmpcpp_config
|
|||||||
Border window_border;
|
Border window_border;
|
||||||
Border active_window_border;
|
Border active_window_border;
|
||||||
|
|
||||||
mpd_TagItems media_lib_primary_tag;
|
mpd_tag_type media_lib_primary_tag;
|
||||||
|
|
||||||
bool colors_enabled;
|
bool colors_enabled;
|
||||||
bool fancy_scrolling;
|
bool fancy_scrolling;
|
||||||
|
|||||||
245
src/song.cpp
245
src/song.cpp
@@ -32,35 +32,52 @@
|
|||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "song.h"
|
#include "song.h"
|
||||||
|
|
||||||
MPD::Song::Song(mpd_Song *s, bool copy_ptr) : itsSong(s ? s : mpd_newSong()),
|
namespace
|
||||||
|
{
|
||||||
|
unsigned calc_hash(const char *p)
|
||||||
|
{
|
||||||
|
unsigned hash = 5381;
|
||||||
|
while (*p)
|
||||||
|
hash = (hash << 5) + hash + *p++;
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MPD::Song::Song(mpd_song *s, bool copy_ptr) : itsSong(s),
|
||||||
|
itsFile(0),
|
||||||
|
itsTags(0),
|
||||||
itsSlash(std::string::npos),
|
itsSlash(std::string::npos),
|
||||||
itsHash(0),
|
itsHash(0),
|
||||||
copyPtr(copy_ptr),
|
copyPtr(copy_ptr),
|
||||||
isLocalised(0)
|
isLocalised(0)
|
||||||
{
|
{
|
||||||
if (itsSong->file)
|
if (itsSong)
|
||||||
SetHashAndSlash();
|
SetHashAndSlash();
|
||||||
}
|
}
|
||||||
|
|
||||||
MPD::Song::Song(const Song &s) : itsSong(0),
|
MPD::Song::Song(const Song &s) : itsSong(s.copyPtr ? s.itsSong : mpd_song_dup(s.itsSong)),
|
||||||
|
itsFile(s.itsFile ? strdup(s.itsFile) : 0),
|
||||||
|
itsTags(s.itsTags ? new TagMap(*s.itsTags) : 0),
|
||||||
itsNewName(s.itsNewName),
|
itsNewName(s.itsNewName),
|
||||||
itsSlash(s.itsSlash),
|
itsSlash(s.itsSlash),
|
||||||
itsHash(s.itsHash),
|
itsHash(s.itsHash),
|
||||||
copyPtr(s.copyPtr),
|
copyPtr(s.copyPtr),
|
||||||
isLocalised(s.isLocalised)
|
isLocalised(s.isLocalised)
|
||||||
{
|
{
|
||||||
itsSong = s.copyPtr ? s.itsSong : mpd_songDup(s.itsSong);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MPD::Song::~Song()
|
MPD::Song::~Song()
|
||||||
{
|
{
|
||||||
if (itsSong)
|
if (itsSong)
|
||||||
mpd_freeSong(itsSong);
|
mpd_song_free(itsSong);
|
||||||
|
delete [] itsFile;
|
||||||
|
delete itsTags;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetLength() const
|
std::string MPD::Song::GetLength() const
|
||||||
{
|
{
|
||||||
return itsSong->time <= 0 ? "-:--" : ShowTime(itsSong->time);
|
unsigned len = mpd_song_get_duration(itsSong);
|
||||||
|
return !len ? "-:--" : ShowTime(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::Localize()
|
void MPD::Song::Localize()
|
||||||
@@ -68,19 +85,28 @@ void MPD::Song::Localize()
|
|||||||
# ifdef HAVE_ICONV_H
|
# ifdef HAVE_ICONV_H
|
||||||
if (isLocalised)
|
if (isLocalised)
|
||||||
return;
|
return;
|
||||||
str_pool_utf_to_locale(itsSong->file);
|
const char *tag, *conv_tag;
|
||||||
SetHashAndSlash();
|
conv_tag = tag = mpd_song_get_uri(itsSong);
|
||||||
str_pool_utf_to_locale(itsSong->artist);
|
utf_to_locale(conv_tag, 0);
|
||||||
str_pool_utf_to_locale(itsSong->title);
|
if (tag != conv_tag) // file has been converted
|
||||||
str_pool_utf_to_locale(itsSong->album);
|
{
|
||||||
str_pool_utf_to_locale(itsSong->track);
|
itsFile = conv_tag;
|
||||||
str_pool_utf_to_locale(itsSong->name);
|
SetHashAndSlash();
|
||||||
str_pool_utf_to_locale(itsSong->date);
|
}
|
||||||
str_pool_utf_to_locale(itsSong->genre);
|
for (unsigned t = MPD_TAG_ARTIST; t <= MPD_TAG_DISC; ++t)
|
||||||
str_pool_utf_to_locale(itsSong->composer);
|
{
|
||||||
str_pool_utf_to_locale(itsSong->performer);
|
unsigned pos = 0;
|
||||||
str_pool_utf_to_locale(itsSong->disc);
|
for (; (tag = mpd_song_get_tag(itsSong, mpd_tag_type(t), pos)); ++pos)
|
||||||
str_pool_utf_to_locale(itsSong->comment);
|
{
|
||||||
|
conv_tag = tag;
|
||||||
|
utf_to_locale(conv_tag, 0);
|
||||||
|
if (tag != conv_tag) // tag has been converted
|
||||||
|
{
|
||||||
|
SetTag(mpd_tag_type(t), pos, conv_tag);
|
||||||
|
delete [] conv_tag;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
isLocalised = 1;
|
isLocalised = 1;
|
||||||
# endif // HAVE_ICONV_H
|
# endif // HAVE_ICONV_H
|
||||||
}
|
}
|
||||||
@@ -88,8 +114,15 @@ void MPD::Song::Localize()
|
|||||||
void MPD::Song::Clear()
|
void MPD::Song::Clear()
|
||||||
{
|
{
|
||||||
if (itsSong)
|
if (itsSong)
|
||||||
mpd_freeSong(itsSong);
|
mpd_song_free(itsSong);
|
||||||
itsSong = mpd_newSong();
|
itsSong = 0;
|
||||||
|
|
||||||
|
delete [] itsFile;
|
||||||
|
itsFile = 0;
|
||||||
|
|
||||||
|
delete itsTags;
|
||||||
|
itsTags = 0;
|
||||||
|
|
||||||
itsNewName.clear();
|
itsNewName.clear();
|
||||||
itsSlash = std::string::npos;
|
itsSlash = std::string::npos;
|
||||||
itsHash = 0;
|
itsHash = 0;
|
||||||
@@ -99,210 +132,172 @@ void MPD::Song::Clear()
|
|||||||
|
|
||||||
bool MPD::Song::Empty() const
|
bool MPD::Song::Empty() const
|
||||||
{
|
{
|
||||||
return !itsSong || (!itsSong->file && !itsSong->title && !itsSong->artist && !itsSong->album && !itsSong->date && !itsSong->track && !itsSong->genre && !itsSong->composer && !itsSong->performer && !itsSong->disc && !itsSong->comment);
|
return !itsSong;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MPD::Song::isFromDB() const
|
bool MPD::Song::isFromDB() const
|
||||||
{
|
{
|
||||||
return (itsSong->file && itsSong->file[0] != '/') || itsSlash == std::string::npos;
|
return (MyFilename()[0] != '/') || itsSlash == std::string::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MPD::Song::isStream() const
|
bool MPD::Song::isStream() const
|
||||||
{
|
{
|
||||||
return !strncmp(itsSong->file, "http://", 7);
|
return !strncmp(MyFilename(), "http://", 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetFile() const
|
std::string MPD::Song::GetFile() const
|
||||||
{
|
{
|
||||||
return !itsSong->file ? "" : itsSong->file;
|
return MyFilename();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetName() const
|
std::string MPD::Song::GetName() const
|
||||||
{
|
{
|
||||||
if (itsSong->name)
|
std::string name = GetTag(MPD_TAG_NAME, 0);
|
||||||
return itsSong->name;
|
if (!name.empty())
|
||||||
else if (!itsSong->file)
|
return name;
|
||||||
return "";
|
|
||||||
else if (itsSlash != std::string::npos)
|
else if (itsSlash != std::string::npos)
|
||||||
return itsSong->file+itsSlash+1;
|
return MyFilename()+itsSlash+1;
|
||||||
else
|
else
|
||||||
return itsSong->file;
|
return MyFilename();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetDirectory() const
|
std::string MPD::Song::GetDirectory() const
|
||||||
{
|
{
|
||||||
if (!itsSong->file || isStream())
|
if (isStream())
|
||||||
return "";
|
return "";
|
||||||
else if (itsSlash == std::string::npos)
|
else if (itsSlash == std::string::npos)
|
||||||
return "/";
|
return "/";
|
||||||
else
|
else
|
||||||
return std::string(itsSong->file, itsSlash);
|
return std::string(MyFilename(), itsSlash);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetArtist() const
|
std::string MPD::Song::GetArtist() const
|
||||||
{
|
{
|
||||||
return !itsSong->artist ? "" : itsSong->artist;
|
return GetTag(MPD_TAG_ARTIST, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetTitle() const
|
std::string MPD::Song::GetTitle() const
|
||||||
{
|
{
|
||||||
return !itsSong->title ? "" : itsSong->title;
|
return GetTag(MPD_TAG_TITLE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetAlbum() const
|
std::string MPD::Song::GetAlbum() const
|
||||||
{
|
{
|
||||||
return !itsSong->album ? "" : itsSong->album;
|
return GetTag(MPD_TAG_ALBUM, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetTrack() const
|
std::string MPD::Song::GetTrack() const
|
||||||
{
|
{
|
||||||
if (!itsSong->track)
|
std::string track = GetTag(MPD_TAG_TRACK, 0);
|
||||||
return "";
|
return track.length() == 1 && track[0] != '0' ? "0"+track : track;
|
||||||
else if (itsSong->track[0] != '0' && !itsSong->track[1])
|
|
||||||
return "0"+std::string(itsSong->track);
|
|
||||||
else
|
|
||||||
return itsSong->track;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetTrackNumber() const
|
std::string MPD::Song::GetTrackNumber() const
|
||||||
{
|
{
|
||||||
if (!itsSong->track)
|
std::string track = GetTag(MPD_TAG_TRACK, 0);
|
||||||
return "";
|
size_t slash = track.find('/');
|
||||||
const char *slash = strrchr(itsSong->track, '/');
|
if (slash != std::string::npos)
|
||||||
if (slash)
|
|
||||||
{
|
{
|
||||||
std::string result(itsSong->track, slash-itsSong->track);
|
track = track.substr(slash+1);
|
||||||
return result[0] != '0' && result.length() == 1 ? "0"+result : result;
|
return track.length() == 1 && track[0] != '0' ? "0"+track : track;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
return GetTrack();
|
return track;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetDate() const
|
std::string MPD::Song::GetDate() const
|
||||||
{
|
{
|
||||||
return !itsSong->date ? "" : itsSong->date;
|
return GetTag(MPD_TAG_DATE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetGenre() const
|
std::string MPD::Song::GetGenre() const
|
||||||
{
|
{
|
||||||
return !itsSong->genre ? "" : itsSong->genre;
|
return GetTag(MPD_TAG_GENRE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetComposer() const
|
std::string MPD::Song::GetComposer() const
|
||||||
{
|
{
|
||||||
return !itsSong->composer ? "" : itsSong->composer;
|
return GetTag(MPD_TAG_COMPOSER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetPerformer() const
|
std::string MPD::Song::GetPerformer() const
|
||||||
{
|
{
|
||||||
return !itsSong->performer ? "" : itsSong->performer;
|
return GetTag(MPD_TAG_PERFORMER, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetDisc() const
|
std::string MPD::Song::GetDisc() const
|
||||||
{
|
{
|
||||||
return !itsSong->disc ? "" : itsSong->disc;
|
return GetTag(MPD_TAG_DISC, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::GetComment() const
|
std::string MPD::Song::GetComment() const
|
||||||
{
|
{
|
||||||
return !itsSong->comment ? "" : itsSong->comment;
|
return GetTag(MPD_TAG_COMMENT, 0);
|
||||||
}
|
|
||||||
|
|
||||||
void MPD::Song::SetFile(const std::string &str)
|
|
||||||
{
|
|
||||||
if (itsSong->file)
|
|
||||||
str_pool_put(itsSong->file);
|
|
||||||
itsSong->file = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
SetHashAndSlash();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetArtist(const std::string &str)
|
void MPD::Song::SetArtist(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->artist)
|
SetTag(MPD_TAG_ARTIST, 0, str);
|
||||||
str_pool_put(itsSong->artist);
|
|
||||||
itsSong->artist = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetTitle(const std::string &str)
|
void MPD::Song::SetTitle(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->title)
|
SetTag(MPD_TAG_TITLE, 0, str);
|
||||||
str_pool_put(itsSong->title);
|
|
||||||
itsSong->title = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetAlbum(const std::string &str)
|
void MPD::Song::SetAlbum(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->album)
|
SetTag(MPD_TAG_ALBUM, 0, str);
|
||||||
str_pool_put(itsSong->album);
|
|
||||||
itsSong->album = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetTrack(const std::string &str)
|
void MPD::Song::SetTrack(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->track)
|
SetTag(MPD_TAG_TRACK, 0, str);
|
||||||
str_pool_put(itsSong->track);
|
|
||||||
itsSong->track = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetTrack(int track)
|
void MPD::Song::SetTrack(unsigned track)
|
||||||
{
|
{
|
||||||
if (itsSong->track)
|
SetTag(MPD_TAG_ARTIST, 0, IntoStr(track));
|
||||||
str_pool_put(itsSong->track);
|
|
||||||
itsSong->track = str_pool_get(IntoStr(track).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetDate(const std::string &str)
|
void MPD::Song::SetDate(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->date)
|
SetTag(MPD_TAG_DATE, 0, str);
|
||||||
str_pool_put(itsSong->date);
|
|
||||||
itsSong->date = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetDate(int year)
|
void MPD::Song::SetDate(unsigned year)
|
||||||
{
|
{
|
||||||
if (itsSong->date)
|
SetTag(MPD_TAG_TRACK, 0, IntoStr(year));
|
||||||
str_pool_put(itsSong->date);
|
|
||||||
itsSong->date = str_pool_get(IntoStr(year).c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetGenre(const std::string &str)
|
void MPD::Song::SetGenre(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->genre)
|
SetTag(MPD_TAG_GENRE, 0, str);
|
||||||
str_pool_put(itsSong->genre);
|
|
||||||
itsSong->genre = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetComposer(const std::string &str)
|
void MPD::Song::SetComposer(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->composer)
|
SetTag(MPD_TAG_COMPOSER, 0, str);
|
||||||
str_pool_put(itsSong->composer);
|
|
||||||
itsSong->composer = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetPerformer(const std::string &str)
|
void MPD::Song::SetPerformer(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->performer)
|
SetTag(MPD_TAG_PERFORMER, 0, str);
|
||||||
str_pool_put(itsSong->performer);
|
|
||||||
itsSong->performer = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetDisc(const std::string &str)
|
void MPD::Song::SetDisc(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->disc)
|
SetTag(MPD_TAG_DISC, 0, str);
|
||||||
str_pool_put(itsSong->disc);
|
|
||||||
itsSong->disc = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetComment(const std::string &str)
|
void MPD::Song::SetComment(const std::string &str)
|
||||||
{
|
{
|
||||||
if (itsSong->comment)
|
SetTag(MPD_TAG_COMMENT, 0, str);
|
||||||
str_pool_put(itsSong->comment);
|
|
||||||
itsSong->comment = str.empty() ? 0 : str_pool_get(str.c_str());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MPD::Song::SetPosition(int pos)
|
void MPD::Song::SetPosition(unsigned pos)
|
||||||
{
|
{
|
||||||
itsSong->pos = pos;
|
mpd_song_set_pos(itsSong, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char *escape_chars) const
|
std::string MPD::Song::ParseFormat(std::string::const_iterator &it, const char *escape_chars) const
|
||||||
@@ -438,8 +433,12 @@ MPD::Song &MPD::Song::operator=(const MPD::Song &s)
|
|||||||
if (this == &s)
|
if (this == &s)
|
||||||
return *this;
|
return *this;
|
||||||
if (itsSong)
|
if (itsSong)
|
||||||
mpd_freeSong(itsSong);
|
mpd_song_free(itsSong);
|
||||||
itsSong = s.copyPtr ? s.itsSong : mpd_songDup(s.itsSong);
|
delete [] itsFile;
|
||||||
|
delete itsTags;
|
||||||
|
itsSong = s.copyPtr ? s.itsSong : (s.itsSong ? mpd_song_dup(s.itsSong) : 0);
|
||||||
|
itsFile = s.itsFile ? strdup(s.itsFile) : 0;
|
||||||
|
itsTags = s.itsTags ? new TagMap(*s.itsTags) : 0;
|
||||||
itsNewName = s.itsNewName;
|
itsNewName = s.itsNewName;
|
||||||
itsSlash = s.itsSlash;
|
itsSlash = s.itsSlash;
|
||||||
itsHash = s.itsHash;
|
itsHash = s.itsHash;
|
||||||
@@ -488,13 +487,39 @@ void MPD::Song::ValidateFormat(const std::string &type, const std::string &s)
|
|||||||
|
|
||||||
void MPD::Song::SetHashAndSlash()
|
void MPD::Song::SetHashAndSlash()
|
||||||
{
|
{
|
||||||
if (!itsSong->file)
|
const char *filename = MyFilename();
|
||||||
return;
|
|
||||||
if (!isStream())
|
if (!isStream())
|
||||||
{
|
{
|
||||||
const char *tmp = strrchr(itsSong->file, '/');
|
const char *tmp = strrchr(filename, '/');
|
||||||
itsSlash = tmp ? tmp-itsSong->file : std::string::npos;
|
itsSlash = tmp ? tmp-filename : std::string::npos;
|
||||||
}
|
}
|
||||||
itsHash = calc_hash(itsSong->file);
|
if (!itsFile)
|
||||||
|
itsHash = calc_hash(filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
const char *MPD::Song::MyFilename() const
|
||||||
|
{
|
||||||
|
return itsFile ? itsFile : mpd_song_get_uri(itsSong);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MPD::Song::SetTag(mpd_tag_type type, unsigned pos, const std::string &value)
|
||||||
|
{
|
||||||
|
if (value.empty())
|
||||||
|
return;
|
||||||
|
if (!itsTags)
|
||||||
|
itsTags = new TagMap;
|
||||||
|
(*itsTags)[std::make_pair(type, pos)] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string MPD::Song::GetTag(mpd_tag_type type, unsigned pos) const
|
||||||
|
{
|
||||||
|
if (itsTags)
|
||||||
|
{
|
||||||
|
TagMap::const_iterator it = itsTags->find(std::make_pair(type, pos));
|
||||||
|
if (it != itsTags->end())
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
const char *tag = mpd_song_get_tag(itsSong, type, pos);
|
||||||
|
return tag ? tag : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
42
src/song.h
42
src/song.h
@@ -21,21 +21,23 @@
|
|||||||
#ifndef _SONG_H
|
#ifndef _SONG_H
|
||||||
#define _SONG_H
|
#define _SONG_H
|
||||||
|
|
||||||
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "libmpdclient.h"
|
#include <mpd/client.h>
|
||||||
|
|
||||||
namespace MPD
|
namespace MPD
|
||||||
{
|
{
|
||||||
class Song
|
class Song
|
||||||
{
|
{
|
||||||
|
typedef std::map<std::pair<mpd_tag_type, unsigned>, std::string> TagMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
typedef void (Song::*SetFunction)(const std::string &);
|
typedef void (Song::*SetFunction)(const std::string &);
|
||||||
typedef std::string (Song::*GetFunction)() const;
|
typedef std::string (Song::*GetFunction)() const;
|
||||||
|
|
||||||
Song() : itsSlash(std::string::npos), itsHash(0), copyPtr(0), isLocalised(0) { itsSong = mpd_newSong(); }
|
Song(mpd_song * = 0, bool = 0);
|
||||||
Song(mpd_Song *, bool = 0);
|
|
||||||
Song(const Song &);
|
Song(const Song &);
|
||||||
~Song();
|
~Song();
|
||||||
|
|
||||||
@@ -56,24 +58,23 @@ namespace MPD
|
|||||||
std::string GetLength() const;
|
std::string GetLength() const;
|
||||||
|
|
||||||
unsigned GetHash() const { return itsHash; }
|
unsigned GetHash() const { return itsHash; }
|
||||||
int GetTotalLength() const { return itsSong->time < 0 ? 0 : itsSong->time; }
|
unsigned GetTotalLength() const { return mpd_song_get_duration(itsSong); }
|
||||||
int GetPosition() const { return itsSong->pos; }
|
unsigned GetPosition() const { return mpd_song_get_pos(itsSong); }
|
||||||
int GetID() const { return itsSong->id; }
|
unsigned GetID() const { return mpd_song_get_id(itsSong); }
|
||||||
|
|
||||||
void SetFile(const std::string &);
|
|
||||||
void SetArtist(const std::string &);
|
void SetArtist(const std::string &);
|
||||||
void SetTitle(const std::string &);
|
void SetTitle(const std::string &);
|
||||||
void SetAlbum(const std::string &);
|
void SetAlbum(const std::string &);
|
||||||
void SetTrack(const std::string &);
|
void SetTrack(const std::string &);
|
||||||
void SetTrack(int);
|
void SetTrack(unsigned);
|
||||||
void SetDate(const std::string &);
|
void SetDate(const std::string &);
|
||||||
void SetDate(int);
|
void SetDate(unsigned);
|
||||||
void SetGenre(const std::string &);
|
void SetGenre(const std::string &);
|
||||||
void SetComposer(const std::string &);
|
void SetComposer(const std::string &);
|
||||||
void SetPerformer(const std::string &);
|
void SetPerformer(const std::string &);
|
||||||
void SetDisc(const std::string &);
|
void SetDisc(const std::string &);
|
||||||
void SetComment(const std::string &);
|
void SetComment(const std::string &);
|
||||||
void SetPosition(int);
|
void SetPosition(unsigned);
|
||||||
|
|
||||||
void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; }
|
void SetNewName(const std::string &name) { itsNewName = name == GetName() ? "" : name; }
|
||||||
std::string GetNewName() const { return itsNewName; }
|
std::string GetNewName() const { return itsNewName; }
|
||||||
@@ -100,8 +101,27 @@ namespace MPD
|
|||||||
void SetHashAndSlash();
|
void SetHashAndSlash();
|
||||||
std::string ParseFormat(std::string::const_iterator &it, const char *escape_chars) const;
|
std::string ParseFormat(std::string::const_iterator &it, const char *escape_chars) const;
|
||||||
|
|
||||||
mpd_Song *itsSong;
|
void SetTag(mpd_tag_type, unsigned, const std::string &);
|
||||||
|
std::string GetTag(mpd_tag_type, unsigned) const;
|
||||||
|
|
||||||
|
/// Used internally for handling filename, since we don't have
|
||||||
|
/// write access to file string in mpd_song, manage our own if
|
||||||
|
/// localization was done and there is localized filename that
|
||||||
|
/// is different than the original one.
|
||||||
|
///
|
||||||
|
const char *MyFilename() const;
|
||||||
|
|
||||||
|
/// internal mpd_song structure
|
||||||
|
mpd_song *itsSong;
|
||||||
|
|
||||||
|
/// localized version of filename
|
||||||
|
const char *itsFile;
|
||||||
|
|
||||||
|
/// map that contains localized tags or these set by tag editor
|
||||||
|
TagMap *itsTags;
|
||||||
|
|
||||||
std::string itsNewName;
|
std::string itsNewName;
|
||||||
|
|
||||||
size_t itsSlash;
|
size_t itsSlash;
|
||||||
unsigned itsHash;
|
unsigned itsHash;
|
||||||
bool copyPtr;
|
bool copyPtr;
|
||||||
|
|||||||
@@ -19,6 +19,8 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
#include <sys/time.h>
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
@@ -160,12 +162,11 @@ void TraceMpdStatus()
|
|||||||
|
|
||||||
void NcmpcppErrorCallback(Connection *, int errorid, const char *msg, void *)
|
void NcmpcppErrorCallback(Connection *, int errorid, const char *msg, void *)
|
||||||
{
|
{
|
||||||
if (errorid == MPD_ACK_ERROR_PERMISSION)
|
if (errorid == MPD_SERVER_ERROR_PERMISSION)
|
||||||
{
|
{
|
||||||
wFooter->SetGetStringHelper(0);
|
wFooter->SetGetStringHelper(0);
|
||||||
Statusbar() << "Password: ";
|
Statusbar() << "Password: ";
|
||||||
std::string password = wFooter->GetString(-1, 0, 1);
|
Mpd.SetPassword(wFooter->GetString(-1, 0, 1));
|
||||||
Mpd.SetPassword(password);
|
|
||||||
Mpd.SendPassword();
|
Mpd.SendPassword();
|
||||||
Mpd.UpdateStatus();
|
Mpd.UpdateStatus();
|
||||||
wFooter->SetGetStringHelper(StatusbarGetStringHelper);
|
wFooter->SetGetStringHelper(StatusbarGetStringHelper);
|
||||||
@@ -193,8 +194,7 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
|||||||
{
|
{
|
||||||
if (!Playlist::BlockUpdate)
|
if (!Playlist::BlockUpdate)
|
||||||
{
|
{
|
||||||
np = Mpd.GetCurrentSong();
|
if (!(np = Mpd.GetCurrentSong()).Empty())
|
||||||
if (Mpd.isPlaying())
|
|
||||||
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
|
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
|
||||||
|
|
||||||
bool was_filtered = myPlaylist->Items->isFiltered();
|
bool was_filtered = myPlaylist->Items->isFiltered();
|
||||||
@@ -297,7 +297,8 @@ void NcmpcppStatusChanged(Connection *, StatusChanges changed, void *)
|
|||||||
}
|
}
|
||||||
case psPlay:
|
case psPlay:
|
||||||
{
|
{
|
||||||
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
|
if (!np.Empty())
|
||||||
|
WindowTitle(utf_to_locale_cpy(np.toString(Config.song_window_title_format)));
|
||||||
player_state = Config.new_design ? "[playing]" : "Playing: ";
|
player_state = Config.new_design ? "[playing]" : "Playing: ";
|
||||||
Playlist::ReloadRemaining = 1;
|
Playlist::ReloadRemaining = 1;
|
||||||
changed.ElapsedTime = 1;
|
changed.ElapsedTime = 1;
|
||||||
|
|||||||
125
src/str_pool.c
125
src/str_pool.c
@@ -1,125 +0,0 @@
|
|||||||
/* ncmpc
|
|
||||||
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
|
|
||||||
* This project's homepage is: http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "str_pool.h"
|
|
||||||
|
|
||||||
//#include <assert.h>
|
|
||||||
#include <stddef.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#define NUM_SLOTS 4096
|
|
||||||
|
|
||||||
struct slot {
|
|
||||||
struct slot *next;
|
|
||||||
unsigned char ref;
|
|
||||||
char value[1];
|
|
||||||
} __attribute__((packed));
|
|
||||||
|
|
||||||
struct slot *slots[NUM_SLOTS];
|
|
||||||
|
|
||||||
inline unsigned
|
|
||||||
calc_hash(const char *p)
|
|
||||||
{
|
|
||||||
unsigned hash = 5381;
|
|
||||||
|
|
||||||
//assert(p != NULL);
|
|
||||||
|
|
||||||
while (*p != 0)
|
|
||||||
hash = (hash << 5) + hash + *p++;
|
|
||||||
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline struct slot *
|
|
||||||
value_to_slot(const char *value)
|
|
||||||
{
|
|
||||||
return (struct slot*)(value - offsetof(struct slot, value));
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct slot *slot_alloc(struct slot *next, const char *value)
|
|
||||||
{
|
|
||||||
size_t length = strlen(value);
|
|
||||||
struct slot *slot = malloc(sizeof(*slot) + length);
|
|
||||||
if (slot == NULL)
|
|
||||||
abort(); /* XXX */
|
|
||||||
|
|
||||||
slot->next = next;
|
|
||||||
slot->ref = 1;
|
|
||||||
memcpy(slot->value, value, length + 1);
|
|
||||||
return slot;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *str_pool_get(const char *value)
|
|
||||||
{
|
|
||||||
struct slot **slot_p, *slot;
|
|
||||||
|
|
||||||
slot_p = &slots[calc_hash(value) % NUM_SLOTS];
|
|
||||||
for (slot = *slot_p; slot != NULL; slot = slot->next) {
|
|
||||||
if (strcmp(value, slot->value) == 0 && slot->ref < 0xff) {
|
|
||||||
//assert(slot->ref > 0);
|
|
||||||
++slot->ref;
|
|
||||||
return slot->value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
slot = slot_alloc(*slot_p, value);
|
|
||||||
*slot_p = slot;
|
|
||||||
return slot->value;
|
|
||||||
}
|
|
||||||
|
|
||||||
const char *str_pool_dup(const char *value)
|
|
||||||
{
|
|
||||||
struct slot *slot = value_to_slot(value);
|
|
||||||
|
|
||||||
//assert(slot->ref > 0);
|
|
||||||
|
|
||||||
if (slot->ref < 0xff) {
|
|
||||||
++slot->ref;
|
|
||||||
return value;
|
|
||||||
} else {
|
|
||||||
/* the reference counter overflows above 0xff;
|
|
||||||
duplicate the value, and start with 1 */
|
|
||||||
struct slot **slot_p =
|
|
||||||
&slots[calc_hash(slot->value) % NUM_SLOTS];
|
|
||||||
slot = slot_alloc(*slot_p, slot->value);
|
|
||||||
*slot_p = slot;
|
|
||||||
return slot->value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void str_pool_put(const char *value)
|
|
||||||
{
|
|
||||||
struct slot **slot_p, *slot;
|
|
||||||
|
|
||||||
slot = value_to_slot(value);
|
|
||||||
//assert(slot->ref > 0);
|
|
||||||
--slot->ref;
|
|
||||||
|
|
||||||
if (slot->ref > 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
for (slot_p = &slots[calc_hash(value) % NUM_SLOTS];
|
|
||||||
*slot_p != slot;
|
|
||||||
slot_p = &(*slot_p)->next) {
|
|
||||||
//assert(*slot_p != NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
*slot_p = slot->next;
|
|
||||||
free(slot);
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
/* ncmpc
|
|
||||||
* Copyright (C) 2008 Max Kellermann <max@duempel.org>
|
|
||||||
* This project's homepage is: http://www.musicpd.org
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation; either version 2 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, write to the Free Software
|
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef STR_POOL_H
|
|
||||||
#define STR_POOL_H
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
unsigned calc_hash(const char *p);
|
|
||||||
|
|
||||||
const char *str_pool_get(const char *value);
|
|
||||||
|
|
||||||
const char *str_pool_dup(const char *value);
|
|
||||||
|
|
||||||
void str_pool_put(const char *value);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
@@ -32,6 +32,7 @@
|
|||||||
#include "vorbisfile.h"
|
#include "vorbisfile.h"
|
||||||
#include "flacfile.h"
|
#include "flacfile.h"
|
||||||
|
|
||||||
|
#include "browser.h"
|
||||||
#include "charset.h"
|
#include "charset.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
@@ -239,7 +240,7 @@ void TagEditor::Update()
|
|||||||
{
|
{
|
||||||
MPD::SongList l;
|
MPD::SongList l;
|
||||||
Mpd.StartSearch(1);
|
Mpd.StartSearch(1);
|
||||||
Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, *it);
|
Mpd.AddSearch(MPD_TAG_ALBUM, *it);
|
||||||
Mpd.CommitSearch(l);
|
Mpd.CommitSearch(l);
|
||||||
if (!l.empty())
|
if (!l.empty())
|
||||||
{
|
{
|
||||||
@@ -288,7 +289,7 @@ void TagEditor::Update()
|
|||||||
if (Config.albums_in_tag_editor)
|
if (Config.albums_in_tag_editor)
|
||||||
{
|
{
|
||||||
Mpd.StartSearch(1);
|
Mpd.StartSearch(1);
|
||||||
Mpd.AddSearch(MPD_TAG_ITEM_ALBUM, Albums->Current().second);
|
Mpd.AddSearch(MPD_TAG_ALBUM, Albums->Current().second);
|
||||||
Mpd.CommitSearch(list);
|
Mpd.CommitSearch(list);
|
||||||
sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
sort(list.begin(), list.end(), CaseInsensitiveSorting());
|
||||||
for (MPD::SongList::iterator it = list.begin(); it != list.end(); ++it)
|
for (MPD::SongList::iterator it = list.begin(); it != list.end(); ++it)
|
||||||
@@ -875,40 +876,27 @@ void TagEditor::PrevColumn()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TagEditor::ReadTags(mpd_Song *s)
|
void TagEditor::ReadTags(MPD::Song &s)
|
||||||
{
|
{
|
||||||
TagLib::FileRef f(s->file);
|
TagLib::FileRef f(s.GetFile().c_str());
|
||||||
if (f.isNull())
|
if (f.isNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
TagLib::MPEG::File *mpegf = dynamic_cast<TagLib::MPEG::File *>(f.file());
|
TagLib::MPEG::File *mpegf = dynamic_cast<TagLib::MPEG::File *>(f.file());
|
||||||
|
|
||||||
s->artist = !f.tag()->artist().isEmpty() ? str_pool_get(f.tag()->artist().toCString(1)) : 0;
|
s.SetArtist(f.tag()->artist().to8Bit(1));
|
||||||
s->title = !f.tag()->title().isEmpty() ? str_pool_get(f.tag()->title().toCString(1)) : 0;
|
s.SetTitle(f.tag()->title().to8Bit(1));
|
||||||
s->album = !f.tag()->album().isEmpty() ? str_pool_get(f.tag()->album().toCString(1)) : 0;
|
s.SetAlbum(f.tag()->album().to8Bit(1));
|
||||||
s->track = f.tag()->track() ? str_pool_get(IntoStr(f.tag()->track()).c_str()) : 0;
|
s.SetTrack(IntoStr(f.tag()->track()));
|
||||||
s->date = f.tag()->year() ? str_pool_get(IntoStr(f.tag()->year()).c_str()) : 0;
|
s.SetDate(IntoStr(f.tag()->year()));
|
||||||
s->genre = !f.tag()->genre().isEmpty() ? str_pool_get(f.tag()->genre().toCString(1)) : 0;
|
s.SetGenre(f.tag()->genre().to8Bit(1));
|
||||||
if (mpegf)
|
if (mpegf)
|
||||||
{
|
{
|
||||||
s->composer = !mpegf->ID3v2Tag()->frameListMap()["TCOM"].isEmpty()
|
s.SetComposer(!mpegf->ID3v2Tag()->frameListMap()["TCOM"].isEmpty() ? mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().to8Bit(1) : "");
|
||||||
? (!mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().isEmpty()
|
s.SetPerformer(!mpegf->ID3v2Tag()->frameListMap()["TOPE"].isEmpty() ? mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().to8Bit(1) : "");
|
||||||
? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TCOM"].front()->toString().toCString(1))
|
s.SetDisc(!mpegf->ID3v2Tag()->frameListMap()["TPOS"].isEmpty() ? mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().to8Bit(1) : "");
|
||||||
: 0)
|
|
||||||
: 0;
|
|
||||||
s->performer = !mpegf->ID3v2Tag()->frameListMap()["TOPE"].isEmpty()
|
|
||||||
? (!mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().isEmpty()
|
|
||||||
? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TOPE"].front()->toString().toCString(1))
|
|
||||||
: 0)
|
|
||||||
: 0;
|
|
||||||
s->disc = !mpegf->ID3v2Tag()->frameListMap()["TPOS"].isEmpty()
|
|
||||||
? (!mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().isEmpty()
|
|
||||||
? str_pool_get(mpegf->ID3v2Tag()->frameListMap()["TPOS"].front()->toString().toCString(1))
|
|
||||||
: 0)
|
|
||||||
: 0;
|
|
||||||
}
|
}
|
||||||
s->comment = !f.tag()->comment().isEmpty() ? str_pool_get(f.tag()->comment().toCString(1)) : 0;
|
s.SetComment(f.tag()->comment().to8Bit(1));
|
||||||
s->time = f.audioProperties()->length();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@@ -1016,7 +1004,7 @@ bool TagEditor::WriteTags(MPD::Song &s)
|
|||||||
Mpd.CommitCommandsList();
|
Mpd.CommitCommandsList();
|
||||||
}
|
}
|
||||||
else // only myBrowser->Main()
|
else // only myBrowser->Main()
|
||||||
s.SetFile(new_name);
|
myBrowser->GetDirectory(myBrowser->CurrentDir());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class TagEditor : public Screen<Window>
|
|||||||
/// NOTICE: this string is always in utf8, no need to convert it
|
/// NOTICE: this string is always in utf8, no need to convert it
|
||||||
const std::string &CurrentDir() { return itsBrowsedDir; }
|
const std::string &CurrentDir() { return itsBrowsedDir; }
|
||||||
|
|
||||||
static void ReadTags(mpd_Song *);
|
static void ReadTags(MPD::Song &);
|
||||||
static bool WriteTags(MPD::Song &);
|
static bool WriteTags(MPD::Song &);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|||||||
Reference in New Issue
Block a user