Re: SVG export - how might you add classes for all graphical objects?

2021-06-29 Thread Matt Hood
That's quite handy to know, thanks for your response Carl.

Cheers,
Matt.

On Wed, Jun 30, 2021 at 2:35 AM Carl Sorensen  wrote:
>
>
>
> On 6/29/21, 2:43 AM, "lilypond-user on behalf of Matt Hood" 
>  mattho...@gmail.com> wrote:
>
> Hi everyone,
>
> I'm working with lilypond output in the browser, using its SVG export
> function. Lilypond permits attaching attributes to particular kinds of
> grobs, e.g.:
>
> {
>   \override NoteHead.output-attributes =
>   #'((class . "NoteHead"))
>   c
> }
>
> The above will cause all NoteHead objects to have the following SVG:
>
> 
>   ...NoteHead grob SVG elements...
> 
>
> My question is: how can I make it so that all graphical objects have
> their name in the class attribute?
>
> I've tried using the following scheme function:
>
> #(define (add-class grob grob-origin context)
>  (let (name (cdr (assoc 'name
> (ly:grob-property grob 'meta
> (set! (ly:grob-property grob 'output-attributes) '((class
> . name)
>
> This successfully (I believe) extracts the correct name, and assigns
> it to the output-attributes field. As per the instructions in the
> lilypond documentation, I then attempted to use \applyOutput Score
> #add-class to apply this function to all graphical objects, but it
> didn't supply all of the required objects. My attempted code is below:
>
> \applyOutput Score #add-class
> \score {
> \new RhythmicStaff {
>   c'2 c'16 c' c' c' \tuplet 5/4 { c'16 c' c' c' c' }
> }
> }
>
> If I add a print call to the add-class function, I can see that it was
> called for the objects with the following names from which crucial
> objects such as NoteHead are missing:
>
> NonMusicalPaperColumn
> PaperColumn
> Clef
> TimeSignature
> LedgerLineSpanner
> StaffSymbol
> VerticalAxisGroup
> SystemStartBar
> SpacingSpanner
> VerticalAlignment
> StaffSpacing
> BreakAlignment
> LeftEdge
> BreakAlignGroup
> BreakAlignGroup
> BreakAlignGroup
>
> Matt, I'm not an expert on \applyOutput, but it appears to me these are all 
> grobs created by engravers that live in the Score context by default.
>
> You may wish to try \applyOutput to Staff and Voice as well.
>
> Haven't tried it, and don't know if it will work, but it's an idea.
>
> HTH,
>
> Carl
>
>



Fwd: SVG export - how might you add classes for all graphical objects?

2021-06-29 Thread Matt Hood
On Wed, Jun 30, 2021 at 3:32 AM Aaron Hill  wrote:
>
> On 2021-06-29 9:43 am, Jean Abou Samra wrote:
> > However, this problem can be solved by writing
> > an engraver (those are the powerful tools that
> > \applyOutput uses under the hood).
> >
> > \version "2.22.0"
> >
> > \layout {
> >   \context {
> > \Score
> > \consists
> >   #(lambda (context)
> >  (make-engraver
> >(acknowledgers
> >  ((grob-interface engraver grob source-engraver)
> > (set! (ly:grob-property grob 'output-attributes)
> >   `((class . ,(grob::name grob
> >   }
> > }
> >
> > <<
> >   { c d e f }
> >   \\
> >   { g a b c' }
> >>>
>
> NOTE: You might want this engraver to *append* to the class attribute,
> so you can still specify classes on an individual basis:
>
> 
> \version "2.22.0"
>
> SvgAddClassName =
> #(lambda (ctxt)
>(define (add-class-name grob)
> (let* ((attribs (ly:grob-property grob 'output-attributes '()))
>(class (ly:assoc-get 'class attribs '()))
>(name (grob::name grob)))
>  (set! class (if (null? class) name (format #f "~a ~a" class name)))
>  (set! attribs (assoc-set! attribs 'class class))
>  (ly:grob-set-property! grob 'output-attributes attribs)))
>(make-engraver
> (acknowledgers
>  ((grob-interface engraver grob source)
>   (add-class-name grob)
>
> \layout { \context { \Score \consists \SvgAddClassName } }
>
> { \tweak output-attributes #'((class . foo)) b'4 }
> 
>
>
> -- Aaron Hill

Hi Aaron, thanks for your response and solution. I just tried it out
and it works an absolute treat!

Thanks for taking the time to put it together, I really appreciate it.

Cheers,
Matt.



Re: SVG export - how might you add classes for all graphical objects?

2021-06-29 Thread Matt Hood
P.S. (Sorry to be spamming the list!)

> Out of curiosity: what tool is this for?

A browser-based rhythm game I'm putting together, which makes use of
Lilypond's fantastic proportional notation feature. The addition of
classes is used to separate moving objects (NoteHead, Stem, BarLine,
etc) from non-moving objects (StaffLine, Clef, TimeSignature).

Cheers,
Matt.

On Wed, Jun 30, 2021 at 2:43 AM Jean Abou Samra  wrote:
>
> Hello,
>
> > Le 29/06/2021 10:42, Matt Hood  a écrit :
> >
> >
> > Hi everyone,
> >
> > I'm working with lilypond output in the browser, using its SVG export
> > function. Lilypond permits attaching attributes to particular kinds of
> > grobs, e.g.:
> >
> > {
> > \override NoteHead.output-attributes =
> > #'((class . "NoteHead"))
> > c
> > }
> >
> > The above will cause all NoteHead objects to have the following SVG:
> >
> > 
> > ...NoteHead grob SVG elements...
> > 
> >
> > My question is: how can I make it so that all graphical objects have
> > their name in the class attribute?
> >
> > I've tried using the following scheme function:
> >
> > #(define (add-class grob grob-origin context)
> > (let (name (cdr (assoc 'name
>
> This lacks a pair of parentheses around the
> bindings. You might have posted the wrong
> version of your code.
>
> > (ly:grob-property grob 'meta
> > (set! (ly:grob-property grob 'output-attributes) '((class
> > . name)
>
> '((class . name)) is literally a list containing a
> list of the symbols 'class and 'name, which is not
> very useful ;-) You rather want quasiquoting:
> `((class . ,name)).
>
> >
> > This successfully (I believe) extracts the correct name, and assigns
> > it to the output-attributes field. As per the instructions in the
> > lilypond documentation, I then attempted to use \applyOutput Score
> > #add-class to apply this function to all graphical objects, but it
> > didn't supply all of the required objects. My attempted code is below:
> >
> > \applyOutput Score #add-class
> > \score {
> > \new RhythmicStaff {
> > c'2 c'16 c' c' c' \tuplet 5/4 { c'16 c' c' c' c' }
> > }
> > }
> >
> > If I add a print call to the add-class function, I can see that it was
> > called for the objects with the following names from which crucial
> > objects such as NoteHead are missing:
> >
> > NonMusicalPaperColumn
> > PaperColumn
> > Clef
> > TimeSignature
> > LedgerLineSpanner
> > StaffSymbol
> > VerticalAxisGroup
> > SystemStartBar
> > SpacingSpanner
> > VerticalAlignment
> > StaffSpacing
> > BreakAlignment
> > LeftEdge
> > BreakAlignGroup
> > BreakAlignGroup
> > BreakAlignGroup
>
> I'm not sure how you got this output. The way
> the code is written, the \applyOutput is separate
> from the main \score, so it is a score of its own
> containing no actual music. If you move it to
> the beginning of the music, you should get at
> least one NoteHead, as illustrated here:
>
> \version "2.22.0"
>
> {
>   \applyOutput Score
> #(lambda (grob origin context)
>(ly:message "~s" grob)
>(set! (ly:grob-property grob 'color)
>  red))
>   <<
> { c d e f }
> \\
> { g a b c' }
>   >>
> }
>
> This also shows the reason why \applyOutput
> isn't working as you are expecting. \applyOutput
> applies to one single time step. Think of it
> as a \once \override. I don't think there
> currently exists an equivalent of \applyOutput
> for the whole score (perhaps because there were
> not many use cases before output-attributes).
>
> However, this problem can be solved by writing
> an engraver (those are the powerful tools that
> \applyOutput uses under the hood).
>
> \version "2.22.0"
>
> \layout {
>   \context {
> \Score
> \consists
>   #(lambda (context)
>  (make-engraver
>(acknowledgers
>  ((grob-interface engraver grob source-engraver)
> (set! (ly:grob-property grob 'output-attributes)
>   `((class . ,(grob::name grob
>   }
> }
>
> <<
>   { c d e f }
>   \\
>   { g a b c' }
> >>
>
>
> Out of curiosity: what tool is this for?
>
> Best,
> Jean



Re: SVG export - how might you add classes for all graphical objects?

2021-06-29 Thread Matt Hood
On Wed, Jun 30, 2021 at 2:43 AM Jean Abou Samra  wrote:
>
> Hello,
>
>...
>
> I'm not sure how you got this output. The way
> the code is written, the \applyOutput is separate
> from the main \score, so it is a score of its own
> containing no actual music. If you move it to
> the beginning of the music, you should get at
> least one NoteHead, as illustrated here:
>
> \version "2.22.0"
>
> {
>   \applyOutput Score
> #(lambda (grob origin context)
>(ly:message "~s" grob)
>(set! (ly:grob-property grob 'color)
>  red))
>   <<
> { c d e f }
> \\
> { g a b c' }
>   >>
> }
>
> This also shows the reason why \applyOutput
> isn't working as you are expecting. \applyOutput
> applies to one single time step. Think of it
> as a \once \override. I don't think there
> currently exists an equivalent of \applyOutput
> for the whole score (perhaps because there were
> not many use cases before output-attributes).
>
> However, this problem can be solved by writing
> an engraver (those are the powerful tools that
> \applyOutput uses under the hood).
>
> \version "2.22.0"
>
> \layout {
>   \context {
> \Score
> \consists
>   #(lambda (context)
>  (make-engraver
>(acknowledgers
>  ((grob-interface engraver grob source-engraver)
> (set! (ly:grob-property grob 'output-attributes)
>   `((class . ,(grob::name grob
>   }
> }
>
> <<
>   { c d e f }
>   \\
>   { g a b c' }
> >>
>
>
> Out of curiosity: what tool is this for?
>
> Best,
> Jean

Thanks for picking up on those errors in the scheme function, Jean. I
may have been a little cavelier in copying over the minimal code
examples, and I hadn't picked up the quoting error. The output came
from inserting (display name "\n"), to observe the output in the
compilation process. I tried a variety of locations to place
\applyOutput Score #add-class and this one gave me the most objects.

Thanks for getting the ball rolling with the suggestion of a custom
engraver - it looks like I have some documentation to read! They seem
wonderfully useful.

I really appreciate your response - thank you again.

Cheers,
Matt.



SVG export - how might you add classes for all graphical objects?

2021-06-29 Thread Matt Hood
Hi everyone,

I'm working with lilypond output in the browser, using its SVG export
function. Lilypond permits attaching attributes to particular kinds of
grobs, e.g.:

{
  \override NoteHead.output-attributes =
  #'((class . "NoteHead"))
  c
}

The above will cause all NoteHead objects to have the following SVG:


  ...NoteHead grob SVG elements...


My question is: how can I make it so that all graphical objects have
their name in the class attribute?

I've tried using the following scheme function:

#(define (add-class grob grob-origin context)
 (let (name (cdr (assoc 'name
(ly:grob-property grob 'meta
(set! (ly:grob-property grob 'output-attributes) '((class
. name)

This successfully (I believe) extracts the correct name, and assigns
it to the output-attributes field. As per the instructions in the
lilypond documentation, I then attempted to use \applyOutput Score
#add-class to apply this function to all graphical objects, but it
didn't supply all of the required objects. My attempted code is below:

\applyOutput Score #add-class
\score {
\new RhythmicStaff {
  c'2 c'16 c' c' c' \tuplet 5/4 { c'16 c' c' c' c' }
}
}

If I add a print call to the add-class function, I can see that it was
called for the objects with the following names from which crucial
objects such as NoteHead are missing:

NonMusicalPaperColumn
PaperColumn
Clef
TimeSignature
LedgerLineSpanner
StaffSymbol
VerticalAxisGroup
SystemStartBar
SpacingSpanner
VerticalAlignment
StaffSpacing
BreakAlignment
LeftEdge
BreakAlignGroup
BreakAlignGroup
BreakAlignGroup

If there were a way to run add-class on all graphical objects, that
might be a good solution to the problem.

Any help would be much appreciated!

Thanks,
Matt.



Re: Issue with tablature in full score

2017-11-15 Thread Matt Hood
Hi David, thanks for your advice, it worked perfectly. A 1 minute text 
replacement job too!

Thanks again,
Matt. 

> On 16 Nov 2017, at 1:57 am, David Kastrup <d...@gnu.org> wrote:
> 
> Matt Hood <mattho...@gmail.com> writes:
> 
>> Hi all,
>> 
>> I’m putting together an arrangement for four guitars, with the parts
>> in tab and the full score in standard notation. Each part is its own
>> variable, and then separate instances of Staff and TabStaff are used
>> to output in the different formats.
>> 
>> I’ve gone back through and added fingering information to make the tab
>> sensible, using these commands:
>> \set TabStaff.minimumFret = #??
>> \set TabStaff.restrainOpenStrings = ##??
>> 
>> This makes a nice looking tab, but now the full score is littered with
>> extra clefs and spacing issues on every instance that I’ve changed
>> some property of TabStaff.
>> Is there a way to disable all occurrences of a TabStaff in the full score?
>> Worst case scenario I can use tags, but that’s awfully tedious. Or I
>> could have two copies of the parts, but then I’ve got to change two
>> files for every alteration, which isn’t a great practice.
>> 
>> Any ideas?
> 
> Use \set Staff.minimumFret ... et al.  A TabStaff will also answer to
> Staff (since it is aliased accordingly), and the settings will not cause
> trouble in a Staff.
> 
> Alternatively, tag those commands and use \removeWithTag to strip them
> from the Staff version.
> 
> -- 
> David Kastrup

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


Issue with tablature in full score

2017-11-15 Thread Matt Hood
Hi all,

I’m putting together an arrangement for four guitars, with the parts in tab and 
the full score in standard notation. Each part is its own variable, and then 
separate instances of Staff and TabStaff are used to output in the different 
formats.

I’ve gone back through and added fingering information to make the tab 
sensible, using these commands:
\set TabStaff.minimumFret = #??
\set TabStaff.restrainOpenStrings = ##??

This makes a nice looking tab, but now the full score is littered with extra 
clefs and spacing issues on every instance that I’ve changed some property of 
TabStaff.
Is there a way to disable all occurrences of a TabStaff in the full score?
Worst case scenario I can use tags, but that’s awfully tedious. Or I could have 
two copies of the parts, but then I’ve got to change two files for every 
alteration, which isn’t a great practice.

Any ideas?

Thanks for any help,
Matt.
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Choice of pitch input mode

2016-04-29 Thread Matt Hood
Hi all,

I’ve got a non-technical question regarding mode of pitch input. What does 
everyone prefer? Relative, absolute, or a mix of both? 

I’ve always stuck to relative, but I feel like I’ve hit a brick wall as far as 
fluency goes. I’m still quite slow at it, and I spend half of my time trying to 
work out whether I need to change octave or not - usually getting it wrong, and 
watching half of a page disappear into ledger lines. Add in temporary 
polyphonic passages, chords, etc, and it all just becomes an exercise in trial 
and error. Any tips for keeping control?

Any anecdotes or mildly related musings are welcome, I feel like it would be 
good to facilitate a general discussion.

Cheers,
Matt.
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Re: Question about output

2016-04-28 Thread Matt Hood

> On 28 Apr 2016, at 1:51 PM, Michiel Sikma  wrote:
> 
> Hi all,
> 
> I'm doing some tests trying to figure out repeating sections and voices, and 
> I've written this so far:
> http://lilybin.com/mwafar/2 
> My question is, does it look OK to you that the end of the second alternative 
> is a repeat bar (e.g. ":..:" ) in both directions? I was expecting to get a 
> ".|:" bar. Here's an example: http://i.imgur.com/PJ9prg1.png 
> 
> Did I accidentally mess up the repeat formatting or is Lilypond's output also 
> valid? To me it looks almost like there should be another repeat of the first 
> part, after playing the second alternative, which is not how the score should 
> be, but maybe I'm mistaken.
> 
> I appreciate any insight you can give, or other tips if you happen to think 
> of any :)
> 
> Michiel Sikma
>  
> Let's Deliver
> http://letsdeliver.com/ 
> m...@letsdeliver.com 
> ___
> lilypond-user mailing list
> lilypond-user@gnu.org
> https://lists.gnu.org/mailman/listinfo/lilypond-user 
> 

Hi Michiel,

Both look fine to me, though I personally agree with you find the example in 
the image you linked to more aesthetically pleasing. You can get this by 
appending ‘ \bar ".|:” ‘ to line 115 of the LilyBin code, though it seems like 
you already knew that ("I was expecting to get a ".|:” bar”).

I checked the output of Sibelius, and it’s the same as Lilypond, for what 
that’s worth. 

Matt.

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


Re: What is the proper way of programmatically generating markup?

2016-04-24 Thread Matt Hood

> On 24 Apr 2016, at 5:28 PM, Thomas Morley <thomasmorle...@gmail.com> wrote:
> 
> 2016-04-24 5:00 GMT+02:00 Matt Hood <mattho...@gmail.com>:
>> Hi everyone,
>> 
>> So I’m writing a function that reimplements the ‘\compoundMeter’ command
>> with an Orff-style time signature, whereby the denominator of the signature
>> is a note head (as opposed to a number),
> 
> I've done this some month ago in the german forum
> http://www.lilypondforum.de/index.php?topic=2127.msg11763#msg11763
> Without account you'll not able to see the image, so I attached it
> below, but the code should be available.
> 
> I was too tired to write documentation about it and didn't return to
> it, maybe I should put it in LSR.
> Note the beat-structure is hard-coded to '() for now. If this gives
> problems, please shout.
> 
> HTH,
>  Harm
> 

Wow, I really like this solution. I’ve been sitting the signatures in the 
normal location, but this is far more clear. Thanks!

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


Re: What is the proper way of programmatically generating markup?

2016-04-23 Thread Matt Hood

> On 24 Apr 2016, at 1:38 PM, Paul Morris <p...@paulwmorris.com> wrote:
> 
>> On Apr 23, 2016, at 11:00 PM, Matt Hood <mattho...@gmail.com 
>> <mailto:mattho...@gmail.com>> wrote:
>> 
>> **So my second question is: How do I programmatically generate markup from 
>> information taken from a list, and then put it into a single markup 
>> variable?**
> 
> Hi again,  I’d suggest looking at snippets in the LSR, searching for "time 
> signature", if you haven’t yet, .  This one looks like it might be helpful:
> 
> http://lsr.di.unimi.it/LSR/Snippet?id=743 
> <http://lsr.di.unimi.it/LSR/Snippet?id=743>
> 
> Cheers,
> -Paul

Thank you very much Paul, for this and your previous message. I think it’s 
going to be really helpful.

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


What is the proper way of programmatically generating markup?

2016-04-23 Thread Matt Hood
Hi everyone,

So I’m writing a function that reimplements the ‘\compoundMeter’ command with 
an Orff-style time signature, whereby the denominator of the signature is a 
note head (as opposed to a number), e.g. 4/4 = 4/crotchet, 9/8 = 
3/dotted-crotchet, 15/16+2/4 = 5/dotted-quaver + 2/crotchet. I’ve been able to 
implement the first two cases, i.e. no additive signatures,  but I’d like to 
make the third example work.

**My first question is: does anyone know where can I find the source (scm or 
otherwise) for \compoundMeter? I can’t find it in the ‘share/scm’ folder. I 
feel like it would be helpful to reference.**

My attempts to make this work have involved trying to generate the markup using 
foreach loops, that crawl through a list of lists that might look like:

(  (3 3 (ly:make-duration 3 1))   (4 (ly:make-duration 2))  )

which would be equal to: (9+9/16)+(4/4). All elements except for the last of 
each loop are numerators, while the last is the denominator.

-

This is the scheme code doing the work (not finished, but the basics should 
work?). The list-of-lists is referred to as ‘durs':

\version “2.18.2"
...
(markup
(#:line
  ( for-each
   (lambda (x) 
(markup "+")
( #:center-column 
 
 ;; Numerator Markup. The list supplied to the for-each loop doesn’t 
contain the duration. [“(cdr (reverse x))”]
 (#:line  
   (for-each 
(lambda (y) 
 (
  ( markup "+") 
  (#:number (number->string y) )
 )
)
(cdr (reverse x))
   )
 )

;; Denominator markup.
(#:note-by-number 
 (ly:duration-log (car (reverse x))) 
 (ly:duration-dot-count (car (reverse x))) 
 DOWN
)
   
   )
  )
  durs
 )
)
)

This haphazard collection of markup needs to somehow fit into:

\override Score.TimeSignature #'text =

which accepts ‘markup’, singular, only. 

This throws errors such as:
warning: type check for `stencil' failed; value `#' must 
be of type `stencil'

--

**So my second question is: How do I programmatically generate markup from 
information taken from a list, and then put it into a single markup variable?**

Any help at all would be greatly appreciated.
Cheers, Matt.___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user