Option Explicit
Dim StdErr, StdIn, StdOut, LineIn, Look, Matches, Match, Head
'Name: Insert Sforzando
'Command: wscript scripts\Sforzando.vbs
Set StdErr = WScript.StdErr
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
Set Look = New RegExp
Look.Global = True
Look.IgnoreCase = True
While Not StdIn.AtEndOfStream
LineIn = StdIn.ReadLine
Look.Pattern = "^\|Note|^\|Chord|^\|RestChord"
If Look.Test(LineIn) Then
StdOut.WriteLine "|Marker|Target:Articulation|Visibility:Never"
StdOut.WriteLine "|DynamicVariance|Style:Sforzando|Justify:Center|Placement:AtNextNote"
If Instr(LineIn, "Accent") = 0 Then
Look.Pattern = "(Dur[^\|]+)"
Set Matches = Look.Execute(LineIn)
Set Match = Matches.Item(Matches.Count - 1) 'the last one
Head = Match.FirstIndex + Match.Length
LineIn = Left(LineIn, Head) & ",Accent" & Right(LineIn, Len(LineIn) - Head)
End If
End If
StdOut.WriteLine LineIn
Wend
This inserts a sforzando mark and accents the note and hides the accent with an invisible marker.
There's one problem though. If you manually insert a dynamic variance it inherits visibility and position from the previous one. Inserting one with a user tool doesn't.