]> git.donarmstrong.com Git - lilypond.git/blob - scm/translation-functions.scm
2a3701ea16e8fb4773c52818201dd4d6f06a6253
[lilypond.git] / scm / translation-functions.scm
1 ;;;; This file is part of LilyPond, the GNU music typesetter.
2 ;;;;
3 ;;;; (c) 1998--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
4 ;;;;                 Jan Nieuwenhuizen <janneke@gnu.org>
5 ;;;;
6 ;;;; LilyPond is free software: you can redistribute it and/or modify
7 ;;;; it under the terms of the GNU General Public License as published by
8 ;;;; the Free Software Foundation, either version 3 of the License, or
9 ;;;; (at your option) any later version.
10 ;;;;
11 ;;;; LilyPond is distributed in the hope that it will be useful,
12 ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 ;;;; GNU General Public License for more details.
15 ;;;;
16 ;;;; You should have received a copy of the GNU General Public License
17 ;;;; along with LilyPond.  If not, see <http://www.gnu.org/licenses/>.
18
19
20 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
21 ;; clefs
22
23 (define-public (clef-transposition-markup oct style)
24   "The transposition sign formatting function.  @var{oct} is supposed to be
25 a string holding the transposition number, @var{style} determines the
26 way the transposition number is displayed."
27   (let* ((delim (if (symbol? style)
28                     (case style
29                       ((parenthesized) (cons "(" ")"))
30                       ((bracketed) (cons "[" "]"))
31                       (else (cons "" "")))
32                     (cons "" "")))
33          (text (string-concatenate (list (car delim) oct (cdr delim)))))
34
35     (make-vcenter-markup text)))
36
37
38 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
39 ;; metronome marks
40
41 (define-public (format-metronome-markup event context)
42    (let ((hide-note (ly:context-property context 'tempoHideNote #f))
43          (text (ly:event-property event 'text))
44          (dur (ly:event-property event 'tempo-unit))
45          (count (ly:event-property event 'metronome-count)))
46    (metronome-markup text dur count hide-note)))
47 (export format-metronome-markup)
48
49 (define (metronome-markup text dur count hide-note)
50   (let* ((note-mark
51             (if (and (not hide-note) (ly:duration? dur))
52                 (make-smaller-markup
53                   (make-note-by-number-markup
54                     (ly:duration-log dur)
55                     (ly:duration-dot-count dur)
56                     UP))
57                 #f))
58          (count-markup (cond ((number? count)
59                               (if (> count 0)
60                                   (make-simple-markup
61                                           (number->string count))
62                                   #f))
63                              ((pair? count)
64                               (make-concat-markup
65                                (list
66                                 (make-simple-markup
67                                         (number->string (car count)))
68                                 (make-simple-markup " ")
69                                 (make-simple-markup "–")
70                                 (make-simple-markup " ")
71                                 (make-simple-markup
72                                         (number->string (cdr count))))))
73                              (else #f)))
74          (note-markup (if (and (not hide-note) count-markup)
75                           (make-concat-markup
76                            (list
77                             (make-general-align-markup Y DOWN note-mark)
78                             (make-simple-markup " ")
79                             (make-simple-markup "=")
80                             (make-simple-markup " ")
81                             count-markup))
82                           #f))
83          (text-markup (if (not (null? text))
84                           (make-bold-markup text)
85                           #f)))
86     (if text-markup
87         (if (and note-markup (not hide-note))
88             (make-line-markup (list text-markup
89                                     (make-concat-markup
90                                      (list (make-simple-markup "(")
91                                            note-markup
92                                            (make-simple-markup ")")))))
93             (make-line-markup (list text-markup)))
94         (if note-markup
95             (make-line-markup (list note-markup))
96             (make-null-markup)))))
97
98 (define-public (format-mark-alphabet mark context)
99   (make-bold-markup (make-markalphabet-markup (1- mark))))
100
101 (define-public (format-mark-box-alphabet mark context)
102   (make-bold-markup (make-box-markup (make-markalphabet-markup (1- mark)))))
103
104 (define-public (format-mark-circle-alphabet mark context)
105   (make-bold-markup (make-circle-markup (make-markalphabet-markup (1- mark)))))
106
107 (define-public (format-mark-letters mark context)
108   (make-bold-markup (make-markletter-markup (1- mark))))
109
110 (define-public (format-mark-numbers mark context)
111   (make-bold-markup (number->string mark)))
112
113 (define-public (format-mark-barnumbers mark context)
114   (make-bold-markup (number->string (ly:context-property context
115                                                          'currentBarNumber))))
116
117 (define-public (format-mark-box-letters mark context)
118   (make-bold-markup (make-box-markup (make-markletter-markup (1- mark)))))
119
120 (define-public (format-mark-circle-letters mark context)
121   (make-bold-markup (make-circle-markup (make-markletter-markup (1- mark)))))
122
123 (define-public (format-mark-box-numbers mark context)
124   (make-bold-markup (make-box-markup (number->string mark))))
125
126 (define-public (format-mark-circle-numbers mark context)
127   (make-bold-markup (make-circle-markup (number->string mark))))
128
129 (define-public (format-mark-box-barnumbers mark context)
130   (make-bold-markup (make-box-markup
131                      (number->string (ly:context-property context
132                                                           'currentBarNumber)))))
133
134 (define-public (format-mark-circle-barnumbers mark context)
135   (make-bold-markup (make-circle-markup
136                      (number->string (ly:context-property context
137                                                           'currentBarNumber)))))
138
139
140 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
141 ;; Bass figures.
142
143 (define-public (format-bass-figure figure event context)
144   (let* ((fig (ly:event-property event 'figure))
145          (fig-markup (if (number? figure)
146
147                          ;; this is not very elegant, but center-aligning
148                          ;; all digits is problematic with other markups,
149                          ;; and shows problems in the (lack of) overshoot
150                          ;; of feta-alphabet glyphs.
151                          ((if (<= 10 figure)
152                               (lambda (y) (make-translate-scaled-markup
153                                            (cons -0.7 0) y))
154                               identity)
155
156                           (cond
157                            ((eq? #t (ly:event-property event 'diminished))
158                             (markup #:slashed-digit figure))
159                            ((eq? #t (ly:event-property event 'augmented-slash))
160                             (markup #:backslashed-digit figure))
161                            (else (markup #:number (number->string figure 10)))))
162                          #f))
163
164          (alt (ly:event-property event 'alteration))
165          (alt-markup
166           (if (number? alt)
167               (markup
168                #:general-align Y DOWN #:fontsize
169                (if (not (= alt DOUBLE-SHARP))
170                    -2 2)
171                (alteration->text-accidental-markup alt))
172               #f))
173
174          (plus-markup (if (eq? #t (ly:event-property event 'augmented))
175                           (markup #:number "+")
176                           #f))
177
178          (alt-dir (ly:context-property context 'figuredBassAlterationDirection))
179          (plus-dir (ly:context-property context 'figuredBassPlusDirection)))
180
181     (if (and (not fig-markup) alt-markup)
182         (begin
183           (set! fig-markup (markup #:left-align #:pad-around 0.3 alt-markup))
184           (set! alt-markup #f)))
185
186
187     ;; hmm, how to get figures centered between note, and
188     ;; lone accidentals too?
189
190     ;;    (if (markup? fig-markup)
191     ;;  (set!
192     ;;   fig-markup (markup #:translate (cons 1.0 0)
193     ;;                      #:center-align fig-markup)))
194
195     (if alt-markup
196         (set! fig-markup
197               (markup #:put-adjacent
198                       X (if (number? alt-dir)
199                             alt-dir
200                             LEFT)
201                       fig-markup
202                       #:pad-x 0.2 alt-markup)))
203
204     (if plus-markup
205         (set! fig-markup
206               (if fig-markup
207                   (markup #:put-adjacent
208                           X (if (number? plus-dir)
209                                 plus-dir
210                                 LEFT)
211                           fig-markup
212                           #:pad-x 0.2 plus-markup)
213                   plus-markup)))
214
215     (if (markup? fig-markup)
216         (markup #:fontsize -2 fig-markup)
217         empty-markup)))
218
219
220 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
221 ;; fret diagrams
222
223 (define (create-fretboard context grob placement-list)
224   "Convert @var{placement-list} into a fretboard @var{grob}."
225
226   (let* ((tunings (ly:context-property context 'stringTunings))
227          (my-string-count (length tunings))
228          (details (ly:grob-property grob 'fret-diagram-details)))
229
230     ;; Add string-count from string-tunings to fret-diagram-details.
231     (set! (ly:grob-property grob 'fret-diagram-details)
232           (acons 'string-count my-string-count details))
233     ;; Create the dot-placement list for the grob
234     (set! (ly:grob-property grob 'dot-placement-list) placement-list)))
235
236 (define-public
237   (determine-frets context notes specified-info . rest)
238   "Determine string numbers and frets for playing @var{notes}
239 as a chord, given specified information @var{specified-info}.
240 @var{specified-info} is a list with two list elements,
241 specified strings @code{defined-strings} and
242 specified fingerings @code{defined-fingers}.  Only a fingering of@tie{}0
243 will affect the fret selection, as it specifies an open string.
244 If @code{defined-strings} is @code{'()}, the context property
245 @code{defaultStrings} will be used as a list of defined strings.
246 Will look for predefined fretboards if @code{predefinedFretboardTable}
247 is not @code {#f}.  If @var{rest} is present, it contains the
248 @code{FretBoard} grob, and a fretboard will be
249 created.  Otherwise, a list of @code{(string fret finger)} lists will
250 be returned."
251
252   ;;  helper functions
253
254   (define (string-frets->placement-list string-frets string-count)
255     "Convert @var{string-frets} to @code{fret-diagram-verbose}
256 dot placement entries."
257     (let* ((placements (list->vector
258                         (map (lambda (x) (list 'mute  x))
259                              (iota string-count 1)))))
260
261       (for-each (lambda (sf)
262                   (let* ((string (car sf))
263                          (fret (cadr sf))
264                          (finger (caddr sf)))
265                     (vector-set!
266                      placements
267                      (1- string)
268                      (if (= 0 fret)
269                          (list 'open string)
270                          (if finger
271                              (list 'place-fret string fret finger)
272                              (list 'place-fret string fret))))))
273                 string-frets)
274       (vector->list placements)))
275
276   (define (placement-list->string-frets placement-list)
277     "Convert @var{placement-list} to string-fret list."
278     (map (lambda (x) (if (eq? (car x) 'place-fret)
279                          (cdr x)
280                          (list (cadr x) 0)))
281          (filter (lambda (l) (or (eq? (car l) 'place-fret)
282                                  (eq? (car l) 'open)))
283                  placement-list)))
284
285   (define (entry-count art-list)
286     "Count the number of entries in a list of articulations."
287     (length (filter (lambda (x) (not (null? x)))
288                     art-list)))
289
290   (define (string-number event)
291     "Get the string-number from @var{event}.  Return @var{#f}
292 if no string-number is present."
293     (let ((num (ly:event-property event 'string-number)))
294       (and (integer? num) (positive? num) num)))
295
296   (define (determine-frets-and-strings
297            notes
298            defined-strings
299            defined-fingers
300            minimum-fret
301            maximum-stretch
302            tuning)
303     "Determine the frets and strings used to play the notes in
304 @var{notes}, given @var{defined-strings} and @var{defined-fingers}
305 along with @var{minimum-fret}, @var{maximum-stretch}, and
306 @var{tuning}.  Returns a list of @code{(string fret finger) lists."
307
308
309     (define restrain-open-strings (ly:context-property context
310                                                        'restrainOpenStrings
311                                                        #f))
312     (define specified-frets '())
313     (define free-strings (iota (length tuning) 1))
314
315     (define (calc-fret pitch string tuning)
316       "Calculate the fret to play @var{pitch} on @var{string} with
317 @var{tuning}."
318       (* 2  (- (ly:pitch-tones pitch) (ly:pitch-tones (list-ref tuning (1- string))))))
319
320     (define (note-pitch note)
321       "Get the pitch (in semitones) from @var{note}."
322       (ly:event-property note 'pitch))
323
324     (define (note-finger ev)
325       "Get the fingering from @var{ev}.  Return @var{#f}
326 if no fingering is present."
327       (let* ((articulations (ly:event-property ev 'articulations))
328              (finger-found #f))
329         (for-each (lambda (art)
330                     (let* ((num (ly:event-property art 'digit)))
331
332                       (if (and (ly:in-event-class? art 'fingering-event)
333                                (number? num)
334                                (> num 0))
335                           (set! finger-found num))))
336                   articulations)
337         finger-found))
338
339     (define (delete-free-string string)
340       (if (number? string)
341           (set! free-strings
342                 (delete string free-strings))))
343
344     (define (close-enough fret)
345       "Decide if @var{fret} is acceptable, given the already used frets."
346       (every (lambda (specced-fret)
347                (or (zero? specced-fret)
348                    (zero? fret)
349                    (>= maximum-stretch (abs (- fret specced-fret)))))
350              specified-frets))
351
352     (define (string-qualifies string pitch)
353       "Can @var{pitch} be played on @var{string}, given already placed
354 notes?"
355       (let* ((fret (calc-fret pitch string tuning)))
356         (and (or (and (not restrain-open-strings)
357                       (zero? fret))
358                  (>= fret minimum-fret))
359              (integer? fret)
360              (close-enough fret))))
361
362     (define (open-string string pitch)
363       "Is @var{pitch} and open-string note on @var{string}, given
364 the current tuning?"
365       (let* ((fret (calc-fret pitch string tuning)))
366         (zero? fret)))
367
368     (define (set-fret! pitch-entry string finger)
369       (let ((this-fret (calc-fret (car pitch-entry)
370                                   string
371                                   tuning)))
372         (if (< this-fret 0)
373             (ly:warning (_ "Negative fret for pitch ~a on string ~a")
374                         (car pitch-entry) string)
375             (if (not (integer? this-fret))
376                 (ly:warning (_ "Missing fret for pitch ~a on string ~a")
377                             (car pitch-entry) string)))
378         (delete-free-string string)
379         (set! specified-frets (cons this-fret specified-frets))
380         (list-set! string-fret-fingers
381                    (cdr pitch-entry)
382                    (list string this-fret finger))))
383
384     (define (kill-note! string-fret-fingers note-index)
385       (list-set! string-fret-fingers note-index (list #f #t)))
386
387     (define string-fret-fingers
388       (map (lambda (string finger)
389              (if (null? finger)
390                  (list string #f)
391                  (list string #f finger)))
392            defined-strings defined-fingers))
393
394     ;;; body of determine-frets-and-strings
395     (let* ((pitches (map note-pitch notes))
396            (pitch-alist (map cons pitches (iota (length pitches)))))
397
398       ;; handle notes with strings assigned and fingering of 0
399       (for-each
400        (lambda (pitch-entry string-fret-finger)
401          (let* ((string (list-ref string-fret-finger 0))
402                 (finger (if (= (length string-fret-finger) 3)
403                             (list-ref string-fret-finger 2)
404                             '()))
405                 (pitch (car pitch-entry))
406                 (digit (if (null? finger)
407                            #f
408                            finger)))
409            (if (or (not (null? string))
410                    (eqv? digit 0))
411                (if (eqv? digit 0)
412                    ;; here we handle fingers of 0 -- open strings
413                    (let ((fit-string
414                           (find (lambda (string)
415                                   (open-string string pitch))
416                                 free-strings)))
417                      (if fit-string
418                          (set-fret! pitch-entry fit-string #f)
419                          (ly:warning (_ "No open string for pitch ~a")
420                                      pitch)))
421                    ;; here we handle assigned strings
422                    (let ((this-fret
423                           (calc-fret pitch string tuning))
424                          (handle-negative
425                           (ly:context-property context
426                                                'handleNegativeFrets
427                                                'recalculate)))
428                      (cond ((or (and (>= this-fret 0) (integer? this-fret))
429                                 (eq? handle-negative 'include))
430                             (set-fret! pitch-entry string finger))
431                            ((eq? handle-negative 'recalculate)
432                             (begin
433                               (ly:warning
434                                (_ "Requested string for pitch requires negative fret: string ~a pitch ~a")
435                                string
436                                pitch)
437                               (ly:warning (_ "Ignoring string request and recalculating."))
438                               (list-set! string-fret-fingers
439                                          (cdr pitch-entry)
440                                          (if (null? finger)
441                                              (list '() #f)
442                                              (list '() #f finger)))))
443                            ((eq? handle-negative 'ignore)
444                             (begin
445                               (ly:warning
446                                (_ "Requested string for pitch requires negative fret: string ~a pitch ~a")
447                                string
448                                pitch)
449                               (ly:warning (_ "Ignoring note in tablature."))
450                               (kill-note! string-fret-fingers
451                                           (cdr pitch-entry))))))))))
452        pitch-alist string-fret-fingers)
453       ;; handle notes without strings assigned -- sorted by pitch, so
454       ;; we need to use the alist to have the note number available
455       (for-each
456        (lambda (pitch-entry)
457          (let* ((string-fret-finger (list-ref string-fret-fingers
458                                               (cdr pitch-entry)))
459                 (string (list-ref string-fret-finger 0))
460                 (finger (if (= (length string-fret-finger) 3)
461                             (list-ref string-fret-finger 2)
462                             '()))
463                 (pitch (car pitch-entry))
464                 (fit-string
465                  (find (lambda (string)
466                          (string-qualifies string pitch))
467                        free-strings)))
468            (if (not (list-ref string-fret-finger 1))
469                (if fit-string
470                    (set-fret! pitch-entry fit-string finger)
471                    (begin
472                      (ly:event-warning
473                       (list-ref notes (cdr pitch-entry))
474                       (_ "No string for pitch ~a (given frets ~a)")
475                       pitch
476                       specified-frets)
477                      (kill-note! string-fret-fingers
478                                  (cdr pitch-entry)))))))
479        (sort pitch-alist (lambda (pitch-entry-a pitch-entry-b)
480                            (ly:pitch<? (car pitch-entry-b)
481                                        (car pitch-entry-a)))))
482       string-fret-fingers)) ;; end of determine-frets-and-strings
483
484   (define (get-predefined-fretboard predefined-fret-table tuning pitches)
485     "Search through @var{predefined-fret-table} looking for a predefined
486 fretboard with a key of @var{(tuning . pitches)}.  The search will check
487 both up and down an octave in order to accomodate transposition of the
488 chords.  Returns a placement-list."
489
490     (define (get-fretboard key)
491       (let ((hash-handle
492              (hash-get-handle predefined-fret-table key)))
493         (if hash-handle
494             (cdr hash-handle)  ; return table entry
495             '())))
496
497     ;; body of get-predefined-fretboard
498     (let ((test-fretboard (get-fretboard (cons tuning pitches))))
499       (if (not (null? test-fretboard))
500           test-fretboard
501           (let ((test-fretboard
502                  (get-fretboard
503                   (cons tuning (map (lambda (x) (shift-octave x 1)) pitches)))))
504             (if (not (null? test-fretboard))
505                 test-fretboard
506                 (get-fretboard
507                  (cons tuning (map (lambda (x) (shift-octave x -1))
508                                    pitches))))))))
509
510   ;; body of determine-frets
511   (let* ((predefined-fret-table
512           (ly:context-property context 'predefinedDiagramTable))
513          (tunings (ly:context-property context 'stringTunings))
514          (string-count (length tunings))
515          (grob (if (null? rest) '() (car rest)))
516          (pitches (map (lambda (x) (ly:event-property x 'pitch)) notes))
517          (defined-strings (map (lambda (x)
518                                  (if (null? x)
519                                      x
520                                      (or (string-number x) '())))
521                                (car specified-info)))
522          (defined-fingers (map (lambda (x)
523                                  (if (null? x)
524                                      x
525                                      (ly:event-property x 'digit)))
526                                (cadr specified-info)))
527          (default-strings (ly:context-property context 'defaultStrings '()))
528          (strings-used (if (and (zero? (entry-count defined-strings))
529                                 (not (zero? (entry-count default-strings))))
530                            default-strings
531                            defined-strings))
532          (predefined-fretboard
533           (if predefined-fret-table
534               (get-predefined-fretboard
535                predefined-fret-table
536                tunings
537                pitches)
538               '())))
539     (if (null? predefined-fretboard)
540         (let ((string-frets
541                (determine-frets-and-strings
542                 notes
543                 strings-used
544                 defined-fingers
545                 (ly:context-property context 'minimumFret 0)
546                 (ly:context-property context 'maximumFretStretch 4)
547                 tunings)))
548           (if (null? grob)
549               string-frets
550               (create-fretboard
551                context grob (string-frets->placement-list
552                              (filter (lambda (entry)
553                                        (car entry))
554                                      string-frets)
555                              string-count))))
556         (if (null? grob)
557             (placement-list->string-frets predefined-fretboard)
558             (create-fretboard context grob predefined-fretboard)))))
559
560
561
562 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
563 ;; tablature
564
565 ;; The TabNoteHead tablatureFormat callbacks.
566
567 ;; Calculate the fret from pitch and string number as letter
568 ;; The fret letter is taken from 'fretLabels if present
569 (define-public (fret-letter-tablature-format
570                 context string-number fret-number)
571   (let ((labels (ly:context-property context 'fretLabels)))
572     (make-vcenter-markup
573      (cond
574       ((= 0 (length labels))
575        (string (integer->char (+ fret-number (char->integer #\a)))))
576       ((and (<= 0 fret-number) (< fret-number (length labels)))
577        (list-ref labels fret-number))
578       (else
579        (ly:warning (_ "No label for fret ~a (on string ~a);
580 only ~a fret labels provided")
581                    fret-number string-number (length labels))
582        ".")))))
583
584 ;; Display the fret number as a number
585 (define-public (fret-number-tablature-format
586                 context string-number fret-number)
587   (make-vcenter-markup
588    (format #f "~a" fret-number)))
589
590 ;; The 5-string banjo has got an extra string, the fifth (duh), which
591 ;; starts at the fifth fret on the neck.  Frets on the fifth string
592 ;; are referred to relative to the other frets:
593 ;;   the "first fret" on the fifth string is really the sixth fret
594 ;;   on the banjo neck.
595 ;; We solve this by defining a new fret-number-tablature function:
596 (define-public (fret-number-tablature-format-banjo
597                 context string-number fret-number)
598   (make-vcenter-markup
599    (number->string (cond
600                     ((and (> fret-number 0) (= string-number 5))
601                      (+ fret-number 5))
602                     (else fret-number)))))
603
604 ;;  Tab note head staff position functions
605 ;;
606 ;;  Define where in the staff to display a given string.  Some forms of
607 ;;  tablature put the tab note heads in the spaces, rather than on the
608 ;;  lines
609
610 (define-public (tablature-position-on-lines context string-number)
611   (let* ((string-tunings (ly:context-property context 'stringTunings))
612          (string-count (length string-tunings))
613          (string-one-topmost (ly:context-property context 'stringOneTopmost))
614          (staff-line (- (* 2 string-number) string-count 1)))
615     (if string-one-topmost
616         (- staff-line)
617         staff-line)))
618
619 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
620 ;; bar numbers
621
622 (define ((every-nth-bar-number-visible n) barnum mp)
623   (= 0 (modulo barnum n)))
624 (export every-nth-bar-number-visible)
625
626 (define ((modulo-bar-number-visible n m) barnum mp)
627   (and (> barnum 1) (= m (modulo barnum n))))
628 (export modulo-bar-number-visible)
629
630 (define ((set-bar-number-visibility n) tr)
631   (let ((bn (ly:context-property tr 'currentBarNumber)))
632     (ly:context-set-property! tr 'barNumberVisibility
633                               (modulo-bar-number-visible n (modulo bn n)))))
634 (export set-bar-number-visibility)
635
636 (define-public (first-bar-number-invisible barnum mp)
637   (> barnum 1))
638
639 (define-public (first-bar-number-invisible-save-broken-bars barnum mp)
640   (or (> barnum 1)
641       (> (ly:moment-main-numerator mp) 0)))
642
643 (define-public (first-bar-number-invisible-and-no-parenthesized-bar-numbers barnum mp)
644   (and (> barnum 1)
645        (= (ly:moment-main-numerator mp) 0)))
646
647 (define-public (robust-bar-number-function barnum measure-pos alt-number context)
648   (define (get-number-and-power an pow)
649     (if (<= an alt-number)
650         (get-number-and-power (+ an (expt 26 (1+ pow))) (1+ pow))
651         (cons (+ alt-number (- (expt 26 pow) an)) (1- pow))))
652   (define (make-letter so-far an pow)
653     (if (< pow 0)
654         so-far
655         (let ((pos (modulo (quotient an (expt 26 pow)) 26)))
656           (make-letter (string-append so-far
657                                       (substring "abcdefghijklmnopqrstuvwxyz"
658                                                  pos
659                                                  (1+ pos)))
660                        an
661                        (1- pow)))))
662   (let* ((number-and-power (get-number-and-power 0 0))
663          (begin-measure (= 0 (ly:moment-main-numerator measure-pos)))
664          (maybe-open-parenthesis (if begin-measure "" "("))
665          (maybe-close-parenthesis (if begin-measure "" ")")))
666     (markup (string-append maybe-open-parenthesis
667                            (number->string barnum)
668                            (make-letter ""
669                                         (car number-and-power)
670                                         (cdr number-and-power))
671                            maybe-close-parenthesis))))
672
673 (define-public (all-bar-numbers-visible barnum mp) #t)
674
675
676 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
677 ;; percent repeat counters
678
679 (define ((every-nth-repeat-count-visible n) count context)
680   (= 0 (modulo count n)))
681 (export every-nth-repeat-count-visible)
682
683 (define-public (all-repeat-counts-visible count context) #t)