• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pymei.XmlImport类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: append_guitar_data

    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,代码行数:27,代码来源:models.py


示例2: post

    def post(self, file):
        '''
        Move a clef on a staff (must not change staff).
        Updates the bounding box information of the clef
        and updates the pitch information (pitch name and
        octave) of all pitched elements on the affected staff.
        '''

        data = json.loads(self.get_argument("data", ""))
        clef_id = str(data["id"])
        
        # bounding box
        ulx = str(data["ulx"])
        uly = str(data["uly"])
        lrx = str(data["lrx"])
        lry = str(data["lry"])

        mei_directory = os.path.abspath(conf.MEI_DIRECTORY)
        fname = os.path.join(mei_directory, file)
        self.mei = XmlImport.read(fname)

        clef = self.mei.getElementById(clef_id)

        # update staff line the clef is on
        clef.addAttribute("line", str(data["line"]))

        self.update_or_add_zone(clef, ulx, uly, lrx, lry)
        self.update_pitched_elements(data["pitchInfo"])

        XmlExport.write(self.mei, fname)

        self.set_status(200)
开发者ID:sequoiar,项目名称:Neon.js,代码行数:32,代码来源:api.py


示例3: post

 def post(self):
     mei = self.request.files.get("mei", [])
     mei_img = self.request.files.get("mei_img", [])
     document_type = self.get_argument("document_type")
     mei_root_directory = os.path.abspath(conf.MEI_DIRECTORY)
     mei_directory = os.path.join(mei_root_directory, document_type)
     mei_directory_backup = os.path.join(mei_directory, "backup") 
     errors = ""
     mei_fn = ""
     if len(mei):
         mei_fn = mei[0]["filename"]
         contents = mei[0]["body"]
         try:
             mei = XmlImport.documentFromText(contents)
             if os.path.exists(os.path.join(mei_directory, mei_fn)):
                 errors = "mei file already exists"
             else:
                 # write to working directory and backup
                 fp = open(os.path.join(mei_directory, mei_fn), "w")
                 fp.write(contents)
                 fp.close()
                 fp = open(os.path.join(mei_directory_backup, mei_fn), "w")
                 fp.write(contents)
                 fp.close()
         except Exception, e:
             errors = "invalid mei file"
开发者ID:avorio,项目名称:Neon.js,代码行数:26,代码来源:interface.py


示例4: test_readmethod_unicode

 def test_readmethod_unicode(self):
     fn = unicode(os.path.join("test", "testdocs", "beethoven.mei"))
     doc = XmlImport.read(fn)
     self.assertNotEqual(None, doc)
     el = doc.getElementById("d1e41")
     self.assertEqual("c", el.getAttribute("pname").value)
     self.assertEqual("4", el.getAttribute("oct").value)
开发者ID:lpugin,项目名称:libmei,代码行数:7,代码来源:xmlimport_test.py


示例5: post

    def post(self, request):
        mei = self.request.files.get("mei", [])
        mei_img = self.request.files.get("mei_img", [])
        document_type = "squarenote"
        mei_root_directory = os.path.abspath(conf.MEI_DIRECTORY)
        mei_directory = os.path.join(mei_root_directory, document_type)
        mei_directory_backup = os.path.join(mei_root_directory, "backup")
        errors = ""
        mei_fn = ""
        if len(mei):
            mei_fn = mei[0]["filename"]
            mei_fn_split = os.path.splitext(mei_fn)
            mei_zero, mei_ext = mei_fn_split
            contents = mei[0]["body"]
            # TODO: Figure out how to validate MEI files properly using pymei
            try:
                mei = XmlImport.documentFromText(contents)
            # if not mei_fn.endswith('.mei'):
            #     errors = "not in mei file format"
                if os.path.exists(os.path.join(mei_directory, mei_fn)):
                    errors = "mei file already exists"
                else:
                    # write to working directory and backup
                    fp = open(os.path.join(mei_directory, mei_fn), "w")
                    fp.write(contents)
                    fp.close()
                    fp = open(os.path.join(mei_directory_backup, mei_fn), "w")
                    fp.write(contents)
                    fp.close()

            except Exception, e:
                errors = "invalid mei file"
开发者ID:DDMAL,项目名称:Neon.js,代码行数:32,代码来源:interface.py


示例6: _get_symbol_widths

    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,代码行数:59,代码来源:homr.py


示例7: parse_file

    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,代码行数:8,代码来源:score.py


示例8: parse_str

    def parse_str(self, mei_str):
        '''
        Read an mei file from string and fill the score model
        '''

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


示例9: sanitize_mei_str

    def sanitize_mei_str(self, mei_str, output_mei_path=None, prune=True):
        self.mei_doc = XmlImport.documentFromText(mei_str)
        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,代码行数:8,代码来源:guitarify.py


示例10: processMeiFile

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,代码行数:9,代码来源:MEI2Solr.py


示例11: __init__

    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,代码行数:12,代码来源:generateglyphs.py


示例12: __init__

    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,代码行数:14,代码来源:meicombine.py


示例13: analyze

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,代码行数:14,代码来源:analyze.py


示例14: massage_mei

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,代码行数:15,代码来源:massage_mei.py


示例15: mei_append_metamusic

    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,代码行数:48,代码来源:models.py


示例16: OnLoadRects

    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,代码行数:46,代码来源:gtruth-canvas-zooming.py


示例17: Run

	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,代码行数:18,代码来源:transformtestrunner.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python MeiElement.MeiElement类代码示例发布时间:2022-05-27
下一篇:
Python pymei.MeiElement类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap