2010-01-07 02:38:12 +00:00
|
|
|
/* -*- mode: c++; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=cpp
|
2009-07-28 21:44:22 +00:00
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
2006-03-16 18:29:23 +00:00
|
|
|
*
|
2007-08-10 19:53:44 +00:00
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
2010-01-01 23:46:17 +00:00
|
|
|
* Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al.
|
2008-02-20 20:30:45 +00:00
|
|
|
* (see AUTHORS)
|
2007-08-10 19:53:44 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 3 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
|
2008-02-20 20:30:45 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2007-08-10 19:53:44 +00:00
|
|
|
*
|
2008-12-09 23:35:49 +00:00
|
|
|
*/
|
2006-03-16 18:29:23 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
#include <mutex>
|
2005-07-20 00:30:40 +00:00
|
|
|
#include "conky.h"
|
2008-12-15 21:40:24 +00:00
|
|
|
#include "logging.h"
|
2010-01-13 18:52:35 +00:00
|
|
|
#include "timed-thread.h"
|
2009-11-09 21:11:06 +00:00
|
|
|
#include "timeinfo.h"
|
2008-12-18 12:37:53 +00:00
|
|
|
#include "libmpdclient.h"
|
|
|
|
#include "mpd.h"
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2010-08-22 10:17:09 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
/* this is true if the current host was set from MPD_HOST */
|
|
|
|
bool mpd_environment_host = false;
|
|
|
|
|
|
|
|
class mpd_host_setting: public conky::simple_config_setting<std::string> {
|
|
|
|
typedef conky::simple_config_setting<std::string> Base;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void lua_setter(lua::state &l, bool init);
|
|
|
|
|
|
|
|
public:
|
|
|
|
mpd_host_setting()
|
|
|
|
: Base("mpd_host", "localhost", false)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
void mpd_host_setting::lua_setter(lua::state &l, bool init)
|
|
|
|
{
|
|
|
|
lua::stack_sentry s(l, -2);
|
|
|
|
|
|
|
|
if(l.isnil(-2)) {
|
|
|
|
// get the value from environment
|
|
|
|
mpd_environment_host = true;
|
|
|
|
const char *t = getenv("MPD_HOST");
|
|
|
|
if(t) {
|
|
|
|
l.checkstack(1);
|
|
|
|
const char *h = strchr(t, '@');
|
|
|
|
if(h) {
|
|
|
|
if(h[1])
|
|
|
|
l.pushstring(h+1);
|
|
|
|
} else
|
|
|
|
l.pushstring(t);
|
|
|
|
l.replace(-3);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Base::lua_setter(l, init);
|
|
|
|
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
|
|
|
|
class mpd_password_setting: public conky::simple_config_setting<std::string> {
|
|
|
|
typedef conky::simple_config_setting<std::string> Base;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual void lua_setter(lua::state &l, bool init);
|
|
|
|
|
|
|
|
public:
|
|
|
|
mpd_password_setting()
|
|
|
|
: Base("mpd_password", std::string(), false)
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
void mpd_password_setting::lua_setter(lua::state &l, bool init)
|
|
|
|
{
|
|
|
|
lua::stack_sentry s(l, -2);
|
|
|
|
|
|
|
|
/* for security, dont use environment password when user specifies host in config */
|
|
|
|
if(l.isnil(-2) && mpd_environment_host) {
|
|
|
|
// get the value from environment
|
|
|
|
const char *t = getenv("MPD_HOST");
|
|
|
|
if(t) {
|
|
|
|
const char *p = strchr(t, '@');
|
|
|
|
if(p) {
|
|
|
|
l.checkstack(1);
|
|
|
|
l.pushstring(t, p-t);
|
|
|
|
l.replace(-3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Base::lua_setter(l, init);
|
|
|
|
|
|
|
|
++s;
|
|
|
|
}
|
2008-12-18 12:37:53 +00:00
|
|
|
|
2010-08-22 10:17:09 +00:00
|
|
|
conky::range_config_setting<int> mpd_port("mpd_port", 1, 65535, 6600, false);
|
|
|
|
mpd_host_setting mpd_host;
|
|
|
|
mpd_password_setting mpd_password;
|
|
|
|
}
|
2009-06-14 23:15:04 +00:00
|
|
|
|
2008-12-18 12:37:53 +00:00
|
|
|
/* global mpd information */
|
2009-11-16 22:43:13 +00:00
|
|
|
static struct {
|
|
|
|
char *title;
|
|
|
|
char *artist;
|
|
|
|
char *album;
|
|
|
|
const char *status;
|
|
|
|
const char *random;
|
|
|
|
const char *repeat;
|
|
|
|
char *track;
|
|
|
|
char *name;
|
|
|
|
char *file;
|
|
|
|
int is_playing;
|
|
|
|
int vol;
|
|
|
|
float progress;
|
|
|
|
int bitrate;
|
|
|
|
int length;
|
|
|
|
int elapsed;
|
|
|
|
} mpd_info;
|
2008-12-18 12:37:53 +00:00
|
|
|
|
|
|
|
/* number of users of the above struct */
|
|
|
|
static int refcount = 0;
|
|
|
|
|
|
|
|
void init_mpd(void)
|
2008-03-19 22:28:23 +00:00
|
|
|
{
|
2008-12-18 12:37:53 +00:00
|
|
|
if (!(refcount++)) /* first client */
|
2009-11-16 22:43:13 +00:00
|
|
|
memset(&mpd_info, 0, sizeof(mpd_info));
|
2008-03-19 22:28:23 +00:00
|
|
|
}
|
|
|
|
|
2008-12-18 12:37:53 +00:00
|
|
|
static void clear_mpd(void)
|
2005-07-20 00:30:40 +00:00
|
|
|
{
|
2010-02-24 01:14:20 +00:00
|
|
|
free_and_zero(mpd_info.title);
|
|
|
|
free_and_zero(mpd_info.artist);
|
|
|
|
free_and_zero(mpd_info.album);
|
2008-12-18 12:37:53 +00:00
|
|
|
/* do not free() the const char *status! */
|
|
|
|
/* do not free() the const char *random! */
|
|
|
|
/* do not free() the const char *repeat! */
|
2010-02-24 01:14:20 +00:00
|
|
|
free_and_zero(mpd_info.track);
|
|
|
|
free_and_zero(mpd_info.name);
|
|
|
|
free_and_zero(mpd_info.file);
|
2009-11-16 22:43:13 +00:00
|
|
|
memset(&mpd_info, 0, sizeof(mpd_info));
|
2008-12-18 12:37:53 +00:00
|
|
|
}
|
2008-06-19 06:17:53 +00:00
|
|
|
|
2009-11-29 19:58:37 +00:00
|
|
|
void free_mpd(struct text_object *obj)
|
2008-12-18 12:37:53 +00:00
|
|
|
{
|
2009-11-29 19:58:37 +00:00
|
|
|
(void)obj;
|
|
|
|
|
2008-12-18 12:37:53 +00:00
|
|
|
if (!(--refcount)) /* last client */
|
|
|
|
clear_mpd();
|
|
|
|
}
|
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
static void update_mpd_thread(thread_handle &handle);
|
2008-12-18 12:37:53 +00:00
|
|
|
|
2010-05-05 16:46:04 +00:00
|
|
|
int update_mpd(void)
|
2008-12-18 12:37:53 +00:00
|
|
|
{
|
2010-01-04 04:50:02 +00:00
|
|
|
static timed_thread_ptr thread;
|
2008-12-18 12:37:53 +00:00
|
|
|
|
|
|
|
if (thread)
|
2010-05-05 16:46:04 +00:00
|
|
|
return 0;
|
2008-12-18 12:37:53 +00:00
|
|
|
|
2010-06-10 17:13:15 +00:00
|
|
|
thread = timed_thread::create(std::bind(update_mpd_thread, std::placeholders::_1),
|
|
|
|
std::chrono::microseconds(long(info.music_player_interval * 1000000)) );
|
2008-12-18 12:37:53 +00:00
|
|
|
if (!thread) {
|
2009-08-01 18:45:43 +00:00
|
|
|
NORM_ERR("Failed to create MPD timed thread");
|
2010-05-05 16:46:04 +00:00
|
|
|
return 0;
|
2008-03-29 05:14:35 +00:00
|
|
|
}
|
2010-05-05 16:46:04 +00:00
|
|
|
return 0;
|
2008-12-18 12:37:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* stringMAXdup dups at most text_buffer_size bytes */
|
|
|
|
#define strmdup(x) strndup(x, text_buffer_size - 1)
|
2008-03-29 05:14:35 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
#define SONGSET(x) { \
|
|
|
|
free(mpd_info.x); \
|
|
|
|
if(song->x) \
|
|
|
|
mpd_info.x = strmdup(song->x); \
|
|
|
|
else \
|
|
|
|
mpd_info.x = strmdup(emptystr); \
|
|
|
|
}
|
|
|
|
|
|
|
|
bool mpd_process(thread_handle &handle)
|
2008-12-18 12:37:53 +00:00
|
|
|
{
|
|
|
|
static mpd_Connection *conn = NULL;
|
|
|
|
mpd_Status *status;
|
|
|
|
mpd_InfoEntity *entity;
|
2009-02-18 05:42:08 +00:00
|
|
|
const char *emptystr = "";
|
2008-06-14 18:41:12 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
do {
|
2008-12-18 12:37:53 +00:00
|
|
|
if (!conn)
|
2010-08-22 10:17:09 +00:00
|
|
|
conn = mpd_newConnection(mpd_host.get(*state).c_str(), mpd_port.get(*state), 10);
|
2008-12-18 12:37:53 +00:00
|
|
|
|
2010-08-22 10:17:09 +00:00
|
|
|
if (mpd_password.get(*state).size()) {
|
|
|
|
mpd_sendPasswordCommand(conn, mpd_password.get(*state).c_str());
|
2008-12-18 12:37:53 +00:00
|
|
|
mpd_finishCommand(conn);
|
2007-08-30 17:21:30 +00:00
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
{
|
|
|
|
std::lock_guard<std::mutex> lock(handle.mutex());
|
2007-08-05 04:47:21 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
if (conn->error || conn == NULL) {
|
|
|
|
NORM_ERR("MPD error: %s\n", conn->errorStr);
|
|
|
|
mpd_closeConnection(conn);
|
|
|
|
conn = 0;
|
|
|
|
clear_mpd();
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
mpd_info.status = "MPD not responding";
|
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
mpd_sendStatusCommand(conn);
|
|
|
|
if ((status = mpd_getStatus(conn)) == NULL) {
|
|
|
|
NORM_ERR("MPD error: %s\n", conn->errorStr);
|
|
|
|
mpd_closeConnection(conn);
|
|
|
|
conn = 0;
|
|
|
|
clear_mpd();
|
2008-12-18 12:37:53 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
mpd_info.status = "MPD not responding";
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2010-01-04 04:50:02 +00:00
|
|
|
mpd_finishCommand(conn);
|
|
|
|
if (conn->error) {
|
|
|
|
// fprintf(stderr, "%s\n", conn->errorStr);
|
|
|
|
mpd_closeConnection(conn);
|
|
|
|
conn = 0;
|
2008-12-18 12:37:53 +00:00
|
|
|
break;
|
2010-01-04 04:50:02 +00:00
|
|
|
}
|
2007-08-30 17:21:30 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
mpd_info.vol = status->volume;
|
|
|
|
if (status->random == 0) {
|
|
|
|
mpd_info.random = "Off";
|
|
|
|
} else if (status->random == 1) {
|
|
|
|
mpd_info.random = "On";
|
|
|
|
} else {
|
|
|
|
mpd_info.random = "";
|
|
|
|
}
|
|
|
|
if (status->repeat == 0) {
|
|
|
|
mpd_info.repeat = "Off";
|
|
|
|
} else if (status->repeat == 1) {
|
|
|
|
mpd_info.repeat = "On";
|
|
|
|
} else {
|
|
|
|
mpd_info.repeat = "";
|
|
|
|
}
|
|
|
|
/* if (status->error) {
|
|
|
|
printf("error: %s\n", status->error);
|
|
|
|
} */
|
|
|
|
|
|
|
|
switch (status->state) {
|
|
|
|
case MPD_STATUS_STATE_PLAY:
|
|
|
|
mpd_info.status = "Playing";
|
|
|
|
break;
|
|
|
|
case MPD_STATUS_STATE_STOP:
|
|
|
|
mpd_info.status = "Stopped";
|
|
|
|
break;
|
|
|
|
case MPD_STATUS_STATE_PAUSE:
|
|
|
|
mpd_info.status = "Paused";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
mpd_info.status = "";
|
|
|
|
clear_mpd();
|
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2007-08-30 17:21:30 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
if (status->state == MPD_STATUS_STATE_PLAY ||
|
|
|
|
status->state == MPD_STATUS_STATE_PAUSE) {
|
|
|
|
mpd_info.is_playing = 1;
|
|
|
|
mpd_info.bitrate = status->bitRate;
|
|
|
|
mpd_info.progress = (float) status->elapsedTime /
|
|
|
|
status->totalTime;
|
|
|
|
mpd_info.elapsed = status->elapsedTime;
|
|
|
|
mpd_info.length = status->totalTime;
|
|
|
|
} else {
|
|
|
|
mpd_info.progress = 0;
|
|
|
|
mpd_info.is_playing = 0;
|
|
|
|
mpd_info.elapsed = 0;
|
|
|
|
}
|
2008-02-20 20:30:45 +00:00
|
|
|
|
2010-01-04 04:50:02 +00:00
|
|
|
if (conn->error) {
|
|
|
|
// fprintf(stderr, "%s\n", conn->errorStr);
|
|
|
|
mpd_closeConnection(conn);
|
|
|
|
conn = 0;
|
|
|
|
break;
|
2007-08-30 17:21:30 +00:00
|
|
|
}
|
2010-01-04 04:50:02 +00:00
|
|
|
|
|
|
|
mpd_sendCurrentSongCommand(conn);
|
|
|
|
while ((entity = mpd_getNextInfoEntity(conn))) {
|
|
|
|
mpd_Song *song = entity->info.song;
|
|
|
|
|
|
|
|
if (entity->type != MPD_INFO_ENTITY_TYPE_SONG) {
|
|
|
|
mpd_freeInfoEntity(entity);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
SONGSET(artist);
|
|
|
|
SONGSET(album);
|
|
|
|
SONGSET(title);
|
|
|
|
SONGSET(track);
|
|
|
|
SONGSET(name);
|
|
|
|
SONGSET(file);
|
2008-12-18 12:37:53 +00:00
|
|
|
#undef SONGSET
|
2010-01-04 04:50:02 +00:00
|
|
|
if (entity != NULL) {
|
|
|
|
mpd_freeInfoEntity(entity);
|
|
|
|
entity = NULL;
|
|
|
|
}
|
2007-08-30 17:21:30 +00:00
|
|
|
}
|
2010-01-04 04:50:02 +00:00
|
|
|
mpd_finishCommand(conn);
|
|
|
|
if (conn->error) {
|
|
|
|
// fprintf(stderr, "%s\n", conn->errorStr);
|
|
|
|
mpd_closeConnection(conn);
|
|
|
|
conn = 0;
|
|
|
|
break;
|
2008-02-20 20:30:45 +00:00
|
|
|
}
|
2010-01-04 04:50:02 +00:00
|
|
|
|
2007-08-30 17:21:30 +00:00
|
|
|
}
|
2005-07-20 00:30:40 +00:00
|
|
|
|
2008-12-18 12:37:53 +00:00
|
|
|
if (conn->error) {
|
|
|
|
// fprintf(stderr, "%s\n", conn->errorStr);
|
|
|
|
mpd_closeConnection(conn);
|
|
|
|
conn = 0;
|
2010-01-04 04:50:02 +00:00
|
|
|
break;
|
2007-08-30 17:21:30 +00:00
|
|
|
}
|
2007-08-31 18:32:51 +00:00
|
|
|
|
2007-08-30 17:21:30 +00:00
|
|
|
mpd_freeStatus(status);
|
2008-12-18 12:37:53 +00:00
|
|
|
/* if (conn) {
|
2010-01-04 04:50:02 +00:00
|
|
|
mpd_closeConnection(conn);
|
|
|
|
conn = 0;
|
|
|
|
} */
|
|
|
|
} while (0);
|
|
|
|
return !handle.test(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_mpd_thread(thread_handle &handle)
|
|
|
|
{
|
2010-03-18 20:26:10 +00:00
|
|
|
while (mpd_process(handle)) ;
|
2008-03-29 11:35:02 +00:00
|
|
|
/* never reached */
|
2006-01-31 03:32:26 +00:00
|
|
|
}
|
2008-12-18 12:37:53 +00:00
|
|
|
|
2009-11-09 21:11:06 +00:00
|
|
|
static inline void format_media_player_time(char *buf, const int size,
|
|
|
|
int seconds)
|
|
|
|
{
|
|
|
|
int days, hours, minutes;
|
|
|
|
|
2010-03-05 13:20:04 +00:00
|
|
|
if (times_in_seconds.get(*state)) {
|
2009-11-09 21:11:06 +00:00
|
|
|
snprintf(buf, size, "%d", seconds);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
days = seconds / (24 * 60 * 60);
|
|
|
|
seconds %= (24 * 60 * 60);
|
|
|
|
hours = seconds / (60 * 60);
|
|
|
|
seconds %= (60 * 60);
|
|
|
|
minutes = seconds / 60;
|
|
|
|
seconds %= 60;
|
|
|
|
|
|
|
|
if (days > 0) {
|
|
|
|
snprintf(buf, size, "%i days %i:%02i:%02i", days,
|
|
|
|
hours, minutes, seconds);
|
|
|
|
} else if (hours > 0) {
|
|
|
|
snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
|
|
|
|
seconds);
|
|
|
|
} else {
|
|
|
|
snprintf(buf, size, "%i:%02i", minutes, seconds);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_mpd_elapsed(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
(void)obj;
|
2009-11-16 22:43:13 +00:00
|
|
|
format_media_player_time(p, p_max_size, mpd_info.elapsed);
|
2009-11-09 21:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_mpd_length(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
(void)obj;
|
2009-11-16 22:43:13 +00:00
|
|
|
format_media_player_time(p, p_max_size, mpd_info.length);
|
2009-11-09 21:11:06 +00:00
|
|
|
}
|
|
|
|
|
2009-11-25 00:57:28 +00:00
|
|
|
uint8_t mpd_percentage(struct text_object *obj)
|
2009-11-09 21:11:06 +00:00
|
|
|
{
|
|
|
|
(void)obj;
|
2009-11-25 00:57:28 +00:00
|
|
|
return round_to_int(mpd_info.progress * 100.0f);
|
2009-11-09 21:11:06 +00:00
|
|
|
}
|
|
|
|
|
2009-12-04 00:29:56 +00:00
|
|
|
double mpd_barval(struct text_object *obj)
|
2009-11-09 21:11:06 +00:00
|
|
|
{
|
2009-11-23 22:45:08 +00:00
|
|
|
(void)obj;
|
2009-12-04 00:29:56 +00:00
|
|
|
return mpd_info.progress;
|
2009-11-09 21:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_mpd_smart(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
int len = obj->data.i;
|
|
|
|
if (len == 0 || len > p_max_size)
|
|
|
|
len = p_max_size;
|
|
|
|
|
|
|
|
memset(p, 0, p_max_size);
|
2009-11-16 22:43:13 +00:00
|
|
|
if (mpd_info.artist && *mpd_info.artist &&
|
|
|
|
mpd_info.title && *mpd_info.title) {
|
|
|
|
snprintf(p, len, "%s - %s", mpd_info.artist,
|
|
|
|
mpd_info.title);
|
|
|
|
} else if (mpd_info.title && *mpd_info.title) {
|
|
|
|
snprintf(p, len, "%s", mpd_info.title);
|
|
|
|
} else if (mpd_info.artist && *mpd_info.artist) {
|
|
|
|
snprintf(p, len, "%s", mpd_info.artist);
|
|
|
|
} else if (mpd_info.file && *mpd_info.file) {
|
|
|
|
snprintf(p, len, "%s", mpd_info.file);
|
2009-11-09 21:11:06 +00:00
|
|
|
} else {
|
|
|
|
*p = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 22:37:01 +00:00
|
|
|
int check_mpd_playing(struct text_object *obj)
|
|
|
|
{
|
|
|
|
(void)obj;
|
2009-11-16 22:43:13 +00:00
|
|
|
return mpd_info.is_playing;
|
2009-11-16 22:37:01 +00:00
|
|
|
}
|
|
|
|
|
2009-11-09 21:11:06 +00:00
|
|
|
#define MPD_PRINT_GENERATOR(name, fmt) \
|
|
|
|
void print_mpd_##name(struct text_object *obj, char *p, int p_max_size) \
|
|
|
|
{ \
|
|
|
|
if (obj->data.i && obj->data.i < p_max_size) \
|
|
|
|
p_max_size = obj->data.i; \
|
2009-11-16 22:43:13 +00:00
|
|
|
snprintf(p, p_max_size, fmt, mpd_info.name); \
|
2009-11-09 21:11:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MPD_PRINT_GENERATOR(title, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(artist, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(album, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(random, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(repeat, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(track, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(name, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(file, "%s")
|
|
|
|
MPD_PRINT_GENERATOR(vol, "%d")
|
|
|
|
MPD_PRINT_GENERATOR(bitrate, "%d")
|
|
|
|
MPD_PRINT_GENERATOR(status, "%s")
|
|
|
|
|
|
|
|
#undef MPD_PRINT_GENERATOR
|