Example #1
0
 def __init__(self, doc):
     self.doc = doc
     self.docinfo = documentinfo.music(doc)
     self.node = None
     self.lilyObject = None
     self.lilyContext = ""
     self.pos = 0
Example #2
0
 def parse_tree(self, doc):
     mustree = documentinfo.music(doc)
     print(mustree.dump())
     tree_nodes = mustree.iter_music()
     for m in tree_nodes:
         print(m)
         print(m.has_output())
Example #3
0
 def __init__(self, doc):
     self.doc = doc
     self.docinfo = documentinfo.music(doc)
     self.node = None
     self.lilyObject = None
     self.lilyContext = ""
     self.pos = 0
Example #4
0
def time_position(cursor):
    import documentinfo
    pos = documentinfo.music(cursor.document()).time_position(
        cursor.position())
    if pos is not None:
        import ly.duration
        return ly.duration.format_fraction(pos)
Example #5
0
 def parse_tree(self, doc):
     mustree = documentinfo.music(doc)
     print(mustree.dump())
     tree_nodes = mustree.iter_music()
     for m in tree_nodes:
         print(m)
         print(m.has_output())
Example #6
0
 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(documentinfo.music(doc))
     xml = writer.musicxml()
     # put the Frescobaldi version in the xml file
     software = xml.root.find('.//encoding/software')
     software.text = "{0} {1}".format(appinfo.appname, appinfo.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))
Example #7
0
def refnode(cursor):
    """Return the music item at the cursor if that probably is a reference to a definition elsewhere."""
    node = documentinfo.music(cursor.document()).node(cursor.position())
    if (node and node.end_position() >= cursor.selectionEnd()
        and isinstance(node, (
                ly.music.items.UserCommand,
                ly.music.items.MarkupUserCommand,
        ))):
        return node
Example #8
0
def time_position(cursor):
    """Returns the time position of the music the cursor points at.

    Format the value as "5/1" etc.

    """
    import documentinfo
    pos = documentinfo.music(cursor.document()).time_position(cursor.position())
    if pos is not None:
        import ly.duration
        return ly.duration.format_fraction(pos)
Example #9
0
def time_position(cursor):
    """Returns the time position of the music the cursor points at.
    
    Format the value as "5/1" etc.
    
    """
    import documentinfo
    pos = documentinfo.music(cursor.document()).time_position(
        cursor.position())
    if pos is not None:
        import ly.duration
        return ly.duration.format_fraction(pos)
Example #10
0
 def may_compile(self):
     """Return True if we could need to compile the document."""
     if self._dirty:
         dinfo = documentinfo.docinfo(self.document())
         if (dinfo.mode() == "lilypond" and dinfo.complete()
                 and documentinfo.music(self.document()).has_output()):
             h = dinfo.token_hash()
             if h != self._hash:
                 self._hash = h
                 if h != hash(tuple()):
                     return True
         self._dirty = False
Example #11
0
 def may_compile(self):
     """Return True if we could need to compile the document."""
     if self._dirty:
         dinfo = documentinfo.docinfo(self.document())
         if (dinfo.mode() == "lilypond"
             and dinfo.complete()
             and documentinfo.music(self.document()).has_output()):
             h = dinfo.token_hash()
             if h != self._hash:
                 self._hash = h
                 if h != hash(tuple()):
                     return True
         self._dirty = False
Example #12
0
 def parse_tree(self, doc):
     mustree = documentinfo.music(doc)
     # print(mustree.dump())
     header_nodes = self.iter_header(mustree)
     if header_nodes:
         self.parse_nodes(header_nodes)
     score = self.get_score(mustree)
     if score:
         mus_nodes = self.iter_score(score, mustree)
     else:
         mus_nodes = self.find_score_sub(mustree)
     self.mediator.new_section("fallback") #fallback/default section
     self.parse_nodes(mus_nodes)
Example #13
0
 def slotTimeout(self):
     """Called when one of the timers fires."""
     view = self._view()
     if view:
         d = view.document()
         c = view.textCursor()
         import documentinfo
         m = documentinfo.music(d)
         import ly.duration
         if c.hasSelection():
             cursortools.strip_selection(c)
             length = m.time_length(c.selectionStart(), c.selectionEnd())
             text = _("Length: {length}").format(
                 length=ly.duration.format_fraction(length)) if length is not None else ''
         else:
             pos = m.time_position(c.position())
             text = _("Pos: {pos}").format(
                 pos=ly.duration.format_fraction(pos)) if pos is not None else ''
         self._label.setText(text)
Example #14
0
 def slotTimeout(self):
     """Called when one of the timers fires."""
     view = self._view()
     if view:
         d = view.document()
         c = view.textCursor()
         import documentinfo
         m = documentinfo.music(d)
         import ly.duration
         if c.hasSelection():
             cursortools.strip_selection(c)
             length = m.time_length(c.selectionStart(), c.selectionEnd())
             text = _("Length: {length}").format(
                 length=ly.duration.format_fraction(length)) if length is not None else ''
         else:
             pos = m.time_position(c.position())
             text = _("Pos: {pos}").format(
                 pos=ly.duration.format_fraction(pos)) if pos is not None else ''
         self._label.setText(text)
Example #15
0
 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(documentinfo.music(doc))
     xml = writer.musicxml()
     # put the Frescobaldi version in the xml file
     software = xml.root.find('.//encoding/software')
     software.text = "{0} {1}".format(appinfo.appname, appinfo.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))
Example #16
0
def time_position(cursor):
    import documentinfo
    pos = documentinfo.music(cursor.document()).time_position(cursor.position())
    if pos is not None:
        import ly.duration
        return ly.duration.format_fraction(pos)