Skip to main content
Topic: Convert (from nwctxt to xml) and back (from xml to nwctxt) (Read 24299 times) previous topic - next topic

Convert (from nwctxt to xml) and back (from xml to nwctxt)

I have written two Python 3 programs:
  1. nwctxt2xml.py  - Converts nwctxt into XML
  2. xml2nwctxt.py  - Converts XML into nwctxt

I have done about a dozen "round trip" tests. All results ran OK. Here is a round trip test:
  1. nwctxt2xml.py converts mySong.nwctxt to mySong.xml
  2. xml2nwctxt.py converts mySong.xml to mySong-out.nwctxt
  3. If fileCompare (mySong.nwctxt, mySong-out.nwctxt) = "files are identical"  -> OK

Having said that, these programs are distributed in the hope that they will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. They are subject to the GNU General Public License 3. See each source code listing.

You can download a zip distribution file at https://sourceforge.net/projects/rtcnwctxt-xml/

The zip distribution contains 4 files:
  0. readme.txt    
  1. nwctxt2xml.py  - Converts nwctxt into XML - Python 3.1 source code
  2. xml2nwctxt.py  - Converts XML into nwctxt - Python 3.1 source code
  4. GPL-3.txt         - GNU GENERAL PUBLIC LICENSE Version 3 details

Contact me at JoeCodeswell@gmail.com

All the best,

Joe

PROGRAM DOC BRIEFS

1. nwctxt2xml.py

  Copyright © 2009 Joe Dorocak (JoeCodeswell@gmail.com)
  Subject to GNU General Public License 3 (see source code listing)
  
nwctxt2xml.py converts nwctxt into XML

Requires: Python 3.1+
Usage:   nwctxt2xml.py infile.nwctxt outfile.xml
Example: nwctxt2xml.py mySong.nwctxt mySong.xml


nwctxt2xml.py Converts
  From: nwctxt format
  To:   Joe Dorocak's xml format. See below for XML structure:
    <jNoteWorthyComposer>
      <SongInfo></SongInfo>
      <PgSetup></PgSetup>
      <jFonts><Font></Font></jFonts>
      <PgMargins></PgMargins>
      <jStaves>
        <jStaff>
          <AddStaff></AddStaff>
          <StaffProperties></StaffProperties>
          <StaffInstrument></StaffInstrument>
          <Clef></Clef>  
          <Key></Key>
          <Tempo></Tempo>    
          <Note></Note>    
          <Chord></Chord>    
          <Bar></Bar>            
        </jStaff>            
      </jStaves>
    </jNoteWorthyComposer>
  
  Note: The xml elements <jFonts>, <jStaves> and <jStaff> were added to those
          elements directly derived from the nwctxt format.

      
2. xml2nwctxt.py

  Copyright © 2009 Joe Dorocak (JoeCodeswell@gmail.com)
  Subject to GNU General Public License 3 (see source code listing)

xml2nwctxt.py converts XML into nwctxt

Requires: Python 3.1+
Usage:   xml2nwctxt.py infile.xml outfile.nwctxt
Example: xml2nwctxt.py mySong.xml mySong.nwctxt


xml2nwctxt.py Converts
  To:     nwctxt format
  From:   Joe Dorocak's xml format. See below for XML structure:
    <jNoteWorthyComposer>
      <SongInfo></SongInfo>
      <PgSetup></PgSetup>
      <jFonts><Font></Font></jFonts>
      <PgMargins></PgMargins>
      <jStaves>
        <jStaff>
          <AddStaff></AddStaff>
          <StaffProperties></StaffProperties>
          <StaffInstrument></StaffInstrument>
          <Clef></Clef>  
          <Key></Key>
          <Tempo></Tempo>    
          <Note></Note>    
          <Chord></Chord>    
          <Bar></Bar>            
        </jStaff>            
      </jStaves>
    </jNoteWorthyComposer>

    Note: The xml elements <jFonts>, <jStaves> and <jStaff> were added to those
            elements directly derived from the nwctxt format.

Love and peace,
Joe

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #1
Great piece of work here Joe.

I confirm that for a number of NWc files, I have sucessfully exported to nwctxt
Used your program to convert to xml
Used your program to convert back to nwctxt

and then loaded into NWC2. All looks to be identical.

That could be useful in a number of instances.

However, I would like to report the following issues that you may or may not wish to consider.

