Skip to main content
Topic: Tool to add (or undo) velocity and volume to a dynamic (Read 1867 times) previous topic - next topic

Tool to add (or undo) velocity and volume to a dynamic

When a note requires constant effort (moving bow, column of air) to produce, it's volume can change with a cresc., decres., or hairpins, but velocity and volume must be specified on each dynamic.  Save the following under the name "dynamic.js".  Installation instructions are shown on the first four lines.
Code: [Select · Download]
/* Dynamic Velocity by Warren Porter "dynamic.js"
   After downloading this file, when setting it up in NWC User Tools create this command line:
   wscript "'Browse can insert the path for you' \dynamic.js"  <PROMPT:DYN?:=|Yes|Undo> <PROMPT:Dynamics:=*127,108,92,75,60,45,30,10>
 //  Substitutions: Wscript.Arguments <-> parms
 //                 Item(n)            <-> [n]
var rc=0, errMsg="";
function calculate(clip) {
  var dyn_table = [ "fff", "ff", "f", "mf", "mp", "p", "pp", "ppp" ]
  var dyn_vol1 = new Array();
  var i, j, OutText = "", relPos=0, absPos=0, goSwitch=false, dynSuffix;
  var lines = new Array(), result = new Array();
  // lines = clip.split("\n");  // As webpage
   lines = clip.split("\r\n");
  if (WScript.Arguments.length != 2) {
    errMsg="Needs option to override velocity or undo it as well as default dynamic levels";
return lines; }
  if (WScript.Arguments.Item(0) == "Undo") {
   for (j = 0; j < lines.length; j++) {
    if (lines[j].slice(1,8) == "Dynamic")
  lines[j]=lines[j].replace(/\|Opts[^\|]*\|/,"|"); }
   return lines;
  // First, break down the 2nd parm
  dyn_vol1 = WScript.Arguments.Item(1).split(",");
  if (dyn_vol1.length != 8 ) {
    errMsg="I need eight dynamic levels, the 2nd prompt was " + WScript.Arguments.Item(1);
return lines; }

  for (j = 0; j < lines.length; j++) { // Main processing loop
    var str = lines[j];
    result = str.match(/\|Dynamic\|Style:(mf|mp|[fp]{1,3})\|Pos:/)
if (result == null)

    switch (result[1]) {
  case "fff":
    i=0; break;
  case "ff":
    i=1; break;
  case "f":
    i=2; break;
  case "mf":
    i=3; break;
  case "mp":
    i=4; break;
  case "ppp":
    i=7; break;
  case "pp":
    i=6; break;
  case "p":
    i=5; break;
  default: errMsg="switch failed on " + result[1]; rc=1; return lines;  }
    var newstr="|Dynamic|Style:" + dyn_table[i] + "|Opts:Velocity=127,Volume=" + dyn_vol1[i] + "|Pos:"
    str = str.replace(result[0],newstr);
lines[j] = str;
}  // end of lines[j] loop;
  return lines;

var myLines=calculate(WScript.StdIn.ReadAll()).join("\r\n");
if (rc == 0)
Since 1998