Author Topic: MusicBee API  (Read 289358 times)

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34392
there is already TrackChanged so you could grab the tags at that point
but i will add a PlayCountersChanged event (which includes SkipCount changing)

boroda

  • Sr. Member
  • ****
  • Posts: 4669
there is already TrackChanged so you could grab the tags at that point
MB changes play count and skip count in very smart way. This tags may be changed in the middle of track playback.

but i will add a PlayCountersChanged event (which includes SkipCount changing)
Thanks.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34392
updated .exe to support PlayCountersChanged
http://www.mediafire.com/?6pu0aa45o44ixlc

i will post a full updated API source code examples later, but these are the changes to manually edit in the MusicBeeInterface file

enum PluginNotifyType
...
        TagsChanging = 10,
        TagsChanged = 11,
        RatingChanged = 12,
        PlayCountersChanged = 13

enum ReceiveNotificationFlags
...
        TagEvents = 0x04

to receive tag event notifications, in the Initialise section of your plugin
...
            about.ReceiveNotifications = (ReceiveNotificationFlags.PlayerEvents | ReceiveNotificationFlags.TagEvents);

boroda

  • Sr. Member
  • ****
  • Posts: 4669

boroda

  • Sr. Member
  • ****
  • Posts: 4669
Steven, how can I get rid of 'Info box' when I click 'Configure' in Prefs/Plugins? I wand to display my own dialog without default dialog.

Elberet

  • Full Member
  • ***
  • Posts: 167
Just return true from Configure and MusicBee assumes that you have handled configuration and won't show the default about dialog.

boroda

  • Sr. Member
  • ****
  • Posts: 4669

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34392
API updated (get the interface definition file from the updated examples in the first post)

function to get all files matching a query in one call. The matching file paths are returned in one string, each path separated by a null char. You still need to call the query beforehand eg. Library_QueryFiles()
            string Library_QueryGetAllFiles();
            string NowPlayingList_QueryGetAllFiles();
            string Playlist_QueryGetAllFiles();

support for creating background tasks that show on the musicbee taskbar - you can create multiple tasks, but each one will be executed sequentially in a background thread so it doesnt interfere with the MusicBee GUI:

            mbApiInterface.MB_CreateBackgroundTask(new System.Threading.ThreadStart(Task1));

            private void Task1()
            {
                mbApiInterface.MB_SetBackgroundTaskMessage("some message");
                ....
            }


boroda

  • Sr. Member
  • ****
  • Posts: 4669
Steven, I'm trying to play around with MB_CreateBackgroundTask function. Actually I didn't start from scratch and maybe my existing code interfere with new API, but I found some strange things:

1. ~50% of commands in my plugin depends on form's data (especially on generated preview, so I cant dispose/destroy/close command window), but if I didn't call Hide() method for form, then clicking on statusbar hangs MB UI.

2. If I hide form, then clicking on 'X' button on statusbar terminates background process, but double-clicking on rotating circle or statusbar text (single-clicking does nothing) hangs MB.

What I would want is to handle single-clicking on 'X' button (if possible - to correctly exit the file querying loop - but this is not very important) and that single-clicking on rotating circle should invoke Show() method of form, i.e I want to have 'Hide' button that should hide command window and clicking on rotating circle should restore the window.
Last Edit: August 15, 2011, 07:58:54 PM by boroda74

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34392
1) its not a good idea to access data in the form controls from a background thread (and infact if you try to do it from an app in the visual studio debugger in debug mode will result an "Illegal cross threaded operation" or something like that but perhaps it doesnt detect that condition from loaded dlls) - you should load the values into local values within the plugin scope. It might work fine though if you are only reading control values. If you mean double clicking then it sounds the same issue as 2

2) double clicking on status bar tries to open the parent form. I'm not sure what its doing as i dont provide any way for you to pass the parent form so i need to check that out.

To handle the user clicking X you can capture the ThreadAbortException and do the cleanup as approriate

boroda

  • Sr. Member
  • ****
  • Posts: 4669
1) its not a good idea to access data in the form controls from a background thread
They weren't background threads initially! They became such in latest beta version. :)

If you mean double clicking then it sounds the same issue as 2
No, I meant even single-clicking.

2) double clicking on status bar tries to open the parent form. I'm not sure what its doing as i dont provide any way for you to pass the parent form so i need to check that out.
You can get object of delegate via delegate.Target, but you should implement some common class for background processes (maybe Form or subclass of Form). Or Mb should ignore double-clicking on statusbar at least (but certainly shouldn't hang up)

To handle the user clicking X you can capture the ThreadAbortException and do the cleanup as appropriate
Thanks. I'll probably try this but I'm mostly feel uncomfortable about terminating thread than actually need to do some cleanup.

EDIT:
Probably it can be useful that single-clicking on rotating circle in statusbar will invoke context menu with all queuing tasks, clicking on menu item should display appropriate window with possibility to change conditions or abort command.
Last Edit: August 15, 2011, 09:05:28 PM by boroda74

boroda

  • Sr. Member
  • ****
  • Posts: 4669
A bug: calling Library_QueryGetAllFiles (probably Library_QueryGetNextFile also and other querying functions) always reset statusbar text from number/size of currently displayed/selected files to number/size of all files in library.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34392
MB_CreateBackgroundTask has been amended to take an extra parameter, the owner form. You can pass null, but if it is supplied, then double clicking on the taskbar will unhide this form

mbApiInterface.MB_CreateBackgroundTask(System.Threading.ThreadStart handler, System.Windows.Forms.Form owner);

the updated interface definition file is available in the language templates from the first post.
Updated MusicBee.exe to support the additional parameter (if this link is dead, just get MusicBee.exe from latest weekly update)

http://www.mediafire.com/?m9y0ix1e679wpc5
Last Edit: August 20, 2011, 10:16:27 AM by Steven

boroda

  • Sr. Member
  • ****
  • Posts: 4669
Steven, I've found a strange bug with updating tags of currently playing track using API. All tag changes made in tag editor are immediately reflected in MB UI. But tag changes made in background thread using API calls are not reflected until playback is finished or stopped. Though several tag updating API calls (for the same track) can make MB to display changes.

P.S. User VX reported that using 'Reencode tag' command of 'Additional tagging tools' plugin sometimes don't update tags in Inbox (and F5 doesn't help), but moving files to the library caused MB to display correct tags - I think it was the same issue.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34392
the GUI wouldnt be reliably updated until you call MB_RefreshPanels()
however if after you have called CommitTags() for a file its possible you could do some action in the MB gui yourself eg. scroll a track into view, it could show the new value but i dont think i can do anything about that
does that explain what you are seeing?