void replaceTrackInActivePlaylist(const metadb_handle_ptr& trackToReplace, const metadb_handle_ptr& replacement) { t_size index = 0; static_api_ptr_t<playlist_manager> pm; if(!pm->activeplaylist_find_item(trackToReplace, index)) { console::printf("Couldn't find track in active playlist to replace it: %s", trackToReplace->get_path()); return; } if(!pm->activeplaylist_replace_item(index, replacement)) { console::printf("Couldn't replace track in active playlist: %s", trackToReplace->get_path()); return; } }
std::wstring LyricSourceLRC::getSavePath(const metadb_handle_ptr &track) { std::string path = track->get_path(); std::wstring wpath = EncodingFunc::ToUTF16(path.substr(boost::find_last(path, "://").end() - path.begin())); wpath = wpath.substr(0, wpath.find_last_of(L".")); if(track->get_subsong_index() != 0) wpath += boost::lexical_cast<std::wstring>(track->get_subsong_index()); wpath += L".lrc"; if(m_config["lrcsavepath"].length()) { class LRCTitleFormatCallback : public main_thread_callback { private: HANDLE m_event; std::string *m_out; const std::string &m_format; const metadb_handle_ptr &m_track; public: LRCTitleFormatCallback(HANDLE event, std::string *out, const std::string &format, const metadb_handle_ptr &track) : m_event(event), m_format(format), m_out(out), m_track(track) {} virtual void callback_run() { core_api::ensure_main_thread(); pfc::string8 out; service_ptr_t<titleformat_object> script; static_api_ptr_t<titleformat_compiler>()->compile(script, m_format.c_str()); m_track->format_title(NULL, out, script, NULL); m_out->assign(out.get_ptr()); SetEvent(m_event); } }; std::wstring dirname = wpath.substr(0, wpath.find_last_of(L'\\') + 1); std::wstring filename = wpath.substr(wpath.find_last_of(L"\\") + 1); HANDLE event = CreateEvent(NULL, TRUE, FALSE, NULL); std::string out; std::string pathtmp = m_config["lrcsavepath"]; if(pathtmp.at(pathtmp.length() - 1) != '\\') pathtmp += '\\'; service_ptr_t<LRCTitleFormatCallback> p_callback = new service_impl_t<LRCTitleFormatCallback>(event, &out, pathtmp, track); static_api_ptr_t<main_thread_callback_manager>()->add_callback(p_callback); p_callback.release(); WaitForSingleObject(event, INFINITE); CloseHandle(event); wpath = EncodingFunc::ToUTF16(out); if(PathIsRelative(wpath.c_str())) wpath = dirname + wpath; if(GetFileAttributes(wpath.c_str()) & FILE_ATTRIBUTE_DIRECTORY && (GetLastError() != ERROR_FILE_NOT_FOUND && GetLastError() != ERROR_PATH_NOT_FOUND)) wpath += filename; return wpath; } if(path.find_first_of("file://") == std::string::npos) return std::wstring(L""); if(path.find_first_of("unpack://") == std::string::npos) return std::wstring(L""); return wpath; }
void SmoothArtUIE::on_playback_new_track(metadb_handle_ptr p_track) { GetArt(p_track->get_path()); }