Hi, I more or less finished my music function. The result is added.I didn't really solved the issues I addressed to the list but avoided them. Now I store the default format for the rehearsal mark in my own function "format-mark-default" so that I can use it in my music function RehearsalMarkWithText and can change back to the default after printing with RehearsalMark.
I still think that it should be possible to use the calculated value for the alignment directly so help on that point is appreciated.
Greetings, Ed Op 01-04-11 13:57, Ed Gordijn schreef:
Hi,
I'am working on a music function that creates a rehearsal mark with
extra text added. It would be nice if the end result would be
something that would work as: \mark \default "text".
These are my first steps into the world of scheme, so I suppose that
some of my questions are rather basic.
The code below more or less works and shows what I am trying to
achieve but is not perfect at all! So, I need some help to solve the
drawbacks.
Here are the issues that need attention:
1 - I would like to use the current format for the rehearsal mark. Is
it possible to call/use the current Score.markFormatter and store the
mark in a markup-variable?
2 - Now I redefine the Score.markFormater with "/once /set" but
"/once" generates warnings. What is wrong?
3 - Is it possible to avoid the /set Score.markFormatter and use the
/mark /markup /center-at-mark directly?
I could use [1] to retrieve the current mark and should increment
the counter: Score.rehearsalMark = Score.rehearsalMark + 1
4 - Allignment is ok but the extend is not correct, see the allignment
of the first rehearsal mark that moves up because of the second mark.
\version "2.13.39"
% #(ly:set-option 'debug-skylines)
#(define (format-mark-default mark context)
" Set the format for the RehearsalMark.
From the manual: The file scm/translation-functions.scm contains the
definitions of format-mark-numbers
"
; Uncomment one of these options
; (format-mark-alphabet mark context)
; (format-mark-box-alphabet mark context)
; (format-mark-circle-alphabet mark context)
; (format-mark-letters mark context)
; (format-mark-box-letters mark context)
; (format-mark-circle-letters mark context)
; (format-mark-numbers mark context)
(format-mark-box-numbers mark context)
; (format-mark-circle-numbers mark context)
; (format-mark-barnumbers mark context)
; (format-mark-box-barnumbers mark context)
; (format-mark-circle-barnumbers mark context)
)
#(define-markup-command (center-at-mark layout props mark text x-align)
(markup? string? number?)
" Markup command used in RehearsalMarkWithText
Check the value of x-align and print the correct value when neccessary
"
(let* (
(txt (markup #:normal-text #:bold #:normalsize #:concat (" "
text)))
(txt-stencil (interpret-markup layout props txt))
(txt-x-ext (ly:stencil-extent txt-stencil X))
(txt-width (- (cdr txt-x-ext)(car txt-x-ext)))
(mrk-stencil (interpret-markup layout props mark))
(mrk-x-ext (ly:stencil-extent mrk-stencil X))
(mrk-width (- (cdr mrk-x-ext)(car mrk-x-ext)))
(x-align-new (- (/ mrk-width (+ txt-width mrk-width)) 1 ))
(x-dif (abs (- x-align-new x-align)))
(x-dif-markup (markup #:small (format "Change x-align to: ~5,2F"
x-align-new)))
)
(interpret-markup layout props
(if (< x-dif 0.02)
(markup #:concat (mark txt))
;else
(markup #:with-color blue #:box (#:column (x-dif-markup
#:with-color black #:concat (mark txt))))
)
)
))
RehearsalMarkWithText = #(define-music-function (parser location text x-align)
(string? number?)
" Calculate the value for x-align inside a markup script and hint the user for
the correct value.
This a a manual solution that (in my opinion) shouldn't be neccessary.
The format for the RehearsalMark is defined in the procedure:
format-mark-default
text this is a string that is addded with a dividing space to the
RehearsalMark
x-align this defines the alignment: -1 is left and +1 is right. Use -1 for
your first call
and the correct value will be printed near the RehearsalMark.
"
#{
% Redefine the Rehearsal mark
% \once does work but generates multiple warning.
\set Score.markFormatter = #(lambda (mark context)
(markup #:center-at-mark
(format-mark-default mark context)$text $x-align))
\once \override Score.RehearsalMark #'self-alignment-X = #$x-align
\mark \default
% Revert to the original format: This doesn't work in here!
% Thats why I defined \RehearsalMark which is used instead of \mark \default
%\set Score.markFormatter = #format-mark-box-numbers
%\unset Score.markFormatter
#})
% Use this function instead of \mark \default
RehearsalMark = { \set Score.markFormatter = #format-mark-default
\mark \default }
\score {
\relative c'' {
\clef "G"
\key c \major
\time 4/4
% Setting the startingpoint can be omitted as you would normaly start
at #1
\set Score.rehearsalMark = #10
\RehearsalMarkWithText #"Theme from 007" #-1 % This means left
aligned which is a good start
c1
e( f) \bar "||"
\RehearsalMarkWithText #"Theme from 007" #-0.83 % The calculated value
for x-align is applied
g( e) \break
\RehearsalMark % Revert to \mark \default
c1
e( f) \bar "||"
\RehearsalMark
g( e)
}
}
\layout{
indent = 0
ragged-right = ##t
\context {
\Staff
\remove "Time_signature_engraver" }
}
%%% end of example<<attachment: CenterMark.png>>
_______________________________________________ lilypond-user mailing list [email protected] http://lists.gnu.org/mailman/listinfo/lilypond-user
