Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Francis <francis@sugarlabs.org>2012-07-19 17:18:45 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-07-19 17:18:45 (GMT)
commite87aaf3691454d9445066386fee2f14a6dd68689 (patch)
treecba1ff6b26f5363fb34f4acecf8f69a6c48302d5
parentd570bd3684165608e47ee0f74556e31a5611e388 (diff)
More decent Accolade (I found the correct musical name for the bracket in english). Show instrument name.
-rw-r--r--canvas.py3
-rw-r--r--instruments/instrument.py19
-rw-r--r--staff.py8
-rw-r--r--symbols/accolade.svg32
-rw-r--r--symbols/bracket.svg60
-rw-r--r--track.py30
6 files changed, 75 insertions, 77 deletions
diff --git a/canvas.py b/canvas.py
index bdb5750..aa811b2 100644
--- a/canvas.py
+++ b/canvas.py
@@ -35,8 +35,9 @@ class StaffCanvas(gtk.DrawingArea):
def _expose_event_cb(self, widget, event):
window = widget.get_window()
+ context = widget.create_pango_context()
width = event.area[2]
height = event.area[3]
for track in self.tracks:
track.linespacing = height * 0.025
- track.draw(window, width)
+ track.draw(window, width, context)
diff --git a/instruments/instrument.py b/instruments/instrument.py
index 65ebdbc..d6871b4 100644
--- a/instruments/instrument.py
+++ b/instruments/instrument.py
@@ -33,27 +33,32 @@ class Instrument:
ymin = 0
ymax = 0
show_bracket = False
+ staffx = 0
def __init__(self):
self.svg = rsvg.Handle(file=os.path.join(
- os.environ['SUGAR_BUNDLE_PATH'], 'symbols/bracket.svg'))
+ os.environ['SUGAR_BUNDLE_PATH'], 'symbols/accolade.svg'))
def draw(self, context, width, lmarg, rmarg, linespacing, bracket_cr):
+
+ xx = lmarg * 0.20 / self.svg.props.width
+ x0 = lmarg
+ y0 = linespacing * 3.5
+ self.staffx = lmarg + lmarg * 0.20
for staff in self.staves:
- staff.lmarg = lmarg
+ staff.lmarg = self.staffx
staff.rmarg = rmarg
staff.spacing = linespacing
staff.y = self.ymax
staff.draw(context, width)
self.ymax = staff.ymax
- xx = lmarg * 0.60 / self.svg.props.width
- yy = (self.ymax - self.ymin - linespacing * 3) / self.svg.props.height
- x0 = lmarg * 0.40
- y0 = linespacing * 3
- logger.debug('xx=%f yy=%f x0=%f y0=%f' % (xx, yy, x0, y0))
+ yy = (self.ymax - self.ymin - linespacing * 4) / self.svg.props.height
matrix = cairo.Matrix(xx=xx,
yy=yy,
x0=x0,
y0=y0)
bracket_cr.transform(matrix)
self.svg.render_cairo(bracket_cr)
+
+ def guess_height(self, linespace):
+ return len(self.staves) * linespace * 9
diff --git a/staff.py b/staff.py
index 3ac51e4..18f2dbb 100644
--- a/staff.py
+++ b/staff.py
@@ -29,12 +29,16 @@ class Staff:
def __init__(self):
pass
- def draw(self, context, width):
+ def draw(self, context, width, margin=None):
context.set_source_rgb(0, 0, 0)
context.set_line_width(2)
line_y = self.y + self.spacing * 2
for i in range(5):
- context.move_to(self.lmarg, line_y)
+ if margin != None:
+ x = margin
+ else:
+ x = self.lmarg
+ context.move_to(x, line_y)
context.line_to(width - self.rmarg, line_y)
line_y += self.spacing
self.ymax = line_y + self.spacing * 2
diff --git a/symbols/accolade.svg b/symbols/accolade.svg
new file mode 100644
index 0000000..608168e
--- /dev/null
+++ b/symbols/accolade.svg
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+ xmlns:dc="http://purl.org/dc/elements/1.1/"
+ xmlns:cc="http://creativecommons.org/ns#"
+ xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+ xmlns:svg="http://www.w3.org/2000/svg"
+ xmlns="http://www.w3.org/2000/svg"
+ version="1.1"
+ width="29"
+ height="200"
+ id="svg2">
+ <defs
+ id="defs4" />
+ <metadata
+ id="metadata7">
+ <rdf:RDF>
+ <cc:Work
+ rdf:about="">
+ <dc:format>image/svg+xml</dc:format>
+ <dc:type
+ rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+ <dc:title></dc:title>
+ </cc:Work>
+ </rdf:RDF>
+ </metadata>
+ <path
+ d="M 21.580489,3.0373544 C 18.039855,5.9278861 12.967474,12.690762 10.938218,16.220765 7.8950961,23.62634 6.8807221,32.633816 7.8950961,41.328021 c 0.497002,2.887302 1.511884,9.320751 3.0431219,14.468806 2.526258,12.237123 3.043631,17.385175 3.043631,22.533229 -0.517373,8.36478 -4.0580039,15.111507 -9.6472469,19.616862 -1.014882,0.642695 -1.511886,1.285399 -1.511886,1.614808 0,0.329428 0.497004,0.972114 1.511886,1.614824 5.589243,4.50536 9.1298739,11.25208 9.6472469,19.3036 0,5.46133 -0.517373,10.60938 -3.043631,22.51708 -1.5312379,5.47747 -2.5461199,11.91094 -3.0431219,14.48494 -1.014374,9.0075 0,18.01499 3.0431219,25.09111 2.526258,5.79076 11.656644,15.77037 14.202762,15.77037 1.014373,0 2.028746,-0.64271 2.028746,-1.28863 0,-0.32619 -1.014373,-1.2854 -2.028746,-2.25754 -6.086752,-5.46133 -8.632872,-10.93557 -9.647246,-19.30032 0,-5.14808 0.516865,-9.97963 3.043124,-22.20382 1.014375,-4.81864 2.029258,-10.6094 2.546118,-12.87014 2.029256,-15.44092 -2.028748,-28.63727 -12.1735059,-38.28744 -1.531746,-1.28864 -2.546118,-2.574034 -2.546118,-2.574034 0,0 1.014372,-1.285382 2.546118,-2.574014 C 19.054228,87.337534 23.112232,74.141207 21.082976,58.370854 20.566116,56.439526 19.551233,50.648772 18.536858,45.503951 16.010599,33.605939 15.493734,28.774392 15.493734,23.62634 16.508108,15.26156 19.054228,9.7873121 25.14098,4.3259828 27.169726,2.394655 27.687101,1.7519558 26.672724,1.1092565 25.14098,0.46332922 24.126609,0.77983396 21.580489,3.0373544 z"
+ id="path126"
+ style="fill:#000000;fill-rule:evenodd;stroke:#000000;stroke-width:0pt;stroke-linecap:butt;stroke-linejoin:round;stroke-miterlimit:10" />
+</svg>
diff --git a/symbols/bracket.svg b/symbols/bracket.svg
deleted file mode 100644
index ebb2447..0000000
--- a/symbols/bracket.svg
+++ /dev/null
@@ -1,60 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<!-- Created with Inkscape (http://www.inkscape.org/) -->
-
-<svg
- xmlns:dc="http://purl.org/dc/elements/1.1/"
- xmlns:cc="http://creativecommons.org/ns#"
- xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
- xmlns:svg="http://www.w3.org/2000/svg"
- xmlns="http://www.w3.org/2000/svg"
- version="1.1"
- width="80"
- height="200"
- id="svg2">
- <defs
- id="defs4" />
- <metadata
- id="metadata7">
- <rdf:RDF>
- <cc:Work
- rdf:about="">
- <dc:format>image/svg+xml</dc:format>
- <dc:type
- rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
- <dc:title></dc:title>
- </cc:Work>
- </rdf:RDF>
- </metadata>
- <g
- transform="translate(0,-852.3622)"
- id="layer1">
- <path
- d="M 26.433035,26.505267 A 13.214286,9.8214283 0 0 1 40.184075,16.436813"
- transform="matrix(2.7733937,0,0,2.9697326,-40.37732,808.81541)"
- id="path2985"
- style="fill:none;stroke:#000000;stroke-width:0.8606618;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
- <path
- d="M 33.134804,885.13949 32.837183,942.759 z"
- id="path3757"
- style="fill:none;stroke:#000000;stroke-width:2.42612767;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
- <path
- d="m 32.978768,965.99252 -0.297621,49.28908 z"
- id="path3757-3"
- style="fill:none;stroke:#000000;stroke-width:2.24390268;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
- <path
- d="M 26.433035,26.505267 A 13.214286,9.8214283 0 0 1 40.184075,16.436813"
- transform="matrix(-0.48207933,-2.7311741,2.9245241,-0.51620753,3.7833715,1132.6905)"
- id="path2985-8"
- style="fill:none;stroke:#000000;stroke-width:0.82581717;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
- <path
- d="M 52.820557,26.980331 A 13.214286,9.8214283 0 0 1 35.473803,35.569818"
- transform="matrix(-0.21324541,-0.89823723,1.2936488,-0.16977197,-5.5051825,1005.2888)"
- id="path2985-8-5"
- style="fill:none;stroke:#000000;stroke-width:2.37067223;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
- <path
- d="M 52.820557,26.980331 A 13.214286,9.8214283 0 0 1 35.473803,35.569818"
- transform="matrix(0.91250102,-0.14016284,0.06496458,1.3031229,-17.072426,911.69346)"
- id="path2985-8-5-3"
- style="fill:none;stroke:#000000;stroke-width:2.37067223;stroke-miterlimit:4;stroke-opacity:1;stroke-dasharray:none" />
- </g>
-</svg>
diff --git a/track.py b/track.py
index cd0a946..e4a21ae 100644
--- a/track.py
+++ b/track.py
@@ -18,6 +18,8 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
+import pango
+
from instruments.piano import Piano
@@ -28,19 +30,33 @@ class Track:
self._linespacing = 10
self.piano = Piano()
- def draw(self, window, width):
- lmarg = width * 0.1
- rmarg = width * 0.05
+ def create_instrument_layout(self, name, pango_context):
+ layout = pango.Layout(pango_context)
+ layout.set_font_description(pango.FontDescription(
+ 'Century Schoolbook L Roman 20'))
+ layout.set_text(name)
+ return layout
+
+ def draw(self, window, width, pango_context):
+ #lmarg = width * 0.1
+ rmarg = width * 0.01
self.piano.ymax = self.piano.ymin = self.linespacing * 2
context = window.cairo_create()
- self.piano.draw(context, width, lmarg, rmarg, self.linespacing,
- window.cairo_create())
+ layout = self.create_instrument_layout(self.piano.name, pango_context)
+ text_width, height = layout.get_pixel_size()
+ context.move_to(5,
+ self.linespacing * 10 * len(self.piano.staves) / 2 - height / 2)
+ context.show_layout(layout)
+ self.piano.draw(context, width, text_width + 10,
+ rmarg, self.linespacing, window.cairo_create())
#start and end line
context.set_line_width(2)
context.set_source_rgb(0, 0, 0)
- context.move_to(lmarg, self.piano.ymin + self.linespacing * 2)
- context.line_to(lmarg, self.piano.ymax - self.linespacing * 3)
+ context.move_to(self.piano.staffx,
+ self.piano.ymin + self.linespacing * 2)
+ context.line_to(self.piano.staffx,
+ self.piano.ymax - self.linespacing * 3)
context.stroke()
context.move_to(width - rmarg, self.piano.ymin + self.linespacing * 2)
context.line_to(width - rmarg, self.piano.ymax - self.linespacing * 3)