Author Topic: API request  (Read 8078 times)

boroda

  • Sr. Member
  • ****
  • Posts: 4595
Steven, actually is very old request, but you had said that its not very easy and it can't implement it in current mb version (i don't remember what version had been current at that moment). maybe you can implement for 3.1

.now virtual tags are very powerfuk, they even support regexes, bur asr is more powerful anyway. i want to use custom functions in virtual tag. its mainly to use asr resets in virtual tags, but if virt. tags are somehow cached in ui, i think its possible to use even 'auto-library reports' presets in them. alr can consume tags of any possinle track unlike existing virt. tag functions and asr. by 'any' i don't mean 'all', but anyway it will be at least several tracks and some caching is required. to tell the more if support for custom functions is implemented it will be possible to combine existing functions, asr presets and alr presets.

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
just so i am clear you want to define some function eg. $FirstChar(<field>) which returns the first character of the field and the user can include $FirstChar in a virtual tag ?

boroda

  • Sr. Member
  • ****
  • Posts: 4595
just so i am clear you want to define some function eg. $FirstChar(<field>) which returns the first character of the field and the user can include $FirstChar in a virtual tag ?
not at all. i think any custom function parameters (except for track url) are useless for MY purposes as neither ASR not ALR cant accept anything. all possible parameters are defined in respective presets. i mean something like: $CustomFunc("plugin id", "preset name", <URL>) where "preset name" is just a string internal for plugin and "plugin id" is either plugin name displayed in 'plugins' section of mb prefs or some new string in "about" structure, which plugin returns from Initialise() function.
Last Edit: February 21, 2017, 07:57:31 AM by boroda74

boroda

  • Sr. Member
  • ****
  • Posts: 4595
actually function syntax should be not $CustomFunc("plugin id", "preset name", <URL>), but $CustomFunc("plugin id", "preset name") because track url must transfered to plugin always and automatically.
Last Edit: February 21, 2017, 08:13:31 AM by boroda74

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
I am still not really clear on this. Do you see these functions being used in virtual tags or is it just a way for one plugin to invoke a function in another plugin?

boroda

  • Sr. Member
  • ****
  • Posts: 4595
asr/alr presets can write processed tags of 1 and several tracks respectively to custom tag. it may be more useful if they could return string value to virtual tag (or some part of virtual tag) rather than save results to custom tags. no need to invoke another plugin from given plugin. asr/alr presets can be adjusted by user to use any tags he wants, but there is need for mb to transfer tag values to them, only track url. i think it would be too difficult for you to maintain separate custom functions for possible presets, so having just 1 func. $CustonFunc() is sufficient, but mb must know what preset user wants to involve, therefore $CustomFunc must accept some plugin id or name (this info is needed for mb only, not for plugin) and preset id/name (these ids/names will depend on plugin in question). $CustomFunc will return just a string, which must be substituted instead of func. in the virt. tag.

boroda

  • Sr. Member
  • ****
  • Posts: 4595
also: i don't this at the moment, but it may be useful in future to prototype $CustomFunc as $CustomFunc(string pluginId, string presetOrFunctionIdName, params string[] p), where p are optional list of function parameters (e.g. some <Tag1>, <Tag2>, "explicit string value", etc.).

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
I am afraid I still don't get this request.
If I was to create API support:
- there would need an API function to define the custom function eg. mbApiInterface.Settings_DefineFunction() ? what parameters would that new API function take? eg. just the name of the custom function ("CustomFunc" in your example) and the number of parameters your custom function takes?
- once MB knows of the existence of this custom function, each time MB encounters "$CustomFunc" (eg. in a virtual tag), what should MB do?

boroda

  • Sr. Member
  • ****
  • Posts: 4595
Steven, 1st of all sorry for my english in my previous posts, some words are missing and its hard even for me to read them.

my answer to your questions:

- i think '$CustomFunc' must be the name of universal metafunction to involve any custom function of any plugin. 1st parameter of $CustomFunc metafunction is string with plugin id. i don't know where is the best place to give mb that id: maybe in extended 'about' structure returned from plugin's Initialise() method, maybe in some separate method like 'mbApiInterface.Settings_RegisterVirtualTagFunctionPlugin(string pluginId)'.

- virtual tag function plugin must somehow export for mb ONE function: string VirtrualTagFunctions(string functionName, string trackUrl, params string[] p)
where p is OPTIONAL list of string parameters. I don't need these parameters right now, but i think its useful to implement them from the beginning.

- so we have:

[1] plugin must somehow register itself in mb as virtual tag function plugin. mb doesn't know what functions are supported by plugin, only users (and ofc. plugin developer) know their names.

