Newbie Questions

To discuss development of addons / skins / customization of MediaMonkey.

Moderators: jiri, drakinite, Addon Administrators

MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Newbie Questions

Post by MPG »

VB programmer here, and I'm trying to migrate some custom functionality from MM4 to MM5.
For the most part I am having some success as I can some solutions to load but as you might expect, this javascript is a new beast. As you might expect, I have some newbie questions:

1) What are the actions_add.js, init.js and local.js files? How are they interrelated?

2) I have some code that is able to obtain the songs that are selected when the solution is added to the Edit Tags Submenu, but the same code doesn't work, when I add the solution to the top toolbar:
the actions_add file does the following:
var list = uitools.getSelectedTracklist();
- I then pass "list" as part of the openDialog call.
- "list" isn't populated when opened from the toolbar.

3) I want my solution to be added to the Edit Tags submenu and the toolbar. Seems I can do one or the either, but not both.
To add my solution to the toolbar I have the following in the local.js:
(function () {
window.uitools.addToolButton('righttoolbuttons', 'javascript' /* icon */ , function () {
var dlg = uitools.openDialog('dlgReplaceString', {
show: true,
notShared: true,
title: 'Replace String',
});
});
})();

To add my solution to the submenu I have the following in the actions_add.js:
window._menuItems.editTags.action.submenu.push({
action: actions.ReplaceString,
order: 30,
grouporder: 20
});

4) How do I save and retrieve the values entered in a dialog screen?

5) How does one go about creating a svg file?
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Newbie Questions

Post by drakinite »

Great to have you migrating your scripts!

1) The answer to your question about _add files and init.js can be found here: https://www.mediamonkey.com/wiki/Gettin ... dons)#Code
There's nothing intrinsically special about local.js; it's just an extra script you can call with localRequirejs (more info here: https://www.mediamonkey.com/wiki/Import ... #requirejs)

2) Could you show me more of your code? Does it await the tracklist's whenLoaded() ?

3) If you've created actions.ReplaceString and it already has code to open the dlgReplaceString dialog inside its execute function, you could do the following instead of your provided toolbutton code:

Code: Select all

window.uitools.addToolButton('righttoolbuttons', 'javascript', actions.ReplaceString.execute);
Just make sure that you define actions.ReplaceString inside actions_add.js. If it's created in a different file, it might not load properly.

4) https://www.mediamonkey.com/wiki/Gettin ... oring_Data
If your dialog has an OK button, then you should listen to its "click" event and do all your business code there. You can then retrieve the values of your controls (i.e. checkboxes, dropdowns, text inputs, etc.) and store them with app.setValue. For an example, check out the Split Multi-Value Fields addon.

5) You can use any vector graphics editor, such as Adobe Illustrator (paid) or Inkscape (free). Looks like there's also a free web-based one: http://svgeditoronline.com/editor/
Sometimes the SVG code that's output from those programs doesn't play nice with MediaMonkey, so you might have to edit the code after the fact. If an icon doesn't display properly, try changing the <svg> at the top with this:

Code: Select all

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
	 viewBox="0 0 1000 1000" style="enable-background:new 0 0 1000 1000;" xml:space="preserve">
The viewBox attribute might lead to the icon scaling wrong, so you might need to change the numbers around a bit.
It's definitely not an exact science, but with some trial and error, you can get it to work!
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Newbie Questions

Post by MPG »

Thanks for your help....I'm getting closer and closer...
Questions 1, 2 & 4 are resolved.
I'm still not getting my add-on to add itself to the toolbar and the sub-menu. Could it be due to my image file as it isn't loading either.

the original svg file is:

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="480" height="335" viewBox="0 0 480 335" xml:space="preserve">
<desc>Created with Fabric.js 3.6.3</desc>
<defs>
</defs>
<g transform="matrix(0.97 0 0 0.97 240.06 167.94)"  >
<image style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;"  xlink:href="data:image/png;base64,... (the image code)
</g>
</svg>
My updated file:

Code: Select all

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Generator: svgeditoronline.com  -->
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" style="enable-background:new 0 0 1000 1000;" xml:space="preserve">
<desc>Created with Fabric.js 3.6.3</desc>
<defs>
</defs>
<g transform="matrix(0.97 0 0 0.97 240.06 167.94)"  >
	<image style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-dashoffset: 0; stroke-linejoin: miter; stroke-miterlimit: 4; fill: rgb(0,0,0); fill-rule: nonzero; opacity: 1;"  xlink:href="data:image/png;base64,...(the image code)
	</g>
</svg>
See anything blatantly wrong?
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Newbie Questions

Post by drakinite »

I can't tell; I haven't used embedded images in SVGs before. Try using an existing icon, like "options" or "music" to see if your toolbutton shows up. Also, did you place it in skin/icon/<name>.svg?
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Newbie Questions

Post by MPG »

Hey drakinite,
I'm making serious headway....the script loads on the toolbar and the icon is now displayed....even has scroll over help text. :)

