vitunes
 All Data Structures
player.h
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 "../paint.h"
24 
25 /* "static" backends (those that aren't dynamically loaded) */
26 #include "mplayer/mplayer.h"
27 #if defined(ENABLE_GSTREAMER)
28 # include "gstreamer/gstplayer.h"
29 #endif
30 
31 /*
32  * Available play-modes.
33  * Linear: Songs in the queue play in the order they appear
34  * Loop: Like linear, but when the end is reached, the queue restarts
35  * Random: Songs are chosen at random and play never ends
36  */
37 typedef enum {
38  MODE_LINEAR,
39  MODE_LOOP,
40  MODE_RANDOM
41 } playmode;
42 
43 
44 /* player setup/destroy functions */
45 void player_init(const char *backend,
46  void (message_handler)(char *fmt, ...),
47  void (error_handler)(char *fmt, ...));
48 void player_destroy();
49 
50 void player_set_queue(playlist *queue, int position);
51 
52 /* player control functions */
53 void player_play();
54 void player_stop();
55 void player_pause();
56 void player_seek(int seconds);
57 void player_skip_song(int num);
58 void player_volume_step(float percent);
59 
60 /* This is called periodically to monitor the backend player */
61 void player_monitor();
62 
63 
64 /* Available back-end players */
65 typedef enum {
66  BACKEND_MPLAYER,
67  BACKEND_GSTREAMER
68 } backend_id;
69 
70 
71 /* player backends */
72 typedef struct {
73  backend_id type;
74  char *name;
75 
76  /* for dynamically loaded backends */
77  bool dynamic; /* true if dlopen(3) required */
78  char *lib_name; /* name of dynamic lib */
79 
80  /* setup/destroy functions */
81  void (*start)(void);
82  void (*finish)(void);
83  void (*sigchld)(void);
84 
85  /* playback control */
86  void (*play)(const char*);
87  void (*stop)(void);
88  void (*pause)(void);
89  void (*seek)(int);
90  void (*volume_step)(float);
91 
92  /* query functions */
93  float (*position)(void);
94  float (*volume)(void);
95  bool (*playing)(void);
96  bool (*paused)(void);
97 
98  /* callback functions */
99  void (*set_callback_playnext)(void (*f)(void));
100  void (*set_callback_notice)(void (*f)(char *, ...));
101  void (*set_callback_error)(void (*f)(char *, ...));
102  void (*set_callback_fatal)(void (*f)(char *, ...));
103 
104  /* monitor function */
105  void (*monitor)(void);
107 extern player_backend_t player;
108 
109 
110 /* vitunes-specific record keeping about the player */
111 typedef struct {
112  playmode mode; /* playback mode */
113  playlist *queue; /* pointer to playlist */
114  int qidx; /* index into currently playing playlist */
115 
116  int rseed; /* seed used by rand(3) */
117 } player_info_t;
118 extern player_info_t player_info;
119 
120 #endif