|
1
|
1 #include "foobar2000-sdk-pch.h"
|
|
|
2 #include "metadb.h"
|
|
|
3 #include "metadb_callbacks.h"
|
|
|
4 #include "file_info_filter_impl.h"
|
|
|
5 #include "playback_control.h"
|
|
|
6 #include "playlist.h"
|
|
|
7
|
|
|
8 void metadb::handle_create_replace_path_canonical(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path) {
|
|
|
9 handle_create(p_out,make_playable_location(p_new_path,p_source->get_subsong_index()));
|
|
|
10 }
|
|
|
11
|
|
|
12 void metadb::handle_create_replace_path(metadb_handle_ptr & p_out,const metadb_handle_ptr & p_source,const char * p_new_path) {
|
|
|
13 pfc::string8 path;
|
|
|
14 filesystem::g_get_canonical_path(p_new_path,path);
|
|
|
15 handle_create_replace_path_canonical(p_out,p_source,path);
|
|
|
16 }
|
|
|
17
|
|
|
18 void metadb::handle_replace_path_canonical(metadb_handle_ptr & p_out,const char * p_new_path) {
|
|
|
19 metadb_handle_ptr temp;
|
|
|
20 handle_create_replace_path_canonical(temp,p_out,p_new_path);
|
|
|
21 p_out = temp;
|
|
|
22 }
|
|
|
23
|
|
|
24
|
|
|
25 metadb_io::t_load_info_state metadb_io::load_info(metadb_handle_ptr p_item,t_load_info_type p_type,fb2k::hwnd_t p_parent_window,bool p_show_errors) {
|
|
|
26 return load_info_multi(pfc::list_single_ref_t<metadb_handle_ptr>(p_item),p_type,p_parent_window,p_show_errors);
|
|
|
27 }
|
|
|
28
|
|
|
29 metadb_io::t_update_info_state metadb_io::update_info(metadb_handle_ptr p_item,file_info & p_info,fb2k::hwnd_t p_parent_window,bool p_show_errors)
|
|
|
30 {
|
|
|
31 file_info * blah = &p_info;
|
|
|
32 return update_info_multi(pfc::list_single_ref_t<metadb_handle_ptr>(p_item),pfc::list_single_ref_t<file_info*>(blah),p_parent_window,p_show_errors);
|
|
|
33 }
|
|
|
34
|
|
|
35
|
|
|
36 void metadb_io::hint_async(metadb_handle_ptr p_item,const file_info & p_info,const t_filestats & p_stats,bool p_fresh)
|
|
|
37 {
|
|
|
38 const file_info * blargh = &p_info;
|
|
|
39 hint_multi_async(pfc::list_single_ref_t<metadb_handle_ptr>(p_item),pfc::list_single_ref_t<const file_info *>(blargh),pfc::list_single_ref_t<t_filestats>(p_stats), pfc::bit_array_val(p_fresh));
|
|
|
40 }
|
|
|
41
|
|
|
42
|
|
|
43 bool metadb::g_get_random_handle(metadb_handle_ptr & p_out) {
|
|
|
44 if (playback_control::get()->get_now_playing(p_out)) return true;
|
|
|
45
|
|
|
46 {
|
|
|
47 auto api = playlist_manager::get();
|
|
|
48
|
|
|
49 t_size playlist_count = api->get_playlist_count();
|
|
|
50 t_size active_playlist = api->get_active_playlist();
|
|
|
51 if (active_playlist != ~0) {
|
|
|
52 if (api->playlist_get_focus_item_handle(p_out,active_playlist)) return true;
|
|
|
53 }
|
|
|
54
|
|
|
55 for(t_size n = 0; n < playlist_count; n++) {
|
|
|
56 if (api->playlist_get_focus_item_handle(p_out,n)) return true;
|
|
|
57 }
|
|
|
58
|
|
|
59 if (active_playlist != ~0) {
|
|
|
60 t_size item_count = api->playlist_get_item_count(active_playlist);
|
|
|
61 if (item_count > 0) {
|
|
|
62 if (api->playlist_get_item_handle(p_out,active_playlist,0)) return true;
|
|
|
63 }
|
|
|
64 }
|
|
|
65
|
|
|
66 for(t_size n = 0; n < playlist_count; n++) {
|
|
|
67 t_size item_count = api->playlist_get_item_count(n);
|
|
|
68 if (item_count > 0) {
|
|
|
69 if (api->playlist_get_item_handle(p_out,n,0)) return true;
|
|
|
70 }
|
|
|
71 }
|
|
|
72 }
|
|
|
73
|
|
|
74 return false;
|
|
|
75 }
|
|
|
76
|
|
|
77
|
|
|
78 void metadb_io_v2::update_info_async_simple(const pfc::list_base_const_t<metadb_handle_ptr> & p_list,const pfc::list_base_const_t<const file_info*> & p_new_info, fb2k::hwnd_t p_parent_window,t_uint32 p_op_flags,completion_notify_ptr p_notify) {
|
|
|
79 update_info_async(p_list,new service_impl_t<file_info_filter_impl>(p_list,p_new_info),p_parent_window,p_op_flags,p_notify);
|
|
|
80 }
|
|
|
81
|
|
|
82 void metadb_io_v2::on_file_rechaptered( const char * path, metadb_handle_list_cref newItems ) {
|
|
|
83 PFC_ASSERT(core_api::is_main_thread());
|
|
|
84 metadb_handle_list handles( newItems );
|
|
|
85 pfc::string8 pathLocal( path );
|
|
|
86 auto notify = fb2k::makeCompletionNotify( [handles, pathLocal] (unsigned) {
|
|
|
87 playlist_manager::get()->on_file_rechaptered( pathLocal, handles );
|
|
|
88 } );
|
|
|
89
|
|
|
90 load_info_async( handles, metadb_io::load_info_force, core_api::get_main_window(), metadb_io_v3::op_flag_delay_ui, notify );
|
|
|
91 }
|
|
|
92
|
|
|
93 void metadb_io_v2::on_files_rechaptered( metadb_handle_list_cref newHandles ) {
|
|
|
94 PFC_ASSERT(core_api::is_main_thread());
|
|
|
95 metadb_handle_list local ( newHandles );
|
|
|
96 auto notify = fb2k::makeCompletionNotify( [local] (unsigned) {
|
|
|
97 playlist_manager::get()->on_files_rechaptered(local);
|
|
|
98 } );
|
|
|
99
|
|
|
100 load_info_async( newHandles, metadb_io::load_info_force, core_api::get_main_window(), metadb_io_v3::op_flag_delay_ui, notify );
|
|
|
101 }
|
|
|
102
|
|
|
103
|
|
|
104 metadb_hint_list::ptr metadb_hint_list::create() {
|
|
|
105 return metadb_io_v2::get()->create_hint_list();
|
|
|
106 }
|
|
|
107
|
|
|
108 metadb_hint_list_v2::ptr metadb_hint_list_v2::create() {
|
|
|
109 metadb_hint_list_v2::ptr ret;
|
|
|
110 ret ^= metadb_hint_list::create();
|
|
|
111 return ret;
|
|
|
112 }
|
|
|
113
|
|
|
114 metadb_hint_list_v3::ptr metadb_hint_list_v3::create() {
|
|
|
115 metadb_hint_list_v3::ptr ret;
|
|
|
116 ret ^= metadb_hint_list::create();
|
|
|
117 return ret;
|
|
|
118 }
|
|
|
119
|
|
|
120 metadb_hint_list_v4::ptr metadb_hint_list_v4::create() {
|
|
|
121 metadb_hint_list_v4::ptr ret;
|
|
|
122 ret ^= metadb_hint_list::create();
|
|
|
123 return ret;
|
|
|
124 }
|
|
|
125
|
|
|
126 void metadb_io_callback_dynamic::register_callback() {
|
|
|
127 PFC_ASSERT(core_api::is_main_thread());
|
|
|
128 metadb_io_v3::get()->register_callback(this);
|
|
|
129 }
|
|
|
130
|
|
|
131 void metadb_io_callback_dynamic::unregister_callback() {
|
|
|
132 PFC_ASSERT(core_api::is_main_thread());
|
|
|
133 metadb_io_v3::get()->unregister_callback(this);
|
|
|
134 }
|
|
|
135
|
|
|
136 void metadb_io_callback_v2_dynamic::register_callback() {
|
|
|
137 PFC_ASSERT(core_api::is_main_thread());
|
|
|
138 metadb_io_v5::get()->register_callback_v2(this);
|
|
|
139 }
|
|
|
140
|
|
|
141 void metadb_io_callback_v2_dynamic::unregister_callback() {
|
|
|
142 PFC_ASSERT(core_api::is_main_thread());
|
|
|
143 metadb_io_v5::get()->unregister_callback_v2(this);
|
|
|
144 }
|
|
|
145
|
|
|
146 bool metadb_io_callback_v2_dynamic::try_register_callback() {
|
|
|
147 PFC_ASSERT(core_api::is_main_thread());
|
|
|
148 auto api = metadb_io_v5::tryGet();
|
|
|
149 if (api.is_empty()) return false;
|
|
|
150 api->register_callback_v2(this);
|
|
|
151 return true;
|
|
|
152 }
|
|
|
153
|
|
|
154 void metadb_io_callback_v2_dynamic::try_unregister_callback() {
|
|
|
155 PFC_ASSERT(core_api::is_main_thread());
|
|
|
156 auto api = metadb_io_v5::tryGet();
|
|
|
157 if (api.is_valid()) api->unregister_callback_v2(this);
|
|
|
158 }
|
|
|
159
|
|
|
160 metadb_io_callback_dynamic_impl_base::metadb_io_callback_dynamic_impl_base() {
|
|
|
161 register_callback();
|
|
|
162 }
|
|
|
163
|
|
|
164 metadb_io_callback_dynamic_impl_base::~metadb_io_callback_dynamic_impl_base() {
|
|
|
165 unregister_callback();
|
|
|
166 }
|
|
|
167
|
|
|
168 metadb_io_callback_v2_dynamic_impl_base::metadb_io_callback_v2_dynamic_impl_base() {
|
|
|
169 register_callback();
|
|
|
170 }
|
|
|
171
|
|
|
172 metadb_io_callback_v2_dynamic_impl_base::~metadb_io_callback_v2_dynamic_impl_base() {
|
|
|
173 unregister_callback();
|
|
|
174 }
|