Jump to content

Replacing default MIDI instrument equalization: Difference between revisions

From LilyPond wiki
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
mNo edit summary
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
The default MIDI instrument equalizer can be replaced by setting the <code>instrumentEqualizer</code> property in the <code>Score</code> context to a user-defined Scheme procedure that uses a MIDI instrument name as its argument along with a pair of fractions indicating the minimum and maximum volumes respectively to be applied to that specific instrument.
The default MIDI instrument equalizer can be replaced by setting the <code>instrumentEqualizer</code> property in the <code>Score</code> context to a user-defined Scheme procedure that uses a MIDI instrument name as its argument along with a pair of fractions indicating the minimum and maximum volumes, respectively, to be applied to that specific instrument.


The following example sets the minimum and maximum volumes for flute and clarinet respectively.&quot;
The following example sets the minimum and maximum volumes for flute and clarinet.


<lilypond version="2.24">
<lilypond version="2.24">
Line 8: Line 8:
#(set! my-instrument-equalizer-alist
#(set! my-instrument-equalizer-alist
   (append
   (append
     '(
     '(("flute" . (0.7 . 0.9))
      ("flute" . (0.7 . 0.9))
       ("clarinet" . (0.3 . 0.6)))
       ("clarinet" . (0.3 . 0.6)))
     my-instrument-equalizer-alist))
     my-instrument-equalizer-alist))
Line 46: Line 45:
</lilypond>
</lilypond>


[[Category:Midi]]
[[Category:Scheme]]
[[Category:Scheme]]
[[Category:Midi]]
[[Category:Included in the official documentation]]
[[Category:Included in the official documentation]]
[[Category:Snippet]]

Latest revision as of 10:58, 25 December 2025

The default MIDI instrument equalizer can be replaced by setting the instrumentEqualizer property in the Score context to a user-defined Scheme procedure that uses a MIDI instrument name as its argument along with a pair of fractions indicating the minimum and maximum volumes, respectively, to be applied to that specific instrument.

The following example sets the minimum and maximum volumes for flute and clarinet.

\version "2.24"

#(define my-instrument-equalizer-alist '())

#(set! my-instrument-equalizer-alist
  (append
    '(("flute" . (0.7 . 0.9))
      ("clarinet" . (0.3 . 0.6)))
    my-instrument-equalizer-alist))

#(define (my-instrument-equalizer s)
  (let ((entry (assoc s my-instrument-equalizer-alist)))
    (if entry
      (cdr entry))))

\score {
  <<
    \new Staff {
      \key g \major
      \time 2/2
      \set Score.instrumentEqualizer = #my-instrument-equalizer
      \set Staff.midiInstrument = "flute"
      \new Voice \relative {
        r2 g''\mp g fis~
        4 g8 fis e2~
        4 d8 cis d2
      }
    }
    \new Staff {
      \key g \major
      \set Staff.midiInstrument = "clarinet"
      \new Voice \relative {
        b'1\p a2. b8 a
        g2. fis8 e
        fis2 r
      }
    }
  >>
  \layout { }
  \midi {  }
}