The answer is not exactly 100% of the time, because then there would be no gap, and you would not notice when one note ends and the next one starts.
You're not completely explaining the program, but I think what you mean is: if the pitch and volume do not change, then you won't be able to hear when one note starts and the next ends.
Now we have a better way to start the real discussion. A melodic line will have pitch, duration, and volume - or articulation - elements.
It should be obvious that while duration is 100% of rhythm values changing pitch will distinguish notes. You don't need to cut off durations in that case.
When the pitch stays the same articulation is the important way to distinguish notes. Think about acoustic instruments and it should be clear. Even sustaining instruments like bowed strings, flute, or pipe organ - compared to percussion - will have a audible difference in volume and tone at the initial production of a note. There will be an "attack." Envelope is the technical term with stages: attack, decay, sustain, and release.
Consider a single quarter note. The beginning won't sound the same as the middle and end. When a series of repeated notes is played, for example four quarter notes of C4
, the player then must make some kind of decision about how to articulate them. On a bowed instrument the basic articulation is to change bow direction. Certainly there will be some decrease in volume of sound when the bow direction is changed, but it will be very brief and the instrument will still be resonating. The big difference in sound will be the articulation, how the bow "digs" back into the string. If you analyzed the sound, I expect both timbre (different overtones) and volume/envelope changes would be seen.
What to do in your program depends on how the thing actually produces sound. If the sound generator does not have articulations, if the program is just pitch and duration, then I think you should at least have a function to check whether the next note is a repeated pitch, and only put in a brief space for a simple articulation in those cases. If pitches change, don't add spaces. In a series of changing pitches only add space if there is some kind of notated rest. If volume it an element in the program, you could try envelope modeling of volume over the length of notes. But that could get fairly complex if it looks ahead for pitch changes, rests, or some element to indicate the end of phrases.
It depends on how staccato you want to play
That potentially brings in a different topic: how to interpret a staccato mark. But I image your program's input won't really be dealing with articulation marks. So this shouldn't be a concern.