Help - Search - Members - Calendar
Full Version: How to use metadb_display_field_provider
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
dominura
Hi, all
I want to add a new virtual field.
And, such logic was written.
CODE
class myclass : public metadb_display_field_provider{
public:
    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;
        if(p_handle->get_info(info)){
            pfc::string8 temp;
            if(info.meta_exists("ARTIST")){
                temp.add_string(info.meta_get("ARTIST"));
            }
            if(info.meta_exists("TITLE")){
                temp.add_string(info.meta_get("TITLE"));
            }
            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?
Canar
Yes. Your mistake comes from not reading the documentation.
Yirkha
QUOTE ('metadb.h')
/*!
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
...
*/
dominura
Thanks guys.
My understanding was insufficient.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.