Re: Including only definitions from a Lilypond file

2020-08-23 Thread Jérôme Plût
> On 2020-08-14 4:48 am, David Kastrup wrote:
> > All of the elements in a score are routed through hooks you can
> > redefine.  So you can just redefine your various hooks to do nothing and
> > then include the file.
> 
> Would something like this work?
> 
> 
> \version "2.20.0"
> 
> #(begin
>   (use-modules (ice-9 regex))
>   (let* ((symbols
>(map (lambda (m) (string->symbol (match:substring m 1)))
> (list-matches "define ([a-z-]+-handler)"
>   (ly:gulp-file "declarations-init.ly"
>  (procs (map primitive-eval symbols))
>  (null-proc (lambda args #f)))
> (ly:parser-define! 'disableHandlers
>   (define-void-function () ()
> (for-each
>   (lambda (sym) (primitive-eval `(set! ,sym ,null-proc)))
>   symbols)))
> (ly:parser-define! 'restoreHandlers
>   (define-void-function () ()
> (for-each
>   (lambda (sym proc) (primitive-eval `(set! ,sym ,proc)))
>   symbols procs)

This mostly works (except that I only needed to replace
"toplevel-.*-handler" functions), thanks!

Now I would like to use this to programmatically include a given file,
e.g. defining a Scheme function #(my-function "filename.ly") that would do
something equivalent to

#(compute something with "filename.ly")
\include "filename.ly"
#(compute something else with "filename.ly")

I tried to call (ly:parser-include-string (string-concatenate
`("\\disableHandlers \\include \"" ,filename "\""))) inside
my-function, but this produces
"fatal error: call-after-session used after session start".
(Some variants using ly:parser-parse-string, current-parser,
ly:parser-clone did not fare better).

Currently I see one (poor man's) way of doing that, which is calling

lilypond -e '(include "myfile.scm")' filename.ly

where "myfile.scm" does the first part of computation and sets up one
of the toplevel-.*-handler functions to do the second part of the
computation. (I've not tried it yet, though!). However this is quite
inelegant and, in particular:
 - likely not too robust w.r.t the content of "filename.ly",
 - does not allow including more than one file in sequence.

Is there a better way of doing this?

Thanks,

-- 
Jérôme Plût



Including only definitions from a Lilypond file

2020-08-13 Thread Jérôme Plût
Hello everybody,

I have some lilypond files that contain both music variables and
typesetting instructions, like this:

soprano = \relative {
  % music here...
}

\bookpart {
  % typesetting here...
}

I would like to include this file while importing the definitions and
ignoring the typesetting. (The long-term goal is to display some
statistics (range, etc.) about the various voices in the piece. So the
including file will want to know what \soprano contains, but to
replace all typesetting instructions by its own).

I *could* do this by writing a separate (e.g. Perl) parser that looks
only for music definitions, but it would be cleaner (and also more
robust) if there existed a way to do this from inside Lilypond or
Scheme. Ideally I would need the parser to obtain both the list of
variables defined in the file and the contents of those variables.

Before I start hacking something: does there already exist a simpler
way to do this?

Thanks,

-- 
Jérôme
 



Re: Automatic coloring clef/key signature changes

2019-01-02 Thread Jérôme Plût
> Well, since you don't include any example code

Of course, if I had had any example code, I would not have been asking
the question in the first place!

Here is a working example though, thanks to the second part of your
message. Should some variant of this be added to the snippets database?


#(begin
(define (any->color x) (cond
  ((symbol? x) (x11-color x))
  ((list? x) x)
  (else `(0. 0. 0.

(define (callback-when-non-default x) (lambda (grob)
  (or (null? (ly:grob-property grob 'non-default)) x)))

(define (set-color-when-non-default grob-name color)
  (context-spec-music
(make-grob-property-set grob-name 'color
  (callback-when-non-default (any->color color)))
'Staff))
) %begin

color-signatures = {
  #(set-color-when-non-default 'Clef `(.3 .0 .6))
  #(set-color-when-non-default 'KeySignature `(.5 .2 .0))
}

\score {
 \new Staff {
  \color-signatures

  \key g \major \repeat unfold 20 c'4
  \clef C \repeat unfold 20 c'4
  % Amusingly, the naturals are *not* colored here:
  \key c \minor \repeat unfold 20 c'4
  \clef G \repeat unfold 20 c'4
}
}

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


Automatic coloring clef/key signature changes

2019-01-02 Thread Jérôme Plût
Is there a way to change the color of all clef changes in a score (and
only these, not the clef that is at the beginning of each staff line)?
I cannot manage to change even one of these (I tried \once \override
Staff.Clef.color, to no avail), and what I really want is to change
all of these by a one-time incantation at the beginning of the score.

Also, same question for KeySignature.

Thanks,

-- Jérôme

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


markup->string and user markup commands

2018-11-08 Thread Jérôme Plût


#(begin
; after http://lsr.di.unimi.it/LSR/Snippet?id=969
(define-markup-command (with-background layout props color arg) (color? markup?)
   (let* ((stencil (interpret-markup layout props arg))
  (X-ext (ly:stencil-extent stencil X))
  (Y-ext (ly:stencil-extent stencil Y)))
 (ly:stencil-add (ly:make-stencil
  (list 'color color
(ly:stencil-expr (ly:round-filled-box X-ext Y-ext 0))
X-ext Y-ext)) stencil)))
(display "\"")
(display (markup->string (markup #:with-background `(1. 0. 0.) "something")))
(display "\"")
)

This should display "something". However it displays an empty string.
How could I fix this?

(I tried to manually debug markup->string (in scm/markup.scm): as I
understand it, the problem is likely that with-background does not
belong to the 'lily module. However, I am completely unfamiliar with
guile's module system, so I don't have the slightest idea about how to
fix this).

Thanks,

-- 
Jérôme

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


Re: \goto for Lilypond

2018-11-08 Thread Jérôme Plût
Sexto Idus Octobres MMXVIII scripsit Jérôme Plût :
> Sexto Idus Octobres MMXVIII scripsit Kieren MacMillan :
> > Hi Jérôme,
> > 
> > > and cues in another variable:
> > 
> > May I ask why you don’t use the built-in cue system? I’ve found it very 
> > useful and flexible.
> 
> I do use it! I have another set of macros (not shown here) that
> basically wrap \cueDuringWithClef. (I actually wrote a generator for
> such trivial wrappers, which I use like this:

Oh! I guess you meant, "Why don't I cue directly from the
oboe/bassoon/etc. voice"? In that case, the reason is that I generally
only need to redo the trombone/horn parts (instead of the full 20-25
voices in the orchestra...), so I don't have full oboe/etc. voices to
quote from. Hence the fact that I put all cues in the same voice.

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


Re: \goto for Lilypond

2018-11-08 Thread Jérôme Plût
Sexto Idus Octobres MMXVIII scripsit Kieren MacMillan :
> Hi Jérôme,
> 
> > and cues in another variable:
> 
> May I ask why you don’t use the built-in cue system? I’ve found it very 
> useful and flexible.

I do use it! I have another set of macros (not shown here) that
basically wrap \cueDuringWithClef. (I actually wrote a generator for
such trivial wrappers, which I use like this:

cc = #(cue-gen "cues" "")
ccF = #(cue-gen "cues" "" "F")
ctA = #(cue-gen "tromboneA" "Tbn. I" "F")
ctB = #(cue-gen "tromboneB" "Tbn. II" "F")

{ ... \cc R1*2 ... }

I could send it here in case anyone were interested (but it would need
a bit of code cleansing before)).

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


Re: \goto for Lilypond

2018-11-08 Thread Jérôme Plût
> cues = {
>   % I don't know about you, but I like having *a lot* of cues to
>   % follow. I suspect that being a former pianist, I find it easier
>   % than most brass colleagues to read several lines at once?
>   R1*15 % bar 16
>   \relative { fis'1^"Fl." } % bar 17
>   R1*24
>   \relative { c''1^"Ob." } % bar 41
> }

By the way, a secondary question:

the \cues voice has some cues from a large number of instruments and
therefore a large range. So the clef used for the cues will depend on
the instrument I am currently cueing from.

Currently I use several different macros for cueing in F, G or current
clef. Does there exist a way to put the clef info in the cue voice
itself? (e.g. a oboe cue will always be in G clef, whereas a viola cue
will not provoke a clef change). Or else, to have access to the cued
music (and possibly the current clef) to compute an appropriate
cue-clef?

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


\goto for Lilypond

2018-11-08 Thread Jérôme Plût
I quite often find myself transcribing a part of a big orchestral
score from IMSLP (e.g., putting the horns in F
transposition and the trombones in bass clef -- our brass section is
not too good at exotic sightreading).

For this I put the global structure of a movement in a \global
variable, such as:


global = {
  \time 4/4 \tempo "Al dente ma non troppo"
  s1*47 \mark "A" % bar 48
  s1*38 \mark "B" % bar 86
  ...
}

and cues in another variable:

cues = {
  % I don't know about you, but I like having *a lot* of cues to
  % follow. I suspect that being a former pianist, I find it easier
  % than most brass colleagues to read several lines at once?
  R1*15 % bar 16
  \relative { fis'1^"Fl." } % bar 17
  R1*24
  \relative { c''1^"Ob." } % bar 41
}

Keeping tracks of the bar numbers is a bit tedious, and I find myself
doing a *lot* of additions/subtractions (« sooo this oboe cue is 7
bars before A, and my last cue ended at bar 17, which makes it, let's
see.. 17 measures of rest »). And then spend twice as long fixing the
bugs (and introducing new ones, etc.)



So I wrote a few macros to automate this (and I expect them to pay
for themselves in only 1-2 more symphonies).

Now I can write the previous score in this way:

global = {
  \at-bar 1 { \time 4/4 \tempo "..." }
  \at-bar 48 { \mark "A" }
  \at-bar 86 { \mark "B" }
}

cues = <<
  \relative { \goto 16 fis'1^"Fl." }
  \relative { \goto "A-7" c''1^"Ob." } % we can even make them relative
>>

(In particular, this makes *inserting* a new cue much, much easier).

The functions should work even in the presence of varying time
signatures. A proof of concept (in 608 parentheses) is in the attached file.

Drawbacks (those identified for now):
 - \partial is not recognized yet
   (but this is quite easy to compensate for, by putting the
   appropriate skip at the beginning of \global);
 - this assumes that alternateBarNumbering is 'numbers-with-letters,
   (the other way around is quite easier; I could put some code to
   identify \set Score.alternateBarNumbering commands);
 - it *does not work* (for syntax reasons) in the presence of true
   repeats (they must be simulated using Score.repeatCommands);
 - when a voice uses \at-bar, it must *only* use \at-bar (this is the
   only way to keep track of time; see my previous question).


Oh, and by the way, I have a half-serious bug-report:
negative-length skips don't work.

-- 
Jérôme

#(begin

(use-modules (ice-9 regex))

(define (print . l) (map display l) (newline) #f)
(define (music-length m)
  "Duration of m, as a rational"
(ly:moment-main (ly:music-length m)))


(define (rcons e l) (append! l (list e)))

;  alternatives: 
;   VoltaRepeatedMusic 'element [rpt] 'repeat-count 2 'elements [alternatives]
;   - if 'numbers, then sets bar number to the *sum* of all lengths
;   - if 'numbers-with-letters, sets bar number to the *last* length only
; HOWEVER, inserting \atBar syntaxically prevents us from inserting ture
; \repeat volta  { ... } construct; we are stuck with
; score.repeatCommands, which produces
; 'ContextSpeccedMusic 'context-type 'Score 'element
;('PropertySet 'symbol 'repeatCommands 'value ... )

; the (bar number ↦ time) function* is piecewise affine.
; - slope is current time signature
; - jumps are introduced by \partial, repeats, or currentBarNumber changes.
; The status of timing is given by a list:
; (current-time, last-bar, last-time, last-sig, last-volta) where:
;  - current-time [rational] = duration since beginning of music
;  - last-bar  = bar number of beginning of current affine function part
;  - last-time = position of same (rational)
;  - last-sig  = signature of same (rational)
;  - last-volta= bar number of current volta (or #f)
; The *bars-affine* global holds only the last 4 values.
(define *bars-affine* '()) ; list of (bar pos sig volta)
(define *bars-marks* '())
(define *bars-current-time* 0)
(define *bar-number-defining* #t)

(define (reset-bar-structures!)
  (set! *bars-marks* '())
  (set! *bars-affine* '((1 0 1 #f)))
  #t)
(reset-bar-structures!)
(define (bar-find-affine-part bar data)
  (if (< bar (caar data)) (bar-find-affine-part bar (cdr data))
(car data)))

(define (update-bars-affine! bar pos sig volta)
  (set! *bars-affine* (cons (list bar pos sig volta) *bars-affine*)))
(define (update-bars-marks! bar mark)
  (set! *bars-marks* (cons (cons mark bar) *bars-marks*)))

; this appends (if needed) a new state in structures
; and returns the current state
(define (update-bar-structures! music . state);<<<
  (let* (
(prop (lambda (x . y) (apply ly:music-property music (cons x y
(n (prop 'name))
(state (if (null? state) (list 0 1 0 1 #f) (car state)))
(pos (list-ref state 0))
(last-bar (list-ref state 1))
(last-time (list-ref state 2))
(last-sig (list-ref state 3))
(last-volta (list-ref state 4))
(this-bar (+ last-bar (/ (- pos last-time) last-sig)))
  ) (cond
  ((eq? n 'SequentialMusic)
(fold 

Reading global variables from Scheme [documentation request?]

2018-11-08 Thread Jérôme Plût
I would like to *read*, from within a Scheme function
(define-music-function), the values of variables such as
Score.currentBarNumber or Score.alternativeNumberingStyle.

I can have a guess that this is possible with such functions as
ly:context-property or ly:output-def-lookup, but the documentation of
these functions is quite terse.

How is it possible to access these values?

Thanks,

-- 
Jérôme

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


Re: Helper macros for music analysis

2018-11-07 Thread Jérôme Plût
Tertio Nonas Novembres MMXVIII scripsit Thomas Morley :
> > I tried to hunt this down...
> > Although, I still don't know why #(load "file.scm") done in a ly-file
> > stopped working, [...]
> 
> Still no clue, though, in ly-files (load ...) works only with an absolute 
> path.
> In native guilev2, it works with a relative path as well.
> 
> Any hints to boil this down even further?

I am really not that familiar with the Guile module management system.
My best guess is that it has to do with this:
https://www.gnu.org/software/guile/manual/html_node/Load-Paths.html

Also, scm/lily.scm contains some allusions to a difference of
behaviour between guile v1 and v2:

(define-public (ly:load x)
  (let* ((file-name (%search-load-path x)))
(ly:debug "[~A" file-name)
(if (not file-name)
(ly:error (_ "cannot find: ~A") x))
(primitive-load-path file-name)  ;; to support Guile V2 autocompile
;; TODO: Any chance to use ly:debug here? Need to extend it to prevent
;;   a newline in this case
(if (ly:get-option 'verbose)
(ly:progress "]\n"


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


Re: Helper macros for music analysis

2018-11-01 Thread Jérôme Plût
Kalendis Novembribus MMXVIII scripsit Thomas Morley :
> Part of the problem is you use 'structure as a music-property without
> declaring it. As a consequence using the option -dcheck-internal-types
> makes the compilation fail.

This is why, in a previous iteration of this code, I used an invisible
articulation to hold the metadata (cf. my previous message on this
list; by the way, let me apologize for the triple posting, I was under
the impression that the sending had failed).

I just had a look at define-music-properties.scm -- I had not realized
that it was even possible to *declare* a music property. Adding these
lines makes my code compile even with -dcheck-internal-types:

(music-property-description 'structure markup? "structural markup")
(music-property-description 'harmony markup? "harmony markup")
(music-property-description 'motif-define markup? "motif name")

There are still a few warnings because of an invalid 'origin property,
but these would take quite a bit longer to fix (the correct location
object would need to be passed along a *long* chain of procedure
calls).

By the way, I have one more question: Given (on the Scheme side) a
list L of markup objects, I can build a column with
(make-column-markup L), but this column is left-aligned. How could I
make it right-aligned?

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


Helper macros for music analysis

2018-11-01 Thread Jérôme Plût

I wrote some macros to help write analysis of musical pieces.
Here is an example file (on Bach's Invention I).

Structural analysis is (of course) performed by hand, and displayed on
a Lyrics structure on top of the music. (This part is only a set of
very simple macros).

Harmonic analysis is performed mostly by hand (I also have some code
that does harmonic analysis, but it works mostly on chorales; the code
here only detects octave-drop cadences) and displayed on a Lyrics
structure below the music.

The code also does a bit of motif analysis, which is done
automatically (motives are declared once by hand, then later
occurrences and inversions are identified automatically).

The enclosed files:
  motif.scm  contains most of the parentheses
  bwv772.ly  is the example for Invention I

TThe code compiles with both v2.18 (Debian stable; this is the only
version I have access to on some of my systems) and v2.19.

I am interested in any feedback you would have on this code!

-- 
Jérôme
; (music-fold-time order f data init music):  f(data, leaf, X, pos)

; General utilities {{{1
(define (print . l) (map display l) (newline) #f)
(define (assert b . l) (or b (apply error l)))
; 
https://stackoverflow.com/questions/108169/how-do-i-take-a-slice-of-a-list-a-sublist-in-scheme
(define (slice l start length) (take (drop l start) length))
(define (insert l position x)
  (append (take l position) (cons x (drop l position
; returns interval [start, stop[ with given step
(define (interval-open start step stop) (if (>= start stop) '()
  (cons start (interval-open (+ start step) step stop
; returns the last element of a closed list
(define (last l) (car (last-pair l)))
(define (anything->color c) (cond
   ((symbol? c) (x11-color c))
   ((and (number? c) (> c 1)) (map (lambda (x) (/ x 255.)) `(,c ,c ,c)))
   ((number? c) `(,c ,c ,c))
   ((and (list? c) (> (car c) 1) (map (lambda(x) (/ x 255.)) c)))
   (else c)))
; Cosmetic functions {{{1
; Color variant {{{2
(define (color-comp-variant1 t x) (/ (* x t) (+ 1 (* (- t 1) x
(define (color-variant c n) (let* (;{{{
  (n (modulo (* 4 n) 7))
  (t `((0 0 1) (1 1 0) (0 1 1) (1 0 1) (0 1 0) (1 0 1) (0 0 0)))
  (d (map (lambda (x) (list-ref `(1.3 .8) x)) (list-ref t n)))
  )
  ; c = RGB color
  ; n = integer 0..6
  (map color-comp-variant1 d c))
);}}}
(define (theme-color-variant c m);{{{
  (color-variant c (ly:pitch-notename (first-note m;}}}
; hsv->rgb {{{2
(define (hsv->rgb z) (let* (
  (h (modulo (car z) 360)) (s (cadr z)) (v (caddr z))
  (i (floor (/ h 60.)))
  (c (* v s)) (t (/ h 60.)) (hmod2 (- t (* 2 (floor (/ t 2)
  (absh (abs (- hmod2 1))) (x (* c (- 1 absh)))
  ) (map (lambda (y) (+ y (- v c))) (cond
((<= t 1) `(,c ,x 0))
((<= t 2) `(,x ,c 0))
((<= t 3) `(0 ,c ,x))
((<= t 4) `(0 ,x ,c))
((<= t 5) `(,x 0 ,c))
((<= t 6) `(,c 0 ,x));}}}
; with-background {{{2
; after http://lsr.di.unimi.it/LSR/Snippet?id=969
(define-markup-command (with-background layout props color arg) (color? markup?)
   (let* ((stencil (interpret-markup layout props arg))
  (X-ext (ly:stencil-extent stencil X))
  (Y-ext (ly:stencil-extent stencil Y)))
 (ly:stencil-add (ly:make-stencil
  (list 'color color
(ly:stencil-expr (ly:round-filled-box X-ext Y-ext 0))
X-ext Y-ext)) stencil)))
(define mark-below (define-music-function (parser location label) (markup?)
  (make-sequential-music (list
(prop-override '(Score RehearsalMark extra-offset) '(0 . -8.5) #t)
(prop-override '(Score RehearsalMark baseline-skip) 9 #t)
(make-music 'MarkEvent 'label label)
(define framed-mark (define-music-function (parser location text1) (markup?)
  (make-sequential-music (list
(prop-override `(Bottom LyricText self-alignment-X) LEFT)
(make-music 'MarkEvent
'label (markup #:line (#:box #:fontsize -3 text1)))
(define corner-mark (define-music-function (parser location text2) (markup?)
  (make-music 'MarkEvent 'label (markup #:fontsize -3
(#:combine (#:path .15 '((lineto 0 2) (lineto 3 2)))
   #:line (" " text2))
; General utilities for music {{{1
; Naming convention:
; make-foobar: direct constructor for a foobar
; create-foobar: defines a function which returns a foobar
(define (pitch->int p)
  (assert (ly:pitch? p) "pitch->int: must be a pitch: " p)
  (if (ly:pitch? p)
   (+ (* 7 (ly:pitch-octave p)) (ly:pitch-notename p
(define (pitch->semitone p)
  (assert (ly:pitch? p) "pitch->semitone: must be a pitch: " p)
  (if (ly:pitch? p)
  (+ (* 12 (ly:pitch-octave p))
 (list-ref `(0 2 4 5 7 9 11) (ly:pitch-notename p))
 (* 2 (ly:pitch-alteration p)
; music-length: duration (as a rational) {{{2
(define moment->rational ly:moment-main)
(define (duration->rational dur) (ly:moment-main (ly:duration-length dur)))
(define (music-length m)
  "Duration of m, as a rational"
  (moment->rational (ly:music-length m)))
(define 

A few questions about Scheme functions

2018-10-29 Thread Jérôme Plût
I have a few questions about using Scheme to build Lilypond data.

1. I have some Scheme code that builds custom articulations (more
precisely, it attaches metadata to NoteEvents, and the only way I found
to make this possible is via putting it in a custom, invisible
articulation, but let's not digress too much).

The code I use to declare this custom articulation is:

\layout { \context { \Score
  scriptDefinitions = #(append default-script-alist `(
  ("void" . ((stencil . #f) (direction . ,UP) (avoid-slur . ignore)))
)) } }

However, this is Lilypond code, not Scheme code. My code is in a .scm
file, which is read in the user files as #(load "code.scm").

Does there exist a way to modify the articulations table from inside a
Scheme code block (such as (begin ) )? I tried wrapping this
inside #{ ... #}, but to no effect.


2. A variant of 1. above: say I have a music expression such as

voiceone = \relative {
  c d e f g \mymacro { a b c }
}

where mymacro is defined as

mymacro = #(define-music-function (parser location music) (ly:music?)
  ; ...
  (let (music-rel #{ \relative $music #}) ...))

This works as intended (i.e. the third note is interpreted as a c', not a
c). However, trying to build the exact same expression in a Scheme way
does not work:
  (let (music-rel (make-music 'RelativeOctaveMusic 'element music)) ...)
leaves the music expression untouched.

  So the two questions are:
  2.1 From within the \mymacro function, does there exist a way to know
  that we are called in a \relative scope?
  2.2 Does there exist a “clean Scheme” (no #{ #}) way to interpret the
  parameter as relative music?


3. I have a function that takes some music as input and produces a lyrics
variable, for instance:

voiceone = \relative {
  % the \metadata macro adds some invisible articulation, nothing is
  produced
  c d e\metadata "foobar" f g ...
  %^ HERE ^
}

#(define (myfunction music) ... )

 ; this produces a Lyrics variable containing text "foobar" at the
 appropriate position
\score { \new PianoStaff <<
  \new Staff << \voiceone >>
  % this produces something equivalent to \lyrics { ""2 "foobar"4 }
  \new Lyrics << #(myfunction voiceone) >>
}

My code for now works as I intend it to, but I would like to add info to
the PDF file so that a mouse click on the "foobar" lyrics goes to the
place where \metadata is called (at the HERE comment above)?

(Maybe something with “ly:set-origin!” ? The documentation of this
function is not crystal clear...)

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


A few questions about Scheme functions

2018-10-29 Thread Jérôme Plût
I have a few questions about using Scheme to build Lilypond data.

1. I have some Scheme code that builds custom articulations (more
precisely, it attaches metadata to NoteEvents, and the only way I found
to make this possible is via putting it in a custom, invisible
articulation, but let's not digress too much).

The code I use to declare this custom articulation is:

\layout { \context { \Score
  scriptDefinitions = #(append default-script-alist `(
  ("void" . ((stencil . #f) (direction . ,UP) (avoid-slur . ignore)))
)) } }

However, this is Lilypond code, not Scheme code. My code is in a .scm
file, which is read in the user files as #(load "code.scm").

Does there exist a way to modify the articulations table from inside a
Scheme code block (such as (begin ) )? I tried wrapping this
inside #{ ... #}, but to no effect.



2. A variant of 1. above: say I have a music expression such as

voiceone = \relative {
  c d e f g \mymacro { a b c }
}

where mymacro is defined as

mymacro = #(define-music-function (parser location music) (ly:music?)
  ; ...
  (let (music-rel #{ \relative $music #}) ...))

This works as intended (i.e. the third note is interpreted as a c', not a
c). However, trying to build the exact same expression in a Scheme way
does not work:
  (let (music-rel (make-music 'RelativeOctaveMusic 'element music)) ...)
leaves the music expression untouched.

  So the two questions are:
  2.1 From within the \mymacro function, does there exist a way to know
  that we are called in a \relative scope?
  2.2 Does there exist a “clean Scheme” (no #{ #}) way to interpret the
  parameter as relative music?



3. I have a function that takes some music as input and produces a lyrics
variable, for instance:

voiceone = \relative {
  % the \metadata macro adds some invisible articulation, nothing is
  produced
  c d e\metadata "foobar" f g ...
  %^ HERE ^
}

#(define (myfunction music) ... )

 ; this produces a Lyrics variable containing text "foobar" at the
 appropriate position
\score { \new PianoStaff <<
  \new Staff << \voiceone >>
  % this produces something equivalent to \lyrics { ""2 "foobar"4 }
  \new Lyrics << #(myfunction voiceone) >>
}

My code for now works as I intend it to, but I would like to add info to
the PDF file so that a mouse click on the "foobar" lyrics goes to the
place where \metadata is called (at the HERE comment above)?

(Maybe something with “ly:set-origin!” ? The documentation of this
function is not crystal clear...)

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


Three questions about Scheme functions

2018-10-29 Thread Jérôme Plût
I have a few questions about using Scheme to build Lilypond data.

1. I have some Scheme code that builds custom articulations (more
precisely, it attaches metadata to NoteEvents, and the only way I found
to make this possible is via putting it in a custom, invisible
articulation, but let's not digress too much).

The code I use to declare this custom articulation is:

\layout { \context { \Score
  scriptDefinitions = #(append default-script-alist `(
  ("void" . ((stencil . #f) (direction . ,UP) (avoid-slur . ignore)))
)) } }

However, this is Lilypond code, not Scheme code. My code is in a .scm
file, which is read in the user files as #(load "code.scm").

Does there exist a way to modify the articulations table from inside a
Scheme code block (such as (begin ) )? I tried wrapping this
inside #{ ... #}, but to no effect.


2. A variant of 1. above: say I have a music expression such as

voiceone = \relative {
  c d e f g \mymacro { a b c }
}

where mymacro is defined as

mymacro = #(define-music-function (parser location music) (ly:music?)
  ; ...
  (let (music-rel #{ \relative $music #}) ...))

This works as intended (i.e. the third note is interpreted as a c', not a
c). However, trying to build the exact same expression using the
Scheme constructor does not work:
  (let (music-rel (make-music 'RelativeOctaveMusic 'element music)) ...)
leaves the music expression untouched.

  So the two questions are:
  2.1 From within the \mymacro function, does there exist a way to know
  that we are called in a \relative scope?
  2.2 Does there exist a “clean Scheme” (no #{ #}) way to interpret the
  parameter as relative music?


3. I have a function that takes some music as input and produces a lyrics
variable, for instance:

voiceone = \relative {
  % the \metadata macro adds some invisible articulation, nothing is
  produced
  c4 d e\metadata "foobar" f g ...
  %^ HERE ^
}

#(define (myfunction music) ... )

 ; this produces a Lyrics variable containing text "foobar" at the
 appropriate position
\score { \new PianoStaff <<
  \new Staff << \voiceone >>
  % this produces something equivalent to \lyrics { ""2 "grux"4 }
  \new Lyrics << #(myfunction voiceone) >>
}

I would like to add info to the PDF file so that a mouse click on the
"grux" lyrics goes to the place where \metadata is called (at the HERE
comment above). How would this be possible?

(Maybe something with “ly:set-origin!” ? The documentation of this
function is not crystal clear...)

Thanks in advance,

-- 
Jérôme

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


Re: Schenkerian analysis diagram

2018-04-26 Thread Jérôme Plût
> I don’t think you need to patch LilyPond. Have a look at
> 
> and
> 
> 
> You can just redefine those.

Thanks for the pointers! I did not know that you could play with the
lexer by just assigning to strings, but this seems quite limited (I
can assign to "\\*" or "@", but neither to "@+" nor to "@foo", and
anything starting with a dash is also off-limits).

On the other hand, the dashHat etc. mechanisms are hard-coded in
lily/parser.yy (at the script_abbreviation label), so this is the
place I would need to touch to add any extra shortcuts. At first sight
it seems that enlarging the list to - where  is anything
different from {backslash, space, digits, #, $} would not interfere
with anything (since these are currently syntax errors anyway), is
this correct?

Thanks,

-- 
Jérôme

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


Schenkerian analysis diagram

2018-04-25 Thread Jérôme Plût
I tried to do a few analysis diagrams following the LinuxJournal
example (quoted on the lilypond examples page):
https://www.linuxjournal.com/article/8364

(and also quite outdated, since it was written for Lilypond 2.6).

I think I have a proof of concept (see attached file)
for a version that is simpler to type than the LinuxJournal example
(it now preserves information locality: I do not need to enter any
note more than once).

The way I do this is by attaching “extra data” to notes, as
articulations, indicating how to draw them in the graph, such as:
\white - draw a white note head on this note
\beamR - beam to the right (and add a white note head if none defined)
\slurAL - slur to the right and above (and add a black note head if
none defined). Then some Scheme function parses this and blows out the
music to several voices in the same way as in the LJ example.

And now I have a question. For simplicity of entry (and readability of
source code), I would really really like to have shortcuts in the
style of dashHat, dashPlus etc. Namely, instead of \white, \black,
\beam, \beamR, \slurAL I would prefer (for example) -o, -*, -|, -[, -(
.

Would a patch to the C code enabling such shortcuts be envisageable?
(I don't see them interfering too much with what exists now, since
they only raise syntax errors now).
\version "2.18"
#(begin

(define (create-articulation . l);<<<
  "creates an articulation with invisible output and specified properties"
  (define-event-function () ()
  (apply make-music (append (list 'TextScriptEvent 'text "") l)))
);>>>
(define (voicelead-find-articulation-prop m p);<<<
  "returns the first value found for property p in an articulation of m"
  " (or #f if not found)"
  (let* (
  (a (ly:music-property m 'articulations '()))
  (b (map (lambda (x) (ly:music-property x p #f)) a))
  )
  (find (lambda (x) x) b)
));>>>
(define (voicelead-duration-to d x);<<<
  "converts duration d to a duration (x 0 y) with same length"
  (let* (
(q (ly:moment-main (ly:duration-length d)))
; arriver à q en partant de 2^(-x)
(y (/ q (expt 2 (- x
  )
  (ly:make-duration x 0 y)
));>>>
(define (voicelead-note-heads! m);<<<
  "keep only note heads in the melody m, according to the voicelead-head
  property"
  (cond
  ((ly:music-property m 'elements #f)
(map voicelead-note-heads! (ly:music-property m 'elements)))
  ((ly:music-property m 'element #f)
(voicelead-note-heads! (ly:music-property m 'element)))
  ((eq? (ly:music-property m 'name) 'NoteEvent) (let* (
(h (voicelead-find-articulation-prop m 'voicelead-head))
)
(cond
((eq? h 'white)
  (ly:music-set-property! m 'duration
(voicelead-duration-to (ly:music-property m 'duration) 1)))
((eq? h 'black)
  (ly:music-set-property! m 'duration
(voicelead-duration-to (ly:music-property m 'duration) 2)))
; if no head defined and has a beam, then white head
((voicelead-find-articulation-prop m 'voicelead-beam)
  (ly:music-set-property! m 'duration
(voicelead-duration-to (ly:music-property m 'duration) 1)))
; if no head defined and has a slur, then black head
((voicelead-find-articulation-prop m 'voicelead-slur)
  (ly:music-set-property! m 'duration
(voicelead-duration-to (ly:music-property m 'duration) 2)))
(else  (ly:music-set-property! m 'name 'SkipEvent))
)
(ly:music-set-property! m 'articulations '())
  m ))
  (else m)
) m);>>>
(define (voicelead-note-beams! m);<<<
  "keep only note beams in the melody m, according to the voicelead-stem
  property"
  (cond
  ((ly:music-property m 'elements #f)
(map voicelead-note-beams! (ly:music-property m 'elements)))
  ((ly:music-property m 'element #f)
(voicelead-note-beams! (ly:music-property m 'element)))
  ((eq? (ly:music-property m 'name) 'NoteEvent) (let* (
(h (voicelead-find-articulation-prop m 'voicelead-beam))
)
(ly:music-set-property! m 'articulations '())
(if h
  (ly:music-set-property! m 'duration
(voicelead-duration-to (ly:music-property m 'duration) 3))
  (ly:music-set-property! m 'name 'SkipEvent))
(if (or (eq? h -1) (eq? h 1))
  (ly:music-set-property! m 'articulations (list
(make-music 'BeamEvent 'span-direction h
  m ))
  (else m)
) m);>>>
(define (voicelead-note-slurs! m x);<<<
  "keep only note beams in the melody m, according to the voicelead-stem
  property"
  (cond
  ((ly:music-property m 'elements #f)
(map (lambda (y) (voicelead-note-slurs! y x))
(ly:music-property m 'elements)))
  ((ly:music-property m 'element #f)
(voicelead-note-slurs! (ly:music-property m 'element) x))
  ((eq? (ly:music-property m 'name) 'NoteEvent) (let* (
(h (voicelead-find-articulation-prop m 'voicelead-slur))
)
(ly:music-set-property! m 'articulations '())
(ly:music-set-property! m 'duration
   (voicelead-duration-to (ly:music-property m 'duration) 0))
(if (eq? h x)
  (ly:music-set-property! m 'articulations 

Re: Transposing figured bass

2018-04-12 Thread Jérôme Plût
Tertio Idus Apriles MMXVIII scripsit Jérôme Plût :
> So before I waste too much time on this: given the number of geniuses
> on this mailing-list, certainly one of you already did write the
> relevant Scheme code, am I right?

Given the lack of answer, I did write some Scheme code, which you will
find attached.

This defines a function \transposeFigures, used in the following way:

#(load "transpose-figures.scm")

oldfigures = \figures { ... } % put something in here
oldbass = \relative { ... }   % here too

\new FiguredBass { \transposeFigures c d \oldfigures \oldbass }

-- 
Jérôme
(define (moment-max a b) (if (ly:moment= m (+ (list-ref (car b) 0) (list-ref (car b) 2)))
  (ly:pitch___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Transposing figured bass

2018-04-10 Thread Jérôme Plût

So I want to transpose figured bass.

Of course this is complicated, because the correct way to transpose
depends on the bass note; for instance, transposing a root-position C
minor chord (written, with no key signature, as <_-> on the bass c) up
by a natural 2nd gives a D minor chord (now written, with key
signature ♯♯,  as <_=>).

This is conceptually simple (the algorithm is essentially: for
accidentals [-+=], treat them as *relative to the current key
signature*) and therefore certainly possible, but tedious, to do as a
Scheme function depending on three music expressions (the \figures,
the bass line, and optionally a music expression containing the key
signature — I like to put this in a separate variable from the bass).

So before I waste too much time on this: given the number of geniuses
on this mailing-list, certainly one of you already did write the
relevant Scheme code, am I right?

-- 
Jérôme

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


Two short questions

2017-12-28 Thread Jérôme Plût
1. I am typesetting some music which is in 2/1, and mark using a cut
time signature. How is it possible with Lilypond to put a ℂ symbol for
a 2/1 time ? (see attachment, line 1)

2. In virtually all orchestra scores I play the alphabetic marks skip
the letter J. However format-mark-box-letters skips the letter I. So
at each rehearsal this confuses all my colleagues. Since they are
obviously slow to learn that I == J, does there exist a simple way to
make a format-mark-box-letters that uses I instead of J, or should I
start scheming something out of of make-markalphabet-markup?
(see attachment, line 2)
___
lilypond-user mailing list
lilypond-user@gnu.org
https://lists.gnu.org/mailman/listinfo/lilypond-user


Vertical spacing of figured bass

2017-11-03 Thread Jérôme Plût
I tried applying the contents of
http://lilypond.org/doc/v2.19/Documentation/notation/flexible-vertical-spacing-within-systems
to move the figured bass a bit closer to the staff:

\version "2.19.54"
\score { { \new StaffGroup <<
  \new Staff { \clef "F" c d e f }
  \new Lyrics \with {
  \override VerticalAxisGroup.nonstaff-relatedstaff-spacing =
  #'((basic-distance . 1) (stretchability . 0))
  } \lyrics { "c"4 "d" "e" "f" }
  \new FiguredBass \with {
  \override VerticalAxisGroup.nonstaff-nonstaff-spacing =
  #'((basic-distance . 1))
  } \figures { <5>4 <5>4 <5> <5> }
>> } \layout { indent = 0 \cm } 

Yet this stupid figured bass does not move, even if I input a
ridiculously large value for 'basic-distance.

What is happening?

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


\transpose and quoted music

2017-08-07 Thread Jérôme Plût
Let's say I am typesetting some orchestra music written for a horn in
D and want to output it for some other, more reasonably-pitched
instrument.

I entered the music in this way:

global = { \key d \minor }
cues = \relative { c'4^"Cue" c c c } \addQuote "cues" \cues
hornA = \transpose c d, \relative {
  \cueDuring #"cues" #UP s1 c'4 c c c }
% Both \cues and \hornA are consistently in concert pitch, which
% is the most idiot-proof way of entering music. The \transpose command
% is here to help entering the notes from the original source in D.

\score { \transpose c' f << \global \hornA >> }
% I can also produce a score in concert pitch for the case where the
% horn is replaced by a trombone in an emergency...

Since \transpose has this strange behaviour that it does not touch
quoted music (... but why?), the resulting PDF has the horn notes in
F, but the cues are still in concert pitch, which is less than fully
helpful to the poor horn player.

I tried some various combinations to have cues in F, such as those
below, but to no effect at all :

% this would be preferable, because it is locality-preserving
\transpose c' f << \transposition c' \global \hornA >>
% uglier (need to specify the “f” pitch twice) but would still be workable
{ \transposition f \transpose c' f << \global \hornA >> }

I know one sure-proof way to solve this (by writing a custom
\sanetranspose Scheme function that goes deep in the music and
replaces all the \cueDuring by \transposedCueDuring etc.), but this is
surely not the most elegant way. Is there a simple way to make
\transpose behave reasonably?

Thanks,

-- 
Jérôme

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


Output to single PDF and multiple MIDI files

2017-07-20 Thread Jérôme Plût
I am typesetting a multi-movement work. I want the paper output to be
in a single file (say work.pdf) and the MIDI output to be in separate
files (work-1.pdf, work-2.pdf). Is there a simple and local way to do
this?

I can do it in a not-simple-enough way:

first = \relative { c'4 c c c }
second = \relative { c'4 d e f }

\book {
  \score { \new Staff << \first >> }
  \score { \new Staff << \second >> }  % here
}
\book { \bookOutputSuffix "1"
  \score { \new Staff << \first >> \midi { } } }

\book { \bookOutputSuffix "2"
  \score { \new Staff << \second >> \midi { } } } % and here

However, this is not *local*. What I mean is that if I want to comment
out, say, the second movement (for a test run), I need to comment two
places at once (marked “here” “and here” in the source above). For
consistency and efficiency, I want all lines relating to a single
movement to be grouped together. Besides, I also have some reasons to
want to group the source of the music with the \score commands; my
preferred file structure would be:

% first movement
music = \relative { ... }
\score { ... } % paper output to work.pdf
\score { ... } % MIDI output to work-1.midi

% second movement
music = \relative { ... }
\score { ... } % paper output appended to work.pdf
\score { ... } % MIDI output to work-2.midi


I also tried a variant, resetting the name of the book:

\book { \bookOutputName "work" \score { \new Staff << \first >> } }
\book { \bookOutputName "work" \score { \new Staff << \second >> } }

There would be two consistent ways to act here: the second score
could either overwrite the first one or add some extra pages.
(Concatenation would be more useful, obviously). However lilypond
chooses a bizarre third option: the code above produces two files
named work.pdf and work-1.pdf .

Does this problem have any solution?

Thanks,

--
Jérôme Plût

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


\transposition does nothing?

2017-05-31 Thread Jérôme Plût
I am typing a horn part in F. In the attached file, \transposition
does nothing. Where should I put it: at the voice, Staff, Score level?
The documentation 
(http://lilypond.org/doc/v2.19/Documentation/notation/displaying-pitches#instrument-transpositions)
 is very unclear about this.

The file itself:


\version "2.19"

Ig = \relative {
  \time 4/4 \key g \major \partial 4
}
IcA = \transpose c g \relative {
  r4 R1 r8. c'16\f c4 r2 R1 d4\f r r2 R1*2 e2\p(^"soli" d) c4 r r2 R1*2 R1*5
}
\bookpart { \header { instrument = "Cor I (Fa)" }
\score { { \new Staff { \transposition f << \Ig \transposition f \IcA >> } } }
}
% note that this outputs a score in g major and not, as it should,
% in d major



Thanks,

-- 
Jérôme

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


Staff grouping

2017-04-14 Thread Jérôme Plût
Are there any other ways to tune the vertical spacing between staffs
other than the \paper block? What I want is the following: on the same
page,
 - first a score A (single-staff, no groups) with successive staffs
   extremely close together (about 2 or 3 staff lines of separation
   should be enough),
 - then another score B with successive staffs normally separated. (B
   is a StaffGroup score but that should not change anything to the
   problem).
Ideally the last A staff should also be very close to the first B
line. (In my application, B is a real score and A are blank lines for
comments etc.)

I tried putting two \paper blocks, one before A and one before B, but
it looks like the first one is then ignored. Is there any other way to
do this?

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


Re: Putting a \layout block in a Scheme macro

2017-01-27 Thread Jérôme Plût
> \version "2.19.54"
> 
> BlankStaff =
> #(define-void-function  (count) (integer?)
>   (let* ((blankstaff #{ \score { { s1 \break } } #} )
>  (layout #{ \layout { \context { \Staff \remove "Bar_engraver" }
> } #} )
>  (bookpart   (ly:make-book-part (make-list count blankstaff)))
>  (book   (ly:make-book $defaultpaper $defaultheader)))
> (ly:output-def-set-variable! layout 'indent (ly:mm 0))
> (ly:output-def-set-variable! layout 'ragged-right #f)
> (ly:book-add-bookpart! book bookpart)
> (ly:book-process book $defaultpaper layout (ly:parser-output-name))
> ))
> 
> \BlankStaff 4

Thanks for the answer, but:

your code produces a failed assertion in the lilypond binary:

lilypond: 
/home/gub/NewGub/gub/target/linux-x86/src/lilypond-git.sv.gnu.org--lilypond.git-release-unstable/lily/book.cc:258:
 void Book::process_score(SCM, Paper_book*, Output_def*): Assertion `0' failed.

This assertion is unclear but, looking at the source file, it
obviously means that the top-level book content was neither a Score
nor a markup list (the execution path seems to go ly:book-process ->
Book::process -> Book::process_score). I leave it to the experts from
there!

And while we are there: your solution seems to create a new book for
the score. Is that the case? How would one adapt it to incorporate the
score at top-level?




(More generally, why is it that painful to translate Lilypond
language to Scheme? I would have imagined that there would be some
(relatively) small number of primitive functions in the binary
exported from Scheme, and that Lilypond would be mainly a set of
macros on top of that - a la TeX and LaTeX. But the whole data
structures in ly/scm are completely different, and the syntax makes
absolutely no sense in either incarnation. Is there a design document
somewhere that I missed?)


-- 
Jérôme Plût

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


Putting a \layout block in a Scheme macro

2017-01-22 Thread Jérôme Plût

I want to make a Scheme macro \BlankStaff that outputs a single white
staff. (Optionnally, \BlankStaff #3 would output three of them, etc.
In particular, using “\include "blank-staff.ly"” is a non-solution).

A snippet does the white staff:
http://lilypond.org/doc/v2.19/Documentation/snippets/staff-notation#staff-notation-creating-blank-staves

However, this snippet uses a \layout { } block, which I am unable to
include in the #{ ... #} block of a Scheme function definition:

#(collect-music-for-book #{
  \score { \repeat unfold 12 { s1 } \break
  \layout { \indent = 0 \in
\context { \Staff \remove "Bar_engraver" } } } #})

produces the following error:

scm/lily-library.scm:153:5:Wrong type argument in position 1 (expecting Prob):
#

So my question is this: how does the \layout{ } block translate to
Scheme?

Thanks,

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


Re: autochange and multiple voices

2017-01-22 Thread Jérôme Plût
Decimo tertio Kalendas Februarias MMXVII scripsit Malte Meyn :
> 
> 
> Am 20.01.2017 um 18:39 schrieb Jérôme Plût:
> > Problem 1: why, on the third beat, is the alto voice (playing a g')
> > displayed on the "down" Staff?
> 
> It doesn’t in LilyPond 2.19.53, which version are you using?

I am using 2.18.2 (last stable version according to lilypond.org, also
the version packaged by standard Linux distros).

> Do you really want to have three separate voices? If so you should try
> 2.19. The results look much better IMO.

After installing 2.19 (thanks for providing an install script -
I am still somwehat surprised that it worked out-of-the-box on my
stable Debian!), it is indeed better.

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


autochange and multiple voices

2017-01-20 Thread Jérôme Plût

Consider the following score:
\new PianoStaff <<
  \new Staff = "up" {
  <> % this should do nothing...
  <<
\new Voice \relative { e''4 f e }
\new Voice \autochange \relative { a'~ a g }
\new Voice \autochange \relative { c'~ c b }
  >> }
  \new Staff = "down" { \clef F <<
\new Voice \relative { a d, e }
  >> }
>>


Problem 1: why, on the third beat, is the alto voice (playing a g')
displayed on the "down" Staff?

Problem 2: delete the line saying "<>" and recompile. Now
all hell breaks loose: the score acquires a third staff, which even
eats the soprano on the third beat...
(on the other hand, the chords on beats 1 and 2 are now nicer).
Why? (I guess that the "up" Staff had a default, empty voice
through the "<>" - is that correct? but it does not explain all).

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


Quoting/cueing clef changes

2016-09-09 Thread Jérôme Plût

Hi everybody,

I am typing parts for a (quite long) orchestral score. I would like to
include a cue voice that is quoteded (via \cueDuring, \quoteDuring, or
similar constructs) by other voices. Since the same cue voice is
common to everybody, I want to put as much info in it as possible.

For example:

commonCues = {
  \clef G a''1^"Violini"
  \clef F d1^"Timpani"
  s1
}
\addQuote "common" { \commonCues }

clarinetti = \relative {
  \cueDuring #"common" #0 R1*2 c'1
}

tromboni = \relative {
  \cueDuring #"common" #0 R1*2 c'1
}

The problem is that the resulting score does not include the clef
changes. (For the markup, I can easily fix that by adding
text-script-event to quotedCueEventTypes; however, a clef change
apparently does not produce *any* event.)

I could of course, in my example above, split each \cueDuring in two
\cueDuringWithClef, but that is exactly what I am trying to avoid:
namely, I really want all the information about the common cues to,
well, remain in commonCues. (In a full symphony, that "fix" would be
*extremely long* and error-prone).

Is there any way I could do this?

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


Cue notes in color?

2016-07-12 Thread Jérôme Plût
I would like to have the cues displayed in a different color from the
remainder of the score.

I tried the following (note my strong canon-writing skills) :

dux = {
  a4 a a a
}
comes = {
  \override NoteHead.color = #blue
  \cueDuring #"dux" #UP R1
  \revert NoteHead.color
  e4 e e e
}
\addQuote "dux" { \dux }

\score {
  << \new Staff { \dux } \new Staff { \comes } >>
  \layout { } }

However, all notes are still black.
I also tried some variants:
 - enclosing the whole block in a \new CueVoice: no effect;
 - with \override only: I get black A notes and blue E notes, which is
   quite the converse of what I want...
 - with CueVoice.NoteHead.color: both A and E are black, and now E are
   small.
 - without any \override and \revert: same as above;

How should I do this?

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


Add a little horizontal space?

2016-05-10 Thread Jérôme Plût

Is there a simple way to add a little horizontal space between two
notes (actually, two time moments - preserving staff alignment) in a
score? I want to change something like this: —♩—♫—  to something like
—♩———♫— .

Does there exist an equivalent of TeX's \hskip command? I looked
through the “horizontal spacing” sections of the documentation, and
all I can find is a few words about changing the defaults, and nothing
about punctually inserting a space. (Changing the defaults is *not*
what I want: I just want a space in that one place, the defaults are
fine in all the other places!).

Thanks in advance,

-- 
Jérôme Plût

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


\time command

2015-12-20 Thread Jérôme Plût

% -- first file
\score { \time 4/4 c1 }

error: syntax error, unexpected NOTENAME_PITCH

% -- second file
\score \relative c' { \time 4/4 c1 }

error: syntax error, unexpected MUSIC_FUNCTION, expecting '{'

Why does this not compile? The manual has no indication on where the
\time command is accepted, and plainly says that \score, as a
top-level command, is allowed. This is Lilypond 2.18.2, which I know
is not bleeding-edge new (but this is what Debian stable has, and this
not likely to depend much on Lilypond version).

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


Re: \time command

2015-12-20 Thread Jérôme Plût
Decimo tertio Kalendas Ianuarias MMXVI scripsit Noeck :
> \score { { \time 4/4 c1 } }

Thanks to all three of you for your exceptionnally fast and precise
answers! Indeed, this helped a lot (I usually put a lot of junk
between \score {... } and the actual notes, which helped with the
braces, and did not notice where it failed this time).

-- 
    Jérôme Plût

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


Rehearsal mark number

2015-10-24 Thread Jérôme Plût
Is there a way, from within Scheme, to access (read/write) the following:
 - the current rehearsal \mark number;
 - (optionnally) the current value of Score.markFormatter?

The reason I am asking this is that I am typesetting a score where the
mark J *and K* are skipped (I guess that this is because of Italian
foundries not having this letter in their alphabet, but that's a
digression!). Instead of defining a new format-mark-letters-but-K
functions, I would prefer being able to manually set the mark number
(this would be applicable to more cases!).

Thanks,

-- 
Jérôme

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


Re: 2.18.2 - Thoughts so far

2015-10-05 Thread Jérôme Plût
Quarto Nonas Novembres MMXV scripsit Ivan Kuznetsov :
> > How would somebody like me gain access to vi (and other Unix-like tools)?
> 
> By using Lilypond under Linux.

For the specific case of vi(m), there is a perfectly fine version of
gvim for Windows (this is usually the very first program I install
when I get a new, Windows machine).

If you don't like a modal editor, you may even make it less modal by
using "easy mode" (*) by launching it as "gvim -y". Then it's
more-or-less an enhanced Notepad (but you may still access all of
vi(m)'s power).

(*) (that's the official name BTW, they might as well have called it
"cheat mode enabled")

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


Re: Pull in external LilyPond files into a score of movements

2015-08-04 Thread Jérôme Plût
Pridie Nonas Augustas MMXV scripsit unlabeled :
 Thank you all so much, i'm just getting into lilypond and trying to figure
 out how to make it work for my workflow. i have a solution i like to this,
 or similar, issue, which i will share soon. meanwhile, i have a question
 that will help me finish it: 
 is there such a thing as a null0if, or a ternary operator that can be used
 inline? I want to do something like this:
 
 \header {
 title = \title
   }
 
 but if \title hasn't been defined (because I'm running an ily outside its
 container), then it fails. Would like to do something like title = \title ||
  (to borrow javascript syntax - use \title var if it exists, else use an
 empty string).
 
 I guess if not, I can write a scheme function, but haven't delved into that
 yet, and trying to figure out the simplest approach. 

I think the easiest way is to scheme it:
(warning, I cannot test the code below right now):

#(if (not (defined? 'title)) (set! title ))

You can even meta-scheme it:

#(define (define-default symbol)
  (if (not (defined? symbol)) (module-add! (current-module) symbol )))

#(map define-default '(title subtitle instrument composer))


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


Temporary change to macro definition

2015-08-04 Thread Jérôme Plût
In the attached file, I made a macro \count such that
a^\count a^\count a^\count is understood as a^1 a^2 a^3...

I also wrote a macro \repeatWithCount such that
\repeatWithCount 3 { a^\acount } also evaluates to a^1 a^2 a^3.

However, (for aesthetic reasons!) I would prefer to use \count in both
situations. Is it possible to modify the \repeatWithCount function so
that it basically says
(set! count count-auto)
(do the \repeatWithCount work)
(set! count count-manual)
 ?

If I directly define
repeatWithCount = #(define-music-function (parser location n music) ...)
then the 'music' parameter is evaluated before repeatWithCount gets
its chance to redefine \count. If this were TeX, I could say something like

\def\repeatWithCount{\def\count\countAuto \RealRepeatWithCount}
\def\RealRepeatWithCount#1#2{ % do the work, then
  \def\count\countManual}

However, trying something like this (i.e. returning
#{ \RealRepeatWithoutCount #}) does not work in Lilypond. Is there a
way to do this?

Thanks,

-- 
Jérôme
\version 2.18.2
% Counting notes %
#(begin

; manual counting
(define music-note-count 0)
(define czero (define-music-function (parser location) ()
  (set! music-note-count 0) #{ #}))
(define cset (define-music-function (parser location x) (number?)
  (set! music-note-count x) #{ #} ))

(define (make-count-markup n)
  (markup #:fontsize -1 #:bold #:sans (number-string n)))
(define counter-manual (define-music-function (parser location) ()
  (set! music-note-count (+ 1 music-note-count))
  (make-music 'TextScriptEvent 'direction 1 'text
(make-count-markup music-note-count))
))

; automatic counting
(define counter-symbol 'Counter)
(define counter-auto (make-music 'TextScriptEvent 'direction 1
   'text counter-symbol))
(define acount counter-auto)
(define count counter-manual)

(define (substitute-count music n)
  (let* (
(name (ly:music-property music 'name))
(prop (ly:music-mutable-properties music))
(out (list name))
(add-out! (lambda (s v) (set! out (append! out (list s v)
  ) (map (lambda (x) (let* (
  (s (car x))
  (v (cdr x))
) ; inner let*
(if (eq? s 'element)
  (set! v (substitute-count v n)))
(if (member s '(elements articulations))
  (set! v (map (lambda (y) (substitute-count y n)) v)))
(if (and (eq? name 'TextScriptEvent) (eq? s 'text) (eq? v counter-symbol))
  (set! v (make-count-markup n)))
(add-out! s v))) ; lambda
  prop)
  (apply make-music out)
))

(define (repeat-with-count n music)
  (make-music 'SequentialMusic 'elements
(map (lambda (i) (substitute-count music (+ 1 i))) (iota n))
  )
)

(define repeatWithCount (define-music-function (parser location n music)
  (number? ly:music?)
  (make-music 'SequentialMusic 'elements
(map (lambda (i) (substitute-count music (+ 1 i))) (iota n))
  )
))
) % begin

%
foo = { a4^\count a^\count a^\count }
qux = \repeatWithCount 5 { c'^\acount }

\foo \qux


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


Re: Changing staff size

2015-08-03 Thread Jérôme Plût
Quinto Kalendas Augustas MMXV scripsit Kevin Barry :
 Hi Jerome,
 
 The most relevant part of the manuals for your question is probably here:
 http://lilypond.org/doc/v2.18/Documentation/notation/
 changing-context-default-settings
 
 It should answer all of your questions (and there is even an example of how to
 store a \with block in a variable.

Thanks for your answer. This explains \with a bit more for me.
However, \layout is still a mystery, even after reading through
http://lilypond.org/doc/v2.18/Documentation/notation/the-layout-block
.

I have a few questions about \layout:
 * why does, inside a \layout {} block, the macro \context behave
   differently? Instead of \context Staff = name, I now have to type
   \context { \Staff }, which is surprising, and leads to:
 * is there a way to point to a specific staff to change the settings
   only for this one? \layout { \context { \Staff = name } }
   does not work, cf. example below:

\version 2.18.2
reduce = \with { fontSize = #-3 }
\score {
  \new StaffGroup 
  \new Staff = a { a a a }
  \new Staff = b { b b b }
  
  \layout { \context { \Staff = a \reduce } }
}

 * is there a way, that I missed, to store in a variable a \with or a
   \layout block, and then to apply this *to one element of a score
   only*? The answer your mail pointed to applied it to the whole
   score.
   (Overcomplicated idea that might work: is it, for example, possible
   to clone the Staff context into a SmallerStaff context, and to
   change the settings for that one?)

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


Changing staff size

2015-07-27 Thread Jérôme Plût
I saw in the documentation how to change the size of a single staff
(such as the solist part in a piano accompaniment score) with the
\with command. However, since I might need to do this for several
scores, I would like to factor out the \with snippet in a macro.

My question is therefore: is there a simple way to write a macro such
that
\new Staff \mymacro  ... 
(or \new Staff  \mymacro ... )
would be equivalent to
\new Staff \with { [some properties set] }

 ? (I know about magnifyStaff in 2.19, but I only have 2.18 here).

Also two, maybe-related, questions:
 - what does the \with block do precisely? The index link for
   \with sends to
   
http://lilypond.org/doc/v2.18/Documentation/notation/modifying-context-plug_002dins#index-_005cwith-1
 ,
   which gives a few examples, but not the definition, of \with.

 - as I understand it, changing only fontSize and
   StaffSymbol.staff-space only reduces a single staff, but not the
   inter-staff symbol. I may access this via the StaffGrouper object,
   but what if the piano accompanies two instruments ? Say:
\new StaffGroup 
  \new Staff \oboe
  \new Staff \clarinet
  \new PianoStaff  \new Staff \righthand \new Staff \lefthand 


Here, I would want to reduce the space between \oboe and \clarinet,
but not between \righthand and \lefthand.


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


Re: Custom footers

2013-03-20 Thread Jérôme Plût
Decimo tertio Kalendas Apriles MMXIII scripsit Thomas Morley :
 in the code below you'll see increasing page-numbers throughout the
 book as usual.

Ooh, now that I have had the time to read your code, I see what you
did, and I like it. The \on-the-fly side-effect is devious (and
un-Scheme-like, but who cares). Thanks!

 Though, I didn't manage to code (1/3) for consecutive bookparts,
 because I didn't understand how to get or calculate the
 bookpart-last-page-number.

The simplest way to do it would be the TeX way: saving the page count
for each section in a .aux file and reading this again on second
compilation. Unless, of course, the (open) Scheme function is disabled
in Lilypond. I will have a try at this.

-- 
Jérôme

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


Re: Custom footers

2013-03-19 Thread Jérôme Plût
Decimo quinto Kalendas Apriles MMXIII scripsit james :
 they come from the header.

That's what I figured from the documentation about footer markup. But
this does not answer my question: is there a way to put in there, for
example, a counter that gets incremented at each page and reset at
each bookpart (or some more complicated stuff such as total page count
for the book or bookpart)? This is possible for example in TeX as the footer
markup is actually evaluated on each page. Is there a way to do it in
Lilypond?

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


Re: Custom footers

2013-03-18 Thread Jérôme Plût
Postridie Idus Martias MMXIII scripsit Thomas Morley :
 Where do you store the values you want have printed?
 How is the structure of your file(s).
 Which is your version?
 etc
 
 Please post a compilable example.

I have access to lilypond 2.12.3 (Debian stable).

I of course already looked in the documentation page
http://lilypond.org/doc/v2.12/Documentation/user/lilypond/Custom-titles
and this was why I referred to the extremely poor (and ugly) language of
\on-the-fly and \fromproperty.


Where do I store the values: that is actually part of the question.
And I'm also not able to post a compilable example since that would
mean that the problem would be solved...

Basically, I would like something like the output of the following
code, except that the evenFooterMarkup should not be typed by hand.

% code follows
theme = \relative c'' { c4 d e }
bass = \relative c { c4 d e }

\pageBreak \markup { Title } 
\new Staff { \set Staff.instrumentName = Theme \theme }
\paper { evenFooterMarkup = \markup { Title - 1 - Theme (1/1) } }

\pageBreak \markup { Title }
\new Staff { \set Staff.instrumentName = Bass \bass }
\paper { evenFooterMarkup = \markup { Title - 2 - Bass (1/1) } }

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


Custom footers

2013-03-15 Thread Jérôme Plût
I don't understand how to define custom footers. Is there a hook in
odd/evenpagefooter where I can plug a Scheme function, or are they
limited to the very poor language of \fromproperty and \on-the-fly?

What I want to do in my case: I have a big PDF file containing all
parts for a big piece. I want the page footer to contain something
like

Title - page 33 - Tenor Trombone (1/3)

OK, so counting the number of pages of an individual part might be bit
optimistic, but hey, TeX can do it, so why not. But I hope to at least
be able to add the local page number.

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


Is ly:music? magic?

2013-02-04 Thread Jérôme Plût
Given the following file:

---

#(begin
(define ((K x) y) x)
(define testA (define-music-function (top location x) (ly:music?)
  (make-music 'SequentialMusic 'void #t)))

; now we try to be clever
(define testB (define-music-function (top location x) ((K #t))
  (make-music 'SequentialMusic 'void #t)))
)

\testA a % ok
\testB #'foo % ok
\testB a % fail

--

The file fails to compile only on the third line, \testB a . So
obviously, using ly:music? as a type predicate accepts more inputs than
the always-true predicate. The only explanation would be that the
parser knows that it is expecting a music expression; in other words,
(ly:music?) is not only a predicate.

By the way, (define test1 ly:music?) works as ly:music? in the example
above, whereas (define (test2 x) (ly:music? x)) does not.

So: is there a way to define a polymorphic music function (as testB
should be in the above example)?

--
Jérôme Plût

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


Conditional compilation

2013-01-30 Thread Jérôme Plût
I am writing some ensemble music and want the file to compile in two
modes: with -dfull, compile all individual parts; without it, compile
only the conductor part (for debugging). This is probably a FAQ but I
cannot find an answer on the site: what is the preferred way to
implement conditional compilation in Lilypond-guile? I naively tried
several variants of

\bookpart { \relative c' { c4 e g } }
#(if (ly:get-option 'full) #{
\bookpart { \relative c' { c4 d e } }
#})

but it looks like the second \bookpart is not exported to the
top-level lilypond. I can more or less reimplement \bookpart in Scheme
(why is it not already a Scheme construct anyway?) but there is
certainly a simpler solution.

Also, bonus points for shortness of solution: I am actually writing
lots of small pieces and don't mind including some Scheme in all of
them as the files already include a common header, but I would very
much like to keep the files themelves short and human-readable.

Thanks in advance!

-- 
Jérôme Plût

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


Re: prall with accidental

2013-01-21 Thread Jérôme Plût
Decimo tertio Kalendas Februarias MMXIII scripsit Werner LEMBERG :
 Yeah, this looks like a good syntax suggestion.  Is a Scheme solution
 possible, or does this need a C++ extension?

It seems that this requires a C++ extension.
Namely, \key only generates a KeyChangeEvent, so Scheme macros cannot
access the current key signature. And \key is a C++ primitive, so
replacing it with a Scheme function will not work.

A nice way to make this work would then be to make the current key
signature available to Scheme functions and make a generic function
such as
 b \ornament #'prall { cis }
and then shortcuts (pralltoo foo) = (ornament #'prall foo) etc.

(By the way, couldn't this lead to mainstreaming articulate.ly ?)

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


Re: Headers Placement

2013-01-19 Thread Jérôme Plût
Decimo quinto Kalendas Februarias MMXIII scripsit Thomas Morley :
 LilyPond supports two kinds of headers: book-header and score-header.
 
 a) book-header (top-level!):
 
 \header { ... }
 \score { ... }
 
 b) score-header:
 
 \score {
   some-music
   \header { ... }
 }

I was going to ask more or less the same question as Mark, so thanks
for the explanation. I find the whole header system extremely
confusing (for example, why must the score-header be at the *end* of
the corresponding score, this is a mystery) and would prefer
sectioning commands that work in the LaTeX way, inserting markup where
they are called instead of defining some magic values:

\title #'((title . Concerto) (author . Me))

\title #'((section . I. Allegro ma non troppo))

\score { ... }

\title #'((section . II. Andantino))

\score { ... }

This I can do with Scheme, but maybe something equivalent already
exists?

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