NoteWorthy Composer Forum

Forums => Tips & Tricks => User Tools => Topic started by: Opagust on 2014-09-23 07:49 pm

Title: Template files for developing JavaScript User Tools
Post by: Opagust on 2014-09-23 07:49 pm
After studying a user tool I downloaded a while ago (mmr.js from Warren Porter), I wanted to try to write a tool myself. So I downloaded a Java Script Editor and started to experiment.

After many trials and errors, I decided to first write a template script, that I could use as a starting point for developing a specific tool. When testing it, I discovered the different behaviour of the User Tool Environment, depending of the input type and return format.

So I ended up with 3 different templates: 1 for tools with input type 'Clip Text'  (and also 'Clip Text' as the only allowed return format),  1 for input type 'File Text' and return format 'File Text' and 1 for input type 'File Text' and Return Format 'Clip Text'.

You can find these template files in attachment. (After download, change the extention 'txt' to 'js'.)

I used each of these templates to write a user tool, which you will will find in seperate posts.

Any comments are welcome.

P.S. You can find these tools also on my website http://opagust.wordpress.com
Title: Re: Template files for developing JavaScript User Tools
Post by: Lawrie Pardy on 2014-09-23 11:19 pm
Thank you,
will try to make time to check 'em out soon.
Title: Re: Template files for developing JavaScript User Tools
Post by: Warren Porter on 2014-09-24 02:31 am
After studying a user tool I downloaded a while ago (mmr.js from Warren Porter), I wanted to try to write a tool myself. So I downloaded a Java Script Editor and started to experiment.

Thank you.  And I have to thank Rick G for getting me off the ground.  Probably the most useful thing I discovered was a way to covert a web page to a js tool with minimal changes to the working part of the script.  Browsers have a variety of consoles and debugging tools to quickly identify and fix problems before sharing them with the world.
Title: Re: Template files for developing JavaScript User Tools
Post by: Richard Woodroffe on 2014-09-24 09:00 am
P.S. You can find these tools also on my website http://opagust.wordpress.com

Hmmm, seems to be a private website and requires a logon and password.
Title: Re: Template files for developing JavaScript User Tools
Post by: Opagust on 2014-09-24 01:51 pm
Hmmm, seems to be a private website and requires a logon and password.


Oops, didn't know that. I thought the logon and password was only necessary for me writing in it. Found the setting and changed it to public. Should be solved now.
Title: Re: Template files for developing JavaScript User Tools
Post by: Opagust on 2014-10-03 07:11 am
I added following function to the templates: GetProp, SetProp, RemoveProp, GetOpt, SetOpt, RemoveOpt
Title: Re: Template files for developing JavaScript User Tools
Post by: Warren Porter on 2014-10-05 03:10 am
This is not quite a "template" but shows how I now create a Javascript user tool.  Starting with something like rubato.html (https://nwc-scriptorium.org/wp/rubato.html) I have access to more detailed error messages and debugging tools when working out the problems.  I'm showing it here just as a comparison with the .js version.  Once done, many things are already in place to convert it to a user tool (http://www.wjporter.com/nwc/rubato.js).

Thanks to Rick G for pointing me in the right direction.
Title: Re: Template files for developing JavaScript User Tools
Post by: Opagust on 2014-10-05 08:23 am
I added following function to the templates: GetProp, SetProp, RemoveProp, GetOpt, SetOpt, RemoveOpt

I discovered some bugs in the new functions SetProp and SetOpt (for operators other then "=") , and also in the function ModPositions (handling accidentals, chords with "pos2" and option "Stem" in Restchords).
Updates will follow as soon as possible.
Title: Re: Template files for developing JavaScript User Tools
Post by: Opagust on 2014-10-09 09:44 am
Updates will follow as soon as possible.

I corrected the bugs. Furthermore I isolated the common functions in a seperate file 'functions.js' and removed them from the templates. So in the future I won't have to change three templates for 1 change.
See attached files (and don't forget to change the extension into 'js' after downloading.
Title: Re: Template files for developing JavaScript User Tools
Post by: Opagust on 2014-10-13 07:26 am
I discovered and corrected 2 typos in function GetOpt ('optarry' and 'optary' instead of 'optarray').
Title: Re: Template files for developing JavaScript User Tools
Post by: Opagust on 2014-12-06 09:04 am
I added 2 functions to the tool 'Functions': GetLineProp  and SetLineProp, wich I used in my new tool 'MetronomeStaff' (see https://forum.noteworthycomposer.com/?topic=8963.msg63692#msg63692)