- Main Page
- Namespaces
- Files

- File List
- File Members

# C:/Musimathics_local/Musimat/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 Real unitInterp(Real f, Integer l, Integer u){
    00036         Return(f * (u - l) + l);
    00037 }
    00038
    00039 Static Void para1() {
    00040 /*****************************************************************************
    00041 This is a Real function because f must be a Real to take on fractional values.
    00042 Here are some examples of calling this function.
    00043 *****************************************************************************/
    00044
    00045         Print("*** Unit Interpolation ***");
    00046         Print("unitInterp(0.1, 0, 10)=", unitInterp(.1, 0, 10));
    00047         Print("unitInterp(0.5, 0, 10)=", unitInterp(.5, 0, 10));
    00048         Print("unitInterp(0.9, 0, 10)=", unitInterp(.9, 0, 10));
    00049
    00050 /*****************************************************************************
    00051 When we use it  as follows, we convert the Real result back to an Integer by rounding:
    00052 *****************************************************************************/
    00053 }
    00054
    00055 Integer interpTendency(
    00056         Real f,                                                                 // factor ranging from 0.0 to 1.0
    00057         IntegerList L1, Integer Reference pos1,         // list 1 and its position parameter
    00058         IntegerList L2, Integer Reference pos2,         // list 2 and its position parameter
    00059         Integer inc                                                             // amount by which to adjust position
    00060 ) {
    00061         Integer x = cycle(L1, pos1, inc);
    00062         Integer y = cycle(L2, pos2, inc);
    00063         Return(Integer(Round(unitInterp(f, x, y))));
    00064 }
    00065
    00066 Static Void para2() {
    00067 /*****************************************************************************
    00068 This function can perform a couple of neat tricks. First, we can have the function return exactly L1
    00069 or L2 by setting f = 0.0 or f = 1.0, respectively. By setting f = 0.5, we get the average of the
    00070 two rows. By gradually changing the value of f from 0.0 to 1.0, we mutate L1, transforming it grad-
    00071 ually until it becomes L2. Also, the lengths of L1 and L2 need not be the same. If L1 has a length of
    00072 5 and L2 a length of 6, it will take 5 Þ 6 iterations before the pattern repeats. Both lists use the same
    00073 increment, but redesigning this to use separate increments would provide for even more possibilities.
    00074 *****************************************************************************/
    00075
    00076         IntegerList X(10, 20, 30, 40, 50, 60);
    00077         IntegerList Y(9,   8,  7,  6,  5,  4, 3);
    00078         IntegerList Z;
    00079         Integer posX = 0;
    00080         Integer posY = 0;
    00081         Integer inc = 1;
    00082         Integer i;
    00083
    00084         Print("*** Interpolation Tendency ***");
    00085         Print("First row: ", X);
    00086         Print("Second row: ", Y);
    00087
    00088         For ( i = 0; i < Length( X ); i = i + 1 )
    00089                 Z[i] = interpTendency(0.0, X, posX, Y, posY, inc);
    00090
    00091         Print("interpTendency factor=0.0:", Z );
    00092
    00093         posX = posY = 0; // reset to beginning
    00094         For ( i = 0; i < Length( X ); i = i + 1 )
    00095                 Z[i] = interpTendency(0.5, X, posX, Y, posY, inc);
    00096
    00097         Print("interpTendency factor=0.5:", Z );
    00098
    00099         posX = posY = 0; // reset to beginning
    00100         For ( i = 0; i < Length( X ); i = i + 1 )
    00101                 Z[i] = interpTendency(1.0, X, posX, Y, posY, inc);
    00102
    00103         Print("interpTendency factor=1.0:", Z );
    00104
    00105         posX = posY = 0; // reset to beginning
    00106         For ( i = 0; i < Length( X ); i = i + 1 )
    00107                 Z[i] = interpTendency(Real(i)/Length(X), X, posX, Y, posY, inc);
    00108
    00109         Print("interpTendency factor=(0.0 -> 1.0):", Z );
    00110
    00111 }}
    00112
    00114 /* $Revision: 1.2 $ $Date: 2006/09/09 06:22:42 $ $Author: dgl $ $Name:  $ $Id: _c091201e_8cpp-source.html,v 1.2 2006/09/09 06:22:42 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