Discussion:
Mapping pitches to other pitches when generating MIDI files for percussion?
Vinicius Mascarenhas
2018-11-13 03:22:41 UTC
Permalink
Hey y’all,

TLDR: I need to map different pitches displayed in the layout block / PDF file to a single sound in the midi block / file (like say map both c and a to b,) but I can’t to that to the whole staff — I need to be able to map other sets of pitches to another single sound. Can Lilypond do this?

Rationale if you’re curious (feel free to skip it though):

I’m writing for a group that mostly plays drums — to be more precise, taiko drums. We rely on vertical position a lot so I can’t just use DrumStaff of RhythmicStaff, which print all notes on the line. Instead I override the staff symbol line positions to create a one-line staff for the most part, or an N-line staff for the occasions where the same person has N distinct drums to play simultaneously. This staff is a regular, pitched staff. Like you could write a piano piece on it, even though it only has one line, which is the line a b pitch falls on if you’re going treble clef. Oh and I also change the clef glyph so it looks like a percussion clef but it’s really still the old treble clef.

All in all, pitches are written like c and a because c is the first pitch above the line and a is the first pitch below it. It’s basically a two-key piano for all intents and purposes. We use those two vertical positions for hand selection when playing on a single drum, and this is super important to taiko performers everywhere, so it’s not something I could just decide to rule out. However, no matter which hand you use to play the drum, the sound should be the same.

When using multiple drums though, sometimes those drums are of the same kind (and should still sound the same), and sometimes they’re different instruments entirely. So making the whole staff sound like a single pitch wouldn’t work. I need to map some pitches that appear in the PDF to one sound in the MIDI file (like say map both c and a to b,) and still be able to map other pitches to another sound (e.g. map f, and e, to g,,).

How can I do this with Lilypond? The only way I see is by using a find and replace command for all pitch occurrences and saving the result in a different variable for a different score that will only produce the midi output. But this is a little convoluted and needs to be redone every time a change is made. Not to mention it gets crazy with markups and other commands — even though they’re not going to be displayed in the midi file, they still cause trouble with the parser. Surely there’s a magic way to achieve this more easily?

Thanks in advance! <3
Aaron Hill
2018-11-13 07:31:20 UTC
Permalink
Post by Vinicius Mascarenhas
TLDR: I need to map different pitches displayed in the layout block /
PDF file to a single sound in the midi block / file (like say map both
c and a to b,) but I can’t to that to the whole staff — I need to be
able to map other sets of pitches to another single sound. Can
Lilypond do this?
Sounds like what could work is to define your own drum pitch names.
These would have different visual appearance in the notation but can map
to the same MIDI note. See the following:

http://lilypond.org/doc/v2.19/Documentation/snippets/midi#midi-customize-drumpitchnames-drumstyletable-and-drumpitchtable-in-layout-and-midi

Here is a adaptation of that snippet for a simple left-hand and
right-hand taiko where the left-hand marking lies below and the
right-hand above.

%%%%
\version "2.19.82"

drumPitchNames.taikolefthand = #'taikolefthand
drumPitchNames.tlh = #'taikolefthand
drumPitchNames.taikorighthand = #'taikorighthand
drumPitchNames.trh = #'taikorighthand

#(define taikoStyle
'((taikolefthand default #f -1)
(taikorighthand default #f 1)))

midiDrumPitches.taikolefthand = e
midiDrumPitches.taikorighthand = e

\score {
\new DrumStaff
\with {
\override StaffSymbol.line-count = #1
instrumentName = #"Taiko"
drumStyleTable = #(alist->hash-table taikoStyle)
drumPitchTable = #(alist->hash-table midiDrumPitches)
}
\drummode {
\set Staff.midiInstrument = #"taiko drum"
\tempo 2 = 60
tlh4. trh16 tlh trh2 | tlh8. tlh16~ 8 tlh trh2
}
\layout {}
\midi {}
}
%%%%

-- Aaron Hill
Aaron Hill
2018-11-13 21:51:01 UTC
Permalink
This is only a problem because most of our pieces have one or two
staves
for flutes. So I have to keep the custom pitch names local; otherwise,
every time I need to play a b, if I'm not mistaken, I'd need to type
"trh"
drumPitchTable = #(alist->hash-table midiDrumPitches)
Makes me think your solution IS local rather than the global scope. Is
this
correct? Like do pitch names remain unchanged for voices used in staves
where this line is not present? Sorry if the question is silly; I can't
run
the code you adapted or the one provided in the link right now.
The \with block makes those changes specific to that particular
DrumStaff, so you should not see any issues with other staves.

Also, the new drum pitch names in my example, taikolefthand and
taikorighthand, along with their handy abbreviations, tlh and trh, are
only valid within \drummode. Normal note pitch names are a different
thing, so there should be no worry about the two interfering.

-- Aaron Hill

Loading...