- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/MusimatChapter9/C091406c.cpp

Go to the documentation of this file.

    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 Integer N = 13;                                         //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 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 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 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                 If (i == 0 Or i == K - 1)                               // force first and last notes to
    00048                         f = a;                                                          // be pitch C
    00049                 Else If (progress(i, K) < 0.30)                 // less than 30% of the way?
    00050                         f = b;                                                          // force lower hexachord
    00051                 Else If (progress(i, K) < 0.60)                 // between 30% and 60%?
    00052                         f = c;                                                          // force upper hexachord
    00053                 Else If (i == highPoint)                                // force high point to be high c
    00054                         f = d;
    00055                 Else If (progress(i, K) < 0.80)                 // between 60% and 80%?
    00056                         f = c;                                                          // force upper hexachord
    00057                 Else                                                                    // otherwise force lower hexachord
    00058                         f = b;
    00059                 f = normalize(f, sum(f));                               // replace f with its normalized form
    00060                 accumulate(f);
    00061                 Real r = Random();
    00062                 Integer p = getIndex(f, r);
    00063                 s[i] = n[p];                                                    // n is StringList defined in previous example
    00064         }
    00065
    00066         Print(s);
    00067 }
    00068
    00069 Static Void para1() {
    00070 /*****************************************************************************
    00071 Running this program will generate something like figure 9.24, depending upon the values pro-
    00072 duced by Random(). The distributions responsible for each section are shown in the figure.
    00073 *****************************************************************************/
    00074
    00075         Integer N = 13;                                         // Each list specifies 13 pitches
    00076         // List a forces the choice to be pitch C
    00077         RealList a( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
    00078         // List b forces C#, D, D#, E, or F
    00079         RealList b ( 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
    00080         // List c forces F#, G, G# A, A#, or B
    00081         RealList c ( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0 );
    00082         // List d forces pitch c an octave above
    00083         RealList d ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
    00084         SeedRandom( Time() );   // force a new choice every time
    00085         randomMelody( a, b, c, d );
    00086
    00087 /*****************************************************************************
    00088 The musical example in figure 9.24 is certainly an improvement, but I doubt it would win any
    00089 prizes. Certainly a composer of a melody takes its whole shape into consideration during writing,
    00090 but successive weighted random selections are completely independent of the past and future.
    00091 Many composers have used techniques like this to obtain freedom from predictable musical con-
    00092 texts. But we must have a way to correlate past and future choices to the present before random
    00093 choice techniques are of use in those musical styles that manipulate listener expectation. The next
    00094 section lays the foundations for a mathematics of expectation.
    00095 *****************************************************************************/
    00096 }}
    00097
    00099 /* $Revision: 1.2 $ $Date: 2006/09/09 06:22:44 $ $Author: dgl $ $Name:  $ $Id: _c091406c_8cpp-source.html,v 1.2 2006/09/09 06:22:44 dgl Exp $ */
    00100 // The Musimat Tutorial © 2006 Gareth Loy
    00101 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy
    00102 // and published exclusively by The MIT Press.
    00103 // This program is released WITHOUT ANY WARRANTY; without even the implied
    00104 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00105 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
    00106 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
    00107 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
    00108 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
    00109 // The Musimat website:                 http://www.musimat.com/
    00110 // This program is released under the terms of the GNU General Public License
    00111 // available here:                      http://www.gnu.org/licenses/gpl.txt
    00112