Skip to main content
Topic: Octave Up (Read 8234 times) previous topic - next topic

Octave Up

A new webpage will add to a note (not an existing chord) the same note an octave higher, replicating any accidental and keeping all other attributes of the original note intact.

octaveup.html.  It is on the page: nwc.
Since 1998

Re: Octave Up

Reply #1
That page also will replicate a tie for the new note if there was one on the original note.  I've also changed the Do It Yourself.txt page.
Since 1998

Re: Octave Up

Reply #2
Typical problem from cut & paste: <title>Modify Tempos</title>
It should have been "Octave Up".

Re: Octave Up

Reply #3
Good catch.  Fixed and uploaded.
Since 1998

 

Re: Octave Up

Reply #4
I have converted this to a user tool.  The new note will be an octave up or octave down depending upon the prompt.  See code for installation instructions. Modified to ignore "Fake" input when the selection starts in the middle of a measure.
Code: [Select · Download]
/*
 doOctave.js  by Warren Porter

 <PROMPT:Dir?:=|Up|Down>
                                  Octave Tool
 This tool will convert a note to an octave chord, replicating accidentals and tie status.  The new note will be higher or lower
 than the original note depending on the prompt.

 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 doOctave.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 and " <PROMPT:Dir?:=|Up|Down>" at the end.
 5) Clip text should be selected and check no options.
 */

rc=0, errMsg="";

function doUp(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 (/Fake/.test(lines[i]))
    lines[i] = "#";
  else {
    result = lines[i].match(/(\|Note.*Pos:)([n#bvx]?)(-?\d+)(\^?)(.*)$/) // 1. Note thru Pos 2. Accidental 3. Position 4. Ties 5. To end of line
if (result != null) {
  var note_lit = result[1];
  var acc_lit = result[2]
  displ = parseInt(result[3]);
  var a_tie = result[4]
  var eol = result[5]
  note_lit = note_lit.replace("Note","Chord")
  upDispl = displ + 7;
  lines[i] = note_lit + acc_lit + displ + a_tie + "," + acc_lit + upDispl + a_tie + eol; }
   } }    // End main loop
  return lines;
}
function doDown(clip) {
var displ=0, dnDispl=0;
var result = new Array();
var lines = clip.split("\r\n");
  for (i = 1; i < lines.length; i++) {           // Main processing loop
  if (/Fake/.test(lines[i]))
    lines[i] = "#";
  else {
    result = lines[i].match(/(\|Note.*Pos:)([n#bvx]?)(-?\d+)(\^?)(.*)$/) // 1. Note thru Pos 2. Accidental 3. Position 4. Ties 5. To end of line
if (result != null) {
  var note_lit = result[1];
  var acc_lit = result[2]
  displ = parseInt(result[3]);
  var a_tie = result[4]
  var eol = result[5]
  note_lit = note_lit.replace("Note","Chord")
  dnDispl = displ - 7;
  lines[i] = note_lit + acc_lit + dnDispl + a_tie + "," + acc_lit + displ + a_tie + eol; }
   }  }   // End main loop
  return lines;
}

var myLines;
  if (WScript.Arguments.length != 1) {
    errMsg="NO Prompt read.";
rc=1; }
  else {
    if (WScript.Arguments.Item(0).slice(0,2) == "Up")
  myLines=doUp(WScript.StdIn.ReadAll()).join("\r\n");
else
  myLines=doDown(WScript.StdIn.ReadAll()).join("\r\n"); }

if (rc == 0)
  WScript.StdOut.Write(myLines);
else
  WScript.StdErr.Write(errMsg);
WScript.quit(rc);
Since 1998


Re: Octave Up

Reply #6
If NWC's User Tool implementation is inspired, a simple task should not need a lot of code.
As evidence, I present this:
Code: (php) [Select · Download]
<?php
# rg_AddOctave.php ver 1.1 NWC User Tool
# Ref: http://my.noteworthysoftware.com/?topic=7901.0
$dir = in_array('Up', $argv)? 7: -7;
$io = file('php://stdin');
foreach(preg_grep('/^\|Note\|/', $io) as $k=>$v) {
  preg_match('/^.Note(.*?Pos:(.*?)(-?\d+)(.*?))([|\s].*)$/', $v, $m);
  $io[$k] = '|Chord'.$m[1].','.$m[2].($dir + $m[3]).$m[4].$m[5]."\n";
  if (in_array('-t', $argv)) fwrite(STDERR, print_r($m, true));
}
echo join($io);
?>
and submit that the hypothesis is not disproved by the task of adding octaves to notes.
For those interested in how this works, add '-t' to the command line, as in: <PROMPT:Dir?:=|Up|Down> -t
Registered user since 1996