diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2013-05-10 13:32:59 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2013-05-10 13:32:59 (GMT) |
commit | edb2786fd137d55428036049c98334b29cf3d334 (patch) | |
tree | f80403d299aaff6054066f07ccc52f2ce899cdf3 | |
parent | 5ea3927f181a4ebc17a0eb94588f859b4712fa52 (diff) |
Add 'b' labels in black keys - SL #4496
Signed-off-by: Gonzalo Odiard <gonzalo@laptop.org>
-rw-r--r-- | activity.py | 10 | ||||
-rwxr-xr-x | draw_piano.py | 45 |
2 files changed, 36 insertions, 19 deletions
diff --git a/activity.py b/activity.py index 89a113c..5ae921c 100644 --- a/activity.py +++ b/activity.py @@ -94,12 +94,14 @@ class SimplePianoActivity(activity.Activity): self.keyboard_letters = ['ZSXDCVGBHNJM', 'Q2W3ER5T6Y7U', 'I'] - notes = ['DO', 'DO#', 'RE', 'RE#', 'MI', 'FA', 'FA#', 'SOL', - 'SOL#', 'LA', 'LA#', 'SI'] + notes = ['DO', ['DO#', 'REb'], 'RE', ['RE#', 'MIb'], 'MI', 'FA', + ['FA#', 'SOLb'], 'SOL', + ['SOL#', 'LAb'], 'LA', ['LA#', 'SIb'], 'SI'] self.notes_labels = [notes, notes, ['DO']] - german_notes = ['C', 'C#', 'D', 'D#', 'E', 'F', 'F#', 'G', - 'G#', 'A', 'A#', 'B'] + german_notes = ['C', ['C#', 'Db'], 'D', ['D#', 'Eb'], 'E', 'F', + ['F#', 'Gb'], 'G', + ['G#', 'Ab'], 'A', ['A#', 'Bb'], 'B'] self.german_labels = [german_notes, german_notes, ['C']] diff --git a/draw_piano.py b/draw_piano.py index cce2e75..3ae9825 100755 --- a/draw_piano.py +++ b/draw_piano.py @@ -304,7 +304,7 @@ class PianoKeyboard(Gtk.DrawingArea): cairo.FONT_WEIGHT_BOLD) ctx.set_font_size(self.font_size) _xbear, _ybear, width, height, _xadv, _yadv = ctx.text_extents('M') - self._text_height = height + self._text_height = height + 5 # add a little separation for n in range(0, self._octaves): self._draw_octave(ctx, n) @@ -528,21 +528,36 @@ class PianoKeyboard(Gtk.DrawingArea): #print "Dibujando ",text if self._labels is not None: text = self._labels[octave_number][position] - x_bea, _ybea, width, height, _xadv, _yadv = ctx.text_extents(text) - if black_key: - x_text = x + self._key_width * K1 / D - (width / 2 + x_bea) - y_text = self._black_keys_height - (self._text_height * 2) - if highlighted: - stroke = (0, 0, 0) - else: - stroke = (1, 1, 1) + # to enable use more than one label in the key, for the black keys + # and not need change all the whit key labels + # we allow the use of str or arrays of str + if isinstance(text, basestring): + # put the text in a array + labels = [text] else: - x_text = x + self._key_width / 2 - (width / 2 + x_bea) - y_text = self._height - (self._text_height * 2) - stroke = (0, 0, 0) - ctx.set_source_rgb(*stroke) - ctx.move_to(x_text, y_text) - ctx.show_text(text) + labels = text + i = 0 + for label in labels: + x_bea, _ybea, width, height, _xadv, _yadv = \ + ctx.text_extents(label) + y_pos = len(labels) - i + if black_key: + x_text = x + self._key_width * K1 / D - (width / 2 + x_bea) + y_text = self._black_keys_height - \ + (self._text_height * y_pos + 1) + if highlighted: + stroke = (0, 0, 0) + else: + stroke = (1, 1, 1) + else: + x_text = x + self._key_width / 2 - (width / 2 + x_bea) + y_text = self._height - \ + (self._text_height * y_pos + 1) + stroke = (0, 0, 0) + ctx.set_source_rgb(*stroke) + ctx.move_to(x_text, y_text) + ctx.show_text(label) + i = i + 1 def print_key_pressed(widget, octave_clicked, key_clicked, letter): |