I played with this idea when I was doing an algorithmic composition project. I started with a Markov chain analysis of a simple Chopin etude, which gave me parameters, such as:
- The distance between the lowest and highest note is 2 octaves
- The key won't change, so there are only 8 notes per octave and given the first parameter, I only had 17 notes to choose from.
- The shortest note was an 1/8th and the longest was a half. Most were quarters and there were a few dotted quarters (if I recall) so there were 4 note lengths to choose from.
- The main melody in the original was 4 measures (again, if I recall) so my generated melodies were set to be that length, and always end on the root<p>Given all of these parameters, there were still many thousands of combinations. Applying the Markov chain limited that a lot, but that was only to make it sound like Chopin (which it did, a little). However, most of the thousands of combinations sound like crap, which is not an insignificant point. If you're willing to call some random sequence of notes a melody, then there are an infinite number
Mozart had a dice game to create minuets.<p>(<a href="http://sunsite.univie.ac.at/Mozart/dice/" rel="nofollow">http://sunsite.univie.ac.at/Mozart/dice/</a>)<p>(<a href="http://en.wikipedia.org/wiki/Musikalisches_W%C3%BCrfelspiel" rel="nofollow">http://en.wikipedia.org/wiki/Musikalisches_W%C3%BCrfelspiel</a>)<p>Your question is tricky because you haven't mentioned anything about time signatures or length of time for each note, nor how many octaves you want to work with.<p>A regular piano has 88 keys.<p>So, 88 notes with a 32 note length sequence (with fixed times etc) means 88 ^ 32 or 1.6728057e+62.
More melodies need at most a 2 octave range (especially in pop), which limits us to 24 choices for each melody note.<p>(Actually less, if you factor in the constrains of the specific key the tune is in, but let's be maximalist and get an upper bound).<p>Now, a melody also comes with a rhythm / syncopation pattern, but let's just count simple 8th notes in our test case (one can consider a whole note as 8 consecutive "legato" 8th notes of the same pitch for our purposes).<p>How many bars? 8 bars might be a good starting point (many pop verses are that, eg: <a href="http://en.wikipedia.org/wiki/Thirty-two-bar_form" rel="nofollow">http://en.wikipedia.org/wiki/Thirty-two-bar_form</a> ).<p>So, that would gives us: 8 bars * 8 eights with 24 notes for each eight, which gives us roughly: (8*8)^24 different melodies.<p>Which is like, a lot, man (think 40-figure range).<p>In practice it could be from much less (considering key constraints which limits the notes you could use) to much more (considering higher than 2 octaves Zappa or avant-guard like melodies, durations shorter than 8ths, etc).<p>Another major factor is the "melodic quality" of the melody, which is kinda subjective. 8 bars of 8th C notes, for example, wouldn't be that interesting, and many people would not even consider them a melody.<p>Still that would leave billions of quality melodies in the millions of trillions of possible melodies.