How does phonemic variation in vowel quantity (but not quality) work in e.g. songs? For example, there is a variety of Yiddish that has both /a/ and /aː/. They must differ in quantity but do not seem to differ in quality. How would one distinguish them e.g. if they were in the same place in a particular melody, or in rapid speech?
Songs are special since melody and rhythm dictate the length of a note. A lot of contrasts that are made in speech are neutralised in songs.
The rules for singing German songs prescribe only "pure vowels" (a, e, i, o, u, ø, y), the phonemes ɛ, ə, ɔ, ɪ, ʊ, œ, and ʏ are to be replaced with the closest pure vowel. Vowel length is also not marked in sung German. Note that these rules apply to composed songs (Kunstlied, choruses) but are relaxed in pop songs: Xavier Naidoo uses a very long ɪ: in the chorus of the song "Ich kenne nichts".
I'm not actually sure what you are asking about – "phonemic variation in vowel quantity (but not quality) work in e.g. songs". Indeed, "long" vs "short" vowels in Germanic are typically associated with quality differences. But in many languages (Bantu languages, Japanese, Finnic and Saamic languages) length isn't indirectly expressed by quality differences. The phonetic difference between long and short vowels in those languages is one of duration (I take it that by "phonemic variation" you are referring to the fact that length is phonemically contrastive): long vowels are longer than corresponding short vowels by some amount (we do not have a particularly rich database of phonetic studies that established the ratio of long to short, but languages do differ in how much longer a long vowel is).
It's not clear what you mean by "e.g. song" – other domains for looking at vowel length include metrical structure, tone assignment, syllable structure... Ross & Lehiste The Temporal Structure of Estonian Runic Songs investigate the question for Estonian which has contrastive vowel and consonant length. Regrettably, I don't have a copy of the book, but my understanding is that the requirements of metrical structure for the runo match the foot structure of the spoken language, so for example a long vowel will not be in a metrically weak position (non-initial within the foot).