Help - Search - Members - Calendar
Full Version: preventing plugin from locking gui
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
peterla
Hi all,

I'm new here and trying to develop a plugin that tries to automatically predict the genre of a soong by calculating some features of the audio data.

At the moment I can call by plugin from mainmenu and tell it to calculate for all songs in database, but it locks the gui, until it finished and wrote the prediction to metadata. On a large databese ths can take a few hours foobar won't respond.

So my question:

Is there a way to run the plugin in background, to prevent it from locking the gui?

Thanks for your help.
Peter
Florian
QUOTE(peterla @ Feb 17 2006, 12:06 PM)
Is there a way to run the plugin in background, to prevent it from locking the gui?

Yes, you can create a new thread and do the calculation in this thread.
peterla
Thank you Ganymed,

I tried this before but the gui still gets locked.
What I did:

CODE

virtual void perform_command(unsigned n)
{
 if (n==0 && core_api::assert_main_thread())
 {
  HANDLE hThread;
 
  DWORD id;
  SetThreadPriority(hThread, -1);
  hThread = CreateThread(0,0,g_ThreadFunc,this,0,&id);
 
 }
}


Any idea what is wrong?
foosion
Does your worker thread lock the database?
peterla
QUOTE(foosion @ Feb 17 2006, 01:49 PM)
Does your worker thread lock the database?
*



Yes, it did. Thank you.

Now I can scroll the playlist for a few seconds, before the gui locks again.
Any other suggestion?

Another question:
Is it safe not to lock databease when doing meta data operations?
foosion
QUOTE(peterla @ Feb 17 2006, 02:01 PM)
*

That depends on what exactly you are doing. If you just need to query the list of items in the database, you don't need to lock it. If you need to query path and subsong from metadb_handles, then you don't need to lock it either, since these values are guaranteed to be constant during the lifetime of metadb_handle.

You can get a copy of the metadata associated with a metadb_handle by using the query_info() method. If you do not want to copy the metadata, you an get a reference to it via query_info_locked(); as the name indicates, you have to lock the database when you use this method.

If you want to update metadata, well, I do not remember how this was done in 0.9, so I would have to look it up.

As a rule of thumb, every method that has "locked" in its name can only be used while you hold the required lock. If a method can only be used from the main thread or requires other special synchronization, there should be comment on the method, on the class it is in or at the start of the file it is declared in.
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-2008 Invision Power Services, Inc.