Why is the tonic so important for melodies?

I made a simple melody in FL studio that was in C Major. The melody consisted of two phrases both of which started on D. The only difference between the two is the second phrase ended on C (the tonic of C major). The only problem is it didn’t feel resolved ending on the tonic like I thought it would. When I changed the last note of the tonic to a D it sounded resolved even though D is not the tonic of C Major. I’m assuming it has something to do with the context in which I’m using it. For reference, I didn’t use C at all until I tried to resolve the second phrase and the other notes used we’re D,F,G,A and E. Any insight into why it didn’t sound resolved even though I used the tonic? Is there a fundamental concept I’m missing here?
 
If you used D F G A and E in your melody, that might as weel be in D minor not necessraly C major. It depends on context...You are composing over chords?
I'm not using any chords... Just a melody one note at a time. I think you're right, the notes I used are in more than one scale. My next question would then be, what defines which scale you're in? Why did my melody favor a scale starting at D as the tonic rather than C if the notes I used are in both scales?
 

members online

Top