1 /* 2 * Copyright (c) 2010, 2011 Ryan Flannery <ryan.flannery@gmail.com> 3 * 4 * Permission to use, copy, modify, and distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 #ifndef PLAYER_H 18 #define PLAYER_H 19 20 #include <err.h> 21 22 #include "playlist.h" 23 #include "compat.h" 24 #include "paint.h" 25 #include "debug.h" 26 27 /* "static" backends (those that aren't dynamically loaded) */ 28 #include "players/mplayer.h" 29 30 /* 31 * Available play-modes. 32 * Linear: Songs in the queue play in the order they appear 33 * Loop: Like linear, but when the end is reached, the queue restarts 34 * Random: Songs are chosen at random and play never ends 35 */ 36 typedef enum { 37 MODE_LINEAR, 38 MODE_LOOP, 39 MODE_RANDOM 40 } playmode; 41 42 43 /* player setup/destroy functions */ 44 void player_init(const char *backend); 45 void player_destroy(); 46 47 void player_set_queue(playlist *queue, int position); 48 49 /* player control functions */ 50 void player_play(); 51 void player_stop(); 52 void player_pause(); 53 void player_seek(int seconds); 54 void player_skip_song(int num); 55 void player_volume_step(float percent); 56 57 /* This is called periodically to monitor the backend player */ 58 void player_monitor(); 59 60 61 /* Available back-end players */ 62 typedef enum { 63 BACKEND_MPLAYER, 64 BACKEND_GSTREAMER 65 } backend_id; 66 67 68 /* player backends */ 69 typedef struct { 70 backend_id type; 71 char *name; 72 73 /* for dynamically loaded backends */ 74 bool dynamic; /* true if dlopen(3) required */ 75 char *lib_name; /* name of dynamic lib */ 76 77 /* setup/destroy functions */ 78 void (*start)(void); 79 void (*finish)(void); 80 void (*sigchld)(void); 81 82 /* playback control */ 83 void (*play)(const char*); 84 void (*stop)(void); 85 void (*pause)(void); 86 void (*seek)(int); 87 void (*volume_step)(float); 88 89 /* query functions */ 90 float (*position)(void); 91 float (*volume)(void); 92 bool (*playing)(void); 93 bool (*paused)(void); 94 95 /* callback functions */ 96 void (*set_callback_playnext)(void (*f)(void)); 97 void (*set_callback_notice)(void (*f)(char *, ...)); 98 void (*set_callback_error)(void (*f)(char *, ...)); 99 void (*set_callback_fatal)(void (*f)(char *, ...)); 100 101 /* monitor function */ 102 void (*monitor)(void); 103 } player_backend_t; 104 extern player_backend_t player; 105 106 107 /* vitunes-specific record keeping about the player */ 108 typedef struct { 109 playmode mode; /* playback mode */ 110 playlist *queue; /* pointer to playlist */ 111 int qidx; /* index into currently playing playlist */ 112 113 int rseed; /* seed used by rand(3) */ 114 } player_info_t; 115 extern player_info_t player_info; 116 117 #endif 118