Skip to main content
Topic: rg_ForceAccidentals.php - Force Accidentals on a selection (Read 8621 times) previous topic - next topic

rg_ForceAccidentals.php - Force Accidentals on a selection

Quite easy. Figuring out how easy took several hours.
Code: (php) [Select · Download]
<?php
# rg_ForceAccidentals.php ver 1.0
# Ref: http://my.noteworthysoftware.com/?topic=8445.0
require_once ('lib/nwc2clips.inc');
$clip = new NWC2Clip(); // Input Type: Clip Text
echo $clip->GetClipHeader(), PHP_EOL; // Returns Clip Text
$PlayContext = new NWC2PlayContext();
foreach ($clip->Items as $item) {
  $o = new NWC2ClipItemWithPitchPos($item, true);
  foreach (array('Pos', 'Pos2') as $pos_tag)
    foreach ($o->PitchPos[$pos_tag] as $npp)
      $npp->Accidental = $PlayContext->GetNotePitchAccidental($npp);
  $PlayContext->UpdateContext($o);
  $o->ReconstructPosOpts();
  echo $o->ReconstructClipText(), PHP_EOL;
}
echo NWC2_ENDCLIP, PHP_EOL;
?>
Comments and criticisms welcome.
Registered user since 1996

Re: rg_ForceAccidentals.php - Force Accidentals on a selection

Reply #1
Thanks Rick, that should be useful and will save copying part of a staff to a new staff in order to force accidentals for a section.

One issue I have found is that if you have a tied accidental across a bar line the receiving note does not always get the correct accidental and because of that, the tie is now "searching" for a home. This is not for every case but I haven't been able to pin down the "when" and "why"

Code: (nwc) [Select · Download]
!NoteWorthyComposerClip(2.5,Single)
|Clef|Type:Treble
|TimeSig|Signature:4/4
|Note|Dur:4th|Pos:-1
|Note|Dur:4th|Pos:-2
|Note|Dur:4th|Pos:0
|Note|Dur:4th|Pos:b-3^
|Bar
|Note|Dur:4th|Pos:-3
|Note|Dur:4th|Pos:-3
|Note|Dur:4th|Pos:-2
|Note|Dur:4th|Pos:-1
!NoteWorthyComposerClip-End


Rich.

Re: rg_ForceAccidentals.php - Force Accidentals on a selection

Reply #2
Looks like a problem with NoteWorthy Composer 2 User Tools' library code.
Problem fixed in 2.51 update.
Registered user since 1996

Re: rg_ForceAccidentals.php - Force Accidentals on a selection

Reply #3
I'm going to wait for the update of the Starter Kit. It looks like NoteWorthy is aware of the problem. In the example below, 'nwsw_NoteNames.php' responds rather badly, but the NoteWorthy Composer 2 Note Names WebTool is correct. Assuming that there is some PHP code that is processing the web form, a fix seems to be in the works. Thanks again Richard, for the discovery.

example removed. Problem solved with 2.51 update.
Registered user since 1996

Re: rg_ForceAccidentals.php - Force Accidentals on a selection

Reply #4
The web tool actually uses an older API which does not even attempt to emulate what NWC 2.5 does with ties. The older API actually works better In this case.

We will be releasing a new PHP Starter Kit in NWC 2.51 which will include a fix for this issue.

Re: rg_ForceAccidentals.php - Force Accidentals on a selection

Reply #5
The target fixes for NWC 2.51 have been pushed to github:

Commit on github