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-20 01:23:22 (GMT)
committer Daniel Francis <francis@sugarlabs.org>2012-07-20 01:23:22 (GMT)
commit26aa4b4f4cd640620e8db2a60912000f63c6c5b8 (patch)
tree0d38a1eb5d325ece5f693b2f23a2b112b66db36c
parente87aaf3691454d9445066386fee2f14a6dd68689 (diff)
Show G cleff
-rw-r--r--.gitignore1
-rw-r--r--clef.py46
-rw-r--r--instruments/instrument.py9
-rw-r--r--instruments/piano.py9
-rw-r--r--staff.py11
-rw-r--r--track.py4
6 files changed, 67 insertions, 13 deletions
diff --git a/.gitignore b/.gitignore
index 1e4c0c4..39406f6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,4 @@
*.pyo
*.mo
*~
+clefs.svg
diff --git a/clef.py b/clef.py
new file mode 100644
index 0000000..61f935a
--- /dev/null
+++ b/clef.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright 2012 S. Daniel Francis <francis@sugarlabs.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+import os
+
+import cairo
+import rsvg
+
+CLEF_C3 = 0
+CLEF_C4 = 1
+CLEF_F = 2
+CLEF_G = 3
+
+
+class Clef:
+ clef_type = CLEF_G
+ clefs = [None, None, None, rsvg.Handle(file=os.path.join(
+ os.environ['SUGAR_BUNDLE_PATH'], 'symbols/Gclef.svg'))]
+
+ def __init__(self):
+ pass
+
+ def draw(self, context, xcorner, ytop, width, height):
+ svg = self.clefs[self.clef_type]
+ matrix = cairo.Matrix(xx=width / svg.props.width,
+ yy=height / svg.props.height,
+ x0=xcorner,
+ y0=ytop)
+ context.transform(matrix)
+ svg.render_cairo(context)
diff --git a/instruments/instrument.py b/instruments/instrument.py
index d6871b4..3d3f3fc 100644
--- a/instruments/instrument.py
+++ b/instruments/instrument.py
@@ -39,7 +39,8 @@ class Instrument:
self.svg = rsvg.Handle(file=os.path.join(
os.environ['SUGAR_BUNDLE_PATH'], 'symbols/accolade.svg'))
- def draw(self, context, width, lmarg, rmarg, linespacing, bracket_cr):
+ def draw(self, window, width, lmarg, rmarg, linespacing):
+ accolade_cr = window.cairo_create()
xx = lmarg * 0.20 / self.svg.props.width
x0 = lmarg
@@ -50,15 +51,15 @@ class Instrument:
staff.rmarg = rmarg
staff.spacing = linespacing
staff.y = self.ymax
- staff.draw(context, width)
+ staff.draw(window, width)
self.ymax = staff.ymax
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)
+ accolade_cr.transform(matrix)
+ self.svg.render_cairo(accolade_cr)
def guess_height(self, linespace):
return len(self.staves) * linespace * 9
diff --git a/instruments/piano.py b/instruments/piano.py
index 127a06c..b3cd48d 100644
--- a/instruments/piano.py
+++ b/instruments/piano.py
@@ -22,6 +22,7 @@ from gettext import gettext as _
from staff import Staff
from instrument import Instrument
+import clef
class Piano(Instrument):
@@ -29,5 +30,9 @@ class Piano(Instrument):
def __init__(self):
Instrument.__init__(self)
- self.staves.append(Staff())
- self.staves.append(Staff())
+ top_staff = Staff()
+ top_staff.clef = clef.Clef()
+ bottom_staff = Staff()
+ bottom_staff.clef = clef.Clef()
+ self.staves.append(top_staff)
+ self.staves.append(bottom_staff)
diff --git a/staff.py b/staff.py
index 18f2dbb..710c9a0 100644
--- a/staff.py
+++ b/staff.py
@@ -25,21 +25,22 @@ class Staff:
rmarg = 0
spacing = 0
ymax = 0
+ clef = None
def __init__(self):
pass
- def draw(self, context, width, margin=None):
+ def draw(self, window, width):
+ context = window.cairo_create()
context.set_source_rgb(0, 0, 0)
context.set_line_width(2)
line_y = self.y + self.spacing * 2
for i in range(5):
- if margin != None:
- x = margin
- else:
- x = self.lmarg
+ 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
context.stroke()
+ self.clef.draw(window.cairo_create(), self.lmarg * 1.1, self.y,
+ self.lmarg * 0.3, self.ymax - self.y - self.spacing)
diff --git a/track.py b/track.py
index e4a21ae..0489145 100644
--- a/track.py
+++ b/track.py
@@ -47,8 +47,8 @@ class Track:
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())
+ self.piano.draw(window, width, text_width + 10,
+ rmarg, self.linespacing)
#start and end line
context.set_line_width(2)