Get Width and Height of markup

2024-06-04 Thread William Rehwinkel via LilyPond user discussion

Dear list,

In the following example, I am wondering how I can find the measurements 
of the dimensions, specifically the width, of a markup object. This is 
so I can automatically indent the first line by the length of the 
instrumentName.


Thanks,
-William

% 
\version "2.25.7"

pref = \markup { piece title here }

% How can I determine this from the width of \pref
pref_width = #(ly:inch 1)

extra_pad = #(ly:cm 0.5)

\score {
  \new Staff \with {instrumentName = \pref } {c'1 \break c'1 }
}

\layout {
  #(define indent (+ pref_width extra_pad))
}
% 

--
William Rehwinkel (any pronouns)
Juilliard School '26 - Oberlin Conservatory '24
will...@williamrehwinkel.net - https://williamrehwinkel.net
PGP Public Key: https://ftp.williamrehwinkel.net/pubkey.txt


OpenPGP_signature.asc
Description: OpenPGP digital signature


Re: how to draw lines independent from the notes

2024-06-04 Thread Aaron Hill

On 2024-06-04 9:40 am, Paolo Prete wrote:

That's impressive, thanks!!

I encourage the maintainers of the code to replace the triangle shape 
in
native LilyPond with your code, given that the actual shape is pretty 
weird

and the gap with the segment is not nice to look at...



I had hoped to keep this private, but now I guess I have to share with 
the class.


My apologies for anyone who dares to read through the craziness.  It was 
never really intended to be shared broadly with the mailing list.  The 
PDFs will make absolutely no sense on their own.  The LY files are a 
mixture of code and comments, documenting my workflow.  The idea was to 
solve Paolo's problem but do it in a step-by-step way.  It gets pretty 
rambling here and there, so again I apologize for anyone who decides to 
dive in and look at it.  Ultimately, each stage of experimentation is 
there.  I did start to move faster in the Scheme approach, so there 
might be fewer stopping points.  I had to remember to work in smaller 
chunks to be able to document things.


The final iteration of code in draw-arrow-2.ly is pretty much the 
"solution" to the problem.


All that said, it was a pretty fun activity.  As a developer, we rarely 
show the dirty bits of the process.  We like to wait until everything is 
neatly wrapped in a bow and glitter, mainly to hide all our mistakes, 
wrong paths taken, etc.  :)



P.S. There might be one or two potentially disparaging comments aimed at 
LilyPond.  I must also apologize for them.  Hopefully, no LilyPond devs 
take them too harshly.  Again, this code was never really intended for 
public reveal.  I would have cleaned up such comments and written them 
with more tact if given the chance.


-- Aaron Hill\version "2.25.13"

%% First: See what Lilypond has built-in that we can leverage.
%%
%% \arrow-head is almost useable, but its shape options are not great.
%% \draw-line looks perfectly useable for the main part of our arrow.
%% \path is somewhat a brute-force tool, so let's call it last resort.
%% \polygon is better than \path in terms of usability.
%% \postscript is even worse than \path; too much power, little gain.
%% Ooh, \triangle.  That's almost exactly what we need.
%%
%% Okay, I think we have an initial plan.  Use \draw-line for the main
%% body of the arrow.  \triangle for the ends.  We may need to \scale
%% the arrow heads to lengthen them, unless we are okay with perfect
%% equilateral triangles.  Hmm, that could/should be an adjustable
%% parameter.

%% Let's try putting things together manually and see what is possible.

