File: track.h

package info (click to toggle)
cmus 2.7.1%2Bgit20160225-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,848 kB
  • sloc: ansic: 35,866; sh: 1,548; makefile: 260; python: 159
file content (105 lines) | stat: -rw-r--r-- 3,667 bytes parent folder | download | duplicates (2)
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 2008-2013 Various Authors
 * Copyright 2006 Timo Hirvonen
 *
 * 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, see <http://www.gnu.org/licenses/>.
 */

#ifndef CMUS_TRACK_H
#define CMUS_TRACK_H

#include "list.h"
#include "rbtree.h"
#include "iter.h"
#include "track_info.h"

struct simple_track {
	struct list_head node;
	struct rb_node tree_node;
	struct track_info *info;
	unsigned int marked : 1;
};

struct shuffle_track {
	struct simple_track simple_track;
	struct rb_node tree_node;
	double rand;
};

static inline struct track_info *shuffle_track_info(const struct shuffle_track *track)
{
	return ((struct simple_track *)track)->info;
}

static inline struct simple_track *to_simple_track(const struct list_head *item)
{
	return container_of(item, struct simple_track, node);
}

static inline struct simple_track *iter_to_simple_track(const struct iter *iter)
{
	return iter->data1;
}

static inline struct simple_track *tree_node_to_simple_track(const struct rb_node *node)
{
	return container_of(node, struct simple_track, tree_node);
}

static inline struct shuffle_track *tree_node_to_shuffle_track(const struct rb_node *node)
{
	return container_of(node, struct shuffle_track, tree_node);
}

/* NOTE: does not ref ti */
void simple_track_init(struct simple_track *track, struct track_info *ti);

/* refs ti */
struct simple_track *simple_track_new(struct track_info *ti);

int simple_track_get_prev(struct iter *);
int simple_track_get_next(struct iter *);

/* data is window */
int simple_track_search_get_current(void *data, struct iter *iter);
int simple_track_search_matches(void *data, struct iter *iter, const char *text);

struct shuffle_track *shuffle_list_get_next(struct rb_root *root, struct shuffle_track *cur,
		int (*filter)(const struct simple_track *));

struct shuffle_track *shuffle_list_get_prev(struct rb_root *root, struct shuffle_track *cur,
		int (*filter)(const struct simple_track *));

struct simple_track *simple_list_get_next(struct list_head *head, struct simple_track *cur,
		int (*filter)(const struct simple_track *));

struct simple_track *simple_list_get_prev(struct list_head *head, struct simple_track *cur,
		int (*filter)(const struct simple_track *));

void sorted_list_add_track(struct list_head *head, struct rb_root *tree_root, struct simple_track *track,
		const sort_key_t *keys, int tiebreak);
void sorted_list_remove_track(struct list_head *head, struct rb_root *tree_root, struct simple_track *track);
void sorted_list_rebuild(struct list_head *head, struct rb_root *tree_root, const sort_key_t *keys);
void rand_list_rebuild(struct list_head *head, struct rb_root *tree_root);

void list_add_rand(struct list_head *head, struct list_head *node, int nr);

int simple_list_for_each_marked(struct list_head *head,
		int (*cb)(void *data, struct track_info *ti), void *data, int reverse);

void shuffle_list_add(struct shuffle_track *track, struct rb_root *tree_root);
void shuffle_list_reshuffle(struct rb_root *tree_root);
void shuffle_insert(struct rb_root *root, struct shuffle_track *previous, struct shuffle_track *new);

#endif