-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnwsw_NoteNames.php
executable file
·143 lines (110 loc) · 4.39 KB
/
nwsw_NoteNames.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<?php
/*******************************************************************************
nwsw_NoteNames.php Version 2.01
This script will will automatically create text that includes all of the note
names for the notes in the staff.
Note: In lyric mode, you should always select the entire staff so that the
text is suitable for inclusion as a lyric.
Prompting for staff mode can be added with the following command line:
"/mode=inline" "/font=<PROMPT:Select Font:=|User 1|User 2|User 3|User 4|User 5|User 6>" "/staffpos=<PROMPT:Position:=#[-32,32]>"
Prompting for staff versus lyric mode can be added with the following command line:
"/mode=<PROMPT:Mode:=|inline|lyric>"
Copyright © 2016 by NoteWorthy Software, Inc.
All Rights Reserved
HISTORY:
================================================================================
[2010-07-05] Version 2.00: Support for NWC 2.5
[2010-02-27] Version 1.51: Enhanced to support new NWC 2.1 features
[2009-10-02] Version 1.50: Adapted for inclusion in the NWC2 Starter Kit Version 1.5
[2008-02-01] Version 1.00: Initial release for the web site
*******************************************************************************/
require_once("lib/nwc2clips.inc");
// NOTENAME_MODE can be inline or lyric
$NOTENAME_MODE = "inline";
//
// NOTENAME_FONT can be User [1-6]
$NOTENAME_FONT = "User 1";
//
// NOTENAME_POSITION can be a value [-30..30]
$NOTENAME_POSITION = 10;
foreach ($argv as $k => $v) {
if (preg_match('/^\/mode\=(.*)$/i',$v,$m)) $NOTENAME_MODE = $m[1];
else if (preg_match('/^\/font\=(.*)$/i',$v,$m)) $NOTENAME_FONT = $m[1];
else if (preg_match('/^\/staffpos\=(.*)$/i',$v,$m)) $NOTENAME_POSITION = $m[1];
}
$accmap = array("v"=>"bb","b"=>"b","n"=>"","#"=>"#","x"=>"x");
$useLyric = ($NOTENAME_MODE == "lyric");
$txtFont = str_replace(' ','',$NOTENAME_FONT);
$staffPos = @ intval($NOTENAME_POSITION);
$abortMsg = false;
$txtout = "";
//
$clip = new NWC2Clip('php://stdin');
if (!$useLyric) $txtout .= $clip->GetClipHeader()."\n";
if ($clip->Mode != "Single") trigger_error("Clip mode of {$clip->Mode} is not supported",E_USER_ERROR);
$barnotecnt = 0;
$PlayContext = new NWC2PlayContext();
foreach ($clip->Items as $item) {
$o = new NWC2ClipItem($item,true);
if ($o->IsContextInfo()) {
$PlayContext->UpdateContext($o);
continue;
}
if (in_array($o->GetObjType(),array('Note','Chord','RestChord','Rest'))) {
$notenameText = "";
$lyricOpt = isset($o->Opts["Opts"]["Lyric"]) ? $o->Opts["Opts"]["Lyric"] : "Default";
$isGrace = isset($o->Opts["Dur"]["Grace"]);
$isInTie = false;
$isAllInTie = true;
for ($loop=0;$loop<2;$loop++) {
$notes = $o->GetTaggedOptAsArray(($loop > 0) ? "Pos2" : "Pos",array());
foreach ($notes as $i => $notepitchTxt) {
$notepitchObj = new NWC2NotePitchPos($notepitchTxt);
if (!$i && $notenameText) $notenameText .= ",";
if ($PlayContext->IsTieReceiver($notepitchObj)) $isInTie = true;
else $isAllInTie = false;
$notename = $PlayContext->GetNotePitchName($notepitchObj);
$noteacc = $PlayContext->GetNotePitchAccidental($notepitchObj);
$noteacc = $accmap[$noteacc];
$notenameText .= $notename.$noteacc;
}
}
if ($useLyric) {
$hasLyrics = !($isGrace || $isInTie || $PlayContext->Slur || ($o->GetObjType()=="Rest"));
if ($lyricOpt == "Always") $hasLyrics = true;
else if ($lyricOpt == "Never") $hasLyrics = false;
if ($hasLyrics) {
if ($barnotecnt) $txtout .= " ";
$txtout .= $notenameText ? $notenameText : '-';
//
$barnotecnt++;
}
}
else if ($notenameText && !$isAllInTie) {
$txtout .= "|Text|Text:\"$notenameText\"|Font:$txtFont|Pos:$staffPos|Wide:Y|Justify:Center|Placement:AtNextNote\n";
}
}
else if ($o->GetObjType() == "Bar") {
if ($barnotecnt && $useLyric) $txtout .= "\n";
$barnotecnt = 0;
}
if (!$useLyric) $txtout .= $item;
$PlayContext->UpdateContext($o);
}
if ($useLyric) {
echo <<<___EOTEXT
LYRIC TEXT:
$txtout
INSTRUCTIONS:
The lyric text above is suitable for copying and pasting into a lyric line on this staff.
Note: Note names for grace, tied, or slurred notes will not appear in the lyric text unless they have
been configured to receive lyric text from Edit, Properties.
Instructions:
- Select and copy all of the text after the LYRIC TEXT label at the top of this box
- Press OK, then open the lyric editor and paste the contents into a new lyric line
___EOTEXT;
exit(NWC2RC_REPORT);
}
echo $txtout.NWC2_ENDCLIP."\n";
exit(NWC2RC_SUCCESS);
?>