Re: search and replace on all included files on compile

2024-03-06 Thread Michael Winter via LilyPond user discussion
perfect thanks!

Mar 6, 2024, 14:35 by lilyp...@hillvisions.com:

> On 2024-03-06 10:56 am, Michael Winter via LilyPond user discussion wrote:
>
>> I have a programmatically generated score and am now realizing that I want 
>> to make a small tweak to text markups that are throughout the score in 
>> multiple files that are included at multiple levels. 
>>
>> " 1↑"  replace with " 1" (e.g. remove the up arrow when it is preceded by a 
>> 1)
>>
>> Is it possible to do this with a global search and replace on compile such 
>> that I do not need to edit each individual file (of which there are 
>> hundreds) manually?
>>
>
> LilyPond does support basic replacements for text markup:
>
> 
> \paper {
>  #(add-text-replacements! '(("1↑" . "1")))
> }
> 
>
>
> -- Aaron Hill
>



Re: search and replace on all included files on compile

2024-03-06 Thread Michael Winter via LilyPond user discussion
double thanks

Mar 6, 2024, 14:36 by j...@abou-samra.fr:

>
> Try
>
> \version "2.24.2"\paper {  #(add-text-replacements!'(("1↑" . "1")))}{ 
> c'^\markup "1↑" }
>
> Best,
>
>
> Jean
>
>

Re: search and replace on all included files on compile

2024-03-06 Thread Michael Winter via LilyPond user discussion
Thanks Curt,

Unfortunately, I have already manually edited to the extent that tweaking the 
generating program would result in a lot of lost work. Typically I try not to 
edit post generation, but that was not possible in this particular case.

I am on arch linux. And yes, I am sure it would be possible to do it through 
the terminal, but I am trying to avoid destructively editing the files (simply 
out of fear even though I could always roll back). I would be replacing only a 
few unicode characters, but many, many occurrences.

Best,

Michael

Mar 6, 2024, 14:22 by pla...@fishlet.com:

> Michael,
>
> You mentioned that the score is programmatically generated. If so, can
> you modify the generating program and regenerate the score?
>
> Otherwise, a more complete example would be nice. Are you trying to do a
> simple string replacement of a few (unicode) characters, or are you
> trying to replace larger chunks of LilyPond code?
>
> It would also help to know what operating system environment you are
> using. The answer may be to make a copy of the whole tree and run a
> search/replace utility recursively on all the files.
>
> Regards,
> Curt
>
> On 3/6/2024 10:56 AM, Michael Winter via LilyPond user discussion wrote:
>
>> I have a programmatically generated score and am now realizing that I
>> want to make a small tweak to text markups that are throughout the
>> score in multiple files that are included at multiple levels.
>>
>> " 1↑"  replace with " 1" (e.g. remove the up arrow when it is preceded
>> by a 1)
>>
>> Is it possible to do this with a global search and replace on compile
>> such that I do not need to edit each individual file (of which there
>> are hundreds) manually?
>>
>> I could do this through the terminal, but I would rather not
>> destructively edit the files.
>>
>> Thanks in advance!
>>
>> Best,
>>
>> Michael
>>



search and replace on all included files on compile

2024-03-06 Thread Michael Winter via LilyPond user discussion
I have a programmatically generated score and am now realizing that I want to 
make a small tweak to text markups that are throughout the score in multiple 
files that are included at multiple levels. 

" 1↑"  replace with " 1" (e.g. remove the up arrow when it is preceded by a 1)

Is it possible to do this with a global search and replace on compile such that 
I do not need to edit each individual file (of which there are hundreds) 
manually?

I could do this through the terminal, but I would rather not destructively edit 
the files.

Thanks in advance!

Best,

Michael

Re: function to force accidentals on a subset of notes

2023-10-31 Thread Michael Winter via LilyPond user discussion
This is what happens for me too. I think it has something to do with all the 
other functions I am using. 

Oct 30, 2023, 21:25 by l...@gmx.de:

>
> Hi Michael,
>
> Am 30.10.23 um 10:42 schrieb Michael  Winter:
>
>> But  I am confused about what you said. For me, it is posting the  
>> accidental on tied notes after line breaks.
>>
>
> No I'm confused. :-) If I do
>
>
>
> \transpose a c' \relative
>  {
>    a8 gis~ gis g fis g gis a
>    gis1~ \break gis2 gis
>  }
>
>
>
> in my example file, I get:
>
>
>
>
>
> (To wit, no natural sign on the first b in measure 3).
>
>
> Is this different for you?
>
>
> Lukas
>
>



Re: function to force accidentals on a subset of notes

2023-10-30 Thread Michael Winter via LilyPond user discussion
Thanks!

This seems to work quite well : )

