diff options
author | Daniel Francis <francis@sugarlabs.org> | 2012-07-21 22:55:09 (GMT) |
---|---|---|
committer | Daniel Francis <francis@sugarlabs.org> | 2012-07-21 22:55:09 (GMT) |
commit | 271c6f29b5a4a9008cf9dd87cd4b9bf6ce35b09e (patch) | |
tree | 778b251f653278838980d960f5d5f9b38a0f5beb | |
parent | f2b318808a996705c22c65cd1f5ef29472dc679d (diff) |
Solving some showing bugs, creating class for beats
-rw-r--r-- | clef.py | 1 | ||||
-rw-r--r-- | instruments/instrument.py | 1 | ||||
-rw-r--r-- | instruments/piano.py | 15 | ||||
-rw-r--r-- | staff.py | 27 | ||||
-rw-r--r-- | track.py | 1 |
5 files changed, 35 insertions, 10 deletions
@@ -50,3 +50,4 @@ class Clef: y0=ytop) context.transform(matrix) svg.render_cairo(context) + context.clip() diff --git a/instruments/instrument.py b/instruments/instrument.py index 3d3f3fc..e4653a1 100644 --- a/instruments/instrument.py +++ b/instruments/instrument.py @@ -60,6 +60,7 @@ class Instrument: y0=y0) accolade_cr.transform(matrix) self.svg.render_cairo(accolade_cr) + accolade_cr.clip() def guess_height(self, linespace): return len(self.staves) * linespace * 9 diff --git a/instruments/piano.py b/instruments/piano.py index 8bb975c..1be56fd 100644 --- a/instruments/piano.py +++ b/instruments/piano.py @@ -20,6 +20,7 @@ from gettext import gettext as _ +from staff import Beat from staff import Staff from instrument import Instrument import clef @@ -30,10 +31,14 @@ class Piano(Instrument): def __init__(self): Instrument.__init__(self) - top_staff = Staff() - top_staff.clef = clef.Clef() - bottom_staff = Staff() - bottom_staff.clef = clef.Clef() - bottom_staff.clef.clef_type = clef.CLEF_F + top_beat = Beat() + top_beat.clef = clef.Clef() + top_staff = Staff(top_beat) + + bottom_beat = Beat() + bottom_beat.clef = clef.Clef() + bottom_beat.clef.clef_type = clef.CLEF_F + bottom_staff = Staff(bottom_beat) + self.staves.append(top_staff) self.staves.append(bottom_staff) @@ -18,6 +18,13 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. +import logging +logger = logging.getLogger('staff') + + +class Beat: + clef = None + class Staff: y = 0 @@ -25,10 +32,11 @@ class Staff: rmarg = 0 spacing = 0 ymax = 0 - clef = None - def __init__(self): - pass + def __init__(self, beat): + self.beats = [] + self.beats.append(beat) + logger.debug(self.beats) def draw(self, window, width): context = window.cairo_create() @@ -42,5 +50,14 @@ class Staff: 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.spacing * 3, self.ymax - self.y - self.spacing) + context.clip() + self.draw_beats(window) + + def draw_beats(self, window): + for beat in self.beats: + if beat.clef != None: + beat.clef.draw(window.cairo_create(), + self.lmarg * 1.1, + self.y, + self.spacing * 3, + self.ymax - self.y - self.spacing) @@ -61,6 +61,7 @@ class Track: context.move_to(width - rmarg, self.piano.ymin + self.linespacing * 2) context.line_to(width - rmarg, self.piano.ymax - self.linespacing * 3) context.stroke() + context.clip() def set_y(self, y): self._y = y |