I recently came across a $7 app for your phone (IOS or android) called PITCHBOP, which plays a melody, and then you sing it back (or play it back with your instrument), and the app immediately tells you if you got the pitches and rhythms correct, and then without skipping a beat gives you another melody to try. You can set the app to do very simple 2-3 note melodies with simple, slow rhythms , or melodies with many notes and very complex, fast rhythms.
Here are 2 videos that explain it: the shorter one shows what it can do, and the longer one shows you the different parameters you can set to customize your experience from novice to pro musician.
Pitchbop on Youtube
I just started using the app, but so far it looks ideal for hearing melodies and singing them right back, endlessly.