[2] if mb encounters in virtual tag (and i hope in file organization templates, etc.) substring '$CustomFunc(somePluginId, somePluginFunctionName, <Tag1>, <Tag2>, some explicit string1, etc)', then mb calls plugin's 'VirtrualTagFunctions(somePluginFunctionName, trackUrl, params p1, p2, p3, etc)', plugin here is defined by 1st parameter of $CustomFunc, but this plugin id is not sent to plugin, its needed for mb only to know which plugin must be invoked. trackUrl must be sent to 'VirtrualTagFunctions()' by mb always automatically. mb substitutes substring '$CustomFunc(somePluginId, somePluginFunctionName, <Tag1>, <Tag2>, some explicit string1, etc)' by result of plugin function 'VirtrualTagFunctions()'.

[3] mb shouldn't validate plugin's function names and/or parameters. plugin itself must validate them. personally in MY case custom function names are just asr/alr preset names without optional parameters (except for track url, which is not optional).

[4] i don't know if its very difficult or not, but it might be very useful if $CustomFunc(pluginId, funcName, some optional text parameters) could have any nested mb native functions and/or nested custom functions in the optional parameter list (e.g. $CustomFucn(pluginId, funcName, some text, $Left(<Tag1>, 3))).

P.S. plugin id, function names and their parameters (if any) must be specified for USERS by plugin developer. MB itself doesn't need to know anything except for PLUGIN ID.

P.P.S. i dont know if its good solution, but plugin could send validation exception to mb by returning null intead of any (empty or not) string from VirtrualTagFunctions().
Last Edit: February 25, 2017, 02:46:51 PM by boroda74

boroda

  • Sr. Member
  • ****
  • Posts: 4595
Steven, I do not want to rush you, but any news on this topic?

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
yes its already well under way but there is one more difficult problem to solve. I will do it though

all you will need to do is declare any custom functions in your plugin, named starting "CustomFunc_". The function can take 0..n parameters but they must all be strings

eg.
public string CustomFunc_TagFunc()
{
...
}
public string CustomFunc_TagFuncWith2Params(string p1, string p2)
{
;..
}

MB will detect these custom functions when the plugin is loaded.
The user can then use those functions anywhere a forumula is used
eg.
VirtualTag1 = $TagFuncWith2Params(<Artist>,<Album>)

MB will do some basis validation to ensure the parameter count is consistent with the declaration


edit:
this is done for the next update. One issue is any references to the plugin function are unresolved until the plugin has loaded. I dont think that should be too much of an issue but it means that if you display the virtual tag in a panel for example, the value is blank when MB first starts.

I am tempted to take another approach where you would implement the functions in the same way but using a standalone .dll eg. MB_Func_xxxxx.dll that MB loads straight away.
Do you see any issues with implementing the functions in a separate .dll file?
Last Edit: March 28, 2017, 07:15:52 PM by Steven


boroda

  • Sr. Member
  • ****
  • Posts: 4595
yes its already well under way but there is one more difficult problem to solve. I will do it though

all you will need to do is declare any custom functions in your plugin, named starting "CustomFunc_". The function can take 0..n parameters but they must all be strings

eg.
public string CustomFunc_TagFunc()
{
...
}
public string CustomFunc_TagFuncWith2Params(string p1, string p2)
{
;..
}

MB will detect these custom functions when the plugin is loaded.
The user can then use those functions anywhere a forumula is used
eg.
VirtualTag1 = $TagFuncWith2Params(<Artist>,<Album>)

MB will do some basis validation to ensure the parameter count is consistent with the declaration


edit:
this is done for the next update. One issue is any references to the plugin function are unresolved until the plugin has loaded. I dont think that should be too much of an issue but it means that if you display the virtual tag in a panel for example, the value is blank when MB first starts.
that's great! will try new functionality soon.


I am tempted to take another approach where you would implement the functions in the same way but using a standalone .dll eg. MB_Func_xxxxx.dll that MB loads straight away.
Do you see any issues with implementing the functions in a separate .dll file?

personally i don't need this at the moment, but i think it may be useful for simple pure functions in the future.



------------------

Steven, which symbols are safe to use inside string parameters? especially i'm interested in: . : - _
Last Edit: April 02, 2017, 04:49:17 AM by boroda74

Steven

  • Administrator
  • Sr. Member
  • *****
  • Posts: 34313
Steven, which symbols are safe to use inside string parameters? especially i'm interested in: . : - _
any character that doesnt cause MB to incorrectly parse the template - those characters should be fine

boroda

  • Sr. Member
  • ****
  • Posts: 4595
Steven, i've defined function

CustomFunc_ASR(string url, string presetId)

where presetId is some string identifier. 1st parameter is sent to plugin as is and the second parameter is auto-substituted track url + " " + preset id as defined by user.

you either alway send track url to 1st parameter (and user must not set this hidden 1st param) or don't auto-substitute track url at all.