\paper { #(set-paper-size "a7") tagline = ##f }

\markup {
  \concat {
\triangle ##f % Keeping one side unfilled to tell them apart.
\draw-line #'(5 . 0)
\triangle ##t
  }
}

%% Interesting result.  At least we know the default thickness is the
%% same between the line and triangle (unfilled).  We need to rotate
%% those triangles and keep them aligned with the line.
%%
%% That's curious.  The \rotate command is organized in the text align-
%% ment section.  Does that mean it might not be suited for shapes?
%% Spidey-sense™ tingling.
%%
%% Maths: How far do we need to spin this triangle?  The right side of
%% the unfilled triangle is sitting 60 degrees up from the ground.
%% That means it is falling 30 degrees away from up-right.  We need to
%% spin it 30 degrees clockwise.  The example in the documentation
%% suggests rotations are counter-clockwise.  They also mention the
%% center of the stencil is the rotation point.

\markup {
  \concat {
\rotate #-30 \triangle ##f
\draw-line #'(5 . 0)
\triangle ##t
  }
}

%% Okay.  The documentation lied.  That was not from the center of the
%% object.  But I gather the center is being calculated from the bounds
%% of the stencil, which are rectangular.  We may need to provide our
%% own bounds.  On a positive note, we got the triangle pointing in the
%% right direction.  Let's celebrate and fix the filled triangle.

\markup {
  \concat {
\rotate #-30 \triangle ##f
\draw-line #'(5 . 0)
\rotate #30 \triangle ##t
  }
}

%% More maths: We know an equilateral sits perfectly in a circle.  And
%% that circle sits perfectly in a square.  The coordinates for the
%% three points of a triangle can be fairly easily calculated.  Let's
%% go with the orientation based on the \triangle command.
%%
%% Web search... height of triangle is root(3)/2 times its base.
%% Oh, dear.  The documentation does not specify how wide the shape
%% is expected to be rendered.  It also seems to change size based on
%% the extroversion parameter, which is used to adjust whether the ink
%% should favor being outside the bounds of the shape or to sit inside
%% the bounds.  Do we dig into the source code, or should we just play
%% around and gather empirical data?  I have a hunch the width is one.

\markup {
  \combine
\triangle ##f
\lower #0.2 \draw-line #'(1 . 0)
}

%% Drat.  Not one.

\markup {
  \hspace #3
  \combine

manual vertical alternative marks

2024-06-04 Thread Paul Scott
I have tried several variations of (volta #f) and end-repeat with the 
following code:


\version "2.25.16"

xDS = \markup{\fontsize #4 \line{D.S. al Fine }}
xFine = \markup{\fontsize #4 Fine}

music = \fixed c' {
  g1
  \segnoMark 1
  f 4 g a b
  \set Score.repeatCommands = #`((volta ,xDS) )
  g4 a g a
  \set Score.repeatCommands = #`((volta #f) (volta ,xFine))
  \bar "||"
  b1
  \set Score.repeatCommands = #'((volta #f))
  \bar "|."
}

\score{ \music }
\score{ \unfoldRepeats \music }

How do I get the ending vertical line at the end of the first alternative?

This code also demonstrates the desirablity of getting the repeat segno 
structure to work for more cases.


TIA,

Paul





Re: how to draw lines independent from the notes

2024-06-04 Thread Paolo Prete
That's impressive, thanks!!

I encourage the maintainers of the code to replace the triangle shape in
native LilyPond with your code, given that the actual shape is pretty weird
and the gap with the segment is not nice to look at...

On Tue, Jun 4, 2024 at 2:07 PM Aaron Hill  wrote:

> On 2024-06-03 10:56 am, Paolo Prete wrote:
> > Thanks Aaron, see the attached pdf as an example:
>
>
> I may have gone too far with this.  But I hope it helps.  I'm replying
> privately as I am not sure how best to present the material to the wider
> audience.  Basically, if you read each LY source file, it is a mixture
> of code and comments.  It is flow-of-conscience, as such it can appear
> rambling at times.  I wanted to leave in the some of the dirty bits,
> which you might find interesting.  The hope was to reveal a little of my
> workflow.  That way I am not just giving you the final answer but
> showing the steps along the way.
>
> Attached are two approaches.  The first was done using the built-in
> markup commands as much as possible.  It ran into several issues, so I
> quickly turned to the second approach to write everything from scratch
> in Scheme as a markup command.  By comparing the code from iteration to
> iteration, you should be able to see how the code evolves.
>
>
> P.S. I do not know how much time I have, so I might not be able to
> directly answer questions about the code.  The final iteration in
> draw-arrow-2 should be complete enough for production work if you just
> want to mess about with it.
>
>
> -- Aaron Hill


Re: how to draw lines independent from the notes

2024-06-04 Thread Silvain Dupertuis

To create a drawing in PostScript format,
one option would be to create the drawing with Inkscape and save as PostScript 
(*.ps).

Something to test... Inkscape can open and save Postscript format.
Then one can open the file with a text editor to copy and paste the relevant shape into a 
Lilypond file.


Le 03.06.24 à 19:56, Paolo Prete a écrit :

Thanks Aaron, see the attached pdf as an example:

On Mon, Jun 3, 2024 at 7:49 PM Aaron Hill  wrote:

On 2024-06-03 10:39 am, Paolo Prete wrote:
> On Mon, Jun 3, 2024 at 7:33 PM Aaron Hill 
> wrote:
>
>  so feel free to
>> reach out if this is not your area of expertise.
>>
>
> That's what I just did ;-)
>
> cheers


I must admit I have not followed this thread super closely. Do you have
a drawing of the type of arrow head you are interesting in.  I have time
today to futz around, so I can see about putting together something for
you, hopefully more in the style of "teaching a man to fish" rather than
just "giving a man a fish".


-- Aaron Hill



--
Silvain Dupertuis
Route de Lausanne 335
1293 Bellevue (Switzerland)
tél. +41-(0)22-774.20.67
portable +41-(0)79-604.87.52
web: silvain-dupertuis.org 

Re: gvim point and click

2024-06-04 Thread Stefan Thomas
Dear Timothy,
for all, who are interested in, I finally got it to work (with Your help
and also with chatgpt).
I wrote in okular/settings/configure okular/edior:

> custom editor  gvim --servername GVIM --remote-send ":e %f:call
> SetCursorAdjusted(%l,%c)"

And I wrote in .vimrc

function! SetCursorAdjusted(line, col)
  " Adjust line number down by 1
  let lnum = a:line - 1
  " Use the cursor function to set the cursor position
  call cursor(lnum, a:col)
endfunction

Now I start gvim with
gvim --servername GVIM
and everything works fine!

Am Mo., 3. Juni 2024 um 10:35 Uhr schrieb Timothy Lanfear <
timo...@lanfear.me>:

> Maybe you could try the call cursor command
>
> vim +"call cursor(%l,%c)" %f
>
> As in David' remarks, you may need to adjust the quoting to get the
> desired result.
>
> vim +"call cursor(5,3)" file.ly
>
> works on the shell command line.
> On 03/06/2024 06:24, Stefan Thomas wrote:
>
> Dear David,
> thanks for Your reply.
> Unfortunately, none of your suggestions have brought the desired result!
> Best,
> Stefan
>
> Am Mo., 3. Juni 2024 um 03:19 Uhr schrieb David Wright <
> lily...@lionunicorn.co.uk>:
>
>> On Sun 02 Jun 2024 at 16:10:56 (+0200), Stefan Thomas wrote:
>> > again, I'm trying to activate point and click in gvim. I made a little
>> > success:
>> > I wrote in the editor options of okular:
>> > gvim --remote-silent +%l %f +normal! %c
>> > When I click on a note, the right document is opened and the cursor is
>> > placed at the correct line, but not at the correct note in the lilypond
>> > file.
>> > What can I do?
>>
>> Perhaps the command you're trying to invoke is, for example:
>>
>>   gvim --remote-silent +:123:norm45l path-to-file
>>
>> using literal constants for line number 123 and column 45.
>>
>> Naively, that would mean okular would have something like:
>>
>>   gvim --remote-silent +:%l:norm%cl %f
>>
>> but, not being familiar with okular, I can't tell how it would
>> handle %cl (where l means move to the right by %c columns) and
>> whether it would need any quoting. For example,
>>
>>   gvim --remote-silent '+:%l:norm%c l' %f
>>
>> might work better.
>>
>> Cheers,
>> David.
>>
> --
> Timothy Lanfear, Bristol, UK.
>
>