NoteWorthy Composer Forum

Forums => Tips & Tricks => User Tools => Topic started by: jdorocak on 2014-03-04 06:13 am

Title: Python NWC tool to reverse selected notes in a staff.
Post by: jdorocak on 2014-03-04 06:13 am
Here’s the python code. Enjoy. :)

This code needs to import  nwctxt.py see https://github.com/nwsw/nwc2ut-python

Love and peace,
Joe

Code: [Select · Download]
"""joeSelReverse.py Reverses the Notes that are selected in a NoteWorthy Composer staff
 
see:
    https://github.com/nwsw/nwc2ut-python    
"""
 
import sys
# import joeNWCtxtInPythonNew as nwctxt
import nwctxt # see https://github.com/nwsw/nwc2ut-python
import logging
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]
 
print clip.GetClipHeader()
for textItem in reversedTextItemL[2:]:
    #print "clipItem.GetObjType()= %s, type(clipItem.GetObjType())= %s, "%(clipItem.GetObjType(), type(clipItem.GetObjType()))
    print textItem
print clip.GetClipFooter()
 
 
# TO DEBUG uncomment below to report to NWC STDOUT DIALOG & to CAUSE NO STAFF MODIFICATION
# sys.exit(nwctxt.NWC2RC_REPORT)
Title: Re: Python NWC tool to reverse selected notes in a staff.
Post by: Rick G. on 2014-03-04 07:16 pm
This code needs to import  nwctxt.py see https://github.com/nwsw/nwc2ut-python
Thanks for the link.  nwctxt.py made for interesting reading. Much cleaner than the PHP library. I've not used python so there is not much more I can say. I've resolved to upgrade beyond WinXP before taking on any new languages.
Title: Re: Python NWC tool to reverse selected notes in a staff.
Post by: jdorocak on 2014-03-05 03:06 am
Thanks for the comment, Rick.
Quote
Much cleaner than the PHP library.
For me, Python reads easier than any of the other languages I use.
Eric's nwctxt.py is an example.
Thanks again, Rick.
Love and peace,
Joe