當前位置: 首頁>>代碼示例>>Python>>正文


Python pymei.XmlImport類代碼示例

本文整理匯總了Python中pymei.XmlImport的典型用法代碼示例。如果您正苦於以下問題:Python XmlImport類的具體用法?Python XmlImport怎麽用?Python XmlImport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了XmlImport類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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


注:本文中的pymei.XmlImport類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。