HydrogenAudio

Hosted Forums => foobar2000 => Development - (fb2k) => Topic started by: MordredKLB on 2017-11-30 07:38:26

Title: Help with writing a component utilizing index-data db / metadb_index_client
Post by: MordredKLB on 2017-11-30 07:38:26
So I'm trying to write an alternate playback statistics component (foo_enhanced_playback_statistics) that functions exactly like the official v3.0.2 one except that instead of just recording the count, it stores a string containing a JSON object with all plays timestamped. Maybe it's possible to get it to function like the normal $meta_num / $meta(field, 5) stuff, but I'm not sure.

At the moment I've got a component using the playback_statistics_collector service which gets called after 60secs, and I can retrieve a titleformat string of "%artist% %album% $if2(%discnumber%,1) %tracknumber% %title%" (which is supposedly what foo_playcount uses for differentiating songs) and spit it to the console.

Of course, that doesn't get me very far. Documentation for how to actually use metadb_index_client is basically non-existent, and I guess I'm not smart enough to just figure it out from the method definitions in metadb.h.

So I think what I need to do is in the on_init I need to instantiate my own class based off metadb_index_client. But to do that I need to implement the transform method which seems to return an MD5 hash, but I can't for the life of me figure out how that method is supposed to look. Also that method takes a playable_location which maybe means that I need to call transform when the file is loaded and then cache the hashed value for using later in my playback_statistics_collector?

Anyway, once the playcount is ready to be incremented, I need to call metadb_index_manager->set_user_data which seems relatively straightforward. I also think metadb_display_field_provider probably isn't too bad.

Any help you guys could provide would be much appreciated. Ideally if you could point me towards the source of a component that's already doing something similar it would be super helpful. As it is, I'm flying blind right now. The really frustrating thing is that if the source for foo_playcount was available, I could probably knock this component out in an hour or two. I basically need exactly that, but with only 25% of the functionality.

Thanks.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: MordredKLB on 2017-12-12 22:59:51
So is this really nothing that anybody is doing? From what I can tell playback statistics and foo_lyrics3 are the only components doing this sort of thing, and neither is open source which makes figuring out how this is supposed to work a lot harder.

Does anyone know of other components that are creating a metadb_index_client that are open source?

Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: Peter on 2017-12-13 11:31:29
I made a new foo_sample module implementing a simple rating database, just add this .cpp file to foo_sample project.
The next SDK update will include this.
I hope this helps.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: marc2003 on 2017-12-13 12:34:54
This looks very useful. Is there a way to make the custom fields/values appear in the Properties dialog on the Details tab.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: Peter on 2017-12-13 12:55:33
Now with more track_property_provider
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: marc2003 on 2017-12-13 13:09:19
Excellent. Thank you very much.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: MordredKLB on 2017-12-13 21:53:55
Thanks, Peter! I'll give this a look soon hopefully.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: marc2003 on 2017-12-14 18:12:48
Because I'm incredibly stupid, I've not figured out to get multiple fields working with a single GUID. Could the next SDK example include that as well?

For now, I've hacked around it with multiple GUIDs which seems to work fine. I'm using it to store playcounts from last.fm and I've finally been able to ditch foo_customdb (hooray!  :P )
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: Peter on 2017-12-16 11:18:33
The data pinned to each guid+hash is a blob so it can hold anything that you want, you just have to pack it into a blob on your side. I'll add relevant code to foo_sample for the next update.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: marc2003 on 2017-12-16 13:08:18
Thanks again.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: MordredKLB on 2017-12-19 18:51:37
The data pinned to each guid+hash is a blob so it can hold anything that you want, you just have to pack it into a blob on your side. I'll add relevant code to foo_sample for the next update.
I haven't tried to handle multiple fields yet, but are you saying that if I want my component to handle both %foo_mordred_field1% and %foo_mordred_field2%, then when I call api->set_user_data I'll need to store the values for both fields in the same blob and then unpack them and return the individual fields as needed when doing a get?
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: Peter on 2017-12-19 20:23:31
I haven't tried to handle multiple fields yet, but are you saying that if I want my component to handle both %foo_mordred_field1% and %foo_mordred_field2%, then when I call api->set_user_data I'll need to store the values for both fields in the same blob and then unpack them and return the individual fields as needed when doing a get?
Correct.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: Peter on 2018-01-11 16:22:15
New SDK out.
https://www.foobar2000.org/SDK
The above rating.cpp has been improved further and is included.
Title: Re: Help with writing a component utilizing index-data db / metadb_index_client
Post by: MordredKLB on 2018-01-30 23:03:42
Hey Peter,

If you've got a metadb hash generated for a string like "%artist% %album% %title%", how do you update the value for the hash when the file's title is changed?