Here’s the python code. Enjoy.
This code needs to import nwctxt.py see https://github.com/nwsw/nwc2ut-python
"""joeSelReverse.py Reverses the Notes that are selected in a NoteWorthy Composer staff
import nwctxt # see https://github.com/nwsw/nwc2ut-python
logging.basicConfig(filename='joeNWC_PY.log',level=logging.DEBUG) # DEBUG => print ALL msgs
clip = nwctxt.NWC2Clip()
PlayContext = nwctxt.NWC2PlayContext()
txtItemL = clip.Items
clipItemL = [nwctxt.NWC2ClipItem(txtItem) for txtItem in txtItemL]
first2 = clipItemL[:2]
reversedClipItemL = first2 + list(reversed(clipItemL[2:]))
reversedTextItemL = [item.ReconstructClipText() for item in reversedClipItemL]
for textItem in reversedTextItemL[2:]:
#print "clipItem.GetObjType()= %s, type(clipItem.GetObjType())= %s, "%(clipItem.GetObjType(), type(clipItem.GetObjType()))
# TO DEBUG uncomment below to report to NWC STDOUT DIALOG & to CAUSE NO STAFF MODIFICATION
Read Introduction to User Tool Development. Summary:
- NWC Staff Clip input to your tool is from STDIN.
- Main Output back to NWC Staff is to STDOUT.
- User Interaction via “PROMPT” command line arguments used when calling your tool.
Create your Python Module
Make a Python script to do something to a NoteWorthy Composer clip. Here is a simple example. It copies the NWC clip into a file.
instr = sys.stdin.read()
f = open('joesFirstTestOut.txt', 'w'); f.write(instr); f.close()
Hook Up your Python Module with NWC
1. Copy your module to:
<path>\Program Files\NoteWorthy Composer 2\Scripts\
2. Hook up NWC to your module
2.1 In NWC Click Menu >> Tools >> User Tools
2.2 In User Tools dialog click "New" button
2.3 In User Tool Description dialog enter:
Group: joe <or whatever>
Name: joesFirst.py <or whatever>
Command: python scripts\joesFirst.py <or python scripts\whatever>
Input Type: clip text
compress input: [ ]
returns file text: [ ]
long task handling: [ ]
prompts for user input: [ ]
2.4 In User Tool Description dialog click "OK" button
2.5 In User Tools dialog click "Close" button
Run your Python Module
2.1 In NWC select the staff for which you want the clip
2.2 In NWC Click Menu >> Tools >> User Tools
2.3 In User Tools dialog select your group & command
2.4 In User Tools dialog click "Run" button
N.B. For the example module, the file named 'joesFirstTestOut.txt'
NOT IN <path>\Program Files\NoteWorthy Composer 2\Scripts\
BUT IN <path>\Program Files\NoteWorthy Composer 2\Scripts\
For More Information about NWC2 Scripting
Read also Getting started with NWC2 User Tools
Great Article on MIT’s Scratch & Music
Here is a great article by Howard Abrams. It concentrates on how to make music in MIT’s “Scratch” programming framework for kids and their mentors..
Here’s the link:
Love and peace,
Big thanks to MIT’s Music21 creator, Dr. Michael Scott Cuthbert, for his encouraging comments about my code. It’s nice to know that I am staying current and being of service.
He left comments regarding the code that I published:
On Stack Overflow he said, “…your solution is so elegant that we’ve decided to include some code based on it in spirit in the next release (v1.1) of music21”.
On this blog he said, “Thanks for the great post and ideas! We’ll be incorporating something like this in a music21 midi.realtime module… Please feel free to post this to the music21list (Google Groups). People will be interested!” You can see the Google Group re-post here.
Lastly, let me again express my gratitude to Dr. Cuthbert for his encouragement.
Love and peace,