当前位置: 首页>>代码示例>>Python>>正文


Python XmlImport.documentFromFile方法代码示例

本文整理汇总了Python中pymei.XmlImport.documentFromFile方法的典型用法代码示例。如果您正苦于以下问题:Python XmlImport.documentFromFile方法的具体用法?Python XmlImport.documentFromFile怎么用?Python XmlImport.documentFromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pymei.XmlImport的用法示例。


在下文中一共展示了XmlImport.documentFromFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: append_guitar_data

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def append_guitar_data(self, tuning, capo):
        '''
        Append meta data about the guitar the transcriber is using
        '''

        mei_path = self.get_abs_path()
        mei_doc = XmlImport.documentFromFile(mei_path)

        staff_def = mei_doc.getElementsByName('staffDef')[0]
        g = Guitar(tuning=str(tuning), capo=capo)
        sounding_pitches = g.strings
        # From the MEI guidelines:
        # "this is given using the written pitch, not the sounding pitch. 
        # For example, the Western 6-string guitar, in standard tuning, sounds an octave below written pitch."
        written_pitches = [s.pname + str(s.oct+1) for s in sounding_pitches]

        staff_def.addAttribute('lines', str(len(sounding_pitches)))
        staff_def.addAttribute('tab.strings', " ".join(written_pitches))

        # Capo could be implicitly encoded by setting the pitches of the open strings
        # but I really don't like this solution. Instructions are lost about how to tune
        # and perform the piece on the guitar.
        # TODO: this attribute doesn't exist in MEI, make a custom build
        if capo > 0:
            staff_def.addAttribute('tab.capo', str(capo))

        XmlExport.meiDocumentToFile(mei_doc, mei_path)
开发者ID:gburlet,项目名称:robotaba,代码行数:29,代码来源:models.py

示例2: _get_symbol_widths

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def _get_symbol_widths(self, pages):
        '''
        Calculate the average pixel width of each symbol from a set of pages.

        PARAMETERS
        ----------
        pages (list): a list of pages
        '''
        
        # TODO: make this a global var, since it is used in more than one function now
        symbol_types = ['clef', 'neume', 'custos', 'division']

        # dict of symbol_name -> [cumulative_width_sum, num_occurences]
        symbol_widths = {}

        for p in pages:
            meidoc = XmlImport.documentFromFile(p['mei'])
            num_systems = len(meidoc.getElementsByName('system'))

            flat_tree = meidoc.getFlattenedTree()
            sbs = meidoc.getElementsByName('sb')

            # for each system
            # important: need to iterate system by system because the class labels depend on the acting clef
            for staff_index in range(num_systems):
                try:
                    labels = self._get_symbol_labels(staff_index, meidoc)
                except IndexError:
                    continue

                # retrieve list of MeiElements that correspond to glyphs between system breaks
                start_sb_pos = meidoc.getPositionInDocument(sbs[staff_index])
                if staff_index+1 < len(sbs):
                    end_sb_pos = meidoc.getPositionInDocument(sbs[staff_index+1])
                else:
                    end_sb_pos = len(flat_tree)
                    
                symbols = [s for s in flat_tree[start_sb_pos+1:end_sb_pos] if s.getName() in symbol_types]

                # get bounding box information for each symbol belonging this system
                symbol_zones = [meidoc.getElementById(s.getAttribute('facs').value)
                                    for s in symbols if s.hasAttribute('facs')]

                for l, z in zip(labels, symbol_zones):
                    ulx = int(z.getAttribute('ulx').value)
                    lrx = int(z.getAttribute('lrx').value)
                    
                    if l in symbol_widths:
                        symbol_widths[l][0] += (lrx - ulx)
                        symbol_widths[l][1] += 1
                    else:
                        symbol_widths[l] = [lrx - ulx, 1]

        # calculate average symbol widths across all training pages
        # rounding to the nearest pixel
        for s in symbol_widths:
            symbol_widths[s] = int(round(symbol_widths[s][0] / symbol_widths[s][1]))

        return symbol_widths
开发者ID:DDMAL,项目名称:homr,代码行数:61,代码来源:homr.py

示例3: sanitize_mei_file

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def sanitize_mei_file(self, mei_path, output_mei_path=None, prune=True):
        self.mei_doc = XmlImport.documentFromFile(mei_path)
        self._sanitize_mei(prune)

        if output_mei_path:
            XmlExport.meiDocumentToFile(self.mei_doc, str(output_mei_path))
        else:
            return XmlExport.meiDocumentToText(self.mei_doc)
开发者ID:gburlet,项目名称:robotaba,代码行数:10,代码来源:guitarify.py

示例4: parse_file

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def parse_file(self, mei_path):
        '''
        Read an mei file and fill the score model
        '''

        from pymei import XmlImport
        self.doc = XmlImport.documentFromFile(str(mei_path))
        self.parse_input()
开发者ID:srviest,项目名称:astar-guitar,代码行数:10,代码来源:score.py

