Hi,

I decided to split the problem in pieces, starting with the allignment.

I have two options. The first option (IIa in the script) is how I would do this as I would do this writing a score, setting an override to adjust the allignment. This works fine but I don't know how I could calculate the override value in this way. Is It possible?

Option IIb is something that I got from a snippet about centering Dynamics. It works almost, but doesn't behave as I would expect when the mark is alligned on the clef. Can that be solved?

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.

Any advise?

Greetings, Ed

%%% Example

\version "2.13.39"

#(define-markup-command (center-at-mark layout props mark text)
(markup? string?)
  "x-align on the center of the rehaersal mark"
  (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)))
             )

             (interpret-markup layout props
               (markup #:hspace 0 #:translate (cons txt-width 0)
                       #:concat (mark txt)))
  ))


BoxMarkText = #(define-music-function (parser location AddText) (string?)
"Create a Rehearsal mark and add the string AddText"
#{
    % Redefine the Rehearsal mark
    % \once does work but generates multiple warning.
    \once \set Score.markFormatter = #(lambda (mark context)
                                      (markup #:center-at-mark
(format-mark-box-numbers mark context)$AddText))
    \mark \default
#})


\score {
    \relative c'' {

        \clef "G"
        \key c \major
        \time 4/4

        % Rehearsal mark
        \set Score.rehearsalMark = #10
        \set Score.markFormatter = #format-mark-box-numbers
        \mark \default
        c1 \bar "||"

        % Add text to the next rehearsal mark
        \BoxMarkText #"Theme from 007"
        e( f)

        % Revert to default mark
        \mark \default
        g( e) \break
   }
}

\layout{
    indent = 0
    ragged-right = ##t
}
%%% end of example




\version "2.13.54"
#(ly:set-option 'debug-skylines)

BoxMarkTextIIa = #(define-music-function (parser location MarkText AddText 
x-align) (string? string? number?)
#{
    \once \override Score.RehearsalMark #'self-alignment-X = #$x-align
    \mark \markup { \bold { \box $MarkText \normalsize $AddText }}
#})

#(define-markup-command (center-at-markIIb layout props mark text) (string? 
string?)
"x-align on the center of the rehaersal mark"
    (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 (markup #:normal-text #:box #:bold mark))

        (mrk-stencil (interpret-markup layout props mrk))
        (mrk-x-ext (ly:stencil-extent mrk-stencil X))
        (mrk-width (- (cdr mrk-x-ext)(car mrk-x-ext)))

        (x-align (- (/ mrk-width (+ txt-width mrk-width)) 1 ))
    )

    (interpret-markup layout props
        (markup #:halign x-align #:concat (mrk txt)))
    ))

BoxMarkTextIIb = #(define-music-function (parser location MarkText AddText) 
(string? string?)
#{
    % Alternative using \halign within the markup
    % \halign only has effect if X-offset is set to #0
    \once \override Score.RehearsalMark #'X-offset = #0
    \mark \markup { \center-at-markIIb #$MarkText #$AddText }
#})


\score {
    \relative c'' {

        \clef "G"
        \key c \major
        \time 4/4

    % Option IIa, an override before the markup works as expected
    % I could calulate the value for x-align with a markup script but how do I 
get the resul
    % in the override?
        \BoxMarkTextIIa #"10" #"Theme from 007" #-0.83
        c1 \bar "||"
        e( f) \BoxMarkTextIIa #"11" #"Theme from 007" #-0.83
        g( e) \break

    % Option IIb, /halign inside the markup.
    % Makes it possible to calculate the value for x-align inside a markup 
script.
    % But, setting X-offset to "0" leads to misalignment on the clef. See mark 
12.
        \BoxMarkTextIIb #"12" #"Theme from 007"
        c1 \bar "||"
        e( f) \BoxMarkTextIIb #"13" #"Theme from 007"
        g( e)
  }
}

\layout{
    indent = 0
    ragged-right = ##t

    \context {
        \Staff
        \remove "Time_signature_engraver" }
}
%%% end of example

Attachment: CenterMark.pdf
Description: Adobe PDF document

_______________________________________________
lilypond-user mailing list
lilypond-user@gnu.org
http://lists.gnu.org/mailman/listinfo/lilypond-user

Reply via email to