Unfortunately, the script is not being added to the EditTags submenu. :( The code I have in the actions_add.js file is

Code: Select all

window._menuItems.editTags.action.submenu.push({
        action: actions.ReplaceString,
        order: 30,
        grouporder: 20
});

actions.ReplaceString = {
	title: _('Replace String') + '...',
	hotkeyAble: true,
	icon:'ReplaceString',
	disabled: uitools.notMediaListSelected,
    visible: window.uitools.getCanEdit,
    execute: async function () {
		// get list of selected songs
		var list = uitools.getSelectedTracklist();
        var dlg = uitools.openDialog('dlgReplaceString', {
            show: true,
            modal: true,
            title: _('Replace String'),
            tracks: list
        });
	}
}
I expected the "push" code to add the ReplaceString call to the submenu.

Also, can I add icon to the "push" code? Something along the lines of:
window._menuItems.editTags.action.submenu.push({
action: actions.ReplaceString,
order: 30,
grouporder: 20
icon: 'ReplaceString'
});
I've tried the call, it doesn't fail, but it doesn't add the icon or the call to the submenu.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Newbie Questions

Post by drakinite »

MPG wrote: Sat Nov 06, 2021 12:08 pm

Code: Select all

window._menuItems.editTags.action.submenu.push({
        action: actions.ReplaceString,
        order: 30,
        grouporder: 20
});

actions.ReplaceString = {
	title: _('Replace String') + '...',
	hotkeyAble: true,
	icon:'ReplaceString',
	disabled: uitools.notMediaListSelected,
    visible: window.uitools.getCanEdit,
    execute: async function () {
		// get list of selected songs
		var list = uitools.getSelectedTracklist();
        var dlg = uitools.openDialog('dlgReplaceString', {
            show: true,
            modal: true,
            title: _('Replace String'),
            tracks: list
        });
	}
}
I think I know your issue. If your code is written in that order, then it won't work. You need to define actions.ReplaceString before you add it to the editTags list.
As it is now, your code is doing the following:

Code: Select all

window._menuItems.editTags.action.submenu.push({
        action: [b]undefined[/b],
        order: 30,
        grouporder: 20
});
That is because at the time you are pushing that to the list, actions.ReplaceString is undefined.

Also, I don't believe you can directly specify an icon on the submenu list, because the icons are controlled by the action. But I see that you already specified an icon inside actions.ReplaceString, so you should be good once it works.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Newbie Questions

Post by MPG »

Yep that worked. Strange, I had it reversed for quite some time and it never worked, so I switched them. Anyway...I'm off the races, on to the next one. If anyone wants the solution, I can make it available. Just send me a PM.

The solution allows you to replace text in title, Artist, Album, Album Artist, or All of them.

I use it to remove "&" with the word "And" as it causes difficulties in doing searches.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Newbie Questions

Post by drakinite »

Great! Wanna add it to the Addons listing? I haven't yet written on the Wiki about how to submit addons, but I wrote instructions in this forum reply: viewtopic.php?p=482637#p482637

If you don't yet know how to create an MMIP (addon installer), it's simple: https://www.mediamonkey.com/wiki/Gettin ... ackages.29
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Newbie Questions

Post by MPG »

Hi drakinite,
I attempted to upload my solution and when I added the mmip file I am receiving the following error:
Unable to read file information from the "Install.ini"

I don't have an ini file. Should I?
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Newbie Questions

Post by drakinite »

It needs to either have a valid install.ini (MM4) or a valid info.json (MM5). Did you make sure the folder structure is correct?
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Peke
Posts: 17457
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Newbie Questions

Post by Peke »

MPG wrote: Sun Nov 07, 2021 11:30 pm Hi drakinite,
I attempted to upload my solution and when I added the mmip file I am receiving the following error:
Unable to read file information from the "Install.ini"

I don't have an ini file. Should I?
The best woudl be to open support Ticket and send us MMIP. Someone will look at it ASAP.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Newbie Questions

Post by MPG »

Submitted the file yesterday. Thanks for the help Pete!

On the call, window.uitools.addToolButton, is it possible to use centertoolbuttons instead of right righttoolbuttons? I'd like my addons grouped together in the center of the toolbar and in a specific order.
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Newbie Questions

Post by drakinite »

Not by default, no. The three toolbutton categories in the main window bar are lefttoolbuttons, viewtoolbuttons, and righttoolbuttons. You could add your own category, but it would require adding a new container to the that main toolbar and adding CSS styling to make it fit.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
MPG
Posts: 418
Joined: Tue May 13, 2008 11:22 pm

Re: Newbie Questions

Post by MPG »

Thanks for the response. Any chance we can request it to be added, or have the toolbar enhanced to have functionality similar to mm4?
TIA
MPG
Triumph - Hold On: Music holds the secret, to know it can make you whole.
drakinite
Posts: 965
Joined: Tue May 12, 2020 10:06 am
Contact:

Re: Newbie Questions

Post by drakinite »

Not sure myself - I'd say put it in the beta testing/bugs/feature requests channel, to see if the idea gets any traction.
Image
Student electrical-computer engineer, web programmer, part-time MediaMonkey developer, full-time MediaMonkey enthusiast
I uploaded many addons to MM's addon page, but not all of those were created by me. "By drakinite, Submitted by drakinite" means I made it on my own time. "By Ventis Media, Inc., Submitted by drakinite" means it may have been made by me or another MediaMonkey developer, so instead of crediting/thanking me, please thank the team. You can still ask me for support on any of our addons.
Post Reply