Re: Changing volta number text

2021-05-14 Thread Aaron Hill

On 2021-05-14 6:40 pm, Ralph Palmer wrote:
Excellent! Thank you, Aaron. I wish I could understand what your 
function

does - how it works.


The technique involves querying the current Score.repeatCommands and 
replacing any existing (volta "...") command with the user-provided 
version.  This preserves the other repeat commands such as (end-repeat) 
and (volta #f).


Here is a minorly-refactored version with some documentation, comments, 
and a helpful usage warning:



\version "2.22.0"
\include "english.ly"

changeVoltaText =
#(define-music-function
  (text) (markup?)
  (_i "Replaces the volta text within the currently-set 
@code{repeatCommands}.")


  (define (volta-text? cmd)
   ;; Look for the (volta "...") pattern.
   (and (pair? cmd)
(eq? 'volta (car cmd))
(markup? (cadr cmd
  (define (replacer cmd)
   (if (volta-text? cmd) `(volta ,text) cmd))
  (define (proc ctxt)
   (let ((cmds (ly:context-property ctxt 'repeatCommands '(
(if (any volta-text? cmds)
 (ly:context-set-property! ctxt 'repeatCommands (map replacer cmds))
 (ly:input-warning (*location*) "No volta text was replaced."

  #{ \context Score \applyContext #proc #})

test = {
  \time 3/4
  \repeat volta 3
  {
a'4 b' c' |
\changeVoltaText "dud"
#(ly:expect-warning "No volta text was replaced.")
b'4 c' d' |
  }
  \alternative {
{
  \changeVoltaText "1., 3."
  e'4 f' g' |
}
{
  d'4 c' b' |
}
{
  \changeVoltaText \markup \with-color #red "4."
  g'4 a' b' |
}
  }
  c'1
}

\score {
  \test
}




-- Aaron Hill

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: Changing volta number text

2021-05-14 Thread Ralph Palmer
On Fri, May 14, 2021 at 5:13 PM Aaron Hill  wrote:

> On 2021-05-14 2:47 pm, Ralph Palmer wrote:
> > I *did* find a thread in the archive :
> > change of volta number
> > which has gotten me close, but has an extra end-repeat before the first
> > volta ending bracket. I'm also not sure the format is the most recent.
>
> How about this?
>
> 
> \version "2.22.0"
> \include "english.ly"
>
> changeVoltaText =
> #(define-music-function
>(text) (markup?)
>(define (is-volta-text? cmd)
> (and (pair? cmd) (eq? 'volta (car cmd)) (markup? (cadr cmd
>(define (replace-volta-text cmd)
> (if (is-volta-text? cmd) `(volta ,text) cmd))
>(define (proc ctxt)
> (let ((cmds (ly:context-property ctxt 'repeatCommands)))
>  (set! cmds (map replace-volta-text cmds))
>  (ly:context-set-property! ctxt 'repeatCommands cmds)))
>#{ \context Score \applyContext #proc #} )
>
> test = {
>\time 3/4
>\repeat volta 3
>{
>  a'4 b' c' |
>  b'4 c' d' |
>}
>\alternative {
>  {
>\changeVoltaText "1., 3."
>e'4 f' g' |
>  }
>  {
>d'4 c' b' |
>  }
>  {
>\changeVoltaText \markup \with-color #red "4."
>g'4 a' b' |
>  }
>}
>c'1
> }
>
> \score {
>\test
> }
> 
>
> NOTE: I'm using \markup in the final alternative just to demonstrate
> that it works.
>
>
> -- Aaron Hill
>

Excellent! Thank you, Aaron. I wish I could understand what your function
does - how it works.

Would it make sense to add this to either the Lilypond Snippet Repository
or the documentation or both?

All the best,

Ralph

-- 
Ralph Palmer
Seattle
USA
(he, him, his)
palmer.r.vio...@gmail.com
___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: Changing volta number text

2021-05-14 Thread Peter Chubb
> "Ralph" == Ralph Palmer  writes:

Ralph> I've gone slightly crazy on a couple of occasions, trying to
Ralph> figure out how to change a volta number, either to a different
Ralph> number(s) or to text.

You need to handle the whole thing yourself, rather than using the
\alternative construct,

Something like this:


\version "2.22.0"

test = {
  \time 3/4
  \repeat volta 3
  {
a'4 b' c' |
b'4 c' d' |
  }
  \set Score.repeatCommands = #'((volta "1., 3." ))
  e'4 f' g' |
  d'4 c' b' |
  \set Score.repeatCommands = #'((volta #f) (volta "2.") end-repeat)
  r2.
  \set Score.repeatCommands = #'((volta #f) end-repeat (volta "4."))
  g'4 a' b' |
  \set Score.repeatCommands = #'((volta #f))
  c'2.
}

\score {
  \test
}

-- 
Dr Peter Chubbhttps://trustworthy.systems/
Trustworthy Systems GroupCSE, UNSW

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: Changing volta number text

2021-05-14 Thread Peter Chubb
> "Peter" == Peter Chubb  writes:
> "Ralph" == Ralph Palmer  writes:
Ralph> I've gone slightly crazy on a couple of occasions, trying to
Ralph> figure out how to change a volta number, either to a different
Ralph> number(s) or to text.

Peter> You need to handle the whole thing yourself, rather than using
Peter> the \alternative construct,

I should mention, if you do this, you'll need to do something
different for Midi output.  See e.g., the snippet at
https://lsr.di.unimi.it/LSR/Item?id=915

Peter C

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Re: Changing volta number text

2021-05-14 Thread Aaron Hill

On 2021-05-14 2:47 pm, Ralph Palmer wrote:

I *did* find a thread in the archive :
change of volta number
which has gotten me close, but has an extra end-repeat before the first
volta ending bracket. I'm also not sure the format is the most recent.


How about this?


\version "2.22.0"
\include "english.ly"

changeVoltaText =
#(define-music-function
  (text) (markup?)
  (define (is-volta-text? cmd)
   (and (pair? cmd) (eq? 'volta (car cmd)) (markup? (cadr cmd
  (define (replace-volta-text cmd)
   (if (is-volta-text? cmd) `(volta ,text) cmd))
  (define (proc ctxt)
   (let ((cmds (ly:context-property ctxt 'repeatCommands)))
(set! cmds (map replace-volta-text cmds))
(ly:context-set-property! ctxt 'repeatCommands cmds)))
  #{ \context Score \applyContext #proc #} )

test = {
  \time 3/4
  \repeat volta 3
  {
a'4 b' c' |
b'4 c' d' |
  }
  \alternative {
{
  \changeVoltaText "1., 3."
  e'4 f' g' |
}
{
  d'4 c' b' |
}
{
  \changeVoltaText \markup \with-color #red "4."
  g'4 a' b' |
}
  }
  c'1
}

\score {
  \test
}


NOTE: I'm using \markup in the final alternative just to demonstrate 
that it works.



-- Aaron Hill

___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond


Changing volta number text

2021-05-14 Thread Ralph Palmer
Greetings -

I appreciate the help this list has been over many years.

I've gone slightly crazy on a couple of occasions, trying to figure out how
to change a volta number, either to a different number(s) or to text.

It looked like a snippet in the LSR :
Volta text markup using repeatCommands [0.10714]
was going to help, but it just confused me more.

I *did* find a thread in the archive :
change of volta number
which has gotten me close, but has an extra end-repeat before the first
volta ending bracket. I'm also not sure the format is the most recent.

I think it would be helpful to either have a snippet that shows how to
change a "normal" volta number setup (i.e., change the numbers and/or add
text), or to add something to the documentation.

Here's the best I could come up with. I'd appreciate some help getting rid
of that initial repeat sign.

%%

\version "2.22.0"
\include "english.ly"

test = {
  \time 3/4
  \repeat volta 3
  {
a'4 b' c' |
b'4 c' d' |
  }
  \alternative {
{
  \set Score.repeatCommands = #'(end-repeat (volta "1., 3." ))
  e'4 f' g' |
}
{
  d'4 c' b' |
}
{
  \set Score.repeatCommands = #'(end-repeat (volta "4."))
  g'4 a' b' |
}
  }
  c'1
}

\score {
  \test
}

%%%

Thanks for your help,

Ralph

-- 
Ralph Palmer
Seattle
USA
(he, him, his)
palmer.r.vio...@gmail.com
___
bug-lilypond mailing list
bug-lilypond@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-lilypond