Skip to main content
Topic: adp_GlobalMod.php and accidentals (Read 14396 times) previous topic - next topic

adp_GlobalMod.php and accidentals

When trying to alter the pitch of notes (say outside a range) adp_GlobalMod behaves oddly when the note has an accidental. Instaed of lowering the pitch by say -7 it sets the Pos to -7.

Has anyone found a solution. I am struggling to learn php and understand how GlodalMod works if I find a solution before my brain fails I will post it.
I'll understand all this $thing-> $somethingelse one day...

Re: adp_GlobalMod.php and accidentals

Reply #1
It would help if you could post the command line you're trying.

Are you perhaps using "Pos=-7" instead of "Pos-=7"?  The first sets the pos to -7 (absolute assignment) and the second subtracts 7 from the existing pos (relative assignment).

Edit:  Sorry - after (belatedly) looking at the script, I see now the following comment in it:
Code: [Select · Download]
Known issues: altering positions might not work with accidentals.

I'll look at the code more and see if there's any workaround.

Re: adp_GlobalMod.php and accidentals

Reply #2
The slur can be treated as the accidental see the slightly tidied up clunky code bits
Code: [Select · Download]
			$optVal = rtrim($optVal) ;
$ModOptVal=$optVal;   \\new variable to hold stripped optVal
// is there a colour if so strip the colour code
   $pgiend = strpos($optVal,'!');
   if ($pgiend>0) $ModOptVal = substr($ModOptVal,0,$pgiend);
  // is there a slur if so strip the slur code
  $pgiend = strpos($optVal,'^');
                  if ($pgiend>0) $ModOptVal = substr($ModOptVal,0,$pgiend);
  // is there an accidental if so remove the accidental
