Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/track.py
blob: 0489145362ece14c27f48ee83fd082e74f96f304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 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 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)