libmpd 11.8.17
libmpd.h File Reference
#include "libmpdclient.h"
#include "libmpd-version.h"
#include "libmpd-player.h"
#include "libmpd-status.h"
#include "libmpd-database.h"
#include "libmpd-playlist.h"
#include "libmpd-strfsong.h"
#include "libmpd-sticker.h"

Go to the source code of this file.

Data Structures

struct  _MpdData
 

Macros

#define __MPD_LIB__
 
#define TRUE   1
 
#define FALSE   0
 

Typedefs

typedef struct _MpdObj MpdObj
 
typedef struct _MpdData MpdData
 
typedef void(* StatusChangedCallback) (MpdObj *mi, ChangedStatusType what, void *userdata)
 
typedef int(* ErrorCallback) (MpdObj *mi, int id, char *msg, void *userdata)
 
typedef void(* ConnectionChangedCallback) (MpdObj *mi, int connect, void *userdata)
 

Enumerations

enum  MpdError {
  MPD_OK = 0 , MPD_ARGS_ERROR = -5 , MPD_NOT_CONNECTED = -10 , MPD_STATUS_FAILED = -20 ,
  MPD_LOCK_FAILED = -30 , MPD_STATS_FAILED = -40 , MPD_SERVER_ERROR = -50 , MPD_SERVER_NOT_SUPPORTED = -51 ,
  MPD_DATABASE_PLAYLIST_EXIST = -60 , MPD_PLAYLIST_EMPTY = -70 , MPD_PLAYLIST_QUEUE_EMPTY = -75 , MPD_PLAYER_NOT_PLAYING = -80 ,
  MPD_TAG_NOT_FOUND = -90 , MPD_PLAYLIST_LOAD_FAILED = -100 , MPD_FATAL_ERROR = -1000
}
 
enum  MpdServerCommand { MPD_SERVER_COMMAND_ALLOWED = TRUE , MPD_SERVER_COMMAND_NOT_ALLOWED = FALSE , MPD_SERVER_COMMAND_NOT_SUPPORTED = -1 , MPD_SERVER_COMMAND_ERROR = -2 }
 
enum  MpdDataType {
  MPD_DATA_TYPE_NONE , MPD_DATA_TYPE_TAG , MPD_DATA_TYPE_DIRECTORY , MPD_DATA_TYPE_SONG ,
  MPD_DATA_TYPE_PLAYLIST , MPD_DATA_TYPE_OUTPUT_DEV
}
 
enum  ChangedStatusType {
  MPD_CST_PLAYLIST = 0x0001 , MPD_CST_SONGPOS = 0x0002 , MPD_CST_SONGID = 0x0004 , MPD_CST_DATABASE = 0x0008 ,
  MPD_CST_UPDATING = 0x0010 , MPD_CST_VOLUME = 0x0020 , MPD_CST_TOTAL_TIME = 0x0040 , MPD_CST_ELAPSED_TIME = 0x0080 ,
  MPD_CST_CROSSFADE = 0x0100 , MPD_CST_RANDOM = 0x0200 , MPD_CST_REPEAT = 0x0400 , MPD_CST_AUDIO = 0x0800 ,
  MPD_CST_STATE = 0x1000 , MPD_CST_PERMISSION = 0x2000 , MPD_CST_BITRATE = 0x4000 , MPD_CST_AUDIOFORMAT = 0x8000 ,
  MPD_CST_STORED_PLAYLIST = 0x20000 , MPD_CST_SERVER_ERROR = 0x40000 , MPD_CST_OUTPUT = 0x80000 , MPD_CST_STICKER = 0x100000 ,
  MPD_CST_NEXTSONG = 0x200000 , MPD_CST_SINGLE_MODE = 0x400000 , MPD_CST_CONSUME_MODE = 0x800000 , MPD_CST_REPLAYGAIN = 0x1000000
}
 
enum  MpdServerReplaygainMode { MPD_SERVER_REPLAYGAIN_MODE_OFF = 0 , MPD_SERVER_REPLAYGAIN_MODE_TRACK = 1 , MPD_SERVER_REPLAYGAIN_MODE_ALBUM = 2 , MPD_SERVER_REPLAYGAIN_MODE_AUTO = 3 }
 

Functions

MpdObjmpd_new_default ()
 
