C:/Musimathics_local/Musimat/MusimatChapter9/C091406a.cpp

Go to the documentation of this file.
00001 #include "MusimatChapter9.h"
00002 MusimatChapter9Section(C091406a) {
00003 Print("*** Accumulation ***");
00004 /*****************************************************************************
00005 Accumulation
00006 
00007 If we index the y-axis of figure 9.22 with a random value in the unit interval, the corresponding 
00008 x-axis value will be one of the 12 pitches of the scale. Furthermore, the choice will more likely 
00009 fall on a step that occupies a wider footprint on the y-axis, corresponding in this case to the 
00010 lower pitches of the scale, just as we wanted. We can create the cumulative distribution function 
00011 in figure 9.22 as follows:
00012 *****************************************************************************/
00013         para1(); // Step into this function to continue.
00014 }
00015 
00016 RealList Reference accumulate(RealList Reference L){
00017         For(Integer i = 1; i < Length(L); i = i + 1){
00018                  L[i] = L[i] + L[i - 1];
00019         }
00020         Return(L);
00021 }
00022 
00023 Static Void para1() {
00024 /*****************************************************************************
00025 Starting with the second element in the list (indexed as 1), we replace this element with its original 
00026 value plus the value of the previous element. As we proceed through the list, each list element will 
00027 be equal to itself plus all previous elements. Given the preparation of the RealList r performed 
00028 above, Print(accumulate(r)); prints {0.15, 0.29, 0.42, 0.54, 0.64, 0.73, 0.81, 
00029 0.87, 0.92, 0.96, 0.99, 1.0}.
00030 
00031 We have prepared the cumulative distribution function, and now we can access it with a random 
00032 value to select a pitch. Pick a number in the unit interval to be the next note of the melody: 
00033 *****************************************************************************/
00034 
00035 Real R = Random();
00036 
00037 /*****************************************************************************
00038 R will fall within the range of one of the 12 steps in figure 9.22 because both Random() and the 
00039 cumulative distribution function exactly span the unit interval, 0 to 1. For example, if R equals 0.1, 
00040 then by inspection of figure 9.22, we can see that R lies within the first step, which covers the inter-
00041 val [0, 0.15], so the pitch that this value of R selects is C.
00042 *****************************************************************************/
00043 }}
00044 
00046 /* $Revision: 1.4 $ $Date: 2006/09/12 17:37:27 $ $Author: dgl $ $Name:  $ $Id: _c091406a_8cpp-source.html,v 1.4 2006/09/12 17:37:27 dgl Exp $ */
00047 // The Musimat Tutorial © 2006 Gareth Loy
00048 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00049 // and published exclusively by The MIT Press.
00050 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00051 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00052 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00053 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00054 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00055 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00056 // The Musimat website:                 http://www.musimat.com/
00057 // This program is released under the terms of the GNU General Public License
00058 // available here:                      http://www.gnu.org/licenses/gpl.txt
00059 

Generated on Tue Sep 12 10:14:15 2006 for Musimat Chapter 9 Code Examples by  doxygen 1.4.7