NoteWorthy Composer Forum

Forums => Tips & Tricks => User Tools => Topic started by: Warren Porter on 2017-04-22 06:49 pm

Title: Force Stem Up for unstemmed middle line notes.
Post by: Warren Porter on 2017-04-22 06:49 pm
Code: [Select · Download]
/*
 doStem.js  by Warren Porter
                                  Stem Tool
 This tool will change all notes on the middle line where no stem direction is specified to stem up.

 This tool can operate on ONLY a selected part of a staff, or, if nothing has been selected, the entire staff.

 To install:
 1) Save this file with the name doStem.js on your computer and remember its location.
 2) Start NWC and press Alt/F8.  Pick new
 3) After choosing a name and group, browse for this file and click "Open".
 4) Insert "wscript " at the beginning of the command.
 5) Clip text should be selected and check no options.
 */

rc=0, errMsg="";

function doProcess(clip) {
var displ=0, upDispl=0;
var result = new Array();
var lines = clip.split("\r\n");
  for (i = 1; i < lines.length; i++) {           // Main processing loop
  if (lines[i].indexOf("Stem=") > 0)  // Already has stem direction specified
    continue;
  else {
    result = lines[i].match(/(\|Note.*Pos:)([n#bvx]?)0/) // 1. Note thru Pos 2. Accidental 3. Position 4. Shape 5. Ties 6. To end of line
if (result != null) {
  lines[i] += "|Opts:Stem=Up" }
   } }    // End main loop
  return lines;
}

var myLines;
  myLines=doProcess(WScript.StdIn.ReadAll()).join("\r\n");

if (rc == 0)
  WScript.StdOut.Write(myLines);
else
  WScript.StdErr.Write(errMsg);
WScript.quit(rc);
If you have to transpose after running this, run Audit Note Stems and then rerun it.