Skip to main content
Topic: Tools to favour sharps or flats in chords (Read 5381 times) previous topic - next topic

Tools to favour sharps or flats in chords

These two user tools make it easier to adjust the spelling of accidentals, where the NWC default is not what is required. It is usually safest to Force Accidentals before using these tools.

Copy the code and save it in your Scripts folder as: brm_FavourSharps.php
Code: [Select · Download]
<?php
/*******************************************************************************
brm_FavourSharps 1.00

Brian Maskell

History:
[2010-09-29] Version 1.00 - Initial version
*******************************************************************************/
require_once("lib/nwc2clips.inc");

$clip = new NWC2Clip('php://stdin');

// MAIN PROGRAM

echo $clip->GetClipHeader()."\n";

foreach ($clip->Items as $item) {
    $o = new NWC2ClipItem($item);

    if (($o->GetObjType()=="Note")||($o->GetObjType()=="Chord")) {
$opts = $o->GetOpts();
$pos = $opts["Pos"];
if (is_array($pos)) {
   for ($i=0; $i<count($pos); $i++) {
        $n = new NWC2NotePitchPos($pos[$i]);
if ($n->Accidental=="b") {
   $n->Accidental="#";
      $n->Position--;
      $pos[$i]=$n->ReconstructClipText();
      unset($n);
}
   }
} else {
        $n = new NWC2NotePitchPos($pos);
if ($n->Accidental=="b") {
   $n->Accidental="#";
      $n->Position--;
      $pos=$n->ReconstructClipText();
      unset($n);
}
}
$o->Opts["Pos"] = $pos;
    } elseif ($o->GetObjType()=="RestChord") {
$opts = $o->GetOpts();
$pos = $opts["Pos2"];
if (is_array($pos)) {
   for ($i=0; $i<count($pos); $i++) {
        $n = new NWC2NotePitchPos($pos[$i]);
if ($n->Accidental=="b") {
   $n->Accidental="#";
      $n->Position--;
      $pos[$i]=$n->ReconstructClipText();
      unset($n);
}
   }
} else {
        $n = new NWC2NotePitchPos($pos);
if ($n->Accidental=="b") {
   $n->Accidental="#";
      $n->Position--;
      $pos=$n->ReconstructClipText();
      unset($n);
}
}
$o->Opts["Pos2"] = $pos;
    } else {
       // just echo the item unchanged
    }
    echo $o->ReconstructClipText()."\n";
}
echo NWC2_ENDCLIP."\n";

exit(NWC2RC_SUCCESS);
// exit(NWC2RC_REPORT); // alternative for debugging

?>

Copy the code and save it in your Scripts folder as: brm_FavourFlats.php
Code: [Select · Download]
<?php
/*******************************************************************************
brm_FavourFlats 1.00

Brian Maskell

History:
[2010-01-22] Version 1.00 - Initial version
*******************************************************************************/
require_once("lib/nwc2clips.inc");

$clip = new NWC2Clip('php://stdin');

// MAIN PROGRAM

echo $clip->GetClipHeader()."\n";

foreach ($clip->Items as $item) {
    $o = new NWC2ClipItem($item);

    if (($o->GetObjType()=="Note")||($o->GetObjType()=="Chord")) {
$opts = $o->GetOpts();
$pos = $opts["Pos"];
if (is_array($pos)) {
   for ($i=0; $i<count($pos); $i++) {
        $n = new NWC2NotePitchPos($pos[$i]);
if ($n->Accidental=="#") {
   $n->Accidental="b";
      $n->Position++;
      $pos[$i]=$n->ReconstructClipText();
      unset($n);
}
   }
} else {
        $n = new NWC2NotePitchPos($pos);
if ($n->Accidental=="#") {
   $n->Accidental="b";
      $n->Position++;
      $pos=$n->ReconstructClipText();
      unset($n);
}
}
$o->Opts["Pos"] = $pos;
    } elseif ($o->GetObjType()=="RestChord") {
$opts = $o->GetOpts();
$pos = $opts["Pos2"];
if (is_array($pos)) {
   for ($i=0; $i<count($pos); $i++) {
        $n = new NWC2NotePitchPos($pos[$i]);
if ($n->Accidental=="#") {
   $n->Accidental="b";
      $n->Position++;
      $pos[$i]=$n->ReconstructClipText();
      unset($n);
}
   }
} else {
        $n = new NWC2NotePitchPos($pos);
if ($n->Accidental=="#") {
   $n->Accidental="b";
      $n->Position++;
      $pos=$n->ReconstructClipText();
      unset($n);
}
}
$o->Opts["Pos2"] = $pos;
    } else {
       // just echo the item unchanged
    }
    echo $o->ReconstructClipText()."\n";
}
echo NWC2_ENDCLIP."\n";

exit(NWC2RC_SUCCESS);
// exit(NWC2RC_REPORT); // alternative for debugging

?>