示例5: processMeiFile

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
def processMeiFile(ffile, solr_server, shortest_gram, longest_gram, page_number, project_id):
    solrconn = solr.SolrConnection(solr_server)
    print '\nProcessing ' + str(ffile) + '...'
    try:
        meifile = XmlImport.documentFromFile(str(ffile))
    except Exception, e:
        print "E: ",e
        lg.debug("Could not process file {0}. Threw exception: {1}".format(ffile, e))
        print "Whoops!"
开发者ID:lexpar,项目名称:Rodan,代码行数:11,代码来源:MEI2Solr.py

示例6: __init__

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def __init__(self, image_path, mei_path):
        '''
        Creates a GlyphGen object.

        PARAMETERS
        ----------
        image_path: path to the image to generate glyphs for.
        mei_path: path to the mei file containing glyph bounding box information.
        '''

        self.page_image = Image.open(image_path)
        self.meidoc = XmlImport.documentFromFile(mei_path)
开发者ID:DDMAL,项目名称:Nomr,代码行数:14,代码来源:generateglyphs.py

示例7: analyze

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
def analyze(MEI_filename):
    MEI_doc = XmlImport.documentFromFile(MEI_filename)
    MEI_tree = MEI_doc.getRootElement()
    has_editor_element_ = editorial.has_editor_element(MEI_tree)
    has_arranger_element_ = editorial.has_arranger_element(MEI_tree)
    editor_name_ = editorial.editor_name(MEI_tree)
    staff_list_ = staves.staff_list(MEI_tree)
    alternates_list_ = staves.alternates_list(staff_list_)
    return AnalyzeData(has_editor_element_,
                       has_arranger_element_,
                       editor_name_,
                       staff_list_,
                       alternates_list_,
                       )
开发者ID:RichardFreedman,项目名称:MEIMassaging,代码行数:16,代码来源:analyze.py

示例8: __init__

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def __init__(self, input_mei_paths, output_mei_path):
        '''
        PARAMETERS
        ----------
        input_mei_paths {list}: list of mei paths to combine
        output_mei_path {String}: output file path of type .mei
        '''

        self._input_mei_paths = input_mei_paths
        self._output_mei_path = output_mei_path
        if len(self._input_mei_paths):
            self._meidoc = XmlImport.documentFromFile(self._input_mei_paths[0])
        else:
            self._meidoc = None
开发者ID:DDMAL,项目名称:barlineFinder,代码行数:16,代码来源:meicombine.py

示例9: massage_mei

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
def massage_mei(in_file, out_file): 
    try:
        analysis = make_analysis(in_file)
        MEI_instructions = TransformData(
            arranger_to_editor=True,
            obliterate_incipit=analysis.first_measure_empty,
            replace_longa=True,
            editorial_resp=analysis.has_arranger_element,
            alternates_list=analysis.alternates_list)    
        old_MEI_doc = XmlImport.documentFromFile(in_file)
        new_MEI_doc = transform_mei(old_MEI_doc, MEI_instructions)
        XmlExport.meiDocumentToFile(new_MEI_doc, out_file)
    except Exception as ex:
        logging.critical(ex)
        logging.critical("Error during massaging " + in_file)
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:17,代码来源:massage_mei.py

示例10: mei_append_metamusic

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def mei_append_metamusic(self):
        '''
        Append meta data for the musical work to the mei document
        '''
    
        mei_path = self.get_abs_path()        
        mei_doc = XmlImport.documentFromFile(mei_path)

        mei = mei_doc.getRootElement()
        mei_head = MeiElement('meiHead')
        music = mei.getChildrenByName('music')[0]
        
        file_desc = MeiElement('fileDesc')

        # title
        title_stmt = MeiElement('titleStmt')
        title = MeiElement('title')
        title.setValue(str(self.fk_mid.title))

        # contributers
        resp_stmt = MeiElement('respStmt')
        pers_name_artist = MeiElement('persName')
        pers_name_artist.addAttribute('role', 'artist')
        pers_name_artist.setValue(str(self.fk_mid.artist))
        pers_name_tabber = MeiElement('persName')
        pers_name_tabber.addAttribute('role', 'tabber')
        pers_name_tabber.setValue(str(self.fk_mid.copyright))

        # encoding information
        encoding_desc = MeiElement('encodingDesc')
        app_info = MeiElement('appInfo')
        application = MeiElement('application')
        application.setValue('Robotaba')

        mei_head.addChild(file_desc)
        file_desc.addChild(title_stmt)
        title_stmt.addChild(title)
        title_stmt.addChild(resp_stmt)
        resp_stmt.addChild(pers_name_artist)
        resp_stmt.addChild(pers_name_tabber)
        title_stmt.addChild(encoding_desc)
        encoding_desc.addChild(app_info)
        app_info.addChild(application)

        # attach mei metadata to the document
        mei.addChildBefore(music, mei_head)

        XmlExport.meiDocumentToFile(mei_doc, mei_path)
开发者ID:gburlet,项目名称:robotaba,代码行数:50,代码来源:models.py

