A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2005 Ray Lambert
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include "config.h"
23#include "abrepeat.h"
24
25#ifdef AB_REPEAT_ENABLE
26
27unsigned int ab_A_marker IDATA_ATTR = AB_MARKER_NONE;
28unsigned int ab_B_marker IDATA_ATTR = AB_MARKER_NONE;
29
30
31static inline bool ab_A_marker_set(void)
32{
33 return ab_A_marker != AB_MARKER_NONE;
34}
35
36static inline bool ab_B_marker_set(void)
37{
38 return ab_B_marker != AB_MARKER_NONE;
39}
40
41
42void ab_end_of_track_report(void)
43{
44 if ( ab_A_marker_set() && ! ab_B_marker_set() )
45 {
46 ab_jump_to_A_marker();
47 }
48}
49
50#if 0
51void ab_repeat_init(void)
52{
53 static bool ab_initialized = false;
54 if ( ! ab_initialized )
55 {
56 ab_initialized = true;
57 }
58}
59#endif
60
61/* determines if the given song position is earlier than the A mark;
62intended for use in handling the jump NEXT and PREV commands */
63bool ab_before_A_marker(unsigned int song_position)
64{
65 return (song_position < ab_A_marker);
66}
67
68/* determines if the given song position is later than the A mark;
69intended for use in handling the jump PREV command */
70bool ab_after_A_marker(unsigned int song_position)
71{
72/* following is the size of the virtual A marker; we pretend that the A marker
73is larger than a single instant in order to give the user time to hit PREV again
74to jump back to the start of the song; it should be large enough to allow a
75reasonable amount of time for the typical user to react */
76#define A_MARKER_VIRTUAL_SIZE 1000
77 return (ab_A_marker != AB_MARKER_NONE)
78 && (song_position > (ab_A_marker+A_MARKER_VIRTUAL_SIZE));
79}
80
81void ab_jump_to_A_marker(void)
82{
83 audio_ff_rewind(ab_A_marker);
84}
85
86void ab_reset_markers(void)
87{
88 ab_A_marker = AB_MARKER_NONE;
89 ab_B_marker = AB_MARKER_NONE;
90}
91
92/* following is a fudge factor to help overcome the latency between
93the time the user hears the passage they want to mark and the time
94they actually press the button; the actual song position is adjusted
95by this fudge factor when setting a mark */
96#define EAR_TO_HAND_LATENCY_FUDGE 200
97
98void ab_set_A_marker(unsigned int song_position)
99{
100 ab_A_marker = song_position;
101 ab_A_marker = (ab_A_marker >= EAR_TO_HAND_LATENCY_FUDGE)
102 ? (ab_A_marker - EAR_TO_HAND_LATENCY_FUDGE) : AB_MARKER_NONE;
103 /* check if markers are out of order */
104 if (ab_A_marker > ab_B_marker)
105 ab_B_marker = AB_MARKER_NONE;
106}
107
108void ab_set_B_marker(unsigned int song_position)
109{
110 ab_B_marker = song_position;
111 ab_B_marker = (ab_B_marker >= EAR_TO_HAND_LATENCY_FUDGE)
112 ? (ab_B_marker - EAR_TO_HAND_LATENCY_FUDGE) : AB_MARKER_NONE;
113 /* check if markers are out of order */
114 if (ab_B_marker < ab_A_marker)
115 ab_A_marker = AB_MARKER_NONE;
116}
117
118bool ab_get_A_marker(unsigned *song_position)
119{
120 *song_position = ab_A_marker;
121 return ab_A_marker_set();
122}
123
124bool ab_get_B_marker(unsigned *song_position)
125{
126 *song_position = ab_B_marker;
127 return ab_B_marker_set();
128}
129
130#endif /* AB_REPEAT_ENABLE */