MpdObjmpd_new (char *hostname, int port, char *password)
 
int mpd_set_hostname (MpdObj *mi, char *hostname)
 
const char * mpd_get_hostname (MpdObj *mi)
 
int mpd_set_password (MpdObj *mi, const char *password)
 
int mpd_set_port (MpdObj *mi, int port)
 
int mpd_set_connection_timeout (MpdObj *mi, float timeout)
 
int mpd_connect_real (MpdObj *mi, mpd_Connection *connection)
 
int mpd_connect (MpdObj *mi)
 
int mpd_disconnect (MpdObj *mi)
 
int mpd_check_connected (MpdObj *mi)
 
int mpd_check_error (MpdObj *mi)
 
void mpd_free (MpdObj *mi)
 
int mpd_send_password (MpdObj *mi)
 
void mpd_signal_connect_status_changed (MpdObj *mi, StatusChangedCallback status_changed, void *userdata)
 
void mpd_signal_connect_error (MpdObj *mi, ErrorCallback error, void *userdata)
 
void mpd_signal_connect_connection_changed (MpdObj *mi, ConnectionChangedCallback connection_changed, void *userdata)
 
int mpd_data_is_last (MpdData const *data)
 
void mpd_data_free (MpdData *data)
 
MpdDatampd_data_get_next (MpdData *data)
 
MpdDatampd_data_get_first (MpdData const *data)
 
MpdDatampd_data_delete_item (MpdData *data)
 
MpdDatampd_server_get_output_devices (MpdObj *mi)
 
int mpd_server_set_output_device (MpdObj *mi, int device_id, int state)
 
long unsigned mpd_server_get_database_update_time (MpdObj *mi)
 
int mpd_server_check_version (MpdObj *mi, int major, int minor, int micro)
 
char * mpd_server_get_version (MpdObj *mi)
 
int mpd_server_check_command_allowed (MpdObj *mi, const char *command)
 
char ** mpd_server_get_url_handlers (MpdObj *mi)
 
char ** mpd_server_get_tag_types (MpdObj *mi)
 
int mpd_misc_get_tag_by_name (char *name)
 
int mpd_server_has_idle (MpdObj *mi)
 
int mpd_server_tag_supported (MpdObj *mi, int tag)
 
MpdServerReplaygainMode mpd_server_get_replaygain_mode (MpdObj *mi)
 
int mpd_server_set_replaygain_mode (MpdObj *mi, MpdServerReplaygainMode mode)
 

Variables

char * libmpd_version
 

Macro Definition Documentation

◆ __MPD_LIB__

#define __MPD_LIB__

Definition at line 34 of file libmpd.h.

◆ FALSE

#define FALSE   0

Defined for readability: False is 0.

Definition at line 49 of file libmpd.h.

◆ TRUE

#define TRUE   1

Defined for readability: True is 1.

Definition at line 44 of file libmpd.h.

Typedef Documentation

◆ ConnectionChangedCallback

typedef void(* ConnectionChangedCallback) (MpdObj *mi, int connect, void *userdata)
Parameters
mia MpdObj
connect1 if you are now connected, 0 if you are disconnected.
userdatauser data set when the signal handler was connected. Signal is triggered when the connection state changes.

Definition at line 434 of file libmpd.h.

◆ ErrorCallback

typedef int(* ErrorCallback) (MpdObj *mi, int id, char *msg, void *userdata)
Parameters
mia MpdObj
idThe error Code.
msghuman-readable informative error message.
userdatauser data set when the signal handler was connected. This signal is called when an error has occurred in the communication with mpd.

return: TRUE if libmpd should disconnect.

Examples
testcase.c.

Definition at line 423 of file libmpd.h.

◆ MpdObj

typedef struct _MpdObj MpdObj

The Main Mpd Object. Don't access any of the internal values directly, but use the provided functions.

Definition at line 100 of file libmpd.h.

◆ StatusChangedCallback

typedef void(* StatusChangedCallback) (MpdObj *mi, ChangedStatusType what, void *userdata)
Parameters
mia MpdObj
whata ChangedStatusType that determines what changed triggered the signal. This is a bitmask.
userdatauser data set when the signal handler was connected.

Signal that gets called when the state of mpd has changed. Look ChangedStatusType to see the possible events.

Examples
testcase.c.

Definition at line 409 of file libmpd.h.