The program seems to not like xml files generated from elsewhere (ie scanning software).
This would be more useful (to me) if it was able to attempt to convert such an xml file to nwctxt (in the same way that Nicolas Hatier's program does).

The ones I have attempted give the following :

Quote
D:\pythonfiles>xml2nwctxt.py bwv140002.xml test.nwctxt
bwv140002.xml test.nwctxt
Traceback (most recent call last):
  File "D:\pythonfiles\xml2nwctxt.py", line 152, in <module>
    sys.exit(main())
  File "D:\pythonfiles\xml2nwctxt.py", line 148, in main
    sNwc = x2t.convertToNwctxt()                             # translate sXml into  sNwc
  File "D:\pythonfiles\xml2nwctxt.py", line 118, in convertToNwctxt
    self.procLeaves(nKid)
  File "D:\pythonfiles\xml2nwctxt.py", line 133, in procLeaves
    name = a.tag; value = unescape(a.text, {'&quot;':'"'})   # changed for python 3
  File "C:\Python31\lib\xml\sax\saxutils.py", line 48, in unescape
    data = data.replace("&lt;", "<")
AttributeError: 'NoneType' object has no attribute 'replace'

(This means nothing to me !)

Also, if I take a nwctxt file and convert it to xml using nwctxt2xml.py and then try to feed it into Nicolas' program, this comes back and reports that the xml file is not a music xml file.

I suspect that all music xml files should be recognisable as such and fully interchangeable between different programs.

You may not have intended your programs to be able to generate data files that are interchangeable with other programs and if not, that would be a shame.

Any comments ?

Cheers





Rich.

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #2
Dear Rich,

Thanks ever so much for your gracious reply. I braced myself for this effort being only useful to me. It makes me very glad that someone else thinks it might be useful as well. :)

I'll look into the issue you described and report back.

Thanks again for the encouragement.

Love and peace,
Joe

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #3
Joe, thank you for writing these routines.  Do you see this as a way to, ultimately, convert a NWC2 file into musicxml via NWCtext, so it can be imported into other programs? 


Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #4
Joe, thank you for writing these routines.  Do you see this as a way to, ultimately, convert a NWC2 file into musicxml via NWCtext, so it can be imported into other programs? 
I concur - thanks Joe.

I do hope you decide to extend your project to convert to and from full spec. MusicXML files.
I plays 'Bones, crumpets, coronets, floosgals, youfonymums 'n tubies.

 

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #5
Dear David, Lawrie and Rich,

My original motivation in coding these routines was to get nwctxt into xml, let's call it "nwcxml", so I could manipulate the nwcxml and do multistaff operations on it and return the nwcxml to nwctxt for re-import into NWC. (Whew!)

Anyway I have been vaguely aware of MusicXML and I do think it would be a good idea to
convert to and from full spec. MusicXML files.

I believe this could be a big undertaking based on the sigh it caused virtuoso kahman:
At some point, someone should write a converter to/from MXML...sigh.

I have started a SourceForge open source project at https://sourceforge.net/projects/rtcnwctxt-xml/ Here is the Project Description:
Quote
BASIS FOR AN OPEN SOURCE PROJECT to convert NoteWorthy Composer files from/to MusicXML. Two Python 3 programs for NoteWorthy Composer files in nwctxt format. 1. nwctxt2xml.py - Converts nwctxt into XML 2. xml2nwctxt.py - Converts XML into nwctxt

Let's see if I/we can drum up some participation from others to make useful progress. By the way, I'm not sure that all musical concepts expressible in MusicXML are expressible in NWC. My intent is to have some fun with this and as I say, make useful progress. I hope all who participate will have the same outlook.

Here is the MusicXML wiki page link. http://en.wikipedia.org/wiki/MusicXML And here is the MusicXML definition page from RecordCare, the driving force behind MusicXML. http://www.recordare.com/xml.html

Thanks for the interest and encouragement.
Love and peace,
Joe

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #6
Good luck, and best wishes for success, Joe !!!


Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #8
Double ditto !

Send file as requested. Here's hoping
Rich.

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #9
Good luck, Joe indeed!! You should be awarded hero status.

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #10
I had the idea to write such a converter myself some time ago, but being busy (and lazy :-) the thing didn't ever start.
So, once again good luck Joe!

Re: Convert (from nwctxt to xml) and back (from xml to nwctxt)

Reply #11
Thanks for the tool you created.  I am specifically looking for a tool that converts NWC files to MusicXML, so that I can import all of my old files into MuseScore.

I have been a NWC fan for 10 years, but now that I have discovered MuseScore I am migrating to that tool.  Reasons being that it is open source, multi-platform, and has a fairly large development team.  I still wish the best of luck to the NWC team!