This paper considers a generative model for retrieving music in a corpus that is similar to a given query based on melodic similarity. The model assumes that the melodic contour and contextual variable(pitch range) of the query are generated from those of other music in the corpus. From the model, the contribution of each music in generating the query is considered for retrieval. The music generative model is tested on two systems: similar music searching system, melody recognition system. The similar music searching system is evaluated using the MIREX 2005 symbolic melodic similarity test collections. The melody recognition system is evaluated using the PASCAL collections. The test results show that the systems based on the proposed music generative model are better than previous systems.