Enumeration Type Documentation

◆ ChangedStatusType

Bitwise enumeration to determine what triggered the status_changed signals This is used in combination with the StatusChangedCallback

void status_changed_callback(MpdObj *mi, ChangedStatusType what)
{
if(what&MPD_CST_SONGID)
{
// act on song change
}
if(what&MPD_CST_RANDOM)
{
// act on random change
}
// etc.
}
ChangedStatusType
Definition libmpd.h:349
@ MPD_CST_RANDOM
Definition libmpd.h:369
@ MPD_CST_SONGID
Definition libmpd.h:355
struct _MpdObj MpdObj
Definition libmpd.h:100
Enumerator
MPD_CST_PLAYLIST 

The playlist has changed

MPD_CST_SONGPOS 

The song position of the playing song has changed

MPD_CST_SONGID 

The songid of the playing song has changed

MPD_CST_DATABASE 

The database has changed.

MPD_CST_UPDATING 

the state of updating the database has changed.

MPD_CST_VOLUME 

the volume has changed

MPD_CST_TOTAL_TIME 

The total time of the currently playing song has changed

MPD_CST_ELAPSED_TIME 

The elapsed time of the current song has changed.

MPD_CST_CROSSFADE 

The crossfade time has changed.

MPD_CST_RANDOM 

The random state is changed.

MPD_CST_REPEAT 

repeat state is changed.

MPD_CST_AUDIO 

Not implemented

MPD_CST_STATE 

The state of the player has changed.

MPD_CST_PERMISSION 

The permissions the client has, has changed.

MPD_CST_BITRATE 

The bitrate of the playing song has changed.

MPD_CST_AUDIOFORMAT 

the audio format of the playing song changed.

MPD_CST_STORED_PLAYLIST 

the queue has changed

MPD_CST_SERVER_ERROR 

server error

MPD_CST_OUTPUT 

output changed

MPD_CST_STICKER 

Sticker changed

MPD_CST_NEXTSONG 

Next song changed

MPD_CST_SINGLE_MODE 

Single mode changed

MPD_CST_CONSUME_MODE 

Consume mode changed

MPD_CST_REPLAYGAIN 

Replaygain mode changed

Definition at line 349 of file libmpd.h.

◆ MpdError

enum MpdError

Enum that represent the errors libmpd functions can return

Enumerator
MPD_OK 

Command/function completed succesfull

MPD_ARGS_ERROR 

Error in the function's arguments

MPD_NOT_CONNECTED 

Action failed because there is no connection to an mpd daemon

MPD_STATUS_FAILED 

Failed to grab status

MPD_LOCK_FAILED 

Connection is still locked

MPD_STATS_FAILED 

Failed to grab status

MPD_SERVER_ERROR 

Mpd server returned an error

MPD_SERVER_NOT_SUPPORTED 

Mpd doesn't support this feature

MPD_DATABASE_PLAYLIST_EXIST 

The playlist already exists

MPD_PLAYLIST_EMPTY 

Playlist is empty

MPD_PLAYLIST_QUEUE_EMPTY 

Playlist queue is empty

MPD_PLAYER_NOT_PLAYING 

Player isn't Playing

MPD_TAG_NOT_FOUND 

Tag Item not found

MPD_PLAYLIST_LOAD_FAILED 
MPD_FATAL_ERROR 

Fatal error, something I am not sure what todo with

Definition at line 58 of file libmpd.h.

◆ MpdServerCommand

enum that represents the state of a command.

Enumerator
MPD_SERVER_COMMAND_ALLOWED 
MPD_SERVER_COMMAND_NOT_ALLOWED 
MPD_SERVER_COMMAND_NOT_SUPPORTED 
MPD_SERVER_COMMAND_ERROR 

Definition at line 106 of file libmpd.h.

◆ MpdServerReplaygainMode

Enumerator
MPD_SERVER_REPLAYGAIN_MODE_OFF 
MPD_SERVER_REPLAYGAIN_MODE_TRACK 
MPD_SERVER_REPLAYGAIN_MODE_ALBUM 
MPD_SERVER_REPLAYGAIN_MODE_AUTO 

Definition at line 664 of file libmpd.h.

Function Documentation

◆ mpd_check_connected()

int mpd_check_connected ( MpdObj * mi)
Parameters
mia MpdObj

