Quite easy. Figuring out how easy took several hours.
<?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.
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"
!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
Looks like a problem with NoteWorthy Composer 2 User Tools (http://ntworthy.com/nwc2/usertools/)' library code.
Problem fixed in 2.51 update.
I'm going to wait for the update of the Starter Kit (http://ntworthy.com/nwc2/usertools/). 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 (http://ntworthy.com/webtool/nwc2-notenames.php) 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.
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.
The target fixes for NWC 2.51 have been pushed to github:
Commit on github (https://github.com/nwsw/nwc2utsk/commit/e730bc9902d8c5ec163e841df1fb0b043b7d03f4)
This seems to solve the problem.
The problem in obj_NWC2PlayContext.inc (https://forum.noteworthycomposer.com/?topic=8440.msg59408) remains. Fixed in latest github updates.