Functions

/Users/garethloy/Musimathics/Musimat1.2/MusimatChapter9/C091406c.cpp File Reference

#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 ()

Function Documentation

RealList a ( ,
,
,
,
,
,
,
,
,
,
,
,
 
)
RealList b ( ,
,
,
,
,
,
,
,
,
,
,
,
 
)
RealList c ( ,
,
,
,
,
,
,
,
,
,
,
,
 
)
RealList d ( ,
,
,
,
,
,
,
,
,
,
,
,
 
)
MusimatChapter9Section ( C091406c   )

Definition at line 2 of file C091406c.cpp.

References para1().

                                 {
        Print("*** A Less Boring (?) Musical Example ***");
        /*****************************************************************************
         
         A Less Boring (?) Musical Example
         
         Unfortunately, this melody is dreadfully dull, but it strictly obeys our requirements. This goes to 
         show that one only gets back from an approach like this exactly what one specifies. A more graceful 
         melody might rise to its climax gradually, then fall at the end. The following example accomplishes 
         this by selecting among a set of probability distributions at different points of the melody.
         *****************************************************************************/
        para1(); // Step into this function to continue.
}
StringList n ( "C"  ,
"Cs"  ,
"D"  ,
"Ds"  ,
"E"  ,
"F"  ,
"Fs"  ,
"G"  ,
"Gs"  ,
"A"  ,
"As"  ,
"B"  ,
"c"   
)
Static Void para1 (  )

Definition at line 71 of file C091406c.cpp.

References a(), b(), c(), d(), and randomMelody().

                    {
        /*****************************************************************************
         Running this program will generate something like figure 9.24, depending upon the values pro-
         duced by Random(). The distributions responsible for each section are shown in the figure.
         *****************************************************************************/
        
        // Each list specifies 13 pitches
        // List a forces the choice to be pitch C
        RealList a( 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
        // List b forces C#, D, D#, E, or F
        RealList b ( 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 );
        // List c forces F#, G, G# A, A#, or B
        RealList c ( 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0 );
        // List d forces pitch c an octave above
        RealList d ( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 );
        SeedRandom( Time() );   // force a new choice every time
        randomMelody( a, b, c, d );
        
        /*****************************************************************************
         The musical example in figure 9.24 is certainly an improvement, but I doubt it would win any 
         prizes. Certainly a composer of a melody takes its whole shape into consideration during writing, 
         but successive weighted random selections are completely independent of the past and future. 
         Many composers have used techniques like this to obtain freedom from predictable musical con-
         texts. But we must have a way to correlate past and future choices to the present before random 
         choice techniques are of use in those musical styles that manipulate listener expectation. The next 
         section lays the foundations for a mathematics of expectation.
         *****************************************************************************/
}
Real progress ( Integer  p,
Integer  L 
)

Definition at line 32 of file C091406c.cpp.

                                    {
        Return Real(p) / Real(L);       // L is the total number of notes and p is the current note
}
Void randomMelody ( RealList  a,
RealList  b,
RealList  c,
RealList  d 
)

Definition at line 39 of file C091406c.cpp.

References a(), accumulate(), b(), c(), d(), f(), getIndex(), n(), normalize(), progress(), and sum().

                                                                  {
        Integer K = 25;                                                         // we'll play 25 notes
        Integer highPoint = Integer(K * 2.0/3.0);
        normalize(a, sum(a)); normalize(b, sum(b));
        normalize(c, sum(c)); normalize(d, sum(c));
        StringList s;                                                           // a place to put result
        For (Integer i = 0; i < K; i++) {
                RealList f;
                
                If (i == 0 Or i == K - 1)                               // force first and last notes to
                        f = a;                                                          // be pitch C
                Else If (progress(i, K) < 0.30)                 // less than 30% of the way?
                        f = b;                                                          // force lower hexachord
                Else If (progress(i, K) < 0.60)                 // between 30% and 60%?
                        f = c;                                                          // force upper hexachord
                Else If (i == highPoint)                                // force high point to be high c 
                        f = d;
                Else If (progress(i, K) < 0.80)                 // between 60% and 80%?
                        f = c;                                                          // force upper hexachord
                Else                                                                    // otherwise force lower hexachord
                        f = b;
                
                f = normalize(f, sum(f));                               // replace f with its normalized form
                accumulate(f);
                Real r = Random();
                Integer p = getIndex(f, r);
                s[i] = n[p];                                                    // n is StringList defined in previous example
        }
        
        Print(s);
}