Take the following text and save it on your computer with a name ending in .htm, for example "note2rest.htm". Open the file with your browser at the same time NWC is open. When you want to change notes to rests, cut (Cntl/X) the selected part of the NWC file to the clipboard and paste it into the page's textarea. Click on Read, do a Cntl/C and paste it back into your NWC file.
HTH
<html>
<head>
<title>Replace notes with rests</title>
<!-- This is a simple structure to create a "do it yourself" webpage to manipulate NWC clipboard data. The page takes the data you
pasted into the textarea and splits it into an array of string data. It is examined one line at a time and either the original
text is added back to the OutText area with a newline character "\n" at the end or new text is inserted instead.
To modify this script do a simple replacement of "Replace notes with rests" with its new function. First note the
line the "slice" function is on. Change the literal (enclosed in double quotes) and the second parameter to the length of the
literal. It is to be replaced with the literal on the next line. Change globally the text on the 3rd line to whatever is
appropriate and save it with a name ending with ".htm" or ".html". Learn how to display the error console of your browser.
Misc. "under the hood" facts: "=" changes the variable on the left to the expression on the right while "==" determines if
two expressions are equal (used in "if" statement). "+=" appends new expression or string to the end of the existing one.
Note the zeroth occurance of an array item or character in a string is actually the first one. "++" adds 1 to a numeric variable.
If all parts of an expression are numeric, + does addition but with string data it is concatenation such as "Happy " + "Birthday".
"2" + 3 creates a string with the value "23".
You can immediately display variables with alert(string data here), e.g., alert("lines[" + i + "]= " + lines[i]);
-->
<script language="JavaScript">
function calculate() {
var i, OutText = "";
var lines = new Array();
var result = new Array()
lines = document.nwcform.OutputField.value.split("\n");
for (i=0; i < lines.length; i++) {
if ((lines[i].slice(0,5) == "|Note") || (lines[i].slice(0,6) == "|Chord") || (lines[i].slice(0,10) == "|RestChord")){ //In case your browser puts extra characters at the end, slice ignores them.
result = lines[i].match(/Dur:([^\|]+)\|/)
if (result == null)
alert(lines[i] + " crashed");
else
OutText += "|Rest|Dur:" + result[1] + "\n"; } //Ends with \n. This examples adds 4 lines.
else
{ OutText += lines[i];
if ((i+1) < lines.length) //No need to add a newline character to last line
OutText += "\n"; }
}
document.nwcform.OutputField.value = OutText; //Replaces original data with what was created in OutText
document.nwcform.OutputField.select(); //Output is pre-selected, just Cntl/C to put on clipboard
}
</script>
</head>
<body>
<form name="nwcform" onSubmit="calculate();return false;">
<table width="782" height="350">
<tr>
<td colspan="4" width="1000" height="24">
<b><big>Replace notes with rests</big></b>
</td>
<td height="27" width="100"><input type="button" id="bClick2" value="Read" onclick="calculate()"></td>
</tr>
<tr>
<td colspan=5 width="1044" height="200">
<textarea name="OutputField" rows="16" cols="120"></textarea></td></tr>
</table>
</form>
<br>
Copy the above to your clipboard (it's pre-selected) and paste it into a song you have already open in <b>NoteWorthy Composer</b>.
</body>
</html>