$pgacclist = '\#bnxv';
if (strpbrk($pgacclist,substr($ModOptVal,0,1))) $ModOptVal = substr($ModOptVal,1);
\\ now check for a valid modification using the stripped optVal
switch ($comp)
{
case "<=" : if (!($ModOptVal <= $this->comparesTo[$opt])) return FALSE ; break ;
case "<"  : if (!($ModOptVal  < $this->comparesTo[$opt])) return FALSE ; break ;
case "==" : if (!($ModOptVal == $this->comparesTo[$opt])) return FALSE ; break ;
case ">=" : if (!($ModOptVal >= $this->comparesTo[$opt])) return FALSE ; break ;
case ">"  : if (!($ModOptVal  > $this->comparesTo[$opt])) return FALSE ; break ;
case "!=" : if (!($ModOptVal != $this->comparesTo[$opt])) return FALSE ; break ;
}
}
// well, it didn't disqualify itself, so I'd better return TRUE
return TRUE ;
.................
lines skipped
........................
switch ($this->GetAction())
{
case GM_DELETE: break ; // do nothing, as the action is to NOT PRINT
case GM_MOD:
$opts = gm_getTaggedOpt($this->ActionTarget,$o) ;
if ($opts === FALSE && !(in_array($this->ActionMod, array("+=", "-=")))) // if value doesn't exist, can't modify
{
inform("Couldn't perform ".$this->ActionTarget.$this->ActionMod.$this->ActionValue." in " . $o->ReconstructClipText()."\n");
break ;
}
if ($opts == FALSE) $opts = 0; // but we make an exception for += and -=, since 0 is often a default value for these

//is there a colour if so strip the colour code
                                $pgcolour = '';
                           $pgbcolour = FALSE;        
   $pgiend = strpos($opts,'!');
   if ($pgiend>0) 
   {
       $pgcolour = substr($opts,$pgiend+1);
           $opts = substr($opts,0,$pgiend);
           $pgbcolour = TRUE;
       }
  //is there a slur if so strip the slur code
                                $pgslur = '';
                                $pgbslur = FALSE;        
   $pgiend = strpos($opts,'^');
          if ($pgiend>0) 
        {
          $pgslur = substr($opts,$pgiend+1);
           $opts = substr($opts,0,$pgiend);
           $pgbslur = TRUE;
        }
        //is there an accidental if so remove the accidental
$pgacclist = '\#bnxv';
$pgbacc = FALSE;
$pgacc = '';
if (strpbrk($pgacclist,substr($opts,0,1)))
{
$pgacc = substr($opts,0,1);
$pgbacc = TRUE;
$opts = substr($opts,1);
}
          switch ($this->ActionMod) // now we can do the action
{
case "+=" : $opts += $this->ActionValue ; break ;
case "-=" : $opts -= $this->ActionValue ; break ;
case "*=" : $opts *= $this->ActionValue ; break ;
case "/=" : $opts /= $this->ActionValue ; break ;
}
$opts = (string) round($opts) ; // convert numbers back to string for correct interpretation by ReconstructClipText
if ($pgbacc) $opts = $pgacc.$opts;
if ($pgbcolour) $opts = $opts."!".$pgcolour;
if ($pgbslur) $opts= $opts."^";

gm_setTaggedOpt($this->ActionTarget,$o,$opts) ;
break ;
case GM_SET:
gm_setTaggedOpt($this->ActionTarget,$o,$this->ActionValue) ;
break ;
I'll understand all this $thing-> $somethingelse one day...

Re: adp_GlobalMod.php and accidentals

Reply #3
I strongly urge anyone who wants to to have a go at improving my code.
That was put together several years ago, as much as an exercise in using the new interface as well as to fulfil particular needs, but my lack of notation work recently means that I've had very little to do with the code since then.
So please feel free to improve it.


Re: adp_GlobalMod.php and accidentals

Reply #5
I have moved up to blundering amateur grade 1. The following script works for me. To adjust parts to within the compass of my amateur flautists. Slight mod $t=$m is tidier...sigh
Code: [Select · Download]
<?php
/*******************************************************************************
pjgFluteRange.php Version 1.00 based on nwsw_VarDump 1.5

This script will lower/raise notes by an octave until within a defined range
for the amateur flautists this is middle c to four leger lines above the treble clef

HISTORY:
================================================================================
[2010-03-11] Version 1.00: Write new values back to nwc2 taking account of all note
             attributes
*******************************************************************************/

require_once("lib/nwc2clips.inc");
$final_exit_value = NWC2RC_SUCCESS ;
$clip = new NWC2Clip('php://stdin');

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

foreach ($clip->Items as $item) {
$o = new NWC2ClipItem($item,true);
if ($o->GetObjType() == "Note" && ($t =& $o->GetTaggedOpt("Pos"))) {
        // parse the pos option string
if (preg_match('/^([\#bnxv]{0,1})(\-{0,1}[0-9]+)([oxXz]{0,1})(\^{0,1})(\!{0,1}[0-9]{0,1})/',$t,$m)) {
//modify the note positions
while ($m[2]>13) {
$m[2]=$m[2]-7;  //reduce by 7s until crtieria reached
}
while ($m[2]<-6) {
$m[2]=$m[2]+7;  //increase by 7s until crtieria reached
}
}  // end or pregmatch
          $t=$m;
          }
          echo $o->ReconstructClipText()."\n";        
          unset($o);
         }
 echo NWC2_ENDCLIP."\n";
exit ($final_exit_value) ;
?>
I'll understand all this $thing-> $somethingelse one day...

 

Re: adp_GlobalMod.php and accidentals

Reply #6
You may want to use the NWC2NotePitchPos class from obj_NWC2NotePitchPos.inc to deconstruct and reconstruct your "pos", for future compatibility and for better readability of your script:

Code: [Select · Download]
if ($o->GetObjType() == "Note" && ($t =& $o->GetTaggedOpt("Pos"))) {
        // parse the pos option string
        $npp = new NWC2NotePitchPos($t);

        while ($npp->Position > 13)
                $npp->Position -= 7;

        while ($npp->Position < -6)
                $npp->Position += 7;

        $t = $npp->ReconstructClipText();
}
Of course, this script would not move notes within a chord or restchord, but it is the rare flautist that can play more than one note at a time (I once saw James Galway do it in concert :-).

Edit:  James Galway had an interesting comment on "flutist" vs "flautist" - see "flautist" in Wikipedia.  :-)

Re: adp_GlobalMod.php and accidentals

Reply #7
Our new Pitch Mod user tool might be of some use in modifying note pitch data.