def parseFile(self, fp, number=None): ''' parse fp and number ''' from music21 import converter from music21 import musedata as musedataModule from music21.musedata import translate as musedataTranslate mdw = musedataModule.MuseDataWork() af = converter.ArchiveManager(fp) #environLocal.printDebug(['ConverterMuseData: parseFile', fp, af.isArchive()]) # for dealing with one or more files if fp.endswith('.zip') or af.isArchive(): #environLocal.printDebug(['ConverterMuseData: found archive', fp]) # get data will return all data from the zip as a single string for partStr in af.getData(dataFormat='musedata'): #environLocal.printDebug(['partStr', len(partStr)]) mdw.addString(partStr) else: if os.path.isdir(fp): mdd = musedataModule.MuseDataDirectory(fp) fpList = mdd.getPaths() elif not common.isListLike(fp): fpList = [fp] else: fpList = fp for fp in fpList: mdw.addFile(fp) #environLocal.printDebug(['ConverterMuseData: mdw file count', len(mdw.files)]) musedataTranslate.museDataWorkToStreamScore(mdw, self.stream)
def parseFile(self, fp, number=None): ''' Open from a file path; check to see if there is a pickled version available and up to date; if so, open that, otherwise open source. ''' # return fp to load, if pickle needs to be written, fp pickle # this should be able to work on a .mxl file, as all we are doing # here is seeing which is more recent from music21 import converter from music21.musicxml import xmlToM21 c = xmlToM21.MusicXMLImporter() # here, we can see if this is a mxl or similar archive arch = converter.ArchiveManager(fp) if arch.isArchive(): archData = arch.getData() c.xmlText = archData c.parseXMLText() else: # its a file path or a raw musicxml string c.readFile(fp) # movement titles can be stored in more than one place in musicxml # manually insert file name as a movementName title if no titles are defined if c.stream.metadata.movementName is None: junk, fn = os.path.split(fp) c.stream.metadata.movementName = fn self.stream = c.stream
def parseFile(self, fp, number=None): ''' Open from a file path; check to see if there is a pickled version available and up to date; if so, open that, otherwise open source. ''' # return fp to load, if pickle needs to be written, fp pickle # this should be able to work on a .mxl file, as all we are doing # here is seeing which is more recent from music21 import converter from music21.musicxml import xmlHandler as musicxmlHandler musxmlDocument = musicxmlHandler.Document() environLocal.printDebug(['opening musicxml file:', fp]) # here, we can see if this is a mxl or similar archive arch = converter.ArchiveManager(fp) if arch.isArchive(): archData = arch.getData() musxmlDocument.read(archData) else: # its a file path or a raw musicxml string musxmlDocument.open(fp) # get mxScore object from .score attribute self._mxScore = musxmlDocument.score #print self._mxScore # check that we have parts if self._mxScore is None or len(self._mxScore) == 0: raise SubConverterException( 'score from file path (%s) no parts defined' % fp) # movement titles can be stored in more than one place in musicxml # manually insert file name as a title if no titles are defined if self._mxScore.get('movementTitle') == None: mxWork = self._mxScore.get('workObj') if mxWork == None or mxWork.get('workTitle') == None: junk, fn = os.path.split(fp) # set as movement title self._mxScore.set('movementTitle', fn) self.load()