Re: Microtonal midi output

2021-05-10 Thread Lukas-Fabian Moser

Hi Graham,

Am 10.05.21 um 18:40 schrieb Graham Breed:

I didn't write any C++ but I looked at the C++ code and it looks
trivial to change the pitch bend messages to MTS.


"Trivial" is in the eye of the beholder :-), but it was easy enough for 
me to succeed.



I tested with FluidSynth, and there's an update that I don't think I
pushed.  I think it was that you need to use the all devices Device ID
(0x7f) instead of the channel number.
That information literally saved my life just now: I'm in the process of 
creating some teaching material for tomorrow; timidity behaves strangely 
on my system, and FluidSynth didn't seem to use all of the tuning 
information in the MIDI file. The change in the Device ID you described 
was what did the trick, and there's no way I could have found this out 
by myself this evening.


Thanks much!


   What would be more
difficult is adding all the options so that either pitch bends or MTS
would work — or remembering the current state so you only need to send
a message when something changes.


Yes, that's what I had in mind also. Conceptually, it seems clear what 
to do (keep track of the 'current' tuning for each key for each 
channel), but one has to find the right place to hook this into 
LilyPond's rather involved wiring. That's a task for the upcoming holidays.


Best
Lukas




Re: Microtonal midi output

2021-05-10 Thread Graham Breed
On 09/05/2021, Hans Åberg  wrote:
>
>> On 9 May 2021, at 19:31, Lukas-Fabian Moser  wrote:
>>
>> I looked into it a bit today, and I can gladly report that (while the code
>> still needs some cleaning up), I managed to patch my LilyPond to
>> automatically generate the MTS messages that Graham's Python script adds
>> in post-processing. (Of course, that wouldn't have been possible without
>> being able to use Graham's code as a cheat sheet!)
>
> Graham also wrote some C++ code for generating MTS pitches that was not
> integrated into LilyPond, I think.

I didn't write any C++ but I looked at the C++ code and it looks
trivial to change the pitch bend messages to MTS.  What would be more
difficult is adding all the options so that either pitch bends or MTS
would work — or remembering the current state so you only need to send
a message when something changes.

I tested with FluidSynth, and there's an update that I don't think I
pushed.  I think it was that you need to use the all devices Device ID
(0x7f) instead of the channel number.


Graham



Re: Microtonal midi output

2021-05-09 Thread Hans Åberg


> On 9 May 2021, at 19:31, Lukas-Fabian Moser  wrote:
> 
> I looked into it a bit today, and I can gladly report that (while the code 
> still needs some cleaning up), I managed to patch my LilyPond to 
> automatically generate the MTS messages that Graham's Python script adds in 
> post-processing. (Of course, that wouldn't have been possible without being 
> able to use Graham's code as a cheat sheet!)

Graham also wrote some C++ code for generating MTS pitches that was not 
integrated into LilyPond, I think.





Re: Microtonal midi output

2021-05-09 Thread Jean Abou Samra



Le 09/05/2021 à 19:31, Lukas-Fabian Moser a écrit :

Hi Jean,


It is a well-known trick… See
https://gitlab.com/lilypond/lilypond/-/issues/3139
Ah yes, thank you, I didn't know that. But I'm also relieved that DK 
seems to share my misgivings about the conceptual jumble involved... :-)


Well yes. I'm not particularly happy about
it, just that I couldn't find anything simpler,
and the function would have been somewhat unuseful
without support for non-integers ;-)


As Graham pointed out, LilyPond's habit of setting pitch bends 
before a note and re-setting it immediately after a note whose 
alteration is not in 1/2 * Z leads to strange effects with the 
release (or reverb) of a note. This can be observed in examples 
involving rests between re-tuned notes. I patched my LilyPond for 
this: Now it never explicitly resets MIDI pitch bends, instead each 
and every note gets a pitch-bend command. (Which would be crazy for 
most applications, but is fine for my special needs involving lots 
of re-tuned notes.) I didn't have time to find out how to make this 
user-configurable.


An option would be to go create an issue at
https://gitlab.com/lilypond/lilypond/-/issues
and attach your patch there, noting that it
is a work-in-progress and configurability should
be added. That way, someone might pick it up.
- I'm already looking forward to Graham's solution to this problem 
(post-processing the MIDI files using MTS messages.

I haven't tried it (understanding of MIDI is above
my pay grade), but it shoud certainly yield better
results.


I looked into it a bit today, and I can gladly report that (while the 
code still needs some cleaning up), I managed to patch my LilyPond to 
automatically generate the MTS messages that Graham's Python script 
adds in post-processing. (Of course, that wouldn't have been possible 
without being able to use Graham's code as a cheat sheet!)


As an example I attach the midi files generated by

\score {
  {
    4 r
    <$(ly:make-pitch 0 0 -1/4) e'> r
     r
    <$(ly:make-pitch 0 0 1/4) e'> r
    <$(ly:make-pitch 0 0 1/8) e'> r
     r
  }
  \layout {}
  \midi {}
}

with official 2.22.0 and with my patched master. Compare with special 
focus on the pitch of the e (which should be the same for all three 
chords), and on what happens during release.


I'm a bit nervous about my lack of insight in possible side-effects of 
my tempering with the C++ code, but I'll try to make available a patch 
that more knowledgeable people can at least take as a starting point.


This looks very nice! I look forward to
seeing the patch.

Cheers,
Jean



Re: Microtonal midi output

2021-05-09 Thread Kieren MacMillan
Hi Lukas!

> I think you're mistaken

Well, that certainly wouldn’t be the first time…  ;)
That’s what I get for not testing it myself.

