A computer readable storage medium which stores a music playing program executed by a computer of a music playing apparatus for making a player play a melody of a predetermined piece of music, the music playing apparatus storing music data which indicates at least a pitch of each of sounds which form the melody of the predetermined piece of music and an output timing to output each of the sounds, the music playing program causing the computer to execute: a detection step for sequentially detecting, among the sounds included in the music data, a target sound which is a sound an output timing of which comes after start of playing by the music data; an input acceptance step for accepting an input for instructing a timing of outputting a sound from an input device of the music playing apparatus; a first sound output step for outputting the target sound in the case where the input accepted at the input acceptance step is a first input when or after the output timing of the target sound detected at the detection step comes; an ad-lib sound determination step (S28, S29, S30, S51) for determining a pitch of an ad-lib sound based at least on one of a pitch of the target sound and a pitch of a next target sound an output timing of which comes after the target sound, the ad-lib sound determination step including a nomination range setting step for setting a nomination range based on either or both of a target sound and a next target sound and setting the pitch of the ad-lib sound from within the nomination range, in the case where the input accepted by the input acceptance step is a second or later input after the output timing of the target sound detected at the detection step comes; and a second sound output step for outputting the ad-lib sound at the pitch which is determined at the ad - lib sound determination step. a detection step for sequentially detecting, among the sounds included in the music data, a target sound which is a sound an output timing of which comes after start of playing by the music data; an input acceptance step for accepting an input for instructing a timing of outputting a sound from an input device of the music playing apparatus; a first sound output step for outputting the target sound in the case where the input accepted at the input acceptance step is a first input when or after the output timing of the target sound detected at the detection step comes; an ad-lib sound determination step (S28, S29, S30, S51) for determining a pitch of an ad-lib sound based at least on one of a pitch of the target sound and a pitch of a next target sound an output timing of which comes after the target sound, the ad-lib sound determination step including a nomination range setting step for setting a nomination range based on either or both of a target sound and a next target sound and setting the pitch of the ad-lib sound from within the nomination range, in the case where the input accepted by the input acceptance step is a second or later input after the output timing of the target sound detected at the detection step comes; and a second sound output step for outputting the ad-lib sound at the pitch which is determined at the ad - lib sound determination step.