1
# This file is part of the Frescobaldi project, http://www.frescobaldi.org/
3
# Copyright (c) 2008, 2009, 2010 by Wilbert Berendsen
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.
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.
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.
20
from __future__ import unicode_literals
23
Preview dialog for the Score Wizard (scorewiz/__init__.py).
24
In separate file to ease maintenance.
30
from frescobaldi_app.runlily import LilyPreviewDialog
31
from frescobaldi_app.scorewiz import config
33
class PreviewDialog(LilyPreviewDialog):
34
def __init__(self, scorewiz):
35
self.scorewiz = scorewiz
36
LilyPreviewDialog.__init__(self, scorewiz)
38
def loadSettings(self):
39
self.restoreDialogSize(config("preview"))
41
def saveSettings(self):
42
self.saveDialogSize(config("preview"))
44
def showPreview(self):
45
builder = self.scorewiz.builder()
46
builder.midi = False # not needed
47
doc = builder.document()
49
keysig = doc.findChild(ly.dom.KeySignature)
50
timesig = doc.findChild(ly.dom.TimeSignature)
51
partial = doc.findChild(ly.dom.Partial)
52
# create a list of durations for the example notes.
55
durs.append((partial.dur, partial.dots))
57
dur = int(math.log(int(timesig.beat), 2))
58
num = min(int(timesig.num)*2, 10)
61
durs += [(dur, 0)] * num
63
def addItems(stub, generator):
64
for dur, dots in durs:
65
node = next(generator)
66
node.append(ly.dom.Duration(dur, dots))
69
lyrics = lyricsGen(len(durs))
70
# iter over all the Assignments to add example notes etc.
71
for a in doc.findChildren(ly.dom.Assignment, 1):
73
if isinstance(stub, ly.dom.LyricMode):
74
stub.append(next(lyrics))
75
elif isinstance(stub, ly.dom.Relative):
76
addItems(stub[-1], pitchGen(keysig))
77
elif isinstance(stub, ly.dom.ChordMode):
78
addItems(stub, chordGen(keysig))
79
elif isinstance(stub, ly.dom.FigureMode):
80
addItems(stub, figureGen())
81
elif isinstance(stub, ly.dom.DrumMode):
82
addItems(stub, drumGen())
84
LilyPreviewDialog.showPreview(self, builder.ly(doc))
87
# Generators for different kinds of example input
88
def pitchGen(startPitch):
89
note = startPitch.note
91
for n in (note, note, (note + 9 ) % 7, (note + 8) % 7,
92
note, (note + 11) % 7, note):
93
chord = ly.dom.Chord()
94
ly.dom.Pitch(-1, n, startPitch.alter, parent=chord)
97
def chordGen(startPitch):
98
for n in pitchGen(startPitch):
101
yield ly.dom.TextDur("\\skip")
103
def lyricsGen(length):
105
for i in "ha", "hi", "ho", "he", "hu":
107
result[0] = result[0].title()
108
yield ly.dom.Text(' '.join(result))
112
for i in 5, 6, 3, 8, 7:
113
for s in "<{0}>".format(i), "\\skip", "\\skip":
114
yield ly.dom.TextDur(s)
118
for s in "bd", "hh", "sn", "hh":
119
yield ly.dom.TextDur(s)
b'\\ No newline at end of file'