Skip to main content
Topic: Remove unneeded tags and opts: Tidy.js  (Read 13104 times) previous topic - next topic

Remove unneeded tags and opts: Tidy.js

This tool removes tags and options that do not effect the output.

During the course of editing, it is easy to set options that are superfluous, such as setting a slur direction on a note that is not slurred. Tidy.js will remove most of these.

Specifically, it will remove:
  • Visibility:TopStaff on Flows and Endings
  • Visibility:Never on Instruments and MPC's
  • Visibility:Always on everything else
  • ArticulationsOnStem where there are no articulations
  • Tie direction for notes that are not tied
  • Slur direction for notes that are not slurred

Using this tool before posting a clip to this forum will remove most of the extraneous items.
Using the tool on each staff before the final save should make the file easier to edit months later.
Quote from: Tidy.js
/*
   NWC2 User Tool, Ver 1.00 - Rick G.
   Purpose: remove unneeded tags and opts
   &Command: WScript Scripts\Tidy.js
*/
var io = WScript.StdIn.ReadAll().split("\r\n");
for (var j = 1; io[j].search(/\w+/) + 1; j++){
   switch (RegExp.lastMatch){
      case "Flow": case "Ending":
         Zap(/^!/, /\|Visibility:TopStaff$/); break;
      case "Instrument": case "MPC":
         Zap(/^!/, /\|Visibility:Never$/); break;
      case "Note": case "Chord": case "RestChord":
         Zap(/Staccato|Tenuto|Accent/, /ArticulationsOnStem,?/);
         Zap(/\^/, /Tie=\w+,?/);
      case "Rest":
         Zap(/Slur[,|?]/, /Slur=\w+,?/);
      default:
         Zap(/^!/, /\|Visibility:Always$/);
   }
}
WScript.StdOut.Write(io.join("\r\n"));
function Zap(re, re1) {
   if (!(re.test(io[j]))) io[j] = io[j].replace(re1, "");
} // if re is not in io[j], remove re1 from io[j]
Tidy.js doesn't remove everything that is superfluous. Some stem and tie directions are not removed, but this would require a voice analysis that is beyond the scope of this simple program.
Registered user since 1996