void metadb_handle_list_helper::sort_by_relative_path_partial(pfc::list_base_t<metadb_handle_ptr> & p_list,t_size base,t_size count) { assert(base+count<=p_list.get_count()); pfc::array_t<t_size> order; order.set_size(count); sort_by_relative_path_get_order_partial(p_list,base,count,order.get_ptr()); p_list.reorder_partial(base,order.get_ptr(),count); }
void metadb_handle_list_helper::remove_duplicates(pfc::list_base_t<metadb_handle_ptr> & p_list) { t_size count = p_list.get_count(); if (count>0) { bit_array_bittable mask(count); pfc::array_t<t_size> order; order.set_size(count); order_helper::g_fill(order); p_list.sort_get_permutation_t(pfc::compare_t<metadb_handle_ptr,metadb_handle_ptr>,order.get_ptr()); t_size n; bool found = false; for(n=0;n<count-1;n++) { if (p_list.get_item(order[n])==p_list.get_item(order[n+1])) { found = true; mask.set(order[n+1],true); } } if (found) p_list.remove_mask(mask); } }
t_size file_move_helper::g_filter_dead_files_sorted(pfc::list_base_t<metadb_handle_ptr> & p_data,const pfc::list_base_const_t<const char*> & p_dead) { bit_array_bittable mask(p_data.get_count()); t_size found = g_filter_dead_files_sorted_make_mask(p_data,p_dead,mask); if (found > 0) p_data.remove_mask(mask); return found; }
static void g_get_root_items(pfc::list_base_t<mainmenu_root_group> & p_out) { p_out.remove_all(); mnemonic_manager mnemonics; service_enum_t<mainmenu_group> e; service_ptr_t<mainmenu_group> ptr; service_ptr_t<mainmenu_group_popup> ptrp; while(e.next(ptr)) { if (ptr->get_parent() == pfc::guid_null) { if (ptr->service_query_t(ptrp)) { mainmenu_root_group item; pfc::string8 name; ptrp->get_display_string(name); item.m_guid = ptrp->get_guid(); item.m_sort_priority = ptrp->get_sort_priority(); uFixAmpersandChars_v2(name, item.m_name); name.reset(); mnemonics.process_string(item.m_name, name); pfc::stringcvt::string_os_from_utf8 os(name); item.m_name_with_accelerators.append_fromptr(os.get_ptr(), os.length()); item.m_name_with_accelerators.append_single(0); p_out.add_item(item); } } } p_out.sort_t(g_compare); }
void filterTracksByCloseTitle(const std::string& title, pfc::list_base_t<metadb_handle_ptr>& tracks) { const t_size n = tracks.get_count(); bit_array_bittable deleteMask(n); for(t_size i = 0; i < n; i++) { deleteMask.set(i, !doesTrackHaveSimilarTitle(title, tracks[i])); } tracks.remove_mask(deleteMask); }
void filterTracksByArtist(const std::string& artist, pfc::list_base_t<metadb_handle_ptr>& tracks) { const t_size n = tracks.get_count(); bit_array_bittable deleteMask(n); for(t_size i = 0; i < n; i++) { deleteMask.set(i, !isTrackByArtist(artist, tracks[i])); } tracks.remove_mask(deleteMask); }
t_size file_move_helper::g_filter_dead_files_sorted_make_mask(pfc::list_base_t<metadb_handle_ptr> & p_data,const pfc::list_base_const_t<const char*> & p_dead,bit_array_var & p_mask) { t_size n, m = p_data.get_count(); t_size found = 0; for(n=0;n<m;n++) { t_size dummy; bool dead = p_dead.bsearch_t(metadb::path_compare,p_data.get_item(n)->get_path(),dummy); if (dead) found++; p_mask.set(n,dead); } return found; }
bool splitter_window_impl::is_point_ours(HWND wnd_point, const POINT & pt_screen, pfc::list_base_t<uie::window::ptr> & p_hierarchy) { if (wnd_point == get_wnd() || IsChild(get_wnd(), wnd_point)) { if (wnd_point == get_wnd()) { p_hierarchy.add_item(this); return true; } else { t_size i, count = m_panels.get_count(); for (i = 0; i<count; i++) { uie::splitter_window_v2_ptr sptr; if (m_panels[i]->m_child.is_valid()) { if (m_panels[i]->m_child->service_query_t(sptr)) { pfc::list_t<uie::window::ptr> temp; temp.add_item(this); if (sptr->is_point_ours(wnd_point, pt_screen, temp)) { p_hierarchy.add_items(temp); return true; } } else if (wnd_point == m_panels[i]->m_wnd_child || IsChild(m_panels[i]->m_wnd_child, wnd_point)) { p_hierarchy.add_item(this); p_hierarchy.add_item(m_panels[i]->m_child); return true; } else if (wnd_point == m_panels[i]->m_wnd) { p_hierarchy.add_item(this); return true; } } } } } return false; };
bool input_entry::g_find_inputs_by_content_type(pfc::list_base_t<service_ptr_t<input_entry> > & p_out, const char * p_content_type, bool p_from_redirect) { service_enum_t<input_entry> e; service_ptr_t<input_entry> ptr; bool ret = false; while (e.next(ptr)) { if (!(p_from_redirect && ptr->is_redirect())) { if (ptr->is_our_content_type(p_content_type)) { p_out.add_item(ptr); ret = true; } } } return ret; }
bool input_entry::g_find_inputs_by_path(pfc::list_base_t<service_ptr_t<input_entry> > & p_out, const char * p_path, bool p_from_redirect) { service_enum_t<input_entry> e; service_ptr_t<input_entry> ptr; auto extension = pfc::string_extension(p_path); bool ret = false; while (e.next(ptr)) { if (!(p_from_redirect && ptr->is_redirect())) { if (ptr->is_our_path(p_path, extension)) { p_out.add_item(ptr); ret = true; } } } return ret; }
void splitter_window_impl::splitter_host_impl::get_children(pfc::list_base_t<uie::window::ptr> & p_out) { if (m_this.is_valid()) { t_size i, count = m_this->m_panels.get_count(); for (i = 0; i < count; i++) { if (m_this->m_panels[i]->m_child.is_valid()) p_out.add_item(m_this->m_panels[i]->m_child); } } }
void metadb_handle_list_helper::sort_by_pointer_remove_duplicates(pfc::list_base_t<metadb_handle_ptr> & p_list) { t_size count = p_list.get_count(); if (count>0) { sort_by_pointer(p_list); bool b_found = false; t_size n; for(n=0;n<count-1;n++) { if (p_list.get_item(n)==p_list.get_item(n+1)) { b_found = true; break; } } if (b_found) { bit_array_bittable mask(count); t_size n; for(n=0;n<count-1;n++) { if (p_list.get_item(n)==p_list.get_item(n+1)) mask.set(n+1,true); } p_list.remove_mask(mask); } } }
static bool grab_items_by_path(pfc::list_base_t<metadb_handle_ptr> & p_out,const char * p_path,abort_callback & p_abort) { try { pfc::string8 path; filesystem::g_get_canonical_path(p_path,path); p_out.remove_all(); service_ptr_t<input_info_reader> reader; input_entry::g_open_for_info_read(reader,0,path,p_abort); static_api_ptr_t<metadb> l_metadb; const t_uint32 count = reader->get_subsong_count(); for(t_uint32 n=0;n<count;n++) { p_abort.check_e(); metadb_handle_ptr ptr; l_metadb->handle_create(ptr,make_playable_location(path,reader->get_subsong(n))); p_out.add_item(ptr); } return p_out.get_count() > 0; } catch(std::exception const &) {return false;} }
// all tracks will be analysed; try to cut the size of the list down before calling. metadb_handle_ptr getBestTrackByTitle(const std::string& title, const pfc::list_base_t<metadb_handle_ptr>& tracks) { if(tracks.get_count() == 1) { console::info(("Only one version of " + title + " exists in library").c_str()); return tracks[0]; } console::info(("Finding best version of " + title + ". " + to_string(tracks.get_count()) + " candidates").c_str()); metadb_handle_ptr bestTrack = 0; float bestTrackRating = std::numeric_limits<float>::min(); for(t_size index = 0; index < tracks.get_count(); index++) { const float trackRating = calculateTrackRating(title, tracks[index]); console::info(("Rating: " + to_string(trackRating, 2) + ": " + tracks[index]->get_path()).c_str()); if(trackRating >= 0.0f && trackRating > bestTrackRating) { bestTrackRating = trackRating; bestTrack = tracks[index]; } } if(bestTrack == 0) { console::info(("Couldn't find a match for " + title).c_str()); } else { console::info(("Picked track with rating: " + to_string(bestTrackRating, 2) + ": " + bestTrack->get_path()).c_str()); } return bestTrack; }
void file_move_helper::make_new_item_list(pfc::list_base_t<metadb_handle_ptr> & p_out,const char * p_new_path,file_move_callback_manager & p_cb) { pfc::string8 new_path; filesystem::g_get_canonical_path(p_new_path,new_path); t_size n; const t_size m = m_data.get_size(); static_api_ptr_t<metadb> api; pfc::array_t<metadb_handle_ptr> hint_handles; pfc::array_t<const file_info*> hint_infos; pfc::array_t<t_filestats> hint_stats; hint_handles.set_size(m); hint_infos.set_size(m); hint_stats.set_size(m); t_size hintptr = 0; for(n=0;n<m;n++) { metadb_handle_ptr temp; api->handle_create(temp,make_playable_location(new_path,m_data[n].m_location.get_subsong())); if (m_data[n].m_have_info) { hint_handles[hintptr] = temp; hint_infos[hintptr] = &m_data[n].m_info; hint_stats[hintptr] = m_data[n].m_stats; hintptr++; } p_out.add_item(temp); } if (hintptr > 0) { p_cb.on_hint( pfc::list_const_array_t<metadb_handle_ptr,const pfc::array_t<metadb_handle_ptr> &>(hint_handles,hintptr), pfc::list_const_array_t<const file_info *,const pfc::array_t<const file_info *> &>(hint_infos,hintptr), pfc::list_const_array_t<t_filestats,const pfc::array_t<t_filestats> &>(hint_stats,hintptr) ); /* static_api_ptr_t<metadb_io>()->hint_multi( list_const_array_t<metadb_handle_ptr,const array_t<metadb_handle_ptr> &>(hint_handles,hintptr), list_const_array_t<const file_info *,const array_t<const file_info *> &>(hint_infos,hintptr), list_const_array_t<t_filestats,const array_t<t_filestats> &>(hint_stats,hintptr), bit_array_false());*/ } }
void metadb_handle_list_helper::sort_by_pointer(pfc::list_base_t<metadb_handle_ptr> & p_list) { //it seems MSVC71 /GL does something highly retarded here //p_list.sort_t(pfc::compare_t<metadb_handle_ptr,metadb_handle_ptr>); p_list.sort(); }
void playlist_manager::activeplaylist_get_items(pfc::list_base_t<metadb_handle_ptr> & out,const bit_array & p_mask) { t_size playlist = get_active_playlist(); if (playlist != pfc_infinite) playlist_get_items(playlist,out,p_mask); else out.remove_all(); }
void metadb_handle_list_helper::sort_by_path_quick(pfc::list_base_t<metadb_handle_ptr> & p_list) { p_list.sort_t(metadb::path_compare_metadb_handle); }
void metadb_handle_list_helper::sort_by_path(pfc::list_base_t<metadb_handle_ptr> & p_list) { sort_by_format_partial(p_list,0,p_list.get_count(),"%path_sort%",0); }
void metadb_handle_list_helper::sort_by_format_partial(pfc::list_base_t<metadb_handle_ptr> & p_list,t_size base,t_size count,const service_ptr_t<titleformat_object> & p_script,titleformat_hook * p_hook) { pfc::array_t<t_size> order; order.set_size(count); sort_by_format_get_order_partial(p_list,base,count,order.get_ptr(),p_script,p_hook); p_list.reorder_partial(base,order.get_ptr(),count); }
void splitter_window_impl::get_panels_sizes(unsigned client_width, unsigned client_height, pfc::list_base_t<unsigned> & p_out) { struct t_size_info { unsigned height; bool sized; unsigned parts; }; unsigned n, count = m_panels.get_count(), height_allocated = 0; if (count) { pfc::array_t<t_size_info> size_info; size_info.set_size(count); //size_info.fill(0); memset(size_info.get_ptr(), 0, size_info.get_size()*sizeof(t_size_info)); unsigned caption_size = g_get_caption_size(); //unsigned divider_width = 2; int available_height = get_orientation() == horizontal ? client_width : client_height; unsigned available_parts = 0; for (n = 0; n<count; n++) { unsigned panel_divider_size = get_panel_divider_size(n);; unsigned height = m_panels[n]->m_hidden ? 0 : m_panels[n]->m_size; if (height>MAXLONG) height = MAXLONG; if (available_height > (-MAXLONG + (int)height)) available_height -= height; else available_height = -MAXLONG; if (available_height > (-MAXLONG + (int)panel_divider_size)) available_height -= panel_divider_size; else available_height = -MAXLONG; size_info[n].height = height + panel_divider_size; size_info[n].parts = (m_panels[n]->m_locked || m_panels[n]->m_hidden) ? 0 : 1; available_parts += size_info[n].parts; } do { unsigned this_pass_available_parts = available_parts; int this_pass_available_height = available_height; for (n = 0; n<count; n++) { if (!size_info[n].sized) { unsigned panel_divider_size = get_panel_divider_size(n); unsigned panel_caption_size = (get_orientation() != m_panels[n]->m_caption_orientation && m_panels[n]->m_show_caption) ? caption_size : 0; unsigned height = size_info[n].height; int adjustment = 0; { adjustment = this_pass_available_parts ? MulDiv(this_pass_available_height, size_info[n].parts, this_pass_available_parts) : 0; this_pass_available_parts -= size_info[n].parts; this_pass_available_height -= adjustment; } if ((adjustment < 0 && (height > panel_divider_size ? height - panel_divider_size : 0) < (unsigned)(adjustment*-1))) { adjustment = (height > panel_divider_size ? height - panel_divider_size : 0) * -1; size_info[n].sized = true; } unsigned unadjusted = height; bool hidden = m_panels[n]->m_hidden; height += adjustment; unsigned min_height = hidden ? 0 : (get_orientation() == horizontal ? m_panels[n]->m_size_limits.min_width : m_panels[n]->m_size_limits.min_height); if (min_height < (unsigned)(pfc_infinite)-panel_divider_size - caption_size) min_height += panel_divider_size + panel_caption_size; unsigned max_height = hidden ? 0 : (get_orientation() == horizontal ? m_panels[n]->m_size_limits.max_width : m_panels[n]->m_size_limits.max_height); if (max_height < (unsigned)(pfc_infinite)-panel_divider_size - caption_size) max_height += panel_divider_size + panel_caption_size; if (get_orientation() == horizontal && m_panels[n]->m_show_toggle_area && !m_panels[n]->m_autohide) { if (max_height < unsigned(pfc_infinite) - 1) max_height++; if (min_height < unsigned(pfc_infinite) - 1) min_height++; } if (height < min_height) { height = min_height; adjustment = (height - unadjusted); size_info[n].sized = true; } else if (height > max_height) { height = max_height; adjustment = (height - unadjusted); size_info[n].sized = true; } if (m_panels[n]->m_locked || hidden) size_info[n].sized = true; if (size_info[n].sized) available_parts -= size_info[n].parts; available_height -= (height - unadjusted); size_info[n].height = height; } } } while (available_parts && available_height); for (n = 0; n<count; n++) { p_out.add_item(size_info[n].height); } } }