Thanks for setting the record straight!
(and apologies to the list for my error)

Cheers,
Kieren.


Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: kie...@kierenmacmillan.info




Re: Microtonal midi output

2021-05-09 Thread Lukas-Fabian Moser

Hi Jean,

... using LilyPond's moment-arithmetic (number on the time axis) to 
deal with non-integer tone counts (numbers on the pitch axis) seems 
to me like a reasonable contender for an obfuscated Lily coding 
contest. :-) But impressive it is.


It is a well-known trick… See
https://gitlab.com/lilypond/lilypond/-/issues/3139
Ah yes, thank you, I didn't know that. But I'm also relieved that DK 
seems to share my misgivings about the conceptual jumble involved... :-)
As Graham pointed out, LilyPond's habit of setting pitch bends before 
a note and re-setting it immediately after a note whose alteration is 
not in 1/2 * Z leads to strange effects with the release (or reverb) 
of a note. This can be observed in examples involving rests between 
re-tuned notes. I patched my LilyPond for this: Now it never 
explicitly resets MIDI pitch bends, instead each and every note gets 
a pitch-bend command. (Which would be crazy for most applications, 
but is fine for my special needs involving lots of re-tuned notes.) I 
didn't have time to find out how to make this user-configurable.


An option would be to go create an issue at
https://gitlab.com/lilypond/lilypond/-/issues
and attach your patch there, noting that it
is a work-in-progress and configurability should
be added. That way, someone might pick it up.
- I'm already looking forward to Graham's solution to this problem 
(post-processing the MIDI files using MTS messages.

I haven't tried it (understanding of MIDI is above
my pay grade), but it shoud certainly yield better
results.


