]> git.donarmstrong.com Git - lilypond.git/blobdiff - python/musicexp.py
Merge branch 'master' of git://git.sv.gnu.org/lilypond
[lilypond.git] / python / musicexp.py
index 07af416ab779ef2d024423e98b13baa821fde1d6..2ae8a6784f3ea480f3343d6539323fd79ec706d0 100644 (file)
@@ -2,6 +2,9 @@ import inspect
 import sys
 import string
 import re
+import lilylib as ly
+
+_ = ly._
 
 from rational import Rational
 
@@ -9,6 +12,10 @@ from rational import Rational
 previous_pitch = None
 relative_pitches = False
 
+def warning (str):
+    ly.stderr_write ((_ ("warning: %s") % str) + "\n")
+
+
 def escape_instrument_string (input_string):
     retstring = string.replace (input_string, "\"", "\\\"")
     if re.match ('.*[\r\n]+.*', retstring):
@@ -148,8 +155,12 @@ class Duration:
     def ly_expression (self, factor = None):
         if not factor:
             factor = self.factor
-            
-        str = '%d%s' % (1 << self.duration_log, '.'*self.dots)
+
+        if self.duration_log < 0:
+            str = {-1: "\\breve", -2: "\\longa"}.get (self.duration_log, "1")
+        else:
+            str = '%d' % (1 << self.duration_log)
+        str += '.'*self.dots
 
         if factor <> Rational (1,1):
             if factor.denominator () <> 1:
@@ -567,7 +578,8 @@ class RepeatedMusic:
             self.music = SequentialMusic ()
             self.music.elements = music
         else:
-            sys.stderr.write (_ ("WARNING: Unable to set the music %s for the repeat %s" % (music, self)))
+            warning (_ ("unable to set the music %(music)s for the repeat %(repeat)s" % \
+                            {'music':music, 'repeat':self}))
     def add_ending (self, music):
         self.endings.append (music)
     def print_ly (self, printer):
@@ -575,7 +587,7 @@ class RepeatedMusic:
         if self.music:
             self.music.print_ly (printer)
         else:
-            sys.stderr.write (_ ("WARNING: Encountered repeat without body\n"))
+            warning (_ ("encountered repeat without body"))
             printer.dump ('{}')
         if self.endings:
             printer.dump ('\\alternative {')
@@ -661,6 +673,31 @@ class Paper:
         printer.dump ('}')
         printer.newline ()
 
+class Layout:
+    def __init__ (self):
+        self.context_dict = {}
+    def add_context (self, context):
+        if not self.context_dict.has_key (context):
+            self.context_dict[context] = []
+    def set_context_item (self, context, item):
+        self.add_context (context)
+        if not item in self.context_dict[context]:
+            self.context_dict[context].append (item)
+    def print_ly (self, printer):
+        if self.context_dict.items ():
+            printer.dump ('\\layout {')
+            printer.newline ()
+            for (context, defs) in self.context_dict.items ():
+                printer.dump ('\\context { \\%s' % context)
+                printer.newline ()
+                for d in defs:
+                    printer.dump (d)
+                    printer.newline ()
+                printer.dump ('}')
+                printer.newline ()
+            printer.dump ('}')
+            printer.newline ()
+
 
 class ChordEvent (NestedMusic):
     def __init__ (self):
@@ -822,12 +859,19 @@ class TextSpannerEvent (SpanEvent):
             1:'\\stopTextSpan'}.get (self.span_direction, '')
 
 class BracketSpannerEvent (SpanEvent):
+    # Ligature brackets use prefix-notation!!!
+    def print_before_note (self, printer):
+        if self.span_direction == -1:
+            printer.dump ('\[')
+    # the the bracket after the last note
+    def print_after_note (self, printer):
+        if self.span_direction == 1:
+            printer.dump ('\]')
+    # we're printing everything in print_(before|after)_note...
     def ly_expression (self):
-        return {-1: '\\startGroup',
-            1:'\\stopGroup'}.get (self.span_direction, '')
+        return '';
 
 
-# type==-1 means octave up, type==-2 means octave down
 class OctaveShiftEvent (SpanEvent):
     def wait_for_note (self):
         return False