forked from oligau/xwax-1.5-osc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cues.c
105 lines (83 loc) · 2.18 KB
/
cues.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
102
103
104
105
/*
* Copyright (C) 2014 Mark Hills <mark@xwax.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2, as published by the Free Software Foundation.
*
* 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 version 2 for more details.
*
* You should have received a copy of the GNU General Public License
* version 2 along with this program; if not, write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301, USA.
*
*/
#include <assert.h>
#include <stdlib.h>
#include "cues.h"
#include "debug.h"
void cues_reset(struct cues *q)
{
size_t n;
for (n = 0; n < MAX_CUES; n++)
q->position[n] = CUE_UNSET;
}
/*
* Unset the given cue point
*/
void cues_unset(struct cues *q, unsigned int label)
{
debug("clearing cue point %d", label);
q->position[label] = CUE_UNSET;
}
void cues_set(struct cues *q, unsigned int label, double position)
{
debug("setting cue point %d to %0.2f", label, position);
assert(label < MAX_CUES);
q->position[label] = position;
}
double cues_get(const struct cues *q, unsigned int label)
{
assert(label < MAX_CUES);
return q->position[label];
}
/*
* Return: the previous cue point before the current position, or CUE_UNSET
*/
double cues_prev(const struct cues *q, double current)
{
size_t n;
double r;
r = CUE_UNSET;
for (n = 0; n < MAX_CUES; n++) {
double p;
p = q->position[n];
if (p == CUE_UNSET)
continue;
if (p > r && p < current)
r = p;
}
return r;
}
/*
* Return: the next cue point after the given position, or CUE_UNSET
*/
double cues_next(const struct cues *q, double current)
{
size_t n;
double r;
r = CUE_UNSET;
for (n = 0; n < MAX_CUES; n++) {
double p;
p = q->position[n];
if (p == CUE_UNSET)
continue;
if (p < r && p > current)
r = p;
}
return r;
}