Skip to main content

Notice

Please be aware that much of the software linked to or mentioned on this forum is niche and therefore infrequently downloaded. Lots of anti-virus scanners and so-called malware detectors like to flag infrequently downloaded software as bad until it is either downloaded enough times, or its developer actually bothers with getting each individual release allow listed by every single AV vendor. You can do many people a great favor when encountering such a "problem" example by submitting them to your AV vendor for examination. For almost everything on this forum, it is a false positive.
Topic: Using title formatting (precompiling scripts, console output) (Read 3789 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Using title formatting (precompiling scripts, console output)

Hello,
more questions.

Can't seem to understand how title formatting is done.

Here's my attempt which I made from various posts I found on this forum.

My code:
Code: [Select]
#include "SDK\foobar2000.h"

DECLARE_COMPONENT_VERSION("foo_test","1.777","blah")

const GUID myguid = { 0x000F0001, 0x3300, 0x3452, { 0x00, 0x00, 0x12, 0x10, 0xAF, 0x00, 0x45, 0xFF } };

void context_click( const pfc::list_base_const_t<metadb_handle_ptr> & p_data )
{
    service_ptr_t<titleformat_object> g_to_global;
    service_ptr_t<titleformat_compiler> compiler;
    compiler->compile_safe(g_to_global,"%artist%");
    for (int i=0;i<p_data.get_count();i++){
        pfc::string8 out;
        p_data.get_item(i)->format_title(NULL,out,compiler,NULL);
        console::print(out.get_ptr());
    }

    return;
}


class entry: public initquit
{
public:
    virtual void on_init()
    {
        console::print("plugin started");
    }
    virtual void on_quit(){}
};

DECLARE_CONTEXT_MENU_ITEM (item_test,
                            "Copy artist name",
                            "foo_test",
                            context_click,
                            myguid,
                            "Copy artists")

static initquit_factory_t<entry> myinstance;


Thanks
I just like listening to music

Using title formatting (precompiling scripts, console output)

Reply #1
[font= "Courier New"]static_api_ptr_t<titleformat_compiler> compiler;[/font]
Full-quoting makes you scroll past the same junk over and over.

Using title formatting (precompiling scripts, console output)

Reply #2
I actually tried that first, but the compiler throws me:

error C2664: 'metadb_handle::format_title' : cannot convert parameter 3 from 'static_api_ptr_t<t_interface>' to 'const service_ptr_t<T> &'

So I thought I needed to use the service_ptr_t template instead.
I just like listening to music

Using title formatting (precompiling scripts, console output)

Reply #3
You need to pass the compiled script to metadb_handle::format_title(), not the compiler.
Also, it is recommendable to pre-allocate and reuse the output string.

Code: [Select]
titleformat_object::ptr script;
static_api_ptr_t<titleformat_compiler>()->compile_safe(script, "%artist%");
pfc::string8_fast_aggressive buffer;
buffer.prealloc(128);
console::formatter out;
for (t_size i = 0, n = p_data.get_count(); i < n; ++i) {
    if (p_data[i]->format_title(NULL, buffer, script, NULL)) {
        out << buffer.get_ptr() << "\n";
    }
}

Using title formatting (precompiling scripts, console output)

Reply #4
Aah, makes sense.

Thanks.
I just like listening to music

 
SimplePortal 1.0.0 RC1 © 2008-2021