Skip to main content


Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How to use metadb_display_field_provider (Read 3264 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to use metadb_display_field_provider

Hi, all
I want to add a new virtual field.
And, such logic was written.
Code: [Select]
class myclass : public metadb_display_field_provider{
    virtual t_uint32 get_field_count(){
        return 1;
    virtual void get_field_name(t_uint32 index, pfc::string_base & out){
        out = "TEST";
    virtual bool process_field(t_uint32 index, metadb_handle * handle, titleformat_text_out * out){
        // test (Time-consuming processing)
        file_info_impl info;
            pfc::string8 temp;
            out->write( titleformat_inputtypes::meta, temp);
            return true;
        return false;

static service_factory_single_t<myclass> foo;

However, trouble is found.

Default UI:
First of all, 300 items are added to the playlist.
Next, the %TEST% field is added to Playlist view.
It sorts it with %TEST%.
sorted broken or freezing foobar2000.

Have it made a mistake in any ways?

How to use metadb_display_field_provider

Reply #1
Yes. Your mistake comes from not reading the documentation.

How to use metadb_display_field_provider

Reply #2
[font= "Courier New"]/*!
        Implementing this service lets you provide your own title-formatting fields that are parsed globally with each call to metadb_handle::format_title methods. \n
        This should be implemented only where absolutely necessary, for safety and performance reasons. Any expensive operations inside the process_field() method may severely damage performance of affected title-formatting calls. \n
        You must NEVER make any other foobar2000 API calls from inside process_field, other than possibly querying information from the passed metadb_handle pointer; you should read your own implementation-specific private data and return as soon as possible. You must not make any assumptions about calling context (threading etc). \n
        It is guaranteed that process_field() is called only inside a metadb lock scope so you can safely call "locked" metadb_handle methods on the metadb_handle pointer you get. You must not lock metadb by yourself inside process_field() - while it is always called from inside a metadb lock scope, it may be called from another thread than the one maintaining the lock because of multi-CPU optimizations active. \n
Full-quoting makes you scroll past the same junk over and over.

How to use metadb_display_field_provider

Reply #3
Thanks guys.
My understanding was insufficient.