Checks if MpdObj is connected

Returns
True when connected

◆ mpd_check_error()

int mpd_check_error ( MpdObj * mi)
Parameters
mia MpdObj

Checks if there was an error

Returns
True when there is an error

◆ mpd_connect()

int mpd_connect ( MpdObj * mi)
Parameters
mia MpdObj

Connect to the mpd daemon. Warning: mpd_connect connects anonymous, to authenticate use mpd_send_password

Returns
returns a MpdError, MPD_OK when successful
Examples
testcase.c.

◆ mpd_connect_real()

int mpd_connect_real ( MpdObj * mi,
mpd_Connection * connection )

◆ mpd_data_delete_item()

MpdData * mpd_data_delete_item ( MpdData * data)
Parameters
dataa MpdData item

removes the passed MpdData from the underlying list, and returns the element before data

Returns
a MpdData list

◆ mpd_data_free()

void mpd_data_free ( MpdData * data)
Parameters
dataa MpdData

Free's a MpdData List

◆ mpd_data_get_first()

MpdData * mpd_data_get_first ( MpdData const * data)
Parameters
dataa MpdData

Returns the first MpdData in the list.

Returns
The first MpdData or NULL

◆ mpd_data_get_next()

MpdData * mpd_data_get_next ( MpdData * data)
Parameters
dataa MpdData

Returns the next MpdData in the list. If it's the last item in the list, it will free the list.

You can iterate through a list like this and have it freed afterwards.

for(data = mpd_database_get_albums(mi);data != NULL; data = mpd_data_get_next(data))
{
// do your thing
}
MpdData * mpd_database_get_albums(MpdObj *mi, const char *artist)
MpdData * mpd_data_get_next(MpdData *data)
Returns
The next MpdData or NULL
Examples
testcase.c.

◆ mpd_data_is_last()

int mpd_data_is_last ( MpdData const * data)
Parameters
dataa MpdData

Checks if the passed MpdData is the last in a list

Returns
TRUE when data is the last in the list.

◆ mpd_disconnect()

int mpd_disconnect ( MpdObj * mi)
Parameters
miThe MpdObj to disconnect

Disconnect the current connection

Returns
MPD_OK (always)

◆ mpd_free()

void mpd_free ( MpdObj * mi)
Parameters
mia MpdObj

Free the MpdObj, when still connected the connection will be disconnected first

Examples
testcase.c.

◆ mpd_get_hostname()

const char * mpd_get_hostname ( MpdObj * mi)
Parameters
mia MpdObj

gets the set hostname

Returns
a const char representing the hostname

◆ mpd_misc_get_tag_by_name()

int mpd_misc_get_tag_by_name ( char * name)
Parameters
namea NULL terminated string

gets the Matching MpdDataType matching at the string

Returns
a MpdDataType

◆ mpd_new()

MpdObj * mpd_new ( char * hostname,
int port,
char * password )
Parameters
hostnameThe hostname to connect to
portThe port to connect to
passwordThe password to use for the connection, or NULL for no password

Create a new MpdObj with provided settings:

Returns
the new MpdObj
Examples
testcase.c.

◆ mpd_new_default()

MpdObj * mpd_new_default ( )

mpd_new_default

Create a new MpdObj with default settings. Hostname will be set to "localhost". Port will be 6600.

same as calling:

mpd_new("localhost",6600,NULL);
MpdObj * mpd_new(char *hostname, int port, char *password)
Returns
the new MpdObj

◆ mpd_send_password()

int mpd_send_password ( MpdObj * mi)
Parameters
mia MpdObj

Forces libmpd to re-authenticate itself.

When successful it will trigger the "permission" changed signal.

Returns
: a MpdError
Examples
testcase.c.

◆ mpd_server_check_command_allowed()

int mpd_server_check_command_allowed ( MpdObj * mi,
const char * command )
Parameters
mia MpdObj
commandthe command to check

Checks if the user is allowed to execute the command and if the server supports it

Returns
Returns MpdServerCommand
Examples
testcase.c.

◆ mpd_server_check_version()

int mpd_server_check_version ( MpdObj * mi,
int major,
int minor,
int micro )
Parameters
mia MpdObj
majorthe major version number
minorthe minor version number
microthe micro version number

Checks if the connected mpd server version is equal or higher.

