#include "MusimatChapter9.h"Go to the source code of this file.
Functions | |
| MusimatChapter9Section (C091406a) | |
| RealList Reference | accumulate (RealList Reference L) |
| Static Void | para1 () |
| RealList Reference accumulate | ( | RealList Reference | L | ) |
Definition at line 16 of file C091406a.cpp.
00016 { 00017 For(Integer i = 1; i < Length(L); i = i + 1){ 00018 L[i] = L[i] + L[i - 1]; 00019 } 00020 Return(L); 00021 }
| MusimatChapter9Section | ( | C091406a | ) |
Definition at line 2 of file C091406a.cpp.
References para1().
00002 { 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 }
| Static Void para1 | ( | ) |
Definition at line 23 of file C091406a.cpp.
References Random().
00023 { 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 }}
1.4.7