I looked into it a bit today, and I can gladly report that (while the 
code still needs some cleaning up), I managed to patch my LilyPond to 
automatically generate the MTS messages that Graham's Python script adds 
in post-processing. (Of course, that wouldn't have been possible without 
being able to use Graham's code as a cheat sheet!)


As an example I attach the midi files generated by

\score {
  {
    4 r
    <$(ly:make-pitch 0 0 -1/4) e'> r
     r
    <$(ly:make-pitch 0 0 1/4) e'> r
    <$(ly:make-pitch 0 0 1/8) e'> r
     r
  }
  \layout {}
  \midi {}
}

with official 2.22.0 and with my patched master. Compare with special 
focus on the pitch of the e (which should be the same for all three 
chords), and on what happens during release.


I'm a bit nervous about my lack of insight in possible side-effects of 
my tempering with the C++ code, but I'll try to make available a patch 
that more knowledgeable people can at least take as a starting point.


Lukas



test-2.22.0.midi
Description: MIDI audio


test-patched-master.midi
Description: MIDI audio


Re: Microtonal midi output

2021-05-09 Thread Lukas-Fabian Moser

Hi Kieren,


If they’re in the same file (which they appear to be), then I believe the MIDI 
output of your second \score block — the non-detuned one! — will overwrite the 
MIDI output of the first one. You need to have separate files (or at least 
separate \book blocks, with explicit and different target file names) in order 
to output two separate MIDI files.


I think you're mistaken:

\version "2.22.0"

music = { c' }

\score {
  \music
  \layout {}
  \midi {}
}


\score {
  \music
  \midi {}
}

generates test.midi and test-1.midi.

Lukas




Re: Microtonal midi output

2021-05-09 Thread brahim.pro
My bad sorry for the spam. Looks fine to me I found my silly mistake.

Thanks

Brahim

‐‐‐ Original Message ‐‐‐
On Sunday 9 May 2021 16:07, Jacques Menu  wrote:

> Hello Brahim,
>
> What do you mean by ‘run this script’?
>
> JM
>
> > Le 9 mai 2021 à 15:58, brahim.pro brahim@protonmail.com a écrit :
> > Hello,
> > Thanks for the feedback.
> > Actually I cannot manage to run this script.
> > I tried this for example:
> > \version "2.22.0"
> > tuneMIDI =
> > #(define-music-function (scale music) (list? ly:music?)
> > (let ((copy (ly:music-deep-copy music)))
> > (for-some-music
> > (lambda (m)
> > (let ((pitch (ly:music-property m 'pitch)))
> > (if (ly:pitch? pitch)
> > (let* ((note-name (ly:pitch-notename pitch))
> > (alteration (ly:pitch-alteration pitch))
> > (offset (assoc-ref scale
> > (cons note-name alteration
> > (if offset
> > (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
> > (new-pitch (ly:pitch-transpose pitch
> > transpose-pitch)))
> > (ly:music-set-property! m 'pitch new-pitch)
> > #f))
> > copy)
> > copy))
> > myNotes = \relative { a b c d e f gis aes a b c d e f gis aes a }
> > { \myNotes }
> > \midi {
> > \tempo 4 = 120
> > }
> > \score {
> > \tuneMIDI
> > #'(
> > ; Lower F (index 3 in C major scale if 0 is C, no alteration) by
> > 1/10 tone.
> > ((3 . 0) . -1/2)
> > ; Raise G# (index 4, sharp) by 1/10 tone.
> > ((4 . 1/2) . 1/2)
> > )
> > \myNotes
> > \midi { }
> > }
> > \score {
> > \myNotes
> > \midi { }
> > }
> > And I have two same midi files.
> > I tried also to make big detuning, but I just cannot hear that. I 
> > downloaded the last version of lilypond, and I still cannot manage to run 
> > this script.
> > I don't know what am I doing wrong?
> > Brahim
> > ‐‐‐ Original Message ‐‐‐
> > On Sunday 9 May 2021 10:06, Jean Abou Samra j...@abou-samra.fr wrote:
> >
> > > Le 08/05/2021 à 23:50, Lukas-Fabian Moser a écrit :
> > >
> > > > Hi Jean,
> > > >
> > > > > (let* ((tones (ly:pitch-tones pitch))
> > > > > (r (ly:moment-main
> > > > > (ly:moment-mod
> > > > > (ly:make-moment tones 0)
> > > > > (ly:make-moment 6 0
> > > >
> > > > ... using LilyPond's moment-arithmetic (number on the time axis) to
> > > > deal with non-integer tone counts (numbers on the pitch axis) seems to
> > > > me like a reasonable contender for an obfuscated Lily coding contest.
> > > > :-) But impressive it is.
> > >
> > > It is a well-known trick… See
> > > https://gitlab.com/lilypond/lilypond/-/issues/3139
> > > Guile's modulo and remainder functions only
> > > support integers, which is pitiful. Guile 2
> > > brought an improvement with euclidean-quotient
> > > and euclidean-remainder, which always yield a
> > > positive remainder, and support rationals as well
> > > as floats.
> > >
> > > > Maybe it's worth pointing out that your solution hardwires enharmonic
> > > > identification (if I'm not mistaken). Of course I don't know what the
> > > > OP intends to do, but in lots of real-life applications for re-tuning
> > > > it's worth keeping the difference between f-sharp and g-flat alive.
> > >
> > > Here is an enhanced version that stops enharmonic
> > > identification, and copies the music before processing
> > > it, to address Brahim's request.
> > > \version "2.22.0"
> > > tuneMIDI =
> > > #(define-music-function (scale music) (list? ly:music?)
> > > (let ((copy (ly:music-deep-copy music)))
> > > (for-some-music
> > > (lambda (m)
> > > (let ((pitch (ly:music-property m 'pitch)))
> > > (if (ly:pitch? pitch)
> > > (let* ((note-name (ly:pitch-notename pitch))
> > > (alteration (ly:pitch-alteration pitch))
> > > (offset (assoc-ref scale
> > > (cons note-name alteration
> > > (if offset
> > > (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
> > > (new-pitch (ly:pitch-transpose pitch
> > > transpose-pitch)))
> > > (ly:music-set-property! m 'pitch new-pitch)
> > > #f))
> > > copy)
> > > copy))
> > > myNotes = \relative { a b c d e f gis aes a b c d e f gis aes a }
> > > { \myNotes }
> > > \midi {
> > > \tempo 4 = 120
> > > }
> > > \score {
> > > \tuneMIDI
> > > #'(
> > > ; Lower F (index 3 in C major scale if 0 is C, no alteration) by
> > > 1/10 tone.
> > > ((3 . 0) . -1/10)
> > > ; Raise G# (index 4, sharp) by 1/10 tone.
> > > ((4 . 1/2) . 2/10)
> > > )
> > > \myNotes
> > > \midi { }
> > > }
> > > \score {
> > > \tuneMIDI
> > > #'(((3 . 0) . -1/10))
> > > \myNotes
> > > \midi { }
> > > }
> > >
> > > > As Graham pointed out, LilyPond's habit of setting pitch bends before
> > > > a note and re-setting it immediately after a note whose alteration is
> > > > not in 1/2 * Z leads to strange effects with the release (or reverb)
> > > > of a note. This can be observed in examples involving rests between
> > > > re-tuned notes. I patched my LilyPond for this: Now it never
> > > > explicitly resets MIDI pitch bends, instead each and every note gets a
> > > > pitch-bend command. (Which would be crazy for most applications, but
> > > > is fine for my special needs involving lots 

Re: Microtonal midi output

2021-05-09 Thread Kieren MacMillan
Hi there,

> Actually I cannot manage to run this script.
> I tried this for example:
[…]
> And I have two same midi files.

If they’re in the same file (which they appear to be), then I believe the MIDI 
output of your second \score block — the non-detuned one! — will overwrite the 
MIDI output of the first one. You need to have separate files (or at least 
separate \book blocks, with explicit and different target file names) in order 
to output two separate MIDI files.

Hope that helps!
Kieren.


Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: kie...@kierenmacmillan.info




Re: Microtonal midi output

2021-05-09 Thread Jacques Menu
Hello Brahim,

What do you mean by ‘run this script’?

JM

> Le 9 mai 2021 à 15:58, brahim.pro  a écrit :
> 
> Hello,
> 
> Thanks for the feedback.
> Actually I cannot manage to run this script.
> I tried this for example:
> 
> \version "2.22.0"
> 
> tuneMIDI =
> #(define-music-function (scale music) (list? ly:music?)
>(let ((copy (ly:music-deep-copy music)))
>  (for-some-music
>(lambda (m)
>  (let ((pitch (ly:music-property m 'pitch)))
>(if (ly:pitch? pitch)
>(let* ((note-name (ly:pitch-notename pitch))
>   (alteration (ly:pitch-alteration pitch))
>   (offset (assoc-ref scale
>  (cons note-name alteration
>  (if offset
>  (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
> (new-pitch (ly:pitch-transpose pitch
> transpose-pitch)))
>(ly:music-set-property! m 'pitch new-pitch)
>#f))
>copy)
>  copy))
> 
> myNotes = \relative { a b c d e f gis aes a b c d e f gis aes a }
> 
> { \myNotes }
> 
> \midi {
>   \tempo 4 = 120
> }
> 
> \score {
>   \tuneMIDI
> #'(
>; Lower F (index 3 in C major scale if 0 is C, no alteration) by
> 1/10 tone.
>((3 . 0) . -1/2)
>; Raise G# (index 4, sharp) by 1/10 tone.
>((4 . 1/2) . 1/2)
>)
> \myNotes
>   \midi { }
> }
> 
> \score {
>   \myNotes
>   \midi { }
> }
> 
> And I have two same midi files.
> I tried also to make big detuning, but I just cannot hear that. I downloaded 
> the last version of lilypond, and I still cannot manage to run this script.
> 
> I don't know what am I doing wrong?
> 
> Brahim
> 
> 
> ‐‐‐ Original Message ‐‐‐
> On Sunday 9 May 2021 10:06, Jean Abou Samra  wrote:
> 
>> Le 08/05/2021 à 23:50, Lukas-Fabian Moser a écrit :
>> 
>>> Hi Jean,
>>> 
 (let* ((tones (ly:pitch-tones pitch))
 (r (ly:moment-main
  (ly:moment-mod
(ly:make-moment tones 0)
(ly:make-moment 6 0
>>> 
>>> ... using LilyPond's moment-arithmetic (number on the time axis) to
>>> deal with non-integer tone counts (numbers on the pitch axis) seems to
>>> me like a reasonable contender for an obfuscated Lily coding contest.
>>> :-) But impressive it is.
>> 
>> It is a well-known trick… See
>> https://gitlab.com/lilypond/lilypond/-/issues/3139
>> 
>> Guile's modulo and remainder functions only
>> support integers, which is pitiful. Guile 2
>> brought an improvement with euclidean-quotient
>> and euclidean-remainder, which always yield a
>> positive remainder, and support rationals as well
>> as floats.
>> 
>>> Maybe it's worth pointing out that your solution hardwires enharmonic
>>> identification (if I'm not mistaken). Of course I don't know what the
>>> OP intends to do, but in lots of real-life applications for re-tuning
>>> it's worth keeping the difference between f-sharp and g-flat alive.
>> 
>> Here is an enhanced version that stops enharmonic
>> identification, and copies the music before processing
>> it, to address Brahim's request.
>> 
>> \version "2.22.0"
>> 
>> tuneMIDI =
>> #(define-music-function (scale music) (list? ly:music?)
>>(let ((copy (ly:music-deep-copy music)))
>>  (for-some-music
>>(lambda (m)
>>  (let ((pitch (ly:music-property m 'pitch)))
>>(if (ly:pitch? pitch)
>>(let* ((note-name (ly:pitch-notename pitch))
>>   (alteration (ly:pitch-alteration pitch))
>>   (offset (assoc-ref scale
>>  (cons note-name alteration
>>  (if offset
>>  (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
>> (new-pitch (ly:pitch-transpose pitch
>> transpose-pitch)))
>>(ly:music-set-property! m 'pitch new-pitch)
>>#f))
>>copy)
>>  copy))
>> 
>> myNotes = \relative { a b c d e f gis aes a b c d e f gis aes a }
>> 
>> { \myNotes }
>> 
>> \midi {
>>   \tempo 4 = 120
>> }
>> 
>> \score {
>>   \tuneMIDI
>> #'(
>>; Lower F (index 3 in C major scale if 0 is C, no alteration) by
>> 1/10 tone.
>>((3 . 0) . -1/10)
>>; Raise G# (index 4, sharp) by 1/10 tone.
>>((4 . 1/2) . 2/10)
>>)
>> \myNotes
>>   \midi { }
>> }
>> 
>> \score {
>>   \tuneMIDI
>> #'(((3 . 0) . -1/10))
>> \myNotes
>>   \midi { }
>> }
>> 
>>> As Graham pointed out, LilyPond's habit of setting pitch bends before
>>> a note and re-setting it immediately after a note whose alteration is
>>> not in 1/2 * Z leads to strange effects with the release (or reverb)
>>> of a note. This can be observed in examples involving rests between
>>> re-tuned notes. I patched my LilyPond for this: Now it never
>>> explicitly resets 

Re: Microtonal midi output

2021-05-09 Thread brahim.pro
Hello,

Thanks for the feedback.
Actually I cannot manage to run this script.
I tried this for example:

\version "2.22.0"

tuneMIDI =
#(define-music-function (scale music) (list? ly:music?)
(let ((copy (ly:music-deep-copy music)))
  (for-some-music
(lambda (m)
  (let ((pitch (ly:music-property m 'pitch)))
(if (ly:pitch? pitch)
(let* ((note-name (ly:pitch-notename pitch))
   (alteration (ly:pitch-alteration pitch))
   (offset (assoc-ref scale
  (cons note-name alteration
  (if offset
  (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
 (new-pitch (ly:pitch-transpose pitch
transpose-pitch)))
(ly:music-set-property! m 'pitch new-pitch)
#f))
copy)
  copy))

myNotes = \relative { a b c d e f gis aes a b c d e f gis aes a }

{ \myNotes }

\midi {
   \tempo 4 = 120
}

\score {
   \tuneMIDI
 #'(
; Lower F (index 3 in C major scale if 0 is C, no alteration) by
1/10 tone.
((3 . 0) . -1/2)
; Raise G# (index 4, sharp) by 1/10 tone.
((4 . 1/2) . 1/2)
)
 \myNotes
   \midi { }
}

\score {
   \myNotes
   \midi { }
}

And I have two same midi files.
I tried also to make big detuning, but I just cannot hear that. I downloaded 
the last version of lilypond, and I still cannot manage to run this script.

I don't know what am I doing wrong?

Brahim


‐‐‐ Original Message ‐‐‐
On Sunday 9 May 2021 10:06, Jean Abou Samra  wrote:

> Le 08/05/2021 à 23:50, Lukas-Fabian Moser a écrit :
>
> > Hi Jean,
> >
> > > (let* ((tones (ly:pitch-tones pitch))
> > >     (r (ly:moment-main
> > >  (ly:moment-mod
> > >    (ly:make-moment tones 0)
> > >    (ly:make-moment 6 0
> >
> > ... using LilyPond's moment-arithmetic (number on the time axis) to
> > deal with non-integer tone counts (numbers on the pitch axis) seems to
> > me like a reasonable contender for an obfuscated Lily coding contest.
> > :-) But impressive it is.
>
> It is a well-known trick… See
> https://gitlab.com/lilypond/lilypond/-/issues/3139
>
> Guile's modulo and remainder functions only
> support integers, which is pitiful. Guile 2
> brought an improvement with euclidean-quotient
> and euclidean-remainder, which always yield a
> positive remainder, and support rationals as well
> as floats.
>
> > Maybe it's worth pointing out that your solution hardwires enharmonic
> > identification (if I'm not mistaken). Of course I don't know what the
> > OP intends to do, but in lots of real-life applications for re-tuning
> > it's worth keeping the difference between f-sharp and g-flat alive.
>
> Here is an enhanced version that stops enharmonic
> identification, and copies the music before processing
> it, to address Brahim's request.
>
> \version "2.22.0"
>
> tuneMIDI =
> #(define-music-function (scale music) (list? ly:music?)
>    (let ((copy (ly:music-deep-copy music)))
>  (for-some-music
>    (lambda (m)
>  (let ((pitch (ly:music-property m 'pitch)))
>    (if (ly:pitch? pitch)
>    (let* ((note-name (ly:pitch-notename pitch))
>   (alteration (ly:pitch-alteration pitch))
>   (offset (assoc-ref scale
>  (cons note-name alteration
>  (if offset
>  (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
>     (new-pitch (ly:pitch-transpose pitch
> transpose-pitch)))
>    (ly:music-set-property! m 'pitch new-pitch)
>    #f))
>    copy)
>  copy))
>
> myNotes = \relative { a b c d e f gis aes a b c d e f gis aes a }
>
> { \myNotes }
>
> \midi {
>   \tempo 4 = 120
> }
>
> \score {
>   \tuneMIDI
>     #'(
>    ; Lower F (index 3 in C major scale if 0 is C, no alteration) by
> 1/10 tone.
>    ((3 . 0) . -1/10)
>    ; Raise G# (index 4, sharp) by 1/10 tone.
>    ((4 . 1/2) . 2/10)
>    )
>     \myNotes
>   \midi { }
> }
>
> \score {
>   \tuneMIDI
>     #'(((3 . 0) . -1/10))
>     \myNotes
>   \midi { }
> }
>
> > As Graham pointed out, LilyPond's habit of setting pitch bends before
> > a note and re-setting it immediately after a note whose alteration is
> > not in 1/2 * Z leads to strange effects with the release (or reverb)
> > of a note. This can be observed in examples involving rests between
> > re-tuned notes. I patched my LilyPond for this: Now it never
> > explicitly resets MIDI pitch bends, instead each and every note gets a
> > pitch-bend command. (Which would be crazy for most applications, but
> > is fine for my special needs involving lots of re-tuned notes.) I
> > didn't have time to find out how to make this user-configurable.
>
> An option would be to 

Re: Microtonal midi output

2021-05-09 Thread Jean Abou Samra

Le 08/05/2021 à 23:50, Lukas-Fabian Moser a écrit :


Hi Jean,

(let* ((tones (ly:pitch-tones pitch))
    (r (ly:moment-main
 (ly:moment-mod
   (ly:make-moment tones 0)
   (ly:make-moment 6 0


... using LilyPond's moment-arithmetic (number on the time axis) to 
deal with non-integer tone counts (numbers on the pitch axis) seems to 
me like a reasonable contender for an obfuscated Lily coding contest. 
:-) But impressive it is.


It is a well-known trick… See
https://gitlab.com/lilypond/lilypond/-/issues/3139

Guile's modulo and remainder functions only
support integers, which is pitiful. Guile 2
brought an improvement with euclidean-quotient
and euclidean-remainder, which always yield a
positive remainder, and support rationals as well
as floats.

Maybe it's worth pointing out that your solution hardwires enharmonic 
identification (if I'm not mistaken). Of course I don't know what the 
OP intends to do, but in lots of real-life applications for re-tuning 
it's worth keeping the difference between f-sharp and g-flat alive.


Here is an enhanced version that stops enharmonic
identification, and copies the music before processing
it, to address Brahim's request.

\version "2.22.0"

tuneMIDI =
#(define-music-function (scale music) (list? ly:music?)
   (let ((copy (ly:music-deep-copy music)))
 (for-some-music
   (lambda (m)
 (let ((pitch (ly:music-property m 'pitch)))
   (if (ly:pitch? pitch)
   (let* ((note-name (ly:pitch-notename pitch))
  (alteration (ly:pitch-alteration pitch))
  (offset (assoc-ref scale
 (cons note-name alteration
 (if offset
 (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
    (new-pitch (ly:pitch-transpose pitch 
transpose-pitch)))

   (ly:music-set-property! m 'pitch new-pitch)
   #f))
   copy)
 copy))

myNotes = \relative { a b c d e f gis aes a b c d e f gis aes a }

{ \myNotes }

\midi {
  \tempo 4 = 120
}

\score {
  \tuneMIDI
    #'(
   ; Lower F (index 3 in C major scale if 0 is C, no alteration) by 
1/10 tone.

   ((3 . 0) . -1/10)
   ; Raise G# (index 4, sharp) by 1/10 tone.
   ((4 . 1/2) . 2/10)
   )
    \myNotes
  \midi { }
}

\score {
  \tuneMIDI
    #'(((3 . 0) . -1/10))
    \myNotes
  \midi { }
}


As Graham pointed out, LilyPond's habit of setting pitch bends before 
a note and re-setting it immediately after a note whose alteration is 
not in 1/2 * Z leads to strange effects with the release (or reverb) 
of a note. This can be observed in examples involving rests between 
re-tuned notes. I patched my LilyPond for this: Now it never 
explicitly resets MIDI pitch bends, instead each and every note gets a 
pitch-bend command. (Which would be crazy for most applications, but 
is fine for my special needs involving lots of re-tuned notes.) I 
didn't have time to find out how to make this user-configurable.


An option would be to go create an issue at
https://gitlab.com/lilypond/lilypond/-/issues
and attach your patch there, noting that it
is a work-in-progress and configurability should
be added. That way, someone might pick it up.

- I'm already looking forward to Graham's solution to this problem 
(post-processing the MIDI files using MTS messages.


I haven't tried it (understanding of MIDI is above
my pay grade), but it shoud certainly yield better
results.

Cheers,
Jean



Re: Microtonal midi output

2021-05-08 Thread brahim.pro
This script is great and contains exactly what I want. I would have never found 
that by my own.
Thanks a lot.

Is there a way to call it twice in the same score? Imagine I have two musical 
phrases that I want to tune differently, can I use this script?


‐‐‐ Original Message ‐‐‐
On Saturday 8 May 2021 23:19, Jean Abou Samra  wrote:

> Le 08/05/2021 à 20:33, brahim.pro a écrit :
>
> > Hello,
> > I would like to define a scale, let's say A minor, and slightly change
> > the frequency of the notes in the output MIDI file. I have trouble
> > finding this feature in the documentation. So does this feature exist
> > and how to do that?
> > Thanks,
> > Brahim
>
> Hello,
>
> You can always implement it in Scheme... Something like this,
> tampering with the pitches:
>
> \version "2.22.0"
>
> tuneMIDI =
> #(define-music-function (scale music) (list? ly:music?)
>    (for-some-music
>  (lambda (m)
>    (let ((pitch (ly:music-property m 'pitch)))
>  (if (ly:pitch? pitch)
>  (let* ((tones (ly:pitch-tones pitch))
>     (r (ly:moment-main
>  (ly:moment-mod
>    (ly:make-moment tones 0)
>    (ly:make-moment 6 0
>     (offset (assv-ref scale r)))
>    (ly:message "~s" r)
>    (if offset
>    (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
>   (new-pitch (ly:pitch-transpose pitch
> transpose-pitch)))
>  (ly:music-set-property! m 'pitch new-pitch)
>  #t)
>    #f))
>  #f)))
>  music)
>    music)
>
> myNotes = \relative { a b c d e f gis a b c d e f gis a }
>
> { \myNotes }
>
> \score {
>   \tuneMIDI
>     #'(
>    ; Lower F (5/2 tones above C) by 1/10 tone.
>    (5/2 . -1/10)
>    ; Raise G# by 1/10 tone.
>    (4 . 1/10)
>    )
>     \myNotes
>   \midi { }
> }
>
> Note how this requires separating out MIDI generation in
> a dedicated \score block.
>
> I was told that my email client inserts non-breaking
> spaces in my code examples. If this happens and you
> can't compile the file, please use the attachment.
>
> Best,
> Jean





Re: Microtonal midi output

2021-05-08 Thread Lukas-Fabian Moser

Hi Jean,

(let* ((tones (ly:pitch-tones pitch))
    (r (ly:moment-main
 (ly:moment-mod
   (ly:make-moment tones 0)
   (ly:make-moment 6 0


... using LilyPond's moment-arithmetic (number on the time axis) to deal 
with non-integer tone counts (numbers on the pitch axis) seems to me 
like a reasonable contender for an obfuscated Lily coding contest. :-) 
But impressive it is.


Maybe it's worth pointing out that your solution hardwires enharmonic 
identification (if I'm not mistaken). Of course I don't know what the OP 
intends to do, but in lots of real-life applications for re-tuning it's 
worth keeping the difference between f-sharp and g-flat alive.


As Graham pointed out, LilyPond's habit of setting pitch bends before a 
note and re-setting it immediately after a note whose alteration is not 
in 1/2 * Z leads to strange effects with the release (or reverb) of a 
note. This can be observed in examples involving rests between re-tuned 
notes. I patched my LilyPond for this: Now it never explicitly resets 
MIDI pitch bends, instead each and every note gets a pitch-bend command. 
(Which would be crazy for most applications, but is fine for my special 
needs involving lots of re-tuned notes.) I didn't have time to find out 
how to make this user-configurable. - I'm already looking forward to 
Graham's solution to this problem (post-processing the MIDI files using 
MTS messages.


Lukas




Re: Microtonal midi output

2021-05-08 Thread Kieren MacMillan
Dear Jean,

> You can always implement it in Scheme... Something like this

1. Lilypond is amazing.
2. You are as well.

Cheers,
Kieren.


Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: kie...@kierenmacmillan.info




Re: Microtonal midi output

2021-05-08 Thread Jean Abou Samra


Le 08/05/2021 à 20:33, brahim.pro a écrit :

Hello,

I would like to define a scale, let's say A minor, and slightly change 
the frequency of the notes in the output MIDI file. I have trouble 
finding this feature in the documentation. So does this feature exist 
and how to do that?


Thanks,

Brahim



Hello,

You can always implement it in Scheme... Something like this,
tampering with the pitches:

\version "2.22.0"

tuneMIDI =
#(define-music-function (scale music) (list? ly:music?)
   (for-some-music
 (lambda (m)
   (let ((pitch (ly:music-property m 'pitch)))
 (if (ly:pitch? pitch)
 (let* ((tones (ly:pitch-tones pitch))
    (r (ly:moment-main
 (ly:moment-mod
   (ly:make-moment tones 0)
   (ly:make-moment 6 0
    (offset (assv-ref scale r)))
   (ly:message "~s" r)
   (if offset
   (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
  (new-pitch (ly:pitch-transpose pitch 
transpose-pitch)))

 (ly:music-set-property! m 'pitch new-pitch)
 #t)
   #f))
 #f)))
 music)
   music)

myNotes = \relative { a b c d e f gis a b c d e f gis a }

{ \myNotes }

\score {
  \tuneMIDI
    #'(
   ; Lower F (5/2 tones above C) by 1/10 tone.
   (5/2 . -1/10)
   ; Raise G# by 1/10 tone.
   (4 . 1/10)
   )
    \myNotes
  \midi { }
}

Note how this requires separating out MIDI generation in
a dedicated \score block.

I was told that my email client inserts non-breaking
spaces in my code examples. If this happens and you
can't compile the file, please use the attachment.

Best,
Jean

\version "2.22.0"

tuneMIDI =
#(define-music-function (scale music) (list? ly:music?)
   (for-some-music
 (lambda (m)
   (let ((pitch (ly:music-property m 'pitch)))
 (if (ly:pitch? pitch)
 (let* ((tones (ly:pitch-tones pitch))
(r (ly:moment-main
 (ly:moment-mod
   (ly:make-moment tones 0)
   (ly:make-moment 6 0
(offset (assv-ref scale r)))
   (ly:message "~s" r)
   (if offset
   (let* ((transpose-pitch (ly:make-pitch 0 0 offset))
  (new-pitch (ly:pitch-transpose pitch transpose-pitch)))
 (ly:music-set-property! m 'pitch new-pitch)
 #t)
   #f))
 #f)))
 music)
   music)

myNotes = \relative { a b c d e f gis a b c d e f gis a }

{ \myNotes }

\score {
  \tuneMIDI
#'(
   ; Lower F (5/2 tones above C) by 1/10 tone.
   (5/2 . -1/10)
   ; Raise G# by 1/10 tone.
   (4 . 1/10)
   )
\myNotes
  \midi { }
}

Re: Microtonal midi output

2021-05-08 Thread Graham Breed
On 08/05/2021, Hans Åberg  wrote:
>
>> On 8 May 2021, at 22:18, brahim.pro  wrote:
>>
>> Thanks for the reply. For example, I would like to play A minor scale with
>> normal A(440Hz). But I would like the interval A, B to be 203 cents
>> instead of 200. Or I would like the interval A, C to be 315 cents instead
>> of 300 cents.
>>
>> If I understand your answer correctly the note is tied to the midi value.
>> But I would like for that midi value generate a slightly different
>> frequency. Is that possible?
>
> You can't do it like that. The MIDI value is tied to the note values, the
> other way around. And you can't adjust the tuning frequency, it is C4 not
> A4. One can do fine tunings by going up in ET, Graham Breed is doing that,
> but I do not keep track of that.

No, you can do fine tuning.  LilyPond will do it with pitch bends by
default.  I have scripts to turn the pitch bends into MIDI Tuning
Standard messages, which are much more solid.  Details at
http://x31eq.com/lilypond

Some things break with newer versions of LilyPond.


  Graham



Re: Microtonal midi output

2021-05-08 Thread Kieren MacMillan
Hi there,

> Thanks for the reply. For example, I would like to play A minor scale with 
> normal A(440Hz). But I would like the interval A, B to be 203 cents instead 
> of 200. Or I would like the interval A, C to be 315 cents instead of 300 
> cents.

Sounds to me like you’ll either want to post-process that in your sequencer, or 
possibly apply some sort of script during the Lilypond-to-MIDI stage that 
adjusts the pitch value appropriately.

I’d personally go with the first option: in most sequencers, you can simply 
program a virtual instrument to be tuned how you want it!

Hope that helps,
Kieren.


Kieren MacMillan, composer (he/him/his)
‣ website: www.kierenmacmillan.info
‣ email: kie...@kierenmacmillan.info




Re: Microtonal midi output

2021-05-08 Thread Hans Åberg


> On 8 May 2021, at 22:18, brahim.pro  wrote:
> 
> Thanks for the reply. For example, I would like to play A minor scale with 
> normal A(440Hz). But I would like the interval A, B to be 203 cents instead 
> of 200. Or I would like the interval A, C to be 315 cents instead of 300 
> cents.
> 
> If I understand your answer correctly the note is tied to the midi value. But 
> I would like for that midi value generate a slightly different frequency. Is 
> that possible?

You can't do it like that. The MIDI value is tied to the note values, the other 
way around. And you can't adjust the tuning frequency, it is C4 not A4. One can 
do fine tunings by going up in ET, Graham Breed is doing that, but I do not 
keep track of that.


> ‐‐‐ Original Message ‐‐‐
> On Saturday 8 May 2021 21:17, Hans Åberg  wrote:
> 
>>> On 8 May 2021, at 20:33, brahim.pro brahim@protonmail.com wrote:
>>> I would like to define a scale, let's say A minor, and slightly change the 
>>> frequency of the notes in the output MIDI file. I have trouble finding this 
>>> feature in the documentation. So does this feature exist and how to do that?
>> 
>> In LilyPond, the note and MIDI values are tied together, so you need to be 
>> more specific what you want to do. ETs multiples of 12 are straightforward, 
>> for example E72 is good approximation of the 11-limit. For arbitrary ETs, 
>> there is Graham Breed's fileregular.ly.
> 
> 




Re: Microtonal midi output

2021-05-08 Thread brahim.pro
Thanks for the reply. For example, I would like to play A minor scale with 
normal A(440Hz). But I would like the interval A, B to be 203 cents instead of 
200. Or I would like the interval A, C to be 315 cents instead of 300 cents.

If I understand your answer correctly the note is tied to the midi value. But I 
would like for that midi value generate a slightly different frequency. Is that 
possible?

Thanks



‐‐‐ Original Message ‐‐‐
On Saturday 8 May 2021 21:17, Hans Åberg  wrote:

> > On 8 May 2021, at 20:33, brahim.pro brahim@protonmail.com wrote:
> > I would like to define a scale, let's say A minor, and slightly change the 
> > frequency of the notes in the output MIDI file. I have trouble finding this 
> > feature in the documentation. So does this feature exist and how to do that?
>
> In LilyPond, the note and MIDI values are tied together, so you need to be 
> more specific what you want to do. ETs multiples of 12 are straightforward, 
> for example E72 is good approximation of the 11-limit. For arbitrary ETs, 
> there is Graham Breed's fileregular.ly.





Re: Microtonal midi output

2021-05-08 Thread ebenezer

I am interested in learning about this capability, too.

I have 2 further questions:

1. What is ET?

2. Where is regular.ly available from?

Thank you.


On 2021-05-08 20:17, Hans Åberg wrote:

On 8 May 2021, at 20:33, brahim.pro  wrote:

I would like to define a scale, let's say A minor, and slightly change the 
frequency of the notes in the output MIDI file. I have trouble finding this 
feature in the documentation. So does this feature exist and how to do that?

In LilyPond, the note and MIDI values are tied together, so you need to be more 
specific what you want to do. ETs multiples of 12 are straightforward, for 
example E72 is good approximation of the 11-limit. For arbitrary ETs, there is 
Graham Breed's file regular.ly.








Re: Microtonal midi output

2021-05-08 Thread Hans Åberg


> On 8 May 2021, at 20:33, brahim.pro  wrote:
> 
> I would like to define a scale, let's say A minor, and slightly change the 
> frequency of the notes in the output MIDI file. I have trouble finding this 
> feature in the documentation. So does this feature exist and how to do that?

In LilyPond, the note and MIDI values are tied together, so you need to be more 
specific what you want to do. ETs multiples of 12 are straightforward, for 
example E72 is good approximation of the 11-limit. For arbitrary ETs, there is 
Graham Breed's file regular.ly.





Microtonal midi output

2021-05-08 Thread brahim.pro
Hello,

I would like to define a scale, let's say A minor, and slightly change the 
frequency of the notes in the output MIDI file. I have trouble finding this 
feature in the documentation. So does this feature exist and how to do that?

Thanks,

Brahim