Re: Function with conditional

2025-03-20 Thread Lukas-Fabian Moser

Hi all,


You could write this function more briefly as below. I wonder if there
is any ambiguity about transposition by, for example, one semitone:
should it be \transpose c cis or \transpose c des ?

\version "2.24.0"

#(define pitches (vector #{c#} #{des#} #{d#} #{es#} #{e#} #{f#}
#{fis#} #{g#} #{as#} #{a#} #{bes#} #{b#} #{c'#}))

someFunction =
#(define-music-function
  (note transposeCoeficient)
  (ly:music? integer?)
  (make-relative (note) note
 #{ $note \transpose c #(vector-ref pitches transposeCoeficient)
$note #}))

\score {\relative c' { \someFunction c4 12 }}


Or, if one wants to reduce the number of #{ ... #} constructs:

\version "2.24.0"

pitches =
#(define-scheme-function (mus) (ly:music?)
   (apply circular-list (music-pitches mus)))

myPitches = \pitches { c des d es e f fis g as a bes b c' }

someFunction =
#(define-music-function
  (note transposeCoefficient)
  (ly:music? integer?)
  (make-relative (note) note
 #{ $note \transpose c $(list-ref myPitches transposeCoefficient)
$note #}))

\score {
  \relative c' { \someFunction c4 12 }
}

Lukas




Re: Function with conditional

2025-03-20 Thread Lucas Cavalcanti
At the moment I'm trying to resolve an specific issue that would not fall
on enharmonic ambiguity, so writing with those intervals made sense in this
situation (tonic and dominant being perfect, subdominant being perfect or
augmented, and all the rest being major or minor). Still, thank you very
much, Tim, for the contribution! I didn't know lilypond could be tweaked so
much like this.

Em qui., 20 de mar. de 2025 às 13:18, Timothy Lanfear 
escreveu:

> On 20/03/2025 11:44, Lucas Cavalcanti wrote:
>
> Hello, Lukas. I've re-drafted a mock up of the function in question. but
> now the mock up actually worked... I was just not adding the hash "#" to
> the number argument Still, I'll attach the function below to see if it
> can be better optimized.
>
> You could write this function more briefly as below. I wonder if there is
> any ambiguity about transposition by, for example, one semitone: should it
> be \transpose c cis or \transpose c des ?
>
> \version "2.24.0"
>
> #(define pitches (vector #{c#} #{des#} #{d#} #{es#} #{e#} #{f#} #{fis#}
> #{g#} #{as#} #{a#} #{bes#} #{b#} #{c'#}))
>
> someFunction =
> #(define-music-function
>   (note transposeCoeficient)
>   (ly:music? integer?)
>   (make-relative (note) note
>  #{ $note \transpose c #(vector-ref pitches transposeCoeficient) $note
> #}))
>
> \score {\relative c' { \someFunction c4 12 }}
>
> --
> Timothy Lanfear, Bristol, UK.
>
>


Re: Function with conditional

2025-03-20 Thread Timothy Lanfear

On 20/03/2025 11:44, Lucas Cavalcanti wrote:
Hello, Lukas. I've re-drafted a mock up of the function in question. 
but now the mock up actually worked... I was just not adding the hash 
"#" to the number argument Still, I'll attach the function below 
to see if it can be better optimized.


You could write this function more briefly as below. I wonder if there 
is any ambiguity about transposition by, for example, one semitone: 
should it be \transpose c cis or \transpose c des ?


\version "2.24.0"

#(define pitches (vector #{c#} #{des#} #{d#} #{es#} #{e#} #{f#} #{fis#} 
#{g#} #{as#} #{a#} #{bes#} #{b#} #{c'#}))


someFunction =
#(define-music-function
  (note transposeCoeficient)
  (ly:music? integer?)
  (make-relative (note) note
 #{ $note \transpose c #(vector-ref pitches transposeCoeficient) 
$note #}))


\score {\relative c' { \someFunction c4 12 }}

--
Timothy Lanfear, Bristol, UK.


Re: Function with conditional

2025-03-20 Thread Lucas Cavalcanti
Hello, Lukas. I've re-drafted a mock up of the function in question. but
now the mock up actually worked... I was just not adding the hash "#" to
the number argument Still, I'll attach the function below to see if it
can be better optimized.

%%CODE BEGINS
%%
someFunction =
#(define-music-function
( ; beginning of arguments
 note ; music expression to be repeated and transposed
 transposeCoeficient ; number from 1 to 12 that would filter if (or COND)
statements.
) ; end of arguments
( ; beginning of type predicates
  ly:music?
 number?
) ; end of type predicates
( ; beginning of function block (which is wrong and nonsensical).
  make-relative (note) note ; have the transposed note be relative to it's
original.
   (cond
((= transposeCoeficient 1 ) #{$note \transpose c des { $note }#} ) ;
statement 1, related to a semitone increase from the original/prime note.
((= transposeCoeficient 2 ) #{$note \transpose c d { $note }#} )
((= transposeCoeficient 3 ) #{$note \transpose c ees { $note }#} )
((= transposeCoeficient 4 ) #{$note \transpose c e { $note }#} )
((= transposeCoeficient 5 ) #{$note \transpose c f { $note }#} )
((= transposeCoeficient 6 ) #{$note \transpose c fis { $note }#} )
((= transposeCoeficient 7 ) #{$note \transpose c g { $note }#} )
((= transposeCoeficient 8 ) #{$note \transpose c aes { $note }#} )
((= transposeCoeficient 9 ) #{$note \transpose c a { $note }#} )
((= transposeCoeficient 10 ) #{$note \transpose c bes { $note }#} )
((= transposeCoeficient 11 ) #{$note \transpose c b { $note }#} )
((= transposeCoeficient 12 ) #{$note \transpose c c' { $note }#} )
   ) ; end pre cond parenthesis
) ; end of function block
) % end of function
\score {\relative c' {\someFunction c #12 }}
%%
%%CODE ENDS

Em qui., 20 de mar. de 2025 às 04:32, Lukas-Fabian Moser 
escreveu:

> Hi Lucas,
>
> this sounds absolutely possible, but can you please give more details or -
> better still - an example of what you want to achieve?
>
> Lukas
>
> Lucas Cavalcanti  schrieb am Do., 20. März 2025,
> 02:05:
>
>> Hello! I'm in need of help in regards to writing a music function that
>> has conditions inside it: I need my argument (a number between 1 to 12) to
>> be evaluated by an if statement, so that it can run "\transpose c
>> someNote". This function would reduce a lot of code to a project of mine.
>> I've only found one Stack Exchange post
>> 
>> but it uses #define-scheme-function, something of which I don't know if it
>> affects the function or not.
>>
>


Re: Function with conditional

2025-03-20 Thread Lukas-Fabian Moser
Hi Lucas,

this sounds absolutely possible, but can you please give more details or -
better still - an example of what you want to achieve?

Lukas

Lucas Cavalcanti  schrieb am Do., 20. März 2025,
02:05:

> Hello! I'm in need of help in regards to writing a music function that has
> conditions inside it: I need my argument (a number between 1 to 12) to be
> evaluated by an if statement, so that it can run "\transpose c someNote".
> This function would reduce a lot of code to a project of mine.
> I've only found one Stack Exchange post
> 
> but it uses #define-scheme-function, something of which I don't know if it
> affects the function or not.
>


Function with conditional

2025-03-19 Thread Lucas Cavalcanti
Hello! I'm in need of help in regards to writing a music function that has
conditions inside it: I need my argument (a number between 1 to 12) to be
evaluated by an if statement, so that it can run "\transpose c someNote".
This function would reduce a lot of code to a project of mine.
I've only found one Stack Exchange post

but it uses #define-scheme-function, something of which I don't know if it
affects the function or not.