Find the tonal centre
Identify the note or chord that feels like home. A piano roll, tuner or theory reference can help, but use your ear to confirm whether the result fits the loop.
Minor scales are common in darker moods, while major scales can feel bright or uplifting, yet harmony and rhythm influence emotion just as strongly. No scale guarantees a particular feeling.
Build motifs with rhythm
Try a three- to five-note phrase and vary its rhythm before adding more pitches. Repetition helps listeners recognise a motif.
Use passing notes or occasional notes outside the scale deliberately when they create tension. Resolve them in a way that supports the melody rather than adding complexity for its own sake.
Test the melody with chords and bass
Play the motif over the chord progression and bass line. A note that sounds convincing alone may clash with a chord at a particular moment.
If you are unsure, simplify the harmony and compare alternatives. Theory is most useful when it helps you explain what your ear already notices and discover options you might not have tried.