foobar2000 SDK  2015-08-03
playlist_position_reference_tracker.h
Go to the documentation of this file.
2 public:
4  playlist_position_reference_tracker(bool p_trackitem = true) : playlist_callback_impl_base(~0), m_trackitem(p_trackitem), m_playlist(pfc_infinite), m_item(pfc_infinite) {}
5 
6  void on_items_added(t_size p_playlist,t_size p_start, const pfc::list_base_const_t<metadb_handle_ptr> & p_data,const bit_array & p_selection) {
7  if (p_playlist == m_playlist && m_item != pfc_infinite && p_start <= m_item) {
8  m_item += p_data.get_count();
9  }
10  }
11  void on_items_reordered(t_size p_playlist,const t_size * p_order,t_size p_count) {
12  if (p_playlist == m_playlist) {
13  if (m_item < p_count) {
15  } else {
16  m_item = pfc_infinite;
17  }
18  }
19  }
20 
21  void on_items_removed(t_size p_playlist,const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {
22  if (p_playlist == m_playlist) {
23  if (m_item < p_old_count) {
24  const t_size item_before = m_item;
25  for(t_size walk = p_mask.find_first(true,0,p_old_count); walk < p_old_count; walk = p_mask.find_next(true,walk,p_old_count)) {
26  if (walk < item_before) {
27  m_item--;
28  } else if (walk == item_before) {
29  if (m_trackitem) m_item = pfc_infinite;
30  break;
31  } else {
32  break;
33  }
34  }
35  if (m_item >= p_new_count) m_item = pfc_infinite;
36  } else {
37  m_item = pfc_infinite;
38  }
39  }
40  }
41 
42  //todo? could be useful in some cases
43  void on_items_replaced(t_size p_playlist,const bit_array & p_mask,const pfc::list_base_const_t<t_on_items_replaced_entry> & p_data) {}
44 
45  void on_playlist_created(t_size p_index,const char * p_name,t_size p_name_len) {
46  if (m_playlist != pfc_infinite && p_index <= m_playlist) m_playlist++;
47  }
48  void on_playlists_reorder(const t_size * p_order,t_size p_count) {
50  else m_playlist = pfc_infinite;
51  }
52  void on_playlists_removed(const bit_array & p_mask,t_size p_old_count,t_size p_new_count) {
53  if (m_playlist < p_old_count) {
54  const t_size playlist_before = m_playlist;
55  for(t_size walk = p_mask.find_first(true,0,p_old_count); walk < p_old_count; walk = p_mask.find_next(true,walk,p_old_count)) {
56  if (walk < playlist_before) {
57  m_playlist--;
58  } else if (walk == playlist_before) {
59  m_playlist = pfc_infinite;
60  break;
61  } else {
62  break;
63  }
64  }
65  } else {
66  m_playlist = pfc_infinite;
67  }
68  }
69 
71 private:
72  const bool m_trackitem;
73 };
t_size find_next(bool val, t_size previous, t_size max) const
Definition: bit_array.h:32
void on_items_reordered(t_size p_playlist, const t_size *p_order, t_size p_count)
t_size find_first(bool val, t_size start, t_size max) const
Definition: bit_array.h:31
void on_playlists_reorder(const t_size *p_order, t_size p_count)
Bit array interface class, constant version (you can only retrieve values). Range of valid indexes d...
Definition: bit_array.h:6
playlist_callback implementation helper - registers itself on creation / unregisters on destruction...
Definition: playlist.h:628
size_t t_size
Definition: int_types.h:48
virtual t_size get_count() const =0
void on_playlist_created(t_size p_index, const char *p_name, t_size p_name_len)
void on_items_replaced(t_size p_playlist, const bit_array &p_mask, const pfc::list_base_const_t< t_on_items_replaced_entry > &p_data)
static t_size g_find_reverse(const t_size *order, t_size val)
Insecure - may deadlock or crash on invalid permutation content. In theory faster than walking the pe...
Definition: other.cpp:90
void on_items_added(t_size p_playlist, t_size p_start, const pfc::list_base_const_t< metadb_handle_ptr > &p_data, const bit_array &p_selection)
void on_items_removed(t_size p_playlist, const bit_array &p_mask, t_size p_old_count, t_size p_new_count)
void on_playlists_removed(const bit_array &p_mask, t_size p_old_count, t_size p_new_count)