I never put foam inside of an instrument, just damped from outside, so I don’t know if this would work. If you damp from outside you will need a melodica that is either built like an accordion (Vibrandoneon or Eolina) or that has slits at the bottom, so either you can press the melodica against your body or tape the slits.