-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnwsw_BarNumberDemo.php
executable file
·83 lines (68 loc) · 2.26 KB
/
nwsw_BarNumberDemo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/*******************************************************************************
nwsw_BarNumberDemo.php Version 1.01
This script demonstrates how to work with bar numbers from within a user tool.
It adds a hidden text instruction to the start of every measure in a staff of
the form: "Bar #"
Copyright © 2016 by NoteWorthy Software, Inc.
All Rights Reserved
HISTORY:
================================================================================
[2010-02-27] Version 1.0: Initial release
*******************************************************************************/
require_once("lib/nwc2clips.inc");
$abortMsg = false;
//
$clip = new NWC2Clip('php://stdin');
if ($clip->Mode != "Single") trigger_error("Clip mode of {$clip->Mode} is not supported",E_USER_ERROR);
function IsPossibleBarNumber(&$o)
{
return ($o->GetObjType() == "Text") && preg_match('/^Bar [0-9]+$/',$o->GetTaggedOpt('Text',""));
}
$pendingOutput = array();
$priorBarIndex = -1;
//
echo $clip->GetClipHeader()."\n";
$PlayContext = new NWC2PlayContext();
foreach ($clip->Items as $item) {
$o = new NWC2ClipItem($item,true);
if ($o->IsContextInfo()) {
$PlayContext->UpdateContext($o);
continue;
}
$flushPending = false;
if ($o->GetObjType() == "Bar") {
if ($o->GetTaggedOpt('XBarCnt','N') == 'Y') $flushPending = true;
else $priorBarIndex = count($pendingOutput);
}
else if (IsPossibleBarNumber($o)) {
if (count($pendingOutput) && ($priorBarIndex == (count($pendingOutput)-1))) {
// Remove this existing bar number. If a new one is needed, it will be added later.
continue;
}
}
else if (in_array($o->GetObjType(),array('Note','Chord','RestChord','Rest','RestMultiBar'))) {
if (count($pendingOutput)) {
if ($priorBarIndex >= 0) {
$pendingOutput[$priorBarIndex] .= "|Text|Text:\"Bar ".$PlayContext->NextBarNum."\"|Font:StaffBold|Pos:6|Wide:Y|Placement:AsStaffSignature|Visibility:Never\n";
}
}
$flushPending = true;
}
$PlayContext->UpdateContext($o);
if ($flushPending) {
if (count($pendingOutput)) {
echo implode("",$pendingOutput);
$pendingOutput = array();
}
$priorBarIndex = -1;
echo $item;
}
else {
$pendingOutput[] = $item;
}
}
if (count($pendingOutput)) echo implode("",$pendingOutput);
echo $clip->GetClipFooter()."\n";
exit(NWC2RC_SUCCESS);
?>