#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (C) 2012 S. Daniel Francis # # 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 Street, Fifth Floor, Boston, # MA 02110-1301, USA. import pango from instruments.piano import Piano class Track: def __init__(self): self._y = 0 self._linespacing = 10 self.piano = Piano() 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() 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(window, width, text_width + 10, rmarg, self.linespacing) #start and end line context.set_line_width(2) context.set_source_rgb(0, 0, 0) 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) context.stroke() def set_y(self, y): self._y = y def get_y(self): return self.y y = property(get_y, set_y) def set_linespacing(self, value): self._linespacing = value def get_linespacing(self): return self._linespacing linespacing = property(get_linespacing, set_linespacing)