~ubuntu-branches/ubuntu/vivid/frescobaldi/vivid

« back to all changes in this revision

Viewing changes to python/ly/__init__.py

  • Committer: Package Import Robot
  • Author(s): Ryan Kavanagh
  • Date: 2012-01-03 16:20:11 UTC
  • mfrom: (1.4.1)
  • Revision ID: package-import@ubuntu.com-20120103162011-tsjkwl4sntwmprea
Tags: 2.0.0-1
* New upstream release 
* Drop the following uneeded patches:
  + 01_checkmodules_no_python-kde4_build-dep.diff
  + 02_no_pyc.diff
  + 04_no_binary_lilypond_upgrades.diff
* Needs new dependency python-poppler-qt4
* Update debian/watch for new download path
* Update copyright file with new holders and years

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
2
 
#
3
 
# Copyright (c) 2008, 2009, 2010 by Wilbert Berendsen
4
 
#
5
 
# This program is free software; you can redistribute it and/or
6
 
# modify it under the terms of the GNU General Public License
7
 
# as published by the Free Software Foundation; either version 2
8
 
# of the License, or (at your option) any later version.
9
 
#
10
 
# This program is distributed in the hope that it will be useful,
11
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
# GNU General Public License for more details.
14
 
#
15
 
# You should have received a copy of the GNU General Public License
16
 
# along with this program; if not, write to the Free Software
17
 
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18
 
# See http://www.gnu.org/licenses/ for more information.
19
 
 
20
 
from __future__ import unicode_literals
21
 
 
22
 
""" Basic LilyPond information and utility functions """
23
 
 
24
 
 
25
 
# Exceptions used by modules in this package
26
 
class NoMusicExpressionFound(Exception):
27
 
    """
28
 
    Raised if no music expression could be found in abs->rel.
29
 
    """
30
 
    pass
31
 
 
32
 
 
33
 
class QuarterToneAlterationNotAvailable(Exception):
34
 
    """
35
 
    Raised when there is no pitch name in the target languate
36
 
    when translating pitch names.
37
 
    """
38
 
    pass
39
 
 
40
 
 
41
 
_nums = (
42
 
    'Zero', 'One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight',
43
 
    'Nine', 'Ten', 'Eleven', 'Twelve', 'Thirteen', 'Fourteen', 'Fifteen',
44
 
    'Sixteen', 'Seventeen', 'Eighteen', 'Nineteen')
45
 
 
46
 
_tens = (
47
 
    'Twenty', 'Thirty', 'Forty', 'Fifty', 'Sixty', 'Seventy', 'Eighty',
48
 
    'Ninety', 'Hundred')
49
 
 
50
 
def nums(num):
51
 
    """
52
 
    Returns a textual representation of a number (e.g. 1 -> "One"), for use
53
 
    in LilyPond identifiers (that do not support digits).
54
 
    Supports numbers 0 to 109.
55
 
    """
56
 
    if num < 20:
57
 
        return _nums[num]
58
 
    d, r = divmod(num, 10)
59
 
    n = _tens[d-2]
60
 
    if r:
61
 
        n += _nums[r]
62
 
    return n
63
 
 
64
 
 
65
 
# Thanks: http://billmill.org/python_roman.html
66
 
_roman_numerals = (("M", 1000), ("CM", 900), ("D", 500), ("CD", 400),
67
 
("C", 100),("XC", 90),("L", 50),("XL", 40), ("X", 10), ("IX", 9), ("V", 5),
68
 
("IV", 4), ("I", 1))
69
 
 
70
 
def romanize(n):
71
 
    roman = []
72
 
    for ltr, num in _roman_numerals:
73
 
        k, n = divmod(n, num)
74
 
        roman.append(ltr * k)
75
 
    return "".join(roman)
76
 
 
77
 
 
78
 
def headers(i18nFunc=None):
79
 
    i18n = i18nFunc or (lambda s: s)
80
 
    return (
81
 
        ('dedication',  i18n("Dedication")),
82
 
        ('title',       i18n("Title")),
83
 
        ('subtitle',    i18n("Subtitle")),
84
 
        ('subsubtitle', i18n("Subsubtitle")),
85
 
        ('instrument',  i18n("Instrument")),
86
 
        ('composer',    i18n("Composer")),
87
 
        ('arranger',    i18n("Arranger")),
88
 
        ('poet',        i18n("Poet")),
89
 
        ('meter',       i18n("Meter")),
90
 
        ('piece',       i18n("Piece")),
91
 
        ('opus',        i18n("Opus")),
92
 
        ('copyright',   i18n("Copyright")),
93
 
        ('tagline',     i18n("Tagline")),
94
 
    )
