Re: Request for a stencil alignment helper

2021-02-27 Thread Aaron Hill

On 2021-02-27 3:55 pm, Dimitris Marinakis wrote:

Is it possible to make a "stencil-wrapper" that will show the vertical
centre of a stencil and have an extending line of variable length 
(which of

course won't distort the spacing of the actual score)?


Yes, though much of the particular work depends on how you wish to use 
(and reuse) the functionality.  It is pretty easy to hack any stencil, 
especially with the use of grob-transformer.  There are many examples on 
the mailing list [1] as well as the LSR [2].


[1]: https://lists.gnu.org/archive/html/lilypond-user/
[2]: http://lsr.di.unimi.it/LSR/Search

While a little overengineered in places and certainly in need of 
refactoring, here is one way of doing things:



\version "2.22.0"

#(define ruler-thickness 0.075)

horizontal-ruler =
#(define-scheme-function
  (color alignment extension)
  ((color? red) number? number-pair?)
  (lambda (sten)
   (let* ((xext (ly:stencil-extent sten X))
  (yext (ly:stencil-extent sten Y))
  (y (interval-index yext alignment)))
(apply ly:stencil-in-color
 (ly:make-stencil
  (list 'draw-line ruler-thickness
(+ (car xext) (car extension)) y
(+ (cdr xext) (cdr extension)) y)
  empty-interval empty-interval)
 color

vertical-ruler =
#(define-scheme-function
  (color alignment extension)
  ((color? red) number? number-pair?)
  (lambda (sten)
   (let* ((xext (ly:stencil-extent sten X))
  (yext (ly:stencil-extent sten Y))
  (x (interval-index xext alignment)))
(apply ly:stencil-in-color
 (ly:make-stencil
  (list 'draw-line ruler-thickness
x (+ (car yext) (car extension))
x (+ (cdr yext) (cdr extension)))
  empty-interval empty-interval)
 color

combine-guides =
#(define-scheme-function
  (first-proc second-proc)
  (procedure? procedure?)
  (lambda (sten)
   (ly:stencil-add (first-proc sten) (second-proc sten

stencil-guide =
#(define-music-function
  (guide-proc grob-path)
  (procedure? key-list?)
  (define stencil-proc
   (grob-transformer 'stencil
(lambda (grob orig)
 (ly:stencil-outline
  (ly:stencil-add orig (guide-proc orig))
  orig
  #{ \override $grob-path . stencil = #stencil-proc #})

\fixed c' {
  \stencil-guide \combine-guides
\horizontal-ruler #cyan #DOWN #'(-1 . 1)
\vertical-ruler #'(0.9 0.6 0.3) #CENTER #'(-1 . 1)
Staff.TimeSignature
  \stencil-guide \horizontal-ruler #CENTER #'(-1 . 1) NoteHead
  \stencil-guide \vertical-ruler #green #LEFT #'(-1 . 1) Accidental
  bes4 a8 g 2
}



-- Aaron Hill

Request for a stencil alignment helper

2021-02-27 Thread Dimitris Marinakis
Is it possible to make a "stencil-wrapper" that will show the vertical
centre of a stencil and have an extending line of variable length (which of
course won't distort the spacing of the actual score)?
Something along the lines of the special-points stencil for slurs in the
shapeII code.
This would be extremely useful for alignment of stencils that are place
very far away but need to be aligned.

Dimitris


Re: Lilypond Substitution Function

2021-02-27 Thread Ken Ledeen
Jean,

Merci

This is a perfect solution, and, a clear explanation about why my solution
failed.

Thank you very much


Ken Ledeen

Mobile:617-817-3183
www.nevo.com
www.bitsbook.com
tiny.cc/KenLedeen
tiny.cc/KenLedeenAmazon

ᐧ

On Sat, Feb 27, 2021 at 10:43 AM Jean Abou Samra  wrote:

> Le 27/02/2021 à 02:16, Ken Ledeen a écrit :
>
> > I am struggling to understand the restrictions on substitution functions.
> >
> > For example:
> >
> > 1) can a function include "\score { ...}"  or can it only be invoked
> > INSIDE a \score?
> >
> > 2) is it possible to include \header { ...}  inside a substitution
> > function?  It fails when I try, but I don't understand why.
> >
> > I assume I am missing some basic concepts regarding their use.
> >
> > Thanks!
>
>
> Hello,
>
> Music functions must return music objects; \score blocks are not music
> but general containers that enclose music as well as other objects such
> as \header and \layout blocks.
>
> However, replacing define-music-function with define-scheme-function,
> you can define more versatile functions that are allowed to return any
> kind of object for interpretation. For example:
>
> \version "2.23.1"
>
> failingFunction =
> #(define-music-function () ()
> #{
>   \score {
> \header {
>   piece = "Piece A"
> }
> { c' }
>   }
> #})
>
> % \failingFunction
>
> succeedingFunction =
> #(define-scheme-function () ()
> #{
>   \score {
> \header {
>   piece = "Piece B"
> }
> { c' }
>   }
> #})
>
> \succeedingFunction
>
>
> Hope that helps,
> Jean
>
>


Re: Lilypond Substitution Function

2021-02-27 Thread Jean Abou Samra

Le 27/02/2021 à 02:16, Ken Ledeen a écrit :


I am struggling to understand the restrictions on substitution functions.

For example:

1) can a function include "\score { ...}"  or can it only be invoked 
INSIDE a \score?


2) is it possible to include \header { ...}  inside a substitution 
function?  It fails when I try, but I don't understand why.


I assume I am missing some basic concepts regarding their use.

Thanks!



Hello,

Music functions must return music objects; \score blocks are not music 
but general containers that enclose music as well as other objects such 
as \header and \layout blocks.


However, replacing define-music-function with define-scheme-function, 
you can define more versatile functions that are allowed to return any 
kind of object for interpretation. For example:


\version "2.23.1"

failingFunction =
#(define-music-function () ()
   #{
 \score {
   \header {
 piece = "Piece A"
   }
   { c' }
 }
   #})

% \failingFunction

succeedingFunction =
#(define-scheme-function () ()
   #{
 \score {
   \header {
 piece = "Piece B"
   }
   { c' }
 }
   #})

\succeedingFunction


Hope that helps,
Jean




Lilypond Substitution Function

2021-02-27 Thread Ken Ledeen
I am struggling to understand the restrictions on substitution functions.

For example:

1) can a function include "\score { ...}"  or can it only be invoked INSIDE
a \score?

2) is it possible to include \header { ...}  inside a substitution
function?  It fails when I try, but I don't understand why.

I assume I am missing some basic concepts regarding their use.

Thanks!


Ken Ledeen

Mobile:617-817-3183
www.nevo.com
www.bitsbook.com
tiny.cc/KenLedeen
tiny.cc/KenLedeenAmazon
ᐧ


Re: Explicit placement of rests in a percussion staff

2021-02-27 Thread David Kastrup
Aaron Hill  writes:

> On 2021-02-27 3:10 am, David Kastrup wrote:
>> [...] Which begs the
>> question whether it would not make sense to let Rest_engraver look at
>> drum-type in the same manner it looks at pitch for the sake of
>> potentially resolving the drum-type to staff-position mapping.
>
> I'm not a percussionist; but it would seem reasonable for "sn \rest"
> to work the same as "fis \rest".
>
> I take it parser.yy would need updating to something like this:
>
> 
> simple_element:
>   DRUM_PITCH optional_notemode_duration optional_rest {
> Music *n = 0;
> if (scm_is_true ($3))
>   n = MY_MAKE_MUSIC ("RestEvent", @$);
> else
>   n = MY_MAKE_MUSIC ("NoteEvent", @$);
> set_property (n, "duration", $2);
> set_property (n, "drum-type", $1);
>
> $$ = n->unprotect ();
>   }
> 

Yes, something like that.  The main question is just to what degree
factoring out code from Drum_notes_engraver makes sense or whether one
would just hard-code inline the more limited extraction of just the
position.

-- 
David Kastrup



Re: Explicit placement of rests in a percussion staff

2021-02-27 Thread Aaron Hill

On 2021-02-27 3:10 am, David Kastrup wrote:

[...] Which begs the
question whether it would not make sense to let Rest_engraver look at
drum-type in the same manner it looks at pitch for the sake of
potentially resolving the drum-type to staff-position mapping.


I'm not a percussionist; but it would seem reasonable for "sn \rest" to 
work the same as "fis \rest".


I take it parser.yy would need updating to something like this:


simple_element:
  DRUM_PITCH optional_notemode_duration optional_rest {
Music *n = 0;
if (scm_is_true ($3))
  n = MY_MAKE_MUSIC ("RestEvent", @$);
else
  n = MY_MAKE_MUSIC ("NoteEvent", @$);
set_property (n, "duration", $2);
set_property (n, "drum-type", $1);

$$ = n->unprotect ();
  }



-- Aaron Hill



Re: Explicit placement of rests in a percussion staff

2021-02-27 Thread David Kastrup
Lukas-Fabian Moser  writes:

> Hi Aaron,
>
>> \tweak form is a little shorter, although you could bake this into a
>> function if you needed to use this a lot:
>>
>> 
>> \version "2.22.0"
>>
>> "\\@" =
>> #(define-music-function
>>   (staff-position music)
>>   (integer? ly:music?)
>>   #{ \tweak staff-position #staff-position #music #})
>>
>> \new DrumStaff \drummode { bd4 sn \@4 r4 r8 \@-4 r }
>> 
>>
>> Not sure if \@ is a good name for this, but it is conveniently short
>> like \=.
>
> I think the naming is a stroke of genius :-). But perhaps
> surprisingly, David Kastrup's \etc shorthand is even robust enough to
> allow for:
>
> \version "2.22.0"
>
> "\\@" = \tweak staff-position \etc
>
> \new DrumStaff \drummode { bd4 sn \@2 r4 r8 \@-4 r }

Well, I am not sure whether the drum type is not typically a more
appropriate instruction than the numeric height: I should think that if
you, say, change the notation convention to one using different staff
positions, you'd want the rests to move along.

Now

void
Drum_notes_engraver::process_music ()
{
  if (events_.empty ())
return;

  SCM tab = get_property (this, "drumStyleTable");
  for (vsize i = 0; i < events_.size (); i++)
{
  Stream_event *ev = events_[i];
  Item *note = make_item ("NoteHead", ev->self_scm ());

  SCM drum_type = get_property (ev, "drum-type");

  SCM defn = SCM_EOL;

  if (from_scm (scm_hash_table_p (tab)))
defn = scm_hashq_ref (tab, drum_type, SCM_EOL);

  if (scm_is_pair (defn))
{
  SCM pos = scm_caddr (defn);
  SCM style = scm_car (defn);
  SCM script = scm_cadr (defn);

  if (scm_is_integer (pos))
set_property (note, "staff-position", pos);
  if (scm_is_symbol (style))
set_property (note, "style", style);

  if (scm_is_string (script))
{
  Item *p = make_item ("Script", ev->self_scm ());
  make_script_from_event (p, context (), script,
  0);

  p->set_y_parent (note);
  Side_position_interface::add_support (p, note);
  scripts_.push_back (p);
}
}
}
}

looks like the logic could easily be put in Scheme, but the lookup of
drumStyleTable would have to happen at engraving time.  Which begs the
question whether it would not make sense to let Rest_engraver look at
drum-type in the same manner it looks at pitch for the sake of
potentially resolving the drum-type to staff-position mapping.

Thoughts?

-- 
David Kastrup



Re: Explicit placement of rests in a percussion staff

2021-02-27 Thread Lukas-Fabian Moser

Hi Aaron,

\tweak form is a little shorter, although you could bake this into a 
function if you needed to use this a lot:



\version "2.22.0"

"\\@" =
#(define-music-function
  (staff-position music)
  (integer? ly:music?)
  #{ \tweak staff-position #staff-position #music #})

\new DrumStaff \drummode { bd4 sn \@4 r4 r8 \@-4 r }


Not sure if \@ is a good name for this, but it is conveniently short 
like \=.


I think the naming is a stroke of genius :-). But perhaps surprisingly, 
David Kastrup's \etc shorthand is even robust enough to allow for:


\version "2.22.0"

"\\@" = \tweak staff-position \etc

\new DrumStaff \drummode { bd4 sn \@2 r4 r8 \@-4 r }

Lukas




Re: Explicit placement of rests in a percussion staff

2021-02-27 Thread Aaron Hill

On 2021-02-27 1:22 am, Thomas Morley wrote:

I'd use an override for 'staff-position:
\once \override Rest.staff-position = -4
looks ok here.


\tweak form is a little shorter, although you could bake this into a 
function if you needed to use this a lot:



\version "2.22.0"

"\\@" =
#(define-music-function
  (staff-position music)
  (integer? ly:music?)
  #{ \tweak staff-position #staff-position #music #})

\new DrumStaff \drummode { bd4 sn \@4 r4 r8 \@-4 r }


Not sure if \@ is a good name for this, but it is conveniently short 
like \=.



-- Aaron Hill

Re: Explicit placement of rests in a percussion staff

2021-02-27 Thread Thomas Morley
Am Sa., 27. Feb. 2021 um 00:05 Uhr schrieb Calvin Ransom
:
>
> I copied the wrong snippet version, my apologies.
> **begining of snippet**
> \score{
>   \new DrumStaff
> \drummode {
>   bd4\rest
> }
> }
> **end of snippet**
>
> On Sat, Feb 27, 2021 at 3:03 PM Calvin Ransom  wrote:
>>
>> Good afternoon everyone,
>> I am trying to move the vertical position of a rest in some percussion music 
>> I am typesetting for my teacher.
>> I am using v. 2.22.0
>> In the manual it says 'To explicitly specify a rest’s vertical position, 
>> write a note followed by \rest."
>> When I use the following snippet it does not work and gives me an error 
>> message:
>> *start of snippet*
>> \score{
>>   \new DrumStaff
>> \drummode {
>>   bd4
>> }
>> }
>> %end of snippet%
>> with this error message:
>> 'error: syntax error, unexpected \rest'

I'd use an override for 'staff-position:
\once \override Rest.staff-position = -4
looks ok here.

Cheers,
  Harm



Re: Explicit placement of rests in a percussion staff

2021-02-27 Thread Lukas-Fabian Moser




   \once \override Rest.Y-offset = #2
   r


Or, saving a few keystrokes:

\tweak Y-offset 2 r4

Lukas