But I am confused about what you said. For me, it is posting the accidental on 
tied notes after line breaks.

Best,

Michael

Oct 28, 2023, 22:40 by l...@gmx.de:

> Hi Michael,
>
>> Thanks Lukas!
>>
>> This works but also forces the accidental on tied notes.
>>
>
> Sorry for not getting back to you sooner.
>
> The following version registers ties and removes our auto-generated 
> accidentals for notes in which a tie ends. (It's a bit overeager and also 
> removes tied accidentals after line breaks, so we get a behaviour as if 
> Accidental.hide-tied-accidental-after-break is set to ##t. Please give word 
> if you want me to change that.)
>
> Lukas
>
> \version "2.24.0"
>
> forced-accidentals-pitches =
> #(music-pitches #{ bes b #})
>
> #(define (diatonic-pitch-class= p q)
>    (and (= (ly:pitch-notename p) (ly:pitch-notename q))
>     (= (ly:pitch-alteration p) (ly:pitch-alteration q
>
> Force_accidentals_engraver =
> #(lambda (context)
>    (let
>     ((ties '())
>  (affected-note-events '()))
>    (make-engraver
>     (end-acknowledgers
>  ((tie-interface engraver grob source-engraver)
>   (set! ties (cons grob ties
>     ((stop-translation-timestep engraver)
>  (for-each
>   (lambda (tie)
>     (let* ((right-notehead (ly:spanner-bound tie RIGHT))
>    (right-notehead-cause (ly:grob-property right-notehead 
> 'cause)))
>   (if (member right-notehead-cause affected-note-events)
>   (ly:grob-suicide!
>    ;;; the accidental grob should be guaranteed to
>    ;;; exist since we forced it into existence...
>    (ly:grob-object
>     right-notehead 'accidental-grob)
>   ties)
>  (set! ties '())
>  (set! affected-note-events '()))
>     (listeners
>  ((note-event engraver event)
>   (when (member (ly:event-property event 'pitch)
>     forced-accidentals-pitches
>     diatonic-pitch-class=)
>     (ly:event-set-property! event 'force-accidental #t)
>     (set! affected-note-events
>   (cons event affected-note-events
>
> \layout {
>   \context {
>     \Voice
>     \consists #Force_accidentals_engraver
>   }
> }
>
> \transpose a c' \relative
> {
>   a8 gis~ gis g fis g gis a
>   gis1~ gis2 gis
> }
>



Re: function to force accidentals on a subset of notes

2023-10-22 Thread Michael Winter via LilyPond user discussion
Thanks Lukas!

This works but also forces the accidental on tied notes.

Best,

Michael

Oct 22, 2023, 10:19 by l...@gmx.de:

>
> Hi Michael,
>
>
> this is easily accomplished with an custom engraver. (I perfectly  
> understand that the terms "easily" and "custom engraver" don't  seem to 
> go well together at first - I thought so for many years as  well -, but 
> after some getting used to it, the concept is actually  quite simple and 
> elegant.)
>
>
>
> \version "2.24.0"
>  
>  forced-accidentals-pitches =
>  #(music-pitches #{ bes b #})
>  
>  #(define (diatonic-pitch-class= p q)
>     (and (= (ly:pitch-notename p) (ly:pitch-notename q))
>      (= (ly:pitch-alteration p) (ly:pitch-alteration q
>  
>  Force_accidentals_engraver =
>  #(lambda (context)
>     (make-engraver
>      (listeners
>   ((note-event engraver event)
>    (if (member (ly:event-property event 'pitch)
>    forced-accidentals-pitches
>    diatonic-pitch-class=)
>    (ly:event-set-property! event 'force-accidental #t))
>  
>  \layout {
>    \context {
>      \Voice
>      \consists #Force_accidentals_engraver
>    }
>  }
>  
>  \transpose a c' \relative
>  {
>    a8 gis g fis g gis a4
>  }
>
>
>
> Lukas
>
> Am 21.10.23 um 11:37 schrieb Michael  Winter via LilyPond user discussion:
>
>> Thanks Jean,
>>
>> I am not sure I completely follow.
>>
>> Lets say I have a music sequence:
>>
>> a b c d e f g a bes c d e f g ...
>>
>> How do I apply what you have written as a functionto only show the 
>> flats and naturals for b and bes. Again. I donot want to apply this 
>> to individual notes.
>>
>> Sorry if I am missing something.
>>
>> Best,
>>
>> Michael
>>
>>
>> Oct 21, 2023, 01:37 by >> j...@abou-samra.fr>> :
>>
>>>
>>> Try
>>>
>>> \displayMusic c'!
>>>
>>> This shows you that the >>> !>>>  syntax corresponds to  setting
>>>   the >>> force-accidental>>>  property to true. Thus, if  you 
>>> have  identified the note events you want to force accidentals  
>>> on, you can do
>>>
>>> (ly:music-set-property! the-note-event 'force-accidental #t)
>>>
>>> on each of them.
>>>
>>>
>>> Best,
>>>
>>>
>>> Jean
>>>
>>>
>>
>>



Re: function to force accidentals on a subset of notes

2023-10-21 Thread Michael Winter via LilyPond user discussion
Thanks Jean,

I am not sure I completely follow.

Lets say I have a music sequence:

a b c d e f g a bes c d e f g ...

How do I apply what you have written as a function to only show the flats and 
naturals for b and bes. Again. I do not want to apply this to individual notes.

Sorry if I am missing something.

Best,

Michael

Oct 21, 2023, 01:37 by j...@abou-samra.fr:

>
> Try
>
> \displayMusic c'!
>
> This shows you that the > !>  syntax corresponds to settingthe > 
> force-accidental>  property to true. Thus, if you haveidentified the note 
> events you want to force accidentalson, you can do
>
> (ly:music-set-property! the-note-event 'force-accidental #t)
>
> on each of them.
>
>
> Best,
>
>
> Jean
>
>



function to force accidentals on a subset of notes

2023-10-20 Thread Michael Winter via LilyPond user discussion
I have a piece that is in the following scale:

c d e fis g aes bes b

Is it possible to force the accidentals just for the bes and the b?

But here is the catch...
I am both transposing the part and respelling pitch-classes as show below. The 
scale above is actually the resulting printed set of notes. The music is 
already generated and I would not want to have to do this manually for each 
occurance.

Thanks in advance,

Michael


transposePitchClasses =
#(define-music-function (scaleA scaleB music) (ly:music? ly:music? ly:music?)
  (let* ((scaleA (ly:music-property scaleA 'elements))
 (scaleB (ly:music-property scaleB 'elements))
 (scaleA (map (lambda (x) (ly:music-property x 'pitch)) scaleA))
 (scaleB (map (lambda (x) (ly:music-property x 'pitch)) scaleB))
 (classesA (map (lambda (p) (cons (ly:pitch-notename p) 
(ly:pitch-alteration p))) scaleA)))
  (map-some-music
    (lambda (m)
  (let ((p (ly:music-property m 'pitch)))
    (if (not (null? p))
    (let* ((nn (ly:pitch-notename p))
   (oct (ly:pitch-octave p))
   (alt (ly:pitch-alteration p))
   (pos (list-index (lambda (x) (and (= (car x) nn) (= (cdr x) 
alt))) classesA)))
    (if pos
  (let* ((p2 (list-ref scaleA pos))
 (oct2 (ly:pitch-octave p2))
 (p3 (list-ref scaleB pos))
 (new-pitch (ly:pitch-transpose p3 (ly:make-pitch (- oct 
oct2) 0
  (ly:music-set-property! m 'pitch new-pitch)))
  m)
  #f)))
   music)
 music))
\new Staff \with {
  instrumentName = #"synth I (2)"
  shortInstrumentName = #"synI"
  \remove "Time_signature_engraver"
    }
    <<
  \transpose a c'
  \transposePitchClasses {a b cis dih e fih geh gis} {a b cis dis e f g gis}
  \include "includes/ammann_part_6.ly" %this is the music
    >>


Re: custom replace/map of one set of pitches to another

2023-08-31 Thread Michael Winter via LilyPond user discussion
Thank you Valentin for this solution and the following explanation why it is 
likely safer.

All responses have been much appreciated.

Best,

Michael

Sep 1, 2023, 00:15 by valen...@petzel.at:

> Hi Michael,
>
> some time ago I created a function for exactly that for a stackexchange 
> question:
> https://music.stackexchange.com/questions/127175/lilypond-transpose-a-sequence-to-modes-with-different-intervallic-structure
>
> Essentially it introduces a function to map one scale to another, and it does 
> so by basepitch to retain alteration. One could easily adapt this function to 
> match by base pitch and alteration:
>
> transposePitchClasses =
> #(define-music-function (scaleA scaleB music) (ly:music? ly:music? ly:music?)
>  (let* ((scaleA (ly:music-property scaleA 'elements))
>  (scaleB (ly:music-property scaleB 'elements))
>  (scaleA (map (lambda (x) (ly:music-property x 'pitch)) scaleA))
>  (scaleB (map (lambda (x) (ly:music-property x 'pitch)) scaleB))
>  (classesA (map (lambda (p) (cons (ly:pitch-notename p) (ly:pitch-
> alteration p))) scaleA)))
>  (map-some-music
>  (lambda (m)
>  (let ((p (ly:music-property m 'pitch)))
>  (if (not (null? p))
>  (let* ((nn (ly:pitch-notename p))
>  (oct (ly:pitch-octave p))
>  (alt (ly:pitch-alteration p))
>  (pos (list-index (lambda (x) (and (= (car x) nn) (= (cdr x) 
> alt))) classesA)))
>  (if pos
>  (let* ((p2 (list-ref scaleA pos))
>  (oct2 (ly:pitch-octave p2))
>  (p3 (list-ref scaleB pos))
>  (new-pitch (ly:pitch-transpose p3 (ly:make-pitch (- 
> oct oct2) 0
>  (ly:music-set-property! m 'pitch new-pitch)))
>  m)
>  #f)))
>  music)
>  music))
>
> \transposePitchClasses {d fih g aih} {dih f gis a}
> { c' cis' d' dis' f' fih' fis' g' a' aih' }
>
> Am Donnerstag, 31. August 2023, 12:53:26 CEST schrieb Michael Winter via 
> LilyPond user discussion:
>
>> I would like to do something (hopefully simple), which is basically a custom
>> find and replace for a set of notes in an entire score.
>>
>> For example {c cis d dis fih g aih} -> {c cis dih dis f gis a}
>>
>> So basically on arbitrary list of pitches / scale  to another.
>>
>> Is this possible without writing a custom function. If not, any hints on how
>> to tackle the problem would be much appreciated. Thanks in advance.
>>
>> -Michael
>>



Re: custom replace/map of one set of pitches to another

2023-08-31 Thread Michael Winter via LilyPond user discussion
That is very helpful. Thank you. I will ping again if I have any further 
questions.

Aug 31, 2023, 14:35 by l...@gmx.de:

> Hi Michael,
>
> over time, I found that doing something like this in an engraver (as opposed 
> to a music function) is actually much easier and conceptually clear, in spite 
> of the seeming difficulty of the engraver syntax. The advantage of using an 
> engraver being that you see the "actual" pitches and don't have to fight with 
> problems of \relative, \transpose and so on.
>
> \version "2.24.0"
>
> pitch-replace-dictionary =
> #(list
>   (cons #{ c #} #{ cis #})
>   (cons #{ d #} #{ des #})
>   )
>
> #(define (pitch-class= p q)
>    (and
>     (= (ly:pitch-notename p) (ly:pitch-notename q))
>     (= (ly:pitch-alteration p) (ly:pitch-alteration q
>
> Pitch_replace_engraver =
> #(lambda (context)
>    (make-engraver
>     (listeners
>  ((note-event engraver event)
>   (let*
>    ((pitch (ly:event-property event 'pitch))
>     (rule (assoc pitch pitch-replace-dictionary pitch-class=)))
>
>    (if rule
>    (ly:event-set-property!
>     event 'pitch
>     (ly:make-pitch (ly:pitch-octave pitch)
>    (ly:pitch-notename (cdr rule))
>    (ly:pitch-alteration (cdr rule))
>
> \layout {
>   \context {
>     \Score
>     \consists #Pitch_replace_engraver
>   }
> }
>
> \relative {
>   c'4 d e c8 8
>   \transpose f c \relative {
>     f'4 g a
>   }
> }
>
> This engraver can also be added to just a single score (\layout inside \score 
> {}) or even a single Staff or Voice. At the moment, the replacement 
> dictionary is global, but this could be changed if needed.
>
> At the moment the mechanism I chose is too crude to do replacements that 
> involve changing the pitch-octave (eg from c to b,). Do you need this?
>
> Lukas
>
> Am 31.08.23 um 12:53 schrieb Michael Winter via LilyPond user discussion:
>
>> I would like to do something (hopefully simple), which is basically a custom 
>> find and replace for a set of notes in an entire score.
>>
>> For example {c cis d dis fih g aih} -> {c cis dih dis f gis a}
>>
>> So basically on arbitrary list of pitches / scale to another.
>>
>> Is this possible without writing a custom function. If not, any hints on how 
>> to tackle the problem would be much appreciated. Thanks in advance.
>>
>> -Michael
>>



Re: custom replace/map of one set of pitches to another

2023-08-31 Thread Michael Winter via LilyPond user discussion
I am now realizing that it would be useful to have this both at the level of 
the entire score and individually for each part.

Aug 31, 2023, 12:53 by mwin...@unboundedpress.org:

> I would like to do something (hopefully simple), which is basically a custom 
> find and replace for a set of notes in an entire score.
>
> For example {c cis d dis fih g aih} -> {c cis dih dis f gis a}
>
> So basically on arbitrary list of pitches / scale  to another.
>
> Is this possible without writing a custom function. If not, any hints on how 
> to tackle the problem would be much appreciated. Thanks in advance.
>
> -Michael
>



custom replace/map of one set of pitches to another

2023-08-31 Thread Michael Winter via LilyPond user discussion
I would like to do something (hopefully simple), which is basically a custom 
find and replace for a set of notes in an entire score.

For example {c cis d dis fih g aih} -> {c cis dih dis f gis a}

So basically on arbitrary list of pitches / scale  to another.

Is this possible without writing a custom function. If not, any hints on how to 
tackle the problem would be much appreciated. Thanks in advance.

-Michael

Re: two lv ties on merged notehead

2020-06-04 Thread Michael Winter via LilyPond user discussion
Thanks all, 

Seems like there are many solutions. Also know I understand the problem so will 
be able to look for such things in the future.

Best,

Michael

Jun 4, 2020, 04:20 by r...@dabble.ch:

> Michael Winter wrote:
>
> It seems that when a notehead is merged in two voices no matter what you do 
> you, lilypond only adds on lv tie. 
> There are indeed two lv ties.  But in your example they are using the same 
> (default) settings and so end up exactly superimposed.
>
> Try giving the one of them a difference:
>
>  d,4-\tweak direction #UP \laissezVibrer
>
>
> Cheers,
> Robin
>



two lv ties on merged notehead

2020-06-03 Thread Michael Winter via LilyPond user discussion
It seems that when a notehead is merged in two voices no matter what you do 
you, lilypond only adds on lv tie. Is there a way to force 2 lv ties?

<<{ d,4\laissezVibrer ^ \markup{ 0.0 }  } \new Voice { \voiceTwo 
d,4\laissezVibrer  }>>

Thanks in advance.

-Michael

Re: forced \break or \pageBreak with ragged-right

2020-06-02 Thread Michael Winter via LilyPond user discussion
On cursory glance this looks like a viable solution. Perhaps I can tweak it to 
people to use it at the end of a system as opposed to the beginning of a 
system. That would make my life a bit easier but not completely necessary.

Jun 2, 2020, 09:31 by r...@dabble.ch:

> Michael Winter wrote:
>
>>
>> I thought about something like that but I have tied notes that would be 
>> interrupted by that approach. Which is also why I cannot use multiple single 
>> scores.
>>
>> It also seems like trying to fit a square peg in a round whole. Again, I 
>> think there should be a way to have ragged-right for a single system after a 
>> \break or \pageBreak. That is the correct solution.
>>
>
> Have a look at http://lsr.di.unimi.it/LSR/Item?id=1098
> (and be sure to read all the small print)
>
>
> Cheers,
> Robin
>



Re: forced \break or \pageBreak with ragged-right

2020-06-02 Thread Michael Winter via LilyPond user discussion
Thanks,

I thought about something like that but I have tied notes that would be 
interrupted by that approach. Which is also why I cannot use multiple single 
scores.

It also seems like trying to fit a square peg in a round whole. Again, I think 
there should be a way to have ragged-right for a single system after a \break 
or \pageBreak. That is the correct solution.
Perhaps I should note that another solution for me would be to have 
ragged-right = ##t if it were actually possible to have proportional notation 
where every beat is EXACTLY the same horizontal space. But that really just 
does not seem to be possible. No matter what, I have measures of the same time 
signature that are not the same length and thus break at different spots when 
ragged-right = ##t for (for example, two 4/4 systems where one automatically 
breaks after 4 measures and the other after 3 with minimal-breaking on).

Best,

Michael

Jun 2, 2020, 07:35 by pierre.schneider.pa...@gmail.com:

> How about:
>
> \version "2.20.0"
> {
>   \repeat unfold 20 s1 \bar "||" 
>   \stopStaff s1 \bar ""\break
>   \startStaff 
>   \set Score.currentBarNumber = 21
>   \repeat unfold 20 s1 
> }
>
> \layout {
>   system-count = 8
> }
>
> Otherwise you can do two single scores.
> HTH, cheers,
> Pierre
>
> PS. > http://lilypond.org/tiny-examples.html
>
> Le mar. 2 juin 2020 à 13:23, Michael Winter <> mwin...@unboundedpress.org> > 
> a écrit :
>
>> Thanks Pierre,
>>
>> ragged-last only works on the last system of the score. I would like to have 
>> a specific system within a score have a ragged-right even if it is not the 
>> last system in the score. 
>>
>> I can imagine that this should be able to be done after a forced \break or 
>> \pageBreak.
>>
>> Thanks,
>>
>> Michael
>>
>>
>> Jun 2, 2020, 24:48 by >> pierre.schneider.pa...@gmail.com>> :
>>
>>> Hi Michael,
>>> try: 
>>>
>>> ragged-last = ##t
>>>
>>> Cheers
>>> Pierre
>>>
>>> Le mar. 2 juin 2020 à 06:13, Michael Winter via LilyPond user discussion 
>>> <>>> lilypond-user@gnu.org>>> > a écrit :
>>>
>>>> Hello,
>>>>
>>>> Is it possible to have ragged-right = ##f but then allow a single system 
>>>> to be ragged-right after a forced \break or \pageBreak?
>>>>
>>>> Any help on how to do this will be much appreciated.
>>>>
>>>> Thanks in advance.
>>>>
>>>> Michael
>>>>
>>
>>



Re: forced \break or \pageBreak with ragged-right

2020-06-02 Thread Michael Winter via LilyPond user discussion
Thanks Pierre,

ragged-last only works on the last system of the score. I would like to have a 
specific system within a score have a ragged-right even if it is not the last 
system in the score. 

I can imagine that this should be able to be done after a forced \break or 
\pageBreak.

Thanks,

Michael

Jun 2, 2020, 24:48 by pierre.schneider.pa...@gmail.com:

> Hi Michael,
> try: 
>
> ragged-last = ##t
>
> Cheers
> Pierre
>
> Le mar. 2 juin 2020 à 06:13, Michael Winter via LilyPond user discussion <> 
> lilypond-user@gnu.org> > a écrit :
>
>> Hello,
>>
>> Is it possible to have ragged-right = ##f but then allow a single system to 
>> be ragged-right after a forced \break or \pageBreak?
>>
>> Any help on how to do this will be much appreciated.
>>
>> Thanks in advance.
>>
>> Michael
>>



forced \break or \pageBreak with ragged-right

2020-06-01 Thread Michael Winter via LilyPond user discussion
Hello,

Is it possible to have ragged-right = ##f but then allow a single system to be 
ragged-right after a forced \break or \pageBreak?

Any help on how to do this will be much appreciated.

Thanks in advance.

Michael