[ << General input and output ] | [Top][Contents][Index] | [ Spacing issues >> ] |
[ < The MIDI block ] | [ Up : Creating MIDI output ] | [ Dynamic marks in MIDI > ] |
3.6.4 Controlling MIDI dynamics
It is possible to control the overall MIDI volume, the relative volume of dynamic markings and the relative volume of different instruments.
Dynamic marks translate automatically into volume levels in the available MIDI volume range whereas crescendi and decrescendi vary the volume linearly between their two extremes. It is possible to control the relative volume of dynamic markings, and the overall volume levels of different instruments.
Dynamic marks in MIDI | ||
Setting MIDI volume | ||
Setting MIDI block properties |
[ << General input and output ] | [Top][Contents][Index] | [ Spacing issues >> ] |
[ < Controlling MIDI dynamics ] | [ Up : Controlling MIDI dynamics ] | [ Setting MIDI volume > ] |
Dynamic marks in MIDI
Only the dynamic markings from ppppp
to fffff
, including
mp
, mf
and sf
have values assigned to them. This
value is then applied to the value of the overall MIDI volume range to
obtain the final volume included in the MIDI output for that particular
dynamic marking. The default fractions range from 0.25 for
ppppp to 0.95 for fffff. The complete set of
dynamic marks and their associated fractions can be found in
‘scm/midi.scm’.
Selected Snippets
Creating custom dynamics in MIDI output
The following example shows how to create a dynamic marking, not included in the default list, and assign it a specific value so that it can be used to affect MIDI output.
The dynamic mark \rfz
is assigned a value of 0.9
.
#(define (myDynamics dynamic) (if (equal? dynamic "rfz") 0.9 (default-dynamic-absolute-volume dynamic))) \score { \new Staff { \set Staff.midiInstrument = #"cello" \set Score.dynamicAbsoluteVolumeFunction = #myDynamics \new Voice { \relative { a'4\pp b c-\rfz } } } \layout {} \midi {} }
Installed Files: ‘ly/script-init.ly’ ‘scm/midi.scm’.
Snippets: MIDI.
Internals Reference: Dynamic_performer.
[ << General input and output ] | [Top][Contents][Index] | [ Spacing issues >> ] |
[ < Dynamic marks in MIDI ] | [ Up : Controlling MIDI dynamics ] | [ Setting MIDI block properties > ] |
Setting MIDI volume
The minimum and maximum overall volume of MIDI dynamic markings is
controlled by setting the properties midiMinimumVolume
and
midiMaximumVolume
at the Score
level. These properties
have an effect only at the start of a voice and on dynamic marks. The
fraction corresponding to each dynamic mark is modified with this
formula
midiMinimumVolume + (midiMaximumVolume - midiMinimumVolume) * fraction
In the following example the dynamic range of the overall MIDI volume is limited to the range 0.2–0.5.
\score { << \new Staff { \set Staff.midiInstrument = "flute" … music … } \new Staff { \set Staff.midiInstrument = "clarinet" … music … } >> \midi { \context { \Score midiMinimumVolume = #0.2 midiMaximumVolume = #0.5 } } }
Simple MIDI instrument equalization can be achieved by setting
midiMinimumVolume
and midiMaximumVolume
properties within
the Staff
context.
\score { \new Staff { \set Staff.midiInstrument = "flute" \set Staff.midiMinimumVolume = #0.7 \set Staff.midiMaximumVolume = #0.9 … music … } \midi { } }
For scores with multiple staves and multiple MIDI instruments, the relative volumes of each instrument can be set individually;
\score { << \new Staff { \set Staff.midiInstrument = "flute" \set Staff.midiMinimumVolume = #0.7 \set Staff.midiMaximumVolume = #0.9 … music … } \new Staff { \set Staff.midiInstrument = "clarinet" \set Staff.midiMinimumVolume = #0.3 \set Staff.midiMaximumVolume = #0.6 … music … } >> \midi { } }
In this example the volume of the clarinet is reduced relative to the volume of the flute.
If these volumes properties are not set then LilyPond still applies a ‘small degree’ of equalization to certain instruments. See ‘scm/midi.scm’.
Installed Files: ‘scm/midi.scm’.
See also
Notation Reference: Score layout.
Internals Reference: Dynamic_performer.
Selected Snippets
Replacing default MIDI instrument equalization
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 respectively."
#(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 { } }
Known issues and warnings
Changes in the MIDI volume take place only on starting a note, so crescendi and decrescendi cannot affect the volume of a single note.
[ << General input and output ] | [Top][Contents][Index] | [ Spacing issues >> ] |
[ < Setting MIDI volume ] | [ Up : Controlling MIDI dynamics ] | [ Using MIDI instruments > ] |
Setting MIDI block properties
The \midi
block can contain context rearrangements, new context
definitions or code that sets the values of certain properties.
\score { … music … \midi { \tempo 4 = 72 } }
Here the tempo is set to 72 quarter note beats per minute. The tempo
mark in the \midi
block will not appear in the printed score.
Although any other \tempo
indications specified within the
\score
block will also be reflected in the MIDI output.
In a \midi
block the \tempo
command is setting properties
during the interpretation of the music and in the context of output
definitions; so it is interpreted as if it were a context
modification.
Context definitions follow the same syntax as those in a \layout
block;
\score { … music … \midi { \context { \Voice \remove Dynamic_performer } } }
This example removes the effect of dynamics from the MIDI output. Note: LilyPond’s translation modules used for sound are called ‘performers’.
See also
Learning Manual: Other sources of information.
Notation Reference: Expressive marks, Score layout.
Installed Files: ‘ly/performer-init.ly’.
Snippets: MIDI.
Internals Reference: Dynamic_performer.
Known issues and warnings
Some MIDI players do not always correctly handle tempo changes in the midi output.
Changes to the midiInstrument
, as well as some MIDI options, at
the beginning of a staff may appear twice in the MIDI output.
[ << General input and output ] | [Top][Contents][Index] | [ Spacing issues >> ] |
[ < Setting MIDI volume ] | [ Up : Controlling MIDI dynamics ] | [ Using MIDI instruments > ] |