• Main Page
  • Files
  • File List
  • File Members

/Users/garethloy/Musimathics/Musimat1.2/MusimatChapter9/C091201e.cpp

Go to the documentation of this file.
00001 #include "MusimatChapter9.h"
00002 MusimatChapter9Section(C091201e) {
00003         Print("*** Interpolated Tendency Mask ***");
00004         /*****************************************************************************
00005          
00006          Interpolated Tendency Mask
00007          
00008          We can produce a new row that is a mixture of two other rows. 
00009          Let's have a variable that varies continuously between 0.0 and 1.0 such that when it is 0.0, the out-
00010          put row is exactly the same as the first row; when it is 0.5, the output is exactly halfway between 
00011          the first and second; and when it is 1.0, the output is exactly the second row. For example, suppose 
00012          the first pitches in each row are 3 and 9, and the interpolation parameter is 0.5. Then the expected 
00013          result would be 6 because 6 lies halfway between the two values. If the interpolation parameter 
00014          were 0.0, we'd select 3, and if it were 1.0, we'd select 9.
00015          
00016          Table 9.5 shows what happens if row A = {0, 2, 4, 6, 8, 10, 12} and row B = {12, 10, 8, 6, 4, 
00017          2, 0}, and f  is set successively to 0.0, 0.25, 0.5, 0.75, and 1.0. When f = 0, we select the prime row, 
00018          when f = 1.0, we select the retrograde row, and in between, we select weighted mixtures.
00019          
00020          We use unit interpolation to find intermediate values that lie a certain distance between two 
00021          known points. If u is the upper bound and l is the lower bound and f  is a control parameter in the 
00022          unit distance from 0.0 to 1.0, then
00023          
00024          y = f * (u - l) + l
00025          
00026          sets y to a value close to u if 0 is close to f; it sets y to a value close to l 
00027          if f is close to 1; it sets y to a value exactly halfway between u and l if f = 0.5. 
00028          
00029          Below is the function for unit interpolation:
00030          *****************************************************************************/
00031         para1(); // Step into this function to continue.
00032         para2(); // Step into this function to continue.
00033 }
00034 
00035 Static Void para1() {
00036         /*****************************************************************************
00037          This is a Real function because f must be a Real to take on fractional values. 
00038          Here are some examples of calling this function.
00039          *****************************************************************************/
00040         
00041         Print("*** Unit Interpolation ***");
00042         Print("unitInterp(0.1, 0, 10)=", unitInterp(0.1, 0, 10));
00043         Print("unitInterp(0.5, 0, 10)=", unitInterp(0.5, 0, 10));
00044         Print("unitInterp(0.9, 0, 10)=", unitInterp(0.9, 0, 10));
00045         
00046         /*****************************************************************************
00047          When we use it  as follows, we convert the Real result back to an Integer by rounding:
00048          *****************************************************************************/
00049 }
00050 
00051 Integer interpTendency(
00052                 Real f,                                                                 // factor ranging from 0.0 to 1.0
00053                 IntegerList L1, Integer Reference pos1, // list 1 and its position parameter
00054                 IntegerList L2, Integer Reference pos2, // list 2 and its position parameter
00055                 Integer inc                                                             // amount by which to adjust position
00056                 ) {
00057         Integer x = cycle(L1, pos1, inc);
00058         Integer y = cycle(L2, pos2, inc);
00059         Return(Integer(Round(unitInterp(f, x, y))));
00060 }
00061 
00062 Static Void para2() {
00063         /*****************************************************************************
00064          This function can perform a couple of neat tricks. First, we can have the function return exactly L1 
00065          or L2 by setting f = 0.0 or f = 1.0, respectively. By setting f = 0.5, we get the average of the 
00066          two rows. By gradually changing the value of f from 0.0 to 1.0, we mutate L1, transforming it grad-
00067          ually until it becomes L2. Also, the lengths of L1 and L2 need not be the same. If L1 has a length of 
00068          5 and L2 a length of 6, it will take 5 Þ 6 iterations before the pattern repeats. Both lists use the same 
00069          increment, but redesigning this to use separate increments would provide for even more possibilities.
00070          *****************************************************************************/
00071         
00072         IntegerList X(10, 20, 30, 40, 50, 60);
00073         IntegerList Y(9,   8,  7,  6,  5,  4, 3);
00074         IntegerList Z;
00075         Integer posX = 0;
00076         Integer posY = 0;
00077         Integer inc = 1;
00078         Integer i;
00079         
00080         Print("*** Interpolation Tendency ***");
00081         Print("First row: ", X);
00082         Print("Second row: ", Y);
00083         
00084         For ( i = 0; i < Length( X ); i = i + 1 ) {
00085                 Z[i] = interpTendency(0.0, X, posX, Y, posY, inc);
00086         }
00087         
00088         Print("interpTendency factor=0.0:", Z );
00089         
00090         posX = posY = 0; // reset to beginning
00091         For ( i = 0; i < Length( X ); i = i + 1 ) {
00092                 Z[i] = interpTendency(0.5, X, posX, Y, posY, inc);
00093         }
00094         
00095         Print("interpTendency factor=0.5:", Z );
00096         
00097         posX = posY = 0; // reset to beginning
00098         For ( i = 0; i < Length( X ); i = i + 1 ) {
00099                 Z[i] = interpTendency(1.0, X, posX, Y, posY, inc);
00100         }
00101         
00102         Print("interpTendency factor=1.0:", Z );
00103         
00104         posX = posY = 0; // reset to beginning
00105         For ( i = 0; i < Length( X ); i = i + 1 ) {
00106                 Z[i] = interpTendency(Real(i)/Length(X), X, posX, Y, posY, inc);
00107         }
00108         
00109         Print("interpTendency factor=(0.0 -> 1.0):", Z );
00110         
00111 }
00112 
00114 /* $Revision: 1.3 $ $Date: 2006/09/05 08:02:46 $ $Author: dgl $ $Name:  $ $Id: C091201e.cpp,v 1.3 2006/09/05 08:02:46 dgl Exp $ */
00115 // The Musimat Tutorial © 2006 Gareth Loy
00116 // Derived from Chapter 9 and Appendix B of "Musimathics Vol. 1" © 2006 Gareth Loy 
00117 // and published exclusively by The MIT Press.
00118 // This program is released WITHOUT ANY WARRANTY; without even the implied 
00119 // warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
00120 // For information on usage and redistribution, and for a DISCLAIMER OF ALL
00121 // WARRANTIES, see the file, "LICENSE.txt," in this distribution.
00122 // "Musimathics" is available here:     http://mitpress.mit.edu/catalog/item/default.asp?ttype=2&tid=10916
00123 // Gareth Loy's Musimathics website:    http://www.musimathics.com/
00124 // The Musimat website:                 http://www.musimat.com/
00125 // This program is released under the terms of the GNU General Public License
00126 // available here:                      http://www.gnu.org/licenses/gpl.txt
00127 

Generated on Fri Nov 26 2010 16:18:24 for Musimat Chapter 9 Code Examples by  doxygen 1.7.2