Returns
TRUE when version of mpd equals or is higher, else FALSE

◆ mpd_server_get_database_update_time()

long unsigned mpd_server_get_database_update_time ( MpdObj * mi)
Parameters
mia MpdObj

Gets a unix timestamp of the last time the database was updated.

Returns
unix Timestamp

◆ mpd_server_get_output_devices()

MpdData * mpd_server_get_output_devices ( MpdObj * mi)
Parameters
mia MpdObj

Returns a list of audio output devices stored in a MpdData list

Returns
a MpdData

◆ mpd_server_get_replaygain_mode()

MpdServerReplaygainMode mpd_server_get_replaygain_mode ( MpdObj * mi)

◆ mpd_server_get_tag_types()

char ** mpd_server_get_tag_types ( MpdObj * mi)
Parameters
mia MpdObj
Returns
an array with supported tag types. (NULL Terminated). Result must be freed.

◆ mpd_server_get_url_handlers()

char ** mpd_server_get_url_handlers ( MpdObj * mi)
Parameters
mia MpdObj
Returns
an array with urlhandlers (NULL terminated). Result must be freed.

◆ mpd_server_get_version()

char * mpd_server_get_version ( MpdObj * mi)
Parameters
mia MpdObj
Returns
a string with version or NULL when not connected

◆ mpd_server_has_idle()

int mpd_server_has_idle ( MpdObj * mi)
Parameters
mia MpdObj

Reports if the connected mpd supports the idle command.

Returns
a boolean, TRUE if it has idle support

◆ mpd_server_set_output_device()

int mpd_server_set_output_device ( MpdObj * mi,
int device_id,
int state )
Parameters
mia MpdObj
device_idThe id of the output device
stateThe state to change the output device to, 1 is enable, 0 is disable.

Enable or Disable an audio output device

Returns
0 if successful

◆ mpd_server_set_replaygain_mode()

int mpd_server_set_replaygain_mode ( MpdObj * mi,
MpdServerReplaygainMode mode )

◆ mpd_server_tag_supported()

int mpd_server_tag_supported ( MpdObj * mi,
int tag )
Parameters
mia MpdObj
taga mpd_TagItems

Returns if mpd supports this tag.

return 1 if support 0 if not

◆ mpd_set_connection_timeout()

int mpd_set_connection_timeout ( MpdObj * mi,
float timeout )
Parameters
mia MpdObj
timeoutA timeout (in seconds)

Set the timeout of the connection. If already connected the timeout of the running connection

Returns
a MpdError. (MPD_OK if everything went ok)
Examples
testcase.c.

◆ mpd_set_hostname()

int mpd_set_hostname ( MpdObj * mi,
char * hostname )
Parameters
mia MpdObj
hostnameThe new hostname to use

set the hostname

Returns
a MpdError. (MPD_OK if everything went ok)

◆ mpd_set_password()

int mpd_set_password ( MpdObj * mi,
const char * password )
Parameters
mia MpdObj
passwordThe new password to use

Set the password

Returns
a MpdError. (MPD_OK if everything went ok)
Examples
testcase.c.

◆ mpd_set_port()

int mpd_set_port ( MpdObj * mi,
int port )
Parameters
mia MpdObj
portThe port to use. (Default: 6600)

Set the Port number

Returns
a MpdError. (MPD_OK if everything went ok)

◆ mpd_signal_connect_connection_changed()

void mpd_signal_connect_connection_changed ( MpdObj * mi,
ConnectionChangedCallback connection_changed,
void * userdata )
Parameters
mia MpdObj
connection_changeda ConnectionChangedCallback
userdatauser data passed to the callback

◆ mpd_signal_connect_error()

void mpd_signal_connect_error ( MpdObj * mi,
ErrorCallback error,
void * userdata )
Parameters
mia MpdObj
errora ErrorCallback
userdatauser data passed to the callback
Examples
testcase.c.

◆ mpd_signal_connect_status_changed()

void mpd_signal_connect_status_changed ( MpdObj * mi,
StatusChangedCallback status_changed,
void * userdata )
Parameters
mia MpdObj
status_changeda StatusChangedCallback
userdatauser data passed to the callback
Examples
testcase.c.

Variable Documentation

◆ libmpd_version

char* libmpd_version
extern

Copyright 2006 Qball Cow