1 /* simple-libmpd.h 2 * 3 * Copyright (c) 2006-2012 Landry Breuil <landry at xfce.org> 4 * This code is licenced under a BSD-style licence. 5 * (OpenBSD variant modeled after the ISC licence) 6 * All rights reserved. 7 * Permission to use, copy, modify, and distribute this software for any 8 * purpose with or without fee is hereby granted, provided that the above 9 * copyright notice and this permission notice appear in all copies. 10 * 11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 /* for gchar and g_new conveniences */ 21 #include <gtk/gtk.h> 22 23 #define MPD_PLAYER_STOP 1 24 #define MPD_PLAYER_PLAY 2 25 #define MPD_PLAYER_PAUSE 3 26 #define MPD_OK 0 27 #define MPD_FAILED 1 28 #define MPD_NOTOK 2 29 #define MPD_WELCOME_MESSAGE "OK MPD " 30 #define MAXBUFLEN 1000 31 32 #define MPD_ERROR_NOSOCK 9 33 #define MPD_ERROR_TIMEOUT 10 /* timeout trying to talk to mpd */ 34 #define MPD_ERROR_SYSTEM 11 /* system error */ 35 #define MPD_ERROR_UNKHOST 12 /* unknown host */ 36 #define MPD_ERROR_CONNPORT 13 /* problems connecting to port on host */ 37 #define MPD_ERROR_NOTMPD 14 /* mpd not running on port at host */ 38 #define MPD_ERROR_NORESPONSE 15 /* no response on attempting to connect */ 39 #define MPD_ERROR_SENDING 16 /* error sending command */ 40 #define MPD_ERROR_CONNCLOSED 17 /* connection closed by mpd */ 41 42 43 typedef struct { 44 char* file; 45 char* artist; 46 char* album; 47 char* track; 48 char* title; 49 int pos; 50 int id; 51 } mpd_Song; 52 53 typedef struct { 54 int id; 55 char* name; 56 int enabled; 57 } mpd_Output; 58 59 typedef struct { 60 gchar* host; 61 int port; 62 gchar* pass; 63 int socket; 64 int status; 65 int curvol; 66 int song; 67 int songid; 68 int repeat; 69 int random; 70 int playlistlength; 71 mpd_Song* cursong; 72 int error; 73 char buffer[MAXBUFLEN*2]; 74 int buflen; 75 } MpdObj; 76 77 typedef enum { 78 MPD_DATA_TYPE_SONG, 79 MPD_DATA_TYPE_OUTPUT_DEV 80 } MpdDataType; 81 82 /* here, i must cheat, too hard to follow libmpd's behaviour */ 83 typedef struct { 84 /* holds type = song or output */ 85 MpdDataType type; 86 /* ptr to current song */ 87 mpd_Song* song; 88 /* vector of all songs in playlist */ 89 mpd_Song* allsongs; 90 /* ptr to current output */ 91 mpd_Output* output_dev; 92 /* vector of all outputs */ 93 mpd_Output** alloutputs; 94 int nb; 95 int cur; 96 } MpdData; 97 98 MpdObj* mpd_new(char*, int, char*); 99 void mpd_free(MpdObj*); 100 void mpd_connect(MpdObj*); 101 void mpd_disconnect(MpdObj*); 102 int mpd_status_get_volume(MpdObj*); 103 void mpd_status_set_volume(MpdObj*, int); 104 int mpd_status_update(MpdObj*); 105 int mpd_player_get_state(MpdObj*); 106 int mpd_player_prev(MpdObj*); 107 int mpd_player_next(MpdObj*); 108 int mpd_player_stop(MpdObj*); 109 int mpd_player_pause(MpdObj*); 110 int mpd_player_play(MpdObj*); 111 int mpd_player_play_id(MpdObj*, int); 112 int mpd_player_get_current_song_pos(MpdObj*); 113 MpdData* mpd_playlist_get_changes(MpdObj*, int); 114 MpdData* mpd_data_get_next(MpdData*); 115 mpd_Song* mpd_playlist_get_current_song(MpdObj*); 116 MpdData* mpd_server_get_output_devices(MpdObj*); 117 int mpd_server_set_output_device (MpdObj*, int, int); 118 int mpd_playlist_get_playlist_length(MpdObj*); 119 int mpd_check_error(MpdObj*); 120 void mpd_set_hostname(MpdObj*, char*); 121 void mpd_set_password(MpdObj*, char*); 122 void mpd_send_password(MpdObj*); 123 void mpd_set_port(MpdObj*, int); 124 int mpd_player_set_random(MpdObj*,int); 125 int mpd_player_get_random(MpdObj*); 126 int mpd_player_set_repeat(MpdObj*,int); 127 int mpd_player_get_repeat(MpdObj*); 128