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