Beispiel #1
0
t_size playlist_manager::find_or_create_playlist_unlocked(const char * p_name, t_size p_name_length) {
	t_size n, m = get_playlist_count();
	pfc::string_formatter temp;
	for(n=0;n<m;n++) {
		if (!playlist_lock_is_present(n) && playlist_get_name(n,temp)) {
			if (stricmp_utf8_ex(temp,~0,p_name,p_name_length) == 0) return n;
		}
	}
	return create_playlist(p_name,p_name_length,pfc_infinite);
}
Beispiel #2
0
void playlist_manager::on_file_rechaptered(const char * path, metadb_handle_list_cref newItems) {
	if (newItems.get_size() == 0) return;

	const size_t numPlaylists = this->get_playlist_count();
	for( size_t walkPlaylist = 0; walkPlaylist < numPlaylists; ++ walkPlaylist ) {
		if (!playlist_lock_is_present(walkPlaylist)) {
			auto itemCount = [=] () -> unsigned {
				return this->playlist_get_item_count( walkPlaylist );
			};
			auto itemHandle = [=] ( unsigned item ) -> metadb_handle_ptr {
				return this->playlist_get_item_handle( walkPlaylist, item );
			};
			auto itemMatch = [=] ( unsigned item ) -> bool {
				return metadb::path_compare(path, itemHandle(item)->get_path()) == 0;
			};
			auto itemMatch2 = [=] ( metadb_handle_ptr item ) -> bool {
				return metadb::path_compare(path, item->get_path() ) == 0;
			};

			for( size_t walkItem = 0; walkItem < itemCount(); ) {

				if (itemMatch( walkItem )) {
					pfc::avltree_t<uint32_t> subsongs;
					unsigned base = walkItem;
					bool bSel = false;
					for( ++walkItem ; walkItem < itemCount() ; ++ walkItem ) {
						auto handle = itemHandle( walkItem );
						if (! itemMatch2( handle ) ) break;
						if (! subsongs.add_item_check(handle->get_subsong_index())) break;

						bSel = bSel || this->playlist_is_item_selected(walkPlaylist, walkItem);
					}

					// REMOVE base ... walkItem range and insert newHandles at base
					this->playlist_remove_items( walkPlaylist, pfc::bit_array_range(base, walkItem-base) );
					this->playlist_insert_items( walkPlaylist, base, newItems, pfc::bit_array_val( bSel ) );
					walkItem = base + newItems.get_size();
				} else {
					++walkItem;
				}
			}
		}
	}
}