Tuning the MIDI output in Hertz: Difference between revisions
Appearance
m Replace version="2.24.0" with version="2.24" now that the LilyWiki extension supports auto-selecting the latest release in a stable series |
m New category |
||
| (One intermediate revision by the same user not shown) | |||
| Line 27: | Line 27: | ||
[[Category:Pitches]] | [[Category:Pitches]] | ||
[[Category:Midi]] | [[Category:Midi]] | ||
[[Category:Snippet]] | |||
Latest revision as of 23:36, 21 November 2025
This snippet can be used to tune the MIDI output so that the A has an arbitrary frequency expressed in Hertz. For example, 440 Hz is the most common tuning, and 415 Hz is a typical baroque tuning.
\version "2.24"
%% https://lilypond.community/t/diapason-midi/5559
hertzTuning =
#(define-music-function (freq) (number?)
(let* ((freq-factor (/ freq 440))
(tone-factor (expt 2 1/6))
(diff (/ (log freq-factor) (log tone-factor)))
(simple-diff (rationalize (inexact->exact diff) 1/144)))
#{ \transposition #(ly:make-pitch 0 0 simple-diff) #}))
\score {
\midi { }
\layout { }
\fixed c' {
\hertzTuning 415
c8 d e f g a b c'
\hertzTuning 442
c d e f g a b c'
}
}