1 /*
2  *  Copyright (C) 2009-2015  Christian Heckendorf <heckendorfc@gmail.com>
3  *
4  *  This program is free software: you can redistribute it and/or modify
5  *  it under the terms of the GNU General Public License as published by
6  *  the Free Software Foundation, either version 3 of the License, or
7  *  (at your option) any later version.
8  *
9  *  This program is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  *  GNU General Public License for more details.
13  *
14  *  You should have received a copy of the GNU General Public License
15  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef _DEFS_H
19 #define _DEFS_H
20 
21 /*
22 #if WITH_ALSA==1
23 	#include <alsa/asoundlib.h>
24 #elif WITH_JACK==1
25 	#include <jack/jack.h>
26 #else
27 	#include <sys/fcntl.h>
28 	#include <sys/ioctl.h>
29 	#include <sys/soundcard.h>
30 #endif
31 */
32 
33 #include <regex.h>
34 #include <ctype.h>
35 #include <dlfcn.h>
36 #include <getopt.h>
37 #include <glob.h>
38 #include <pthread.h>
39 #include <signal.h>
40 #include <stdio.h>
41 #include <stdlib.h>
42 #include <string.h>
43 #include <sys/stat.h>
44 #include <sys/types.h>
45 #include <sys/wait.h>
46 #include <termios.h>
47 #include <unistd.h>
48 
49 #include <sqlite3.h>
50 
51 #if WITH_ALSA==1
52 	#include <alsa/asoundlib.h>
53 #elif WITH_JACK==1
54 	#include <jack/jack.h>
55 	#include <jack/ringbuffer.h>
56 	#include <samplerate.h>
57 #elif WITH_PULSE==1
58 	#include <pulse/simple.h>
59 #else
60 	#include <sys/soundcard.h>
61 	#include <sys/fcntl.h>
62 	#include <sys/ioctl.h>
63 #endif
64 
65 #define HARP_RET_ERR (-1)
66 #define HARP_RET_OK (0)
67 
68 #define DB_PATH "~/.harp/"
69 #define DB "harp.db"
70 #define DB_BATCH_SIZE (100)
71 
72 #define MI_TITLE_SIZE (200)
73 #define MI_TRACK_SIZE (9)
74 #define MI_ARTIST_SIZE (100)
75 #define MI_ALBUM_SIZE (100)
76 #define MI_YEAR_SIZE (4)
77 #define MI_TYPE_SIZE (30)
78 
79 #define ICONF_MAX_FORMAT_SIZE (64)
80 
81 #define OUTPUT_TAIL_SIZE (50)
82 
83 #define varstr(x) cppstr(x)
84 #define cppstr(x) #x
85 
86 #include "message.h"
87 
88 struct dbitem{
89 	char **result;	  // All data
90 	char **row;		  // A row of data (pointers to result strings)
91 	int current_row;  // Row to read on the next fetch
92 	int row_count;    // Total data rows (header not included)
93 	int column_count; // Total columns
94 	char *err;
95 };
96 
97 struct musicInfo{
98 	char *title;
99 	char *track;
100 	char *album;
101 	char *year;
102 	char *artist;
103 	int length;
104 };
105 
106 extern pthread_mutex_t outstatus;
107 extern sqlite3 *conn;
108 
109 struct playerHandles;
110 
111 typedef FILE *(*function_open)(const char *path, const char *mod);
112 typedef void (*function_close)(FILE *ffd);
113 typedef int (*function_filetype)(FILE *ffd);
114 typedef void (*function_meta)(FILE *ffd, struct musicInfo *mi);
115 typedef int (*function_play)(struct playerHandles *ph, char *key, int *totaltime);
116 typedef void (*function_seek)(struct playerHandles *ph,int modtime);
117 
118 struct pluginitem{
119 	void *module;
120 	function_open modopen;
121 	function_close modclose;
122 	function_filetype moddata;
123 	function_meta modmeta;
124 	function_play modplay;
125 	function_seek modseek;
126 	int id;
127 	char *contenttype;
128 	char *extension[5];
129 	char *name;
130 	//struct pluginitem *next;
131 };
132 
133 struct argument{
134 	char arg;
135 	char *subarg;
136 	unsigned int active;
137 } extern arglist[];
138 
139 enum cmdarg{
140 	ALIST=0,
141 	APLAY,
142 	ASHUFFLE,
143 	AINSERT,
144 	AEDIT,
145 	AEDITCMD,
146 	AEDITOLD,
147 	AVERBOSE,
148 	ATYPE,
149 	AZSHUFFLE,
150 	AADMIN,
151 	ADEVICE,
152 	AREPEAT,
153 	ANULL,
154 };
155 
156 enum filetype{
157 	FMP3=1,
158 	FASF,
159 	FM4A,
160 	FVOR,
161 	FFLAC
162 };
163 
164 enum portal_ret{
165 	PORTAL_RET_MAIN=-1,
166 	PORTAL_RET_QUIT=0,
167 	PORTAL_RET_PREV=1
168 };
169 
170 struct insert_data{
171 	int fmt;
172 	char *query;
173 	struct musicInfo *mi;
174 	struct dbitem *dbi;
175 	const char *path;
176 	struct pluginitem *plugin_head;
177 };
178 
179 struct lconf{
180 	int maxwidth;
181 	int exception;
182 }extern listconf;
183 
184 enum insertflag_types{
185 	MI_ARTIST=0,
186 	MI_ALBUM,
187 	MI_TITLE,
188 	MI_YEAR,
189 	MI_TRACK,
190 	MI_NULL,
191 };
192 
193 struct iconf{
194 	int **keyorder;
195 	regex_t *pattern;
196 	int format_length;
197 	int (*first_cb)(struct insert_data *data);
198 	int (*second_cb)(struct insert_data *data);
199 	int length;
200 }extern insertconf;
201 
202 struct dconf{
203 	char *dir;
204 	int log;
205 	FILE *playfd;
206 	char *playfilename;
207 	FILE *msgfd;
208 	char *msgfilename;
209 	int level;
210 }extern debugconf;
211 
212 struct commandOption{
213 	char opt;
214 	int (*function)(char *args, void *data);
215 	const char *help;
216 	void *data;
217 };
218 
219 struct dbnode{
220 	struct dbitem dbi;
221 	struct dbnode *prev;
222 	struct dbnode *next;
223 	int depth;
224 };
225 
226 struct titlequery_data{
227 	int count;
228 	int maxwidth;
229 	int *exception;
230 	int *exlen;
231 };
232 
233 struct IDList {
234 	int *songid;
235 	int length;
236 	int tempselectid;
237 };
238 
239 /* */
240 
241 struct playerflag{
242 	volatile int pause;
243 	int mute;
244 	volatile int update;
245 	volatile int rating;
246 	volatile int exit;
247 	volatile char mutec;
248 	volatile char pausec;
249 };
250 
251 enum defkeys{
252 	KEY_QUIT='q',
253 	KEY_NEXT='n',
254 	KEY_NEXT_NOUP='N',
255 	KEY_PREV='p',
256 	KEY_VOLUP='0',
257 	KEY_VOLDN='9',
258 	KEY_MUTE='m',
259 	KEY_PAUSE=' ',
260 	KEY_RATEUP='R',
261 	KEY_RATEDN='r',
262 	KEY_SEEK_UP='.',
263 	KEY_SEEK_DN=',',
264 	KEY_COMMAND=':',
265 	KEY_NULL=0
266 };
267 
268 enum decreturns{
269 	DEC_RET_ERROR=1,
270 	DEC_RET_SUCCESS,
271 	DEC_RET_NEXT,
272 	DEC_RET_NEXT_NOUP
273 };
274 
275 struct outputdetail{
276 	int curtime;
277 	int totaltime;
278 	int percent;
279 	int status;
280 	char tail[OUTPUT_TAIL_SIZE];
281 };
282 
283 struct playerHandles{
284 	FILE *ffd;
285 	char *device;
286 #if WITH_ALSA==1
287 	snd_pcm_t *sndfd;
288 	snd_pcm_hw_params_t *params;
289 #elif WITH_JACK==1
290 	jack_client_t *sndfd;
291 	jack_port_t *out_port1, *out_port2;
292 	const char **jack_ports;
293 	float vol_mod;
294 	jack_default_audio_sample_t *tmpbuf;
295 	jack_default_audio_sample_t *tmpbuf_out;
296 	jack_ringbuffer_t **outbuf;
297 	SRC_STATE **rs_state;
298 	int maxsize;
299 	int out_gain;
300 #elif WITH_PULSE==1
301 	pa_simple *sndfd;
302 	pa_sample_spec ss;
303 	//pa_context *sndfd;
304 	//pa_stream *stream;
305 	//pa_threaded_mainloop *mainloop;
306 #else
307 	int sndfd;
308 	int *params;
309 #endif
310 	int dec_enc,dec_chan,dec_rate,out_rate;
311 	struct playerflag *pflag;
312 	void *dechandle;
313 	struct outputdetail *outdetail;
314 	struct pluginitem **plugin_head;
315 };
316 
317 /* */
318 
319 #endif
320