def outputargs(self): """Returns a list of output arguments in our document. See ly.parse.outputargs(). """ return list(ly.parse.outputargs(tokeniter.all_tokens(self.document())))
def includeargs(self): """Returns a list of \\include arguments in our document. See ly.parse.includeargs(). """ return list(ly.parse.includeargs(tokeniter.all_tokens(self.document())))
def version(self): """Returns the LilyPond version if set in the document, as a tuple of ints. First the functions searches inside LilyPond syntax. Then it looks at the 'version' document variable. Then, if the document is not a LilyPond document, it simply searches for a \\version command string, possibly embedded in a comment. The version is cached until the documents contents change. """ mkver = lambda strings: tuple(map(int, strings)) version = ly.parse.version(tokeniter.all_tokens(self.document())) if version: return mkver(re.findall(r"\d+", version)) # look at document variables version = variables.get(self.document(), "version") if version: return mkver(re.findall(r"\d+", version)) # parse whole document for non-lilypond documents if self.mode() != "lilypond": m = re.search(r'\\version\s*"(\d+\.\d+(\.\d+)*)"', self.document().toPlainText()) if m: return mkver(m.group(1).split('.'))
def exportMusicXML(self): """ Convert the current document to MusicXML """ doc = self.mainwindow().currentDocument() orgname = doc.url().toLocalFile() filename = os.path.splitext(orgname)[0] + '.xml' caption = app.caption(_("dialog title", "Export MusicXML File")) filetypes = '{0} (*.xml);;{1} (*)'.format(_("XML Files"), _("All Files")) filename = QFileDialog.getSaveFileName(self.mainwindow(), caption, filename, filetypes) if not filename: return False # cancelled import ly.musicxml writer = ly.musicxml.writer() writer.parse_tokens(tokeniter.all_tokens(doc)) #writer.parse_tree(doc) xml = writer.musicxml() # put the Frescobaldi version in the xml file software = xml.root.find('.//encoding/software') software.text = "{0} {1}".format(info.appname, info.version) try: xml.write(filename) except (IOError, OSError) as err: QMessageBox.warning( self.mainwindow(), app.caption(_("Error")), _("Can't write to destination:\n\n{url}\n\n{error}").format( url=filename, error=err.strerror))
def exportMusicXML(self): """ Convert the current document to MusicXML """ doc = self.mainwindow().currentDocument() orgname = doc.url().toLocalFile() filename = os.path.splitext(orgname)[0] + '.xml' caption = app.caption(_("dialog title", "Export MusicXML File")) filetypes = '{0} (*.xml);;{1} (*)'.format(_("XML Files"), _("All Files")) filename = QFileDialog.getSaveFileName(self.mainwindow(), caption, filename, filetypes) if not filename: return False # cancelled import ly.musicxml writer = ly.musicxml.writer() writer.parse_tokens(tokeniter.all_tokens(doc)) xml = writer.musicxml() # put the Frescobaldi version in the xml file software = xml.root.find('.//encoding/software') software.text = "{0} {1}".format(info.appname, info.version) try: xml.write(filename) except (IOError, OSError) as err: QMessageBox.warning(self.mainwindow(), app.caption(_("Error")), _("Can't write to destination:\n\n{url}\n\n{error}").format( url=filename, error=err.strerror))
def words(document): """Harvests words from strings, lyrics, markup and comments.""" for t in tokeniter.all_tokens(document): if isinstance(t, _word_types): for m in _words(t): yield m.group()
def schemewords(document): """Harvests all schemewords from the document.""" for t in tokeniter.all_tokens(document): if type(t) is ly.lex.scheme.Word: yield t