Author Topic: MusicBee API  (Read 289360 times)

e-motiv

  • Full Member
  • ***
  • Posts: 188
http://emonic.sourceforge.net/html/usage.html - Emonic is a C#/.NET 2.0 plugin for Eclipse, the link explains how it's set up.
Finally, after many hours, I got it to work and the (example) plugin works in MB! Eureka!

For possible future users of Emonic (Eclipse):
* U have to install NAnt yourself and set the path in Global preferences (.NET, Building, Nant).
* The "Emonic Auto Builder" never works more than once for me, try making your own builder with the same NAnt path (Project properties, builders, new).
edit: it actually does work, I just didn't know you have to "Clean" your project first (after failures?)
* Sometimes some .build file editing helps overcome some otherwise hidden problems...
Last Edit: June 30, 2011, 10:02:28 PM by R U Bn ?
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

e-motiv

  • Full Member
  • ***
  • Posts: 188
Where can I put a little html file I put together for starting plugin developers? (Based on Elberet's info)
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34394
could you set up a topic in the "How To" section?

e-motiv

  • Full Member
  • ***
  • Posts: 188
Sure, but how do I write html on this forum? I'd prefer not to do everything in html and BBcode
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34394
i could host the html page on this website if you want, but it might be better to put it somewhere you can control (eg. dropbox) if you need to edit it

e-motiv

  • Full Member
  • ***
  • Posts: 188
Sure, but how do I write html on this forum? I'd prefer not to do everything in html and BBcode
API Docs, HowTo's etc.. <- Like this OK?
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

Elberet

  • Full Member
  • ***
  • Posts: 167
By the way... in my eternal quest for elegant code (it's a curse, really), I've encapsulated the raw MusicBee API in a nicer, more .NET'ish set of classes with Properties and Events -- fancy stuff. Basically, the idea is that I hate (with a vengeance) longwinded switch-case constructs and rather wanted something like...
Code
api.TrackChanged += (MusicBeeEventArgs args) => { Console.WriteLine(args.RelatedFile.AlbumArtist); };
then...
Code
public void ReceiveNotification(string sourceFileUrl, NotificationType type) {
    switch(type) {
        case NotificationType.TrackChanged:
            Console.WriteLine(mbApiInterface.Library_GetFileTag(relatedFile, MetaDataType.AlbumArtist);
            break;
    }
}

Would something like this make life easier for you, R U Bn?

e-motiv

  • Full Member
  • ***
  • Posts: 188
Would something like this make life easier for you, R U Bn?
It would! Great!  Reminds me of AS 3 (which follows the ECMA standard).  More developer-friendly.
  Developing @ e-motiv.net       --       Musicbee plugins: Speak Back - Ghost Tracks - Radio Dig

Elberet

  • Full Member
  • ***
  • Posts: 167
Right. I'll clean this up and put a preview version on GitHub or something.

---

Now to something completely different (not!): NowPlaying_GetDuration returns the current playback duration as an integer number of milliseconds. Library_GetFileProperty and NowPlaying_GetFileProperty when called with FilePropertyTag.Duration return a less precise formatted string. This is weird, and I'd prefer milliseconds in all three cases. :-/

Elberet

  • Full Member
  • ***
  • Posts: 167
I've pushed my plugin API wrapper to github: https://github.com/Elberet/MusicBeeAPI

You can either fork the repository with any implementation of Git or download an archive. Some highlights:
  • the PluginInfo struct returned to MusicBee is populated from assembly and plugin attributes. See Properties\AssemblyInfo.cs.
  • only Initialize, Dispose and PluginConfigure remain as plugin entrypoints, everything else is driven by event listeners. Example below because it breaks the list if used inline...
  • different plugin types can be specified in the frontend attribute: [PluginFrontend(TargetApplication="app", PluginType=PluginType.ArtworkRetrieval)]. This also requires that the frontend class implements the IArtworkProvider interface, but that constraint is checked at runtime only.
  • currently incomplete: MultiArtist and MultiComposer tags, querying playlists, querying the library, storage plugins, many methods in the now playing list wrapper, miscellaneous.

Example: listen to TrackChanged events and print the changed-to track's title on the console. (Not terribly useful since there is no console, but the code works.)
Code
using System;
using System.Windows.Forms;
using MusicBeePlugin;

namespace ExamplePlugin
{
    [PluginFrontend]
    class Example : IPluginFrontend
    {
        void IPluginFrontend.Initialize(IMusicBeeAPI api, out int configPanelHeight) {
            configPanelHeight = 0;
            api.PluginStartup += PluginStartup;
        }

        private void PluginStartup(NotificationEventArgs args) {
            args.API.TrackChanged += TrackChanged;
        }

        private void TrackChanged(NotificationEventArgs args) {
            Console.WriteLine(args.RelatedFile.TrackTitle);
        }

        bool IPluginFrontend.PluginConfigure(Panel configPanel) {
            return false;
        }

        void IDisposable.Dispose() { }
    }
}

boroda

  • Sr. Member
  • ****
  • Posts: 4669
Steven, for unclear reasons setting album/track rating (using MB API) to "5" or "5.0" actually sets it to 0.3 (half star is displayed instead of 5 stars).

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34394

boroda

  • Sr. Member
  • ****
  • Posts: 4669
Steven, doesn't MB currently send TagsChanged (including on changing 'Play count' and 'Skip count' tags) notification yet?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34394
it doesnt send any tag notification for play or skip count. It should for any when tags are changed by the user (incl rating) and saved to file.
see:
http://getmusicbee.com/forum/index.php?topic=3778.msg21175#msg21175

i havent uploaded the amended interface file, but the enum for the notifications are:
        TagsChanging = 10,
        TagsChanged = 11,
        RatingChanged = 12

boroda

  • Sr. Member
  • ****
  • Posts: 4669
Well, could you add notification 'track is about to be changed'? It should be sent in exactly the same cases as 'track changed', but before track is really changed so one can retrieve all file properties and tags for changing track.