00001 #include "MusimatChapter9.h" 00002 MusimatChapter9Section(C091406c) { 00003 Print("*** A Less Boring (?) Musical Example ***"); 00004 /***************************************************************************** 00005 00006 A Less Boring (?) Musical Example 00007 00008 Unfortunately, this melody is dreadfully dull, but it strictly obeys our requirements. This goes to 00009 show that one only gets back from an approach like this exactly what one specifies. A more graceful 00010 melody might rise to its climax gradually, then fall at the end. The following example accomplishes 00011 this by selecting among a set of probability distributions at different points of the melody. 00012 *****************************************************************************/ 00013 para1(); // Step into this function to continue. 00014 } 00015 00016 00017 //each list specifies 13 pitches 00018 RealList a( //force choice to be pitch C 00019 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 00020 ); 00021 RealList b( //force selection of C#, D, D#, E, or F 00022 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 00023 ); 00024 RealList c( //force selection of F#, G, G# A, A#, or B 00025 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0 00026 ); 00027 RealList d( // force selection of pitch c an octave above 00028 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 00029 ); 00030 00031 // indicate what percentage of the score is completed 00032 Real progress(Integer p, Integer L) { 00033 Return Real(p) / Real(L); // L is the total number of notes and p is the current note 00034 } 00035 00036 StringList n("C", "Cs", "D", "Ds", "E", "F", "Fs", 00037 "G", "Gs", "A", "As", "B", "c"); 00038 00039 Void randomMelody(RealList a, RealList b, RealList c, RealList d) { 00040 Integer K = 25; // we'll play 25 notes 00041 Integer highPoint = Integer(K * 2.0/3.0); 00042 normalize(a, sum(a)); normalize(b, sum(b)); 00043 normalize(c, sum(c)); normalize(d, sum(c)); 00044 StringList s; // a place to put result 00045 For (Integer i = 0; i < K; i++) { 00046 RealList f; 00047 00048 If (i == 0 Or i == K - 1) // force first and last notes to 00049 f = a; // be pitch C 00050 Else If (progress(i, K) < 0.30) // less than 30% of the way? 00051 f = b; // force lower hexachord 00052 Else If (progress(i, K) < 0.60) // between 30% and 60%? 00053 f = c; // force upper hexachord 00054 Else If (i == highPoint) // force high point to be high c 00055 f = d; 00056 Else If (progress(i, K) < 0.80) // between 60% and 80%? 00057 f = c; // force upper hexachord 00058 Else // otherwise force lower hexachord 00059 f = b; 00060 00061 f = normalize(f, sum(f)); // replace f with its normalized form 00062 accumulate(f); 00063 Real r = Random(); 00064 Integer p = getIndex(f, r); 00065 s[i] = n[p]; // n is StringList defined in previous example 00066 } 00067 00068 Print(s); 00069 } 00070 00071 Static Void para1() { 00072 /***************************************************************************** 00073 Running this program will generate something like figure 9.24, depending upon the values pro- 00074 duced by Random(). The distributions responsible for each section are shown in the figure. 00075 *****************************************************************************/ 00076 00077 // Each list specifies 13 pitches 00078 // List a forces the choice to be pitch C 00079 RealList a( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ); 00080 // List b forces C#, D, D#, E, or F 00081 RealList b ( 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 ); 00082 // List c forces F#, G, G# A, A#, or B 00083 RealList c ( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0 ); 00084 // List d forces pitch c an octave above 00085 RealList d ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 ); 00086 SeedRandom( Time() ); // force a new choice every time 00087 randomMelody( a, b, c, d ); 00088 00089 /***************************************************************************** 00090 The musical example in figure 9.24 is certainly an improvement, but I doubt it would win any 00091 prizes. Certainly a composer of a melody takes its whole shape into consideration during writing, 00092 but successive weighted random selections are completely independent of the past and future. 00093 Many composers have used techniques like this to obtain freedom from predictable musical con- 00094 texts. But we must have a way to correlate past and future choices to the present before random 00095 choice techniques are of use in those musical styles that manipulate listener expectation. The next 00096 section lays the foundations for a mathematics of expectation. 00097 *****************************************************************************/ 00098 } 00099 00101 /* $Revision: 1.3 $ $Date: 2006/09/05 08:02:46 $ $Author: dgl $ $Name: $ $Id: C091406c.cpp,v 1.3 2006/09/05 08:02:46 dgl Exp $ */ 00102 // The Musimat Tutorial � 2006 Gareth Loy 00103 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" � 2006 Gareth Loy 00104 // and published exclusively by The MIT Press. 00105 // This program is released WITHOUT ANY WARRANTY; without even the implied 00106 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 00107 // For information on usage and redistribution, and for a DISCLAIMER OF ALL 00108 // WARRANTIES, see the file, "LICENSE.txt," in this distribution. 00109 // "Musimathics" is available here: http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916 00110 // Gareth Loy's Musimathics website: http://www.musimathics.com/ 00111 // The Musimat website: http://www.musimat.com/ 00112 // This program is released under the terms of the GNU General Public License 00113 // available here: http://www.gnu.org/licenses/gpl.txt 00114