95
 
 
96
 
headerNames = zip(*headers())[0]
97
 
 
98
 
def modes(i18nFunc=None):
99
 
    i18n = i18nFunc or (lambda s: s)
100
 
    return (
101
 
        ('major',       i18n("Major")),
102
 
        ('minor',       i18n("Minor")),
103
 
        ('ionian',      i18n("Ionian")),
104
 
        ('dorian',      i18n("Dorian")),
105
 
        ('phrygian',    i18n("Phrygian")),
106
 
        ('lydian',      i18n("Lydian")),
107
 
        ('mixolydian',  i18n("Mixolydian")),
108
 
        ('aeolian',     i18n("Aeolian")),
109
 
        ('locrian',     i18n("Locrian")),
110
 
    )
111
 
 
112
 
keys = (
113
 
    (0, 0), (0, 1),
114
 
    (1, -1), (1, 0), (1, 1),
115
 
    (2, -1), (2, 0),
116
 
    (3, 0), (3, 1),
117
 
    (4, -1), (4, 0), (4, 1),
118
 
    (5, -1), (5, 0), (5, 1),
119
 
    (6, -1), (6, 0),
120
 
)
121
 
 
122
 
keyNames = {
123
 
    'nederlands': (
124
 
        'C', 'Cis',
125
 
        'Des', 'D', 'Dis',
126
 
        'Es', 'E',
127
 
        'F', 'Fis',
128
 
        'Ges', 'G', 'Gis',
129
 
        'As', 'A', 'Ais',
130
 
        'Bes', 'B',
131
 
    ),
132
 
    'english': (
133
 
        'C', 'C#',
134
 
        'Db', 'D', 'D#',
135
 
        'Eb', 'E',
136
 
        'F', 'F#',
137
 
        'Gb', 'G', 'G#',
138
 
        'Ab', 'A', 'A#',
139
 
        'Bb', 'B',
140
 
    ),
141
 
    'deutsch': (
142
 
        'C', 'Cis',
143
 
        'Des', 'D', 'Dis',
144
 
        'Es', 'E',
145
 
        'F', 'Fis',
146
 
        'Ges', 'G', 'Gis',
147
 
        'As', 'A', 'Ais',
148
 
        'B', 'H',
149
 
    ),
150
 
    'norsk': (
151
 
        'C', 'Ciss',
152
 
        'Dess', 'D', 'Diss',
153
 
        'Ess', 'E',
154
 
        'F', 'Fiss',
155
 
        'Gess', 'G', 'Giss',
156
 
        'Ass', 'A', 'Aiss',
157
 
        'B', 'H',
158
 
    ),
159
 
    'italiano': (
160
 
        'Do', 'Do diesis',
161
 
        'Re bemolle', 'Re', 'Re diesis',
162
 
        'Mi bemolle', 'Mi',
163
 
        'Fa', 'Fa diesis',
164
 
        'Sol bemolle', 'Sol', 'Sol diesis',
165
 
        'La bemolle', 'La', 'La diesis',
166
 
        'Si bemolle', 'Si',
167
 
    ),
168
 
    'espanol': (
169
 
        'Do', 'Do sostenido',
170
 
        'Re bemol', 'Re', 'Re sostenido',
171
 
        'Mi bemol', 'Mi',
172
 
        'Fa', 'Fa sostenido',
173
 
        'Sol bemol', 'Sol', 'Sol sostenido',
174
 
        'La bemol', 'La', 'La sostenido',
175
 
        'Si bemol', 'Si',
176
 
    ),
177
 
    'vlaams': (
178
 
        'Do', 'Do kruis',
179
 
        'Re mol', 'Re', 'Re kruis',
180
 
        'Mi mol', 'Mi',
181
 
        'Fa', 'Fa kruis',
182
 
        'Sol mol', 'Sol', 'Sol kruis',
183
 
        'La mol', 'La', 'La kruis',
184
 
        'Si mol', 'Si',
185
 
    ),
186
 
}
187
 
 
188
 
keyNames['svenska'] = keyNames['norsk']
189
 
keyNames['suomi'] = keyNames['deutsch']
190
 
keyNames['catalan'] = keyNames['italiano']
191
 
keyNames['portugues'] = keyNames['espanol']
192
 
 
193
 
paperSizes = ['a3', 'a4', 'a5', 'a6', 'a7', 'legal', 'letter', '11x17']