-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathutils.c
101 lines (89 loc) · 2.8 KB
/
utils.c
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
/*
Waveform seekbar plugin for the DeaDBeeF audio player
Copyright (C) 2014 Christian Boxdörfer <[email protected]>
Based on sndfile-tools waveform by Erik de Castro Lopo.
waveform.c - v1.04
Copyright (C) 2007-2012 Erik de Castro Lopo <[email protected]>
Copyright (C) 2012 Robin Gareus <[email protected]>
Copyright (C) 2013 driedfruit <[email protected]>
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 2
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, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <fcntl.h>
#include <deadbeef/deadbeef.h>
#include "waveform.h"
#include "utils.h"
typedef struct cache_query_s
{
char *fname;
struct cache_query_s *next;
} cache_query_t;
static uintptr_t mutex = 0;
static cache_query_t *queue;
static cache_query_t *queue_tail;
int
queue_add (const char *fname)
{
if (!mutex) {
mutex = deadbeef->mutex_create ();
}
deadbeef->mutex_lock (mutex);
for (cache_query_t *q = queue; q; q = q->next) {
if (!strcmp (fname, q->fname)) {
// already queued
trace ("waveform: already queued. (%s)\n",fname);
deadbeef->mutex_unlock (mutex);
return 0;
}
}
cache_query_t *q = malloc (sizeof (cache_query_t));
memset (q, 0, sizeof (cache_query_t));
q->fname = strdup (fname);
if (queue_tail) {
queue_tail->next = q;
queue_tail = q;
}
else {
queue = queue_tail = q;
}
trace ("waveform: queued. (%s)\n",fname);
deadbeef->mutex_unlock (mutex);
return 1;
}
void
queue_pop (const char *fname)
{
deadbeef->mutex_lock (mutex);
cache_query_t *next = NULL;
for (cache_query_t *q = queue; q; q = q->next) {
if (!strcmp (fname, q->fname)) {
next = q->next;
if (q->fname) {
trace ("waveform: removed from queue. (%s)\n",q->fname);
free (q->fname);
}
free (q);
break;
}
}
queue = next;
if (!queue) {
queue_tail = NULL;
}
deadbeef->mutex_unlock (mutex);
}