foobar2000 SDK  2015-01-14
autoplaylist.h
Go to the documentation of this file.
1 /*
2  Autoplaylist APIs
3  These APIs were introduced in foobar2000 0.9.5, to reduce amount of code required to create your own autoplaylists. Creation of autoplaylists is was also possible before through playlist lock APIs.
4  In most cases, you'll want to turn regular playlists into autoplaylists using the following code:
5  static_api_ptr_t<autoplaylist_manager>()->add_client_simple(querypattern, sortpattern, playlistindex, forceSort ? autoplaylist_flag_sort : 0);
6  If you require more advanced functionality, such as using your own code to filter which part of user's Media Library should be placed in specific autoplaylist, you must implement autoplaylist_client (to let autoplaylist manager invoke your handlers when needed) / autoplaylist_client_factory (to re-instantiate your autoplaylist_client after a foobar2000 restart cycle).
7 */
8 
9 enum {
12 };
14 class NOVTABLE autoplaylist_client : public service_base {
15  FB2K_MAKE_SERVICE_INTERFACE(autoplaylist_client,service_base)
16 public:
17  virtual GUID get_guid() = 0;
19  virtual void filter(metadb_handle_list_cref data, bool * out) = 0;
21  virtual bool sort(metadb_handle_list_cref p_items,t_size * p_orderbuffer) = 0;
23  virtual void get_configuration(stream_writer * p_stream,abort_callback & p_abort) = 0;
24 
25  virtual void show_ui(t_size p_source_playlist) = 0;
26 
28  template<typename t_array> void get_configuration(t_array & p_out) {
29  PFC_STATIC_ASSERT( sizeof(p_out[0]) == 1 );
30  typedef pfc::array_t<t_uint8,pfc::alloc_fast_aggressive> t_temp; t_temp temp;
32  p_out = temp;
33  }
34 };
35 
37 
40  FB2K_MAKE_SERVICE_INTERFACE(autoplaylist_client_v2, autoplaylist_client);
41 public:
46  virtual void set_full_refresh_notify(completion_notify::ptr notify) = 0;
47 
49  virtual bool show_ui_available() = 0;
50 
52  virtual void get_display_name(pfc::string_base & out) = 0;
53 };
54 
56 class NOVTABLE autoplaylist_client_factory : public service_base {
57  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(autoplaylist_client_factory)
58 public:
60  virtual GUID get_guid() = 0;
62  virtual autoplaylist_client_ptr instantiate(stream_reader * p_stream,t_size p_sizehint,abort_callback & p_abort) = 0;
63 };
64 
66 
67 PFC_DECLARE_EXCEPTION(exception_autoplaylist_already_owned,exception_autoplaylist,"This playlist is already an autoplaylist")
68 PFC_DECLARE_EXCEPTION(exception_autoplaylist_not_owned,exception_autoplaylist,"This playlist is not an autoplaylist")
69 PFC_DECLARE_EXCEPTION(exception_autoplaylist_lock_failure,exception_autoplaylist,"Playlist could not be locked")
70 
71 
73 class NOVTABLE autoplaylist_manager : public service_base {
74 public:
77  virtual void add_client(autoplaylist_client_ptr p_client,t_size p_playlist,t_uint32 p_flags) = 0;
78  virtual bool is_client_present(t_size p_playlist) = 0;
80  virtual autoplaylist_client_ptr query_client(t_size p_playlist) = 0;
81  virtual void remove_client(t_size p_playlist) = 0;
85  virtual void add_client_simple(const char * p_query,const char * p_sort,t_size p_playlist,t_uint32 p_flags) = 0;
86 
87  FB2K_MAKE_SERVICE_INTERFACE_ENTRYPOINT(autoplaylist_manager)
88 };
89 
93  FB2K_MAKE_SERVICE_INTERFACE(autoplaylist_manager_v2, autoplaylist_manager)
94 public:
95  virtual t_uint32 get_client_flags(t_size playlist) = 0;
96  virtual void set_client_flags(t_size playlist, t_uint32 newFlags) = 0;
97 
99  virtual t_uint32 get_client_flags(autoplaylist_client::ptr client) = 0;
101  virtual void set_client_flags(autoplaylist_client::ptr client, t_uint32 newFlags) = 0;
102 };
Class needed to re-instantiate autoplaylist_client after a restart. Not directly needed to set up an ...
Definition: autoplaylist.h:56
void sort(pfc::sort_callback &p_callback, t_size p_num)
Definition: sort.cpp:225
Definition: pfc.h:53
abort_callback_impl abort_callback_dummy
Primary class for managing autoplaylists. Implemented by core, do not reimplement; instantiate using ...
Definition: autoplaylist.h:73
PFC_DECLARE_EXCEPTION(exception_autoplaylist, pfc::exception,"Autoplaylist error") PFC_DECLARE_EXCEPTION(exception_autoplaylist_already_owned
void get_configuration(t_array &p_out)
Helper.
Definition: autoplaylist.h:28
size_t t_size
Definition: int_types.h:48
Base class for all service classes. Provides interfaces for reference counter and querying for differ...
Definition: service.h:333
When set, core will keep the autoplaylist sorted and prevent user from reordering it...
Definition: autoplaylist.h:11
std::exception exception
Definition: primitives.h:193
exception_autoplaylist
Definition: autoplaylist.h:67
Main class controlling autoplaylist behaviors. Implemented by autoplaylist client in scenarios where ...
Definition: autoplaylist.h:14
Autopointer class to be used with all services. Manages reference counter calls behind-the-scenes.
Definition: service.h:55
service_ptr_t< autoplaylist_client > autoplaylist_client_ptr
Definition: autoplaylist.h:36
uint32_t t_uint32
Definition: int_types.h:5