Not exactly what you asked for, but one possible approach is to use tags.
Tags allow for conditional use of material.
In this case, you would add a tag that is specific to MIDI
and put the repetitions in a similar way you did in the "manual" version.
Then, have two different scores, one for PDF and one for MIDI,
which use different tags.
Even in the printed score, you need to use the \keepWithTag command,
even though there is no PDF-specific content here,
in order to keep the MIDI-tagged content out.
Note that the tag names "MIDI" and "PDF" are just arbitrary words,
there is no intrinsic significance to them.
This approach becomes handy when coding other differences for MIDI,
such as fermatas, breaths, rit/accel, trills.
\version "2.19.81"
body = { c'4 c' c' c' }
voltaI = { d'4 d' d' d' }
voltaII = { e'4 e' e' e' }
voltaIII = { g'4 g' g' g' }
music = {
\repeat volta 5 \body
\set Score.repeatCommands = #'((volta "1."))
\voltaI
\tag #'MIDI { \body }
\set Score.repeatCommands = #'((volta #f) (volta "2. 3. 4.") end-repeat)
\voltaII
\tag #'MIDI {
\body \voltaII
\body \voltaII
\body }
\set Score.repeatCommands = #'((volta #f) (volta "5.") end-repeat)
\voltaIII
\set Score.repeatCommands = #'((volta #f))
\bar "|."
}
\score {
\keepWithTag #'PDF \music
\layout { }
}
\score {
\keepWithTag #'MIDI \music
\midi { }
}
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-