#include "MusimatChapter9.h"Go to the source code of this file.
Functions | |
| MusimatChapter9Section (C091406c) | |
| RealList | a (1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
| RealList | b (0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0) |
| RealList | c (0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0) |
| RealList | d (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1) |
| Real | progress (Integer p, Integer L) |
| StringList | n ("C","Cs","D","Ds","E","F","Fs","G","Gs","A","As","B","c") |
| Void | randomMelody (RealList a, RealList b, RealList c, RealList d) |
| Static Void | para1 () |
Variables | |
| Integer | N = 13 |
| RealList a | ( | 1 | , | |
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | ||||
| ) |
| RealList b | ( | 0 | , | |
| 1 | , | |||
| 1 | , | |||
| 1 | , | |||
| 1 | , | |||
| 1 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | ||||
| ) |
| RealList c | ( | 0 | , | |
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 1 | , | |||
| 1 | , | |||
| 1 | , | |||
| 1 | , | |||
| 1 | , | |||
| 1 | , | |||
| 0 | ||||
| ) |
| RealList d | ( | 0 | , | |
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 0 | , | |||
| 1 | ||||
| ) |
| MusimatChapter9Section | ( | C091406c | ) |
Definition at line 2 of file C091406c.cpp.
References para1().
00002 { 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 }
| StringList n | ( | "C" | , | |
| "Cs" | , | |||
| "D" | , | |||
| "Ds" | , | |||
| "E" | , | |||
| "F" | , | |||
| "Fs" | , | |||
| "G" | , | |||
| "Gs" | , | |||
| "A" | , | |||
| "As" | , | |||
| "B" | , | |||
| "c" | ||||
| ) |
| Static Void para1 | ( | ) |
Definition at line 69 of file C091406c.cpp.
References a, b, c, d(), N, randomMelody(), and SeedRandom().
00069 { 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 }}
| Real progress | ( | Integer | p, | |
| Integer | L | |||
| ) |
Definition at line 32 of file C091406c.cpp.
00032 { 00033 Return Real(p) / Real(L); // L is the total number of notes and p is the current note 00034 }
| Void randomMelody | ( | RealList | a, | |
| RealList | b, | |||
| RealList | c, | |||
| RealList | d | |||
| ) |
Definition at line 39 of file C091406c.cpp.
References accumulate(), Chapter9::f, getIndex(), n(), normalize(), progress(), Random(), and sum().
00039 { 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 }
| Integer N = 13 |
Definition at line 17 of file C091406c.cpp.
1.4.7