From 271c6f29b5a4a9008cf9dd87cd4b9bf6ce35b09e Mon Sep 17 00:00:00 2001 From: Daniel Francis Date: Sat, 21 Jul 2012 22:55:09 +0000 Subject: Solving some showing bugs, creating class for beats --- diff --git a/clef.py b/clef.py index b54cf28..298705f 100644 --- a/clef.py +++ b/clef.py @@ -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) diff --git a/staff.py b/staff.py index 15ba0fc..0f210cc 100644 --- a/staff.py +++ b/staff.py @@ -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) diff --git a/track.py b/track.py index 0489145..d9f8514 100644 --- a/track.py +++ b/track.py @@ -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 -- cgit v0.9.1