Skip to main content
Topic: Pitch Mod (nwsw) User Tool (Read 10566 times) previous topic - next topic

Pitch Mod (nwsw) User Tool

Inspired by Andrew Purdam's Global Mod script, this script allows you to conditionally modify note pitch/position information. After installing this script Version 2.1 or later of the NWC2 User Tool Starter Kit, the following command will be available from the User Tool command (Alt+F8):

Pitch Mod (nwsw)

Upon invoking this tool, you will be prompted for a pitch mod expression. You can use the pitch mod expression to match against note name, accidental, octave, or duration, and then set the note's accidental, position, and/or notehead style or color. For a detailed explanation of the pitch mod expression, please see below in the first replies of this topic.

Pitch Mod: Matching Note Pitch with a Regular Expression

Reply #1
Each pitch mod expression starts with a regular expression (regex) that will be matched against each single notehead in the clip. For example, "Cb" will  match any note that is spelled as a C flat, either directly by its accidental, or indirectly based on the running key signature. You can match against multiple note names by using the regex grouping feature, so "(C|F)b" will match both a C flat or F flat.

You can also match against each notehead's raw clip text. Start your regex with "t:" in order to match against the notehead's clip text, then enter an expression that you want to match against the text. For example, "t:[^\t!]+![1-4]" will match against any notehead that uses one of the first four highlight colors. The expressions starts with the "t:" to indicate that we want to match against the clip text, followed by "[^\t!]+" which is used to skip note position, accidental, and any other text that precedes the color option, and then the "![1-4]" part is used to match against highlight color indexes one through four.

You can also match against each note's duration by starting your match expression with a "d:" prefix. For example, "d:.*(16th|32nd|64th)" will match against any notes that are 16th or smaller duration. As another example, "d:.*Triplet" will match any triplet notes.

If you are not familiar with regular expressions, here are several links that will help to get you started:

Pitch Mod: Changing the Matching Notes

Reply #2
After you have created your regex to match certain notes, you can add actions by first placing a forward slash at the end of your regex. You then add one or more actions to be done to the matching note, each separated by a comma. No extra whitespace is permitted in the action list.

The following note properties can be changed by an action statement:

colSets the numeric highlight color for the notehead
posUsed to change the note position (beware of chord conflicts)
accSets the accidental to one of bb,b,n,#,x
head  Sets the notehead to one of o,x,X,z
All of the properties support an = operator, which is used to assign a new value to the property. The numeric properties, col and pos, also support += and -= operators for incrementing or decrementing their current value.

Pitch Mod: Combining the Regex with Property Assignments

Reply #3
The complete pitch mod expression combines the matching regex with the property assignment action(s), separated by a slash (/). Additional pitch mod regex/action list pairs can be added by separating them with a space. If you want to see a report of matching and non-matching notes for your expression, you can add "-r" to the end of your expression. The -r report will be sent to STDERR, which will automatically be displayed by NWC2. The -r option is a good way to get started with pitch mod expressions, as it shows you the actual note pitch text that you are matching against when you create an expression.

Here are some example pitch mod expressions with explanations of what they do:

  • ./pos+=0 -r
    This is a "do nothing" expression. You can use it to generate a report that should help you to understand the nature of the note pitch text that you are matching.

  • C/col=0 D/col=1 E/col=2 F/col=3 G/col=4 A/col=5 B/col=6 -r
    This expression assigns a unique color highlight to each note by matching against the named note, ignoring the note's accidental. The -r option at the end is used to trigger a report.

  • d:.*Pos2/col=7 -r
    This expression assigns "Highlight 7" to each passive voice notehead in the clip. The pitch text duration is special in that a "Pos" or "Pos2" indicator is included in the duration to indicate which voice contains this note.

  • A#/pos+=1,acc=b -r
    This expression respells every A# note as a Bb.

  • .+/col=0
    This expression simply resets the notehead color back to default for every note in the selection.

  • k:(10[3-9]|1[1-2][0-9])/col=7
    This expression assigns "Highlight 7" to any note that plays back in the highest two possible midi octaves.