示例11: OnLoadRects

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def OnLoadRects(self, event):
        '''
        Loads rectangles from an mei file.
        Only loads bar boxes and not staff boxes yet.
        '''

        fdlg = wx.FileDialog(self)

        if fdlg.ShowModal() == wx.ID_OK:
            
            print "File loaded: " + fdlg.GetPath()

            meidoc = XmlImport.documentFromFile(str(fdlg.GetPath()))

            # get all the measure elements
            measures = meidoc.getElementsByName('measure')

            # the measures have their coordinates stored in zones
            zones = meidoc.getElementsByName('zone')

            for m in measures:

                # the id of the zone that has the coordinates is stored in 'facs'
                facs = m.getAttribute('facs')

                print facs.getName(), facs.getValue()

                # there's a # sign preceding the id stored in the facs
                # attribute, remove it
                zone = meidoc.getElementById(facs.getValue()[1:])

                # the coordinates stored in zone
                ulx = int(zone.getAttribute('ulx').getValue())
                uly = int(zone.getAttribute('uly').getValue())
                lrx = int(zone.getAttribute('lrx').getValue())
                lry = int(zone.getAttribute('lry').getValue())

                print ulx, uly, lrx, lry

                # make a new panel
                # Rect is looking for top (x,y) coordinates and length and
                # height, so we need to subtract the two corners
                self.scrolledwin.barpanels.append(\
                        Rect(ulx, uly, lrx - ulx, lry - uly))

            self.scrolledwin.Refresh()
开发者ID:DDMAL,项目名称:barlineGroundTruth,代码行数:48,代码来源:gtruth-canvas-zooming.py

示例12: Run

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
	def Run(self):
		old_filename = self.mei_file
		if (len(old_filename) < EXT_LENGTH or
				old_filename[-EXT_LENGTH:] not in EXT):
			logging.info("No file extension provided; " + EXT[0] + " used.")
			old_filename += EXT[0]
		old_MEI_doc = XmlImport.documentFromFile(old_filename)
		logging.info('running test case ' + self.name + ' Input: ' + old_filename)
		new_MEI_doc = transform(old_MEI_doc, self.transform_data)
		new_filename = (old_filename[:-EXT_LENGTH] + self.outsuffix + '_' +
				old_filename[-EXT_LENGTH:])
		status = XmlExport.meiDocumentToFile(new_MEI_doc, new_filename)
		if status:
			logging.info("Done. Transformed file saved as " + new_filename)
			pass
		else:
			logging.error("Transformation failed")
		return new_MEI_doc
开发者ID:zolaemil,项目名称:MEIMassaging,代码行数:20,代码来源:transformtestrunner.py

示例13: combine

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
    def combine(self):
        if self._meidoc and len(input_mei_paths) > 1:
            base_facsimile = self._meidoc.getElementsByName('facsimile')[0]
            base_section = self._meidoc.getElementsByName('section')[0]
            for f in self._input_mei_paths[1:]:
                mei = XmlImport.documentFromFile(f)

                # combine surface
                surface = mei.getElementsByName('surface')
                if len(surface):
                    # have to remove the child from the old document in memory
                    # or else pymei segfaults ...
                    surface[0].getParent().removeChild(surface[0])
                    base_facsimile.addChild(surface[0])

                # combine measures
                pb = MeiElement('pb')
                base_section.addChild(pb)

                # get last measure number
                measures = base_section.getChildrenByName('measure')
                last_measure_n = int(measures[-1].getAttribute('n').value)

                new_section = mei.getElementsByName('section')[0]
                music_elements = new_section.getChildren()

                for e in music_elements:
                    if e.getName() == 'measure':
                        last_measure_n += 1
                        e.addAttribute('n', str(last_measure_n))

                    base_section.addChild(e)

                # remove all musical elements from the old document or else pymei segfaults
                new_section.getParent().deleteAllChildren()

            self._add_revision()
开发者ID:DDMAL,项目名称:barlineFinder,代码行数:39,代码来源:meicombine.py

示例14: test_noversionexception

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
 def test_noversionexception(self):
     with self.assertRaises(NoVersionFoundException) as cm:
         XmlImport.documentFromFile(os.path.join("test", "testdocs", "noversion.mei"))
     self.assertTrue(isinstance(cm.exception, NoVersionFoundException))
开发者ID:lpugin,项目名称:libmei,代码行数:6,代码来源:xmlimport_test.py

示例15: test_badversionexception

# 需要导入模块: from pymei import XmlImport [as 别名]
# 或者: from pymei.XmlImport import documentFromFile [as 别名]
 def test_badversionexception(self):
     with self.assertRaises(VersionMismatchException) as cm:
         XmlImport.documentFromFile(os.path.join("test", "testdocs", "badversion.mei"))
     self.assertTrue(isinstance(cm.exception, VersionMismatchException))
开发者ID:lpugin,项目名称:libmei,代码行数:6,代码来源:xmlimport_test.py


注:本文中的pymei.XmlImport.documentFromFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。