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

« back to all changes in this revision

Viewing changes to frescobaldi_app/ly/data/getdata.ly

  • 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
\version "2.14.1"
 
2
%{
 
3
  Outputs data retrieved from LilyPond as Python code:
 
4
  
 
5
  - version: the lilypond version string
 
6
  - interfaces: maps interface names to the list of their properties
 
7
  - grobs: maps grob names to the list of interfaces they implement
 
8
  - contextproperties: the list of all-user-translation-properties
 
9
  - musicglyphs: the list of all glyphs in the feta font
 
10
  
 
11
%}
 
12
 
 
13
#(begin
 
14
  
 
15
  (define (sort-symbol-list list)
 
16
    "sort a list of symbols"
 
17
    (sort list (lambda (s1 s2)
 
18
                 (string<
 
19
                  (symbol->string s1)
 
20
                  (symbol->string s2)))))
 
21
  
 
22
  (define (hash-keys h)
 
23
    "returns the list of keys of a hash table"
 
24
    (hash-fold
 
25
     (lambda (k v p)
 
26
       (append p (list k)))
 
27
     '()
 
28
     h))
 
29
  
 
30
  ;; the list of properties we also want to complete, besides all
 
31
  ;; user properties
 
32
  (define accepted-properties
 
33
    '(
 
34
      cross-staff
 
35
      positioning-done
 
36
      ))
 
37
  
 
38
  (define (user-property? prop)
 
39
    "is the property a user property?"
 
40
    (or (memq prop accepted-properties)
 
41
        (memq prop all-user-grob-properties)))
 
42
  
 
43
  (define (format-string-list list indent)
 
44
    "formats a list of strings as a python list"
 
45
    (cond
 
46
     ((null? list) "[]")
 
47
     (else 
 
48
      (string-append
 
49
       "[\n"
 
50
       (string-join
 
51
        (map (lambda (s)
 
52
               (string-append
 
53
                (make-string (+ 4 indent) #\space)
 
54
                "\""
 
55
                s
 
56
                "\",\n"))
 
57
          list)
 
58
        "")
 
59
       (make-string indent #\space)
 
60
       "]"))))
 
61
  
 
62
  (define (format-dict-entry k v indent)
 
63
    "formats a dictionary entry: key and value are string"
 
64
    (string-append
 
65
     (make-string indent #\space)
 
66
     "\"" k "\": " v ",\n"))
 
67
  
 
68
  (define (format-interfaces h)
 
69
    "formats the interfaces from ly:all-grob-interfaces as a Python dict"
 
70
    (string-append
 
71
     (fold (lambda (k p)
 
72
             (string-append
 
73
              p
 
74
              (format-dict-entry 
 
75
               (symbol->string k)
 
76
               (format-string-list
 
77
                (sort
 
78
                 (map symbol->string
 
79
                   (filter user-property?
 
80
                           (list-ref (hashq-ref h k) 2)))
 
81
                 string<)
 
82
                4)
 
83
               4)))
 
84
       "interfaces = {\n"
 
85
       (sort-symbol-list (hash-keys h)))
 
86
     "}\n"))
 
87
  
 
88
  (define (alist-keys alist)
 
89
    "returns the list of keys of the specified alist"
 
90
    (fold 
 
91
     (lambda (l p)
 
92
       (append p (list (car l))))
 
93
     '()
 
94
     alist))
 
95
  
 
96
  (define (format-grob-interfaces)
 
97
    "writes out all grob interfaces as a Python dict"
 
98
    (string-append
 
99
     (fold (lambda (k p)
 
100
             (string-append
 
101
              p
 
102
              (format-dict-entry
 
103
               (symbol->string k)
 
104
               (format-string-list
 
105
                (sort
 
106
                 (map symbol->string
 
107
                   (assq-ref
 
108
                    (assq-ref 
 
109
                     (assq-ref all-grob-descriptions k)
 
110
                     'meta)
 
111
                    'interfaces))
 
112
                 string<)
 
113
                4)
 
114
               4)))
 
115
       "grobs = {\n"
 
116
       (sort-symbol-list (alist-keys all-grob-descriptions)))
 
117
     "}\n"))
 
118
  
 
119
  (define (format-context-properties)
 
120
    "writes out the list of context (translation) properties"
 
121
    (string-append
 
122
     "contextproperties = "
 
123
     (format-string-list
 
124
      (sort
 
125
       (map symbol->string all-user-translation-properties)
 
126
       string<)
 
127
      0)
 
128
     "\n"))
 
129
  
 
130
  (define (get-translator-names)
 
131
    "returns the list of names of all engravers"
 
132
    (map
 
133
     (lambda (t)
 
134
       (symbol->string
 
135
        (ly:translator-name t)))
 
136
     (ly:get-all-translators)))
 
137
  
 
138
  (define (format-translators)
 
139
    "writes the list of engravers and performers"
 
140
    (string-append
 
141
     "engravers = "
 
142
     (format-string-list
 
143
      (sort (get-translator-names) string-ci<?)
 
144
      0)
 
145
     "\n"))
 
146
 
 
147
  (define (format-musicglyphs)
 
148
    "writes the list of music glyphs"
 
149
    (string-append
 
150
     "musicglyphs = "
 
151
     (format-string-list
 
152
      (sort
 
153
       (delete ".notdef"
 
154
         (ly:otf-glyph-list (ly:system-font-load "emmentaler-20")))
 
155
       string<)
 
156
      0)
 
157
     "\n"))
 
158
  
 
159
  ;;; output
 
160
  (display
 
161
   (string-append
 
162
    "#! python\n"
 
163
    "# generated by LilyPond " (lilypond-version) "\n\n"
 
164
    "version = \"" (lilypond-version) "\"\n\n"
 
165
    (format-interfaces (ly:all-grob-interfaces))
 
166
    "\n\n"
 
167
    (format-grob-interfaces)
 
168
    "\n\n"
 
169
    (format-context-properties)
 
170
    "\n\n"
 
171
    (format-translators)
 
172
    "\n\n"
 
173
    (format-musicglyphs)
 
174
    "\n\n"
 
175
    )))
 
176
  
 
177
% EOF