Skip to main content
Topic: USing metadb_handle_ptr (Read 2536 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

USing metadb_handle_ptr

Hi all,

I'm trying to get the path from every file selected in the current playlist.

So far, I managed to add a context menu item :


Code: [Select]
DECLARE_CONTEXT_MENU_ITEM (foosync_SendToUsb_menuitem,"Send to USB", "FooSync", send_to_usb, myguid, "Sends the selection to foo_sync's usb drive")



and using both visual studio debug and foosion's doxygen, I wrote this code in the callback function :


Code: [Select]
void send_to_usb( const pfc::list_base_const_t<metadb_handle_ptr> & p_data )
{
    const char* info;
    for (t_size i=0;i<p_data.get_count();i++)
    {
        file_info_impl myInfo;
        
        p_data[i]->get_info(myInfo);
        for (t_size j=0;j<myInfo.info_get_count();j++)
        {
            info=myInfo.info_enum_name(j);
        }

    }
  return;
}


Now the first part work, i.e, if I select some songs in my plalist, right click, then click on FooSync then Send to USB, the code goes to my function  send_to_usb.

But now I'm kind of stuck because:
- the debugger refuses to break inside the loop (that loop : for (t_size i=0;i<p_data.get_count();i++) {...})
- it breaks at the last curly bracket, with i having a really weird value, as if it was uninitialized.

I'm probably doing something wrong here. Actually I'm not sure of what I'm doing at all...

As I understand so far, the p_data parameter contains a list of metadb_handle_ptr. I assumed that I have one metadb_handle_ptr per selected item in the list, is this right ?

Now, if I try to look (in the debugger) what's the value of p_data.get_count(), it tells me that the member function doesn't exist !!! Which is weird because of course it does .

Sorry if it's a bit confusing, but I'm myself a bit confused here.

My goal here is to get the path and file name of every selected entry in the playlist.

Any help would be much appreciated.

Cheers,
D.

USing metadb_handle_ptr

Reply #1
Quote
I assumed that I have one metadb_handle_ptr per selected item in the list, is this right ?

Yes.

(...) p_data.get_count(), it tells me that the member function doesn't exist

Probably because it's declared as pure virtual in the pfc::list_base_const_t interface class.

Quote
My goal here is to get the path and file name of every selected entry in the playlist.

Use metadb_handle::get_path() then. The filename can be extracted with pfc::string_filename_ext.

By the way, metadb_handle::get_info_locked() should be preferred to avoid copying data around.
Also, make sure to check return values, info might not yet be known.

USing metadb_handle_ptr

Reply #2
Awesome ! Thanks again ! The trick was to use get_size() instaed of get_count()

I publish the corrected code (without the checks) :

Code: [Select]
void send_to_usb( const pfc::list_base_const_t<metadb_handle_ptr> & p_data )
{   const char* path;
    unsigned int i;

    for (i=0;i<p_data.get_size();i++)
    {
        path=p_data[i]->get_path();
    }
    
    
  return;
}


I'll implement some checks, as you suggested.

Moderation: Removed useless full quote of the preceding post.

USing metadb_handle_ptr

Reply #3
Considering that get_size() is implemented as the following, I kind of doubt that that was the cause. Remember, just because it appears to not be broken, that doesn't mean it is remotely correct.
inline t_size get_size() const {return get_count();}
Zao shang yong zao nong zao rang zao ren zao.
To, early in the morning, use a chisel to build a bathtub makes impatient people hot-tempered.

USing metadb_handle_ptr

Reply #4
Considering that get_size() is implemented as the following, I kind of doubt that that was the cause. Remember, just because it appears to not be broken, that doesn't mean it is remotely correct.
inline t_size get_size() const {return get_count();}


Mmmh you're right. And it's probably not the only mistake I made in my code. But at least the component works, on my computer.


If some one wants to use it :
http://www.hydrogenaudio.org/forums/index....=76277&st=0

(source is included, and distributed under gpl, so if you want, feel free to modify it or improve it)

 
SimplePortal 1.0.0 RC1 © 2008-2020