Functions

Global Row Functions

Functions for manipulating Lists as musical rows. More...

Functions

template<class Type >
Type Reference Rotate (Type Reference f, Integer n)
 Rotate the elements of a List.
template<class Type1 , class Type2 >
Type1 Transpose (Type1 L, Type2 t, Type2 lim)
 Transpose the elements of a List.
PitchList Transpose (PitchList L, Integer t)
 Transpose the elements of a PitchList.
template<class Type1 , class Type2 >
Type1 Invert (Type1 L, Type2 lim)
 Invert a List.
PitchList Invert (PitchList L, Integer lim=12)
 Invert a PitchList.
template<class Type >
Type Reference Retrograde (Type Reference L)
 Retrograde a List.
template<class MatrixType , class ListType >
MatrixType SetComplex (ListType prime)
 Create a set class (matrix) from a List.
template<class ElementType , class ListType >
ElementType cycle (ListType L, Integer Reference pos, Integer inc)
 Traverse cyclicly through a List.
template<class ElementType , class ListType >
ElementType palindrome (ListType L, Integer Reference pos, Integer Reference inc)
 Traverse a List palindromically.
template<class ElementType , class ListType >
ElementType permute (ListType L, Integer Reference pos, Integer Reference count, Integer inc)
 Permute a List.
Integer InterpTendency (Real f, IntegerList L1, Integer Reference pos1, IntegerList L2, Integer Reference pos2, Integer inc)
 Interpolation tendency.
Pitch LinearInterpolate (Pitch x, Pitch xMin, Pitch xMax, Pitch yMin, Pitch yMax)
 Linear interpolation in Pitch space.
template<class ElementType , class ListType >
ListType stretch (ListType L, ElementType xMin, ElementType xMax, ElementType yMin, ElementType yMax)
 Use linear interpolation to map an entire function to a different range.
template<class ListType >
ListType RandomRow (Integer N)
 RandomRow.
template<class ElementType , class ListType >
Void swap (ListType Reference L, Integer from, Integer to)
 Swap two elements in a List.
template<class ElementType , class ListType >
ListType shuffle (ListType L)
 Perform swap() operation on every element of List, thereby shuffling it.
template<class ElementType , class ListType >
ElementType randTendency (ListType L1, Integer Reference pos1, ListType L2, Integer Reference pos2, Integer inc)
 Use a row to specify an upper boundary and another row to specify a lower boundary, and then pick a pitch in this range.

Detailed Description

Functions for manipulating Lists as musical rows.


Function Documentation

template<class ElementType , class ListType >
ElementType cycle ( ListType  L,
Integer Reference  pos,
Integer  inc 
)

Traverse cyclicly through a List.

cycle() returns to the head of the list when it walks off the end, and returns to the end of the list if it walks off the head.

Parameters:
LList to be traversed
posCurrent position in the list. Updated on return to new position in the list.
incNumber of list elements to skip.
Returns:
The element of the list based on pos and inc

Definition at line 119 of file Row.h.

References Length(), PosMod(), and Return.

                                                                                                                {
        Integer i = PosMod( pos, Length( L ) );
        pos = PosMod( pos + inc, Length( L ) );
        Return( L[ i ] );
}
Integer InterpTendency ( Real  f,
IntegerList  L1,
Integer Reference  pos1,
IntegerList  L2,
Integer Reference  pos2,
Integer  inc 
)

Interpolation tendency.

Parameters:
fFactor ranging from 0.0 to 1.0
L1List 1
pos1Position parameter for List 1
L2List 2
pos2Position parameter for List 2
incAmount by which to adjust position
Returns:
Interpolated tendency value

Definition at line 21 of file Row.cpp.

References Return, Round(), and unitInterp().

                                                                                                                              {
        Integer x = cycle<Integer,IntegerList>(L1, pos1, inc);
        Integer y = cycle<Integer,IntegerList>(L2, pos2, inc);
        Return( Integer( Round( unitInterp( f, x, y ) ) ) );
}
PitchList Invert ( PitchList  L,
Integer  lim = 12 
) [inline]

Invert a PitchList.

Parameters:
LPitchList to invert
limModulo limit to apply
Returns:
Inverted PitchList

Definition at line 74 of file Row.h.

References For, List< Type >::invert(), List< Type >::length(), and Return.

                                                         {
        For ( Integer i = 0; i < L.length(); i = i + 1 ) {
                L[i].invert();
        }
        Return( L );
}
template<class Type1 , class Type2 >
Type1 Invert ( Type1  L,
Type2  lim 
)

Invert a List.

Parameters:
LList to invert
limModulo limit to apply
Returns:
Inverted list

Definition at line 65 of file Row.h.

References Return.

Referenced by SetComplex().

                                                                      {
        L.invert(lim);
        Return( L );
}
Pitch LinearInterpolate ( Pitch  x,
Pitch  xMin,
Pitch  xMax,
Pitch  yMin,
Pitch  yMax 
)

Linear interpolation in Pitch space.

Parameters:
xValue ranging from xMin to xMax
xMinMinimum range of x
xMaxMaximum range of x
yMinTarget minimum range
yMaxTarget maximum range
Returns:
The interpolated value

Definition at line 27 of file Row.cpp.

References Pitch::degree(), and Return.

                                                                                   {
        Real xr = x.degree();
        Real xm = xMin.degree();
        Real xM = xMax.degree();
        Real ym = yMin.degree();
        Real yM = yMax.degree();
        Real a = ( xr - xm) / (xM - xm );
        Real b = yM - ym;
        Return( Integer(a * b + ym) );
}
template<class ElementType , class ListType >
ElementType palindrome ( ListType  L,
Integer Reference  pos,
Integer Reference  inc 
)

Traverse a List palindromically.

palindrome() returns to the head of the list when it walks off the end, and returns to the end of the list if it walks off the head. palindrome() alternates traversal of prime and retrograde form

Parameters:
LList to be traversed
posCurrent position in the list. Updated on return to new position in the list.
incNumber of list elements to skip.
Returns:
The element of the list based on pos and inc

Definition at line 133 of file Row.h.

References If, and Return.

                                                                                                                               {
        Integer curPos = pos;
        ElementType x = cycle<ElementType,ListType>( L, pos, inc );
        If ( curPos + inc != pos ) {
                inc = inc * (-1); // change direction
                pos = curPos;
        }
        Return( x ); 
}
template<class ElementType , class ListType >
ElementType permute ( ListType  L,
Integer Reference  pos,
Integer Reference  count,
Integer  inc 
)

Permute a List.

Iterate the supplied sequence in prime order until exhausted, then permute the entire row by inc steps and repeat from the beginning

Parameters:
LList to be traversed
posCurrent position in the list. Updated on return to new position in the list.
countReference parameter that tracks the number of steps so far
incNumber of list elements to skip when we permute
Returns:
The element of the list based on pos

Definition at line 150 of file Row.h.

References If, Length(), and Return.

                                                                                                                                           { 
        Integer curPos = pos;                   // save the current position
        ElementType x = cycle<ElementType,ListType>( L, pos, 1 );       // update pos and get list value
        count = count + 1;                              // increment counter
        If ( count == Length( L ) ) {   // have we output L items from list?
                count = 0;                                      // reset count
                pos = curPos + inc;                     // permute position for next time
        }
        Return( x ); 
}
template<class ListType >
ListType RandomRow ( Integer  N )

RandomRow.

Parameters:
NLength of row
Returns:
Randomly generated row of length N

Definition at line 198 of file Row.h.

References For, If, IRandom(), and Return.

                                                         {
        IntegerList L;                          // Keep track of the pitches chosen so far
        ListType M;                             // Used to build up our random 12-tone row 
        Integer i;
        // First, set all list elements to zero, which means "unused"
        For ( i = 0; i < N; i = i + 1 ) {
                 L[ i ] = 0;    
        }
        // Now build up M, marking off elements in L when they are chosen
        For ( i = 0; i < N; i = i ) {
                Integer x = IRandom( 0, N - 1 );
                If ( L[ x ] == 0 ) {    // Hasn't been chosen yet?
                         L[ x ] = 1;    // Mark it "used"
                         M[ i ] = x;    // Save the result
                        i = i + 1;      // Now increment the control variable
                }
        }
        Return( M );
}
template<class ElementType , class ListType >
ElementType randTendency ( ListType  L1,
Integer Reference  pos1,
ListType  L2,
Integer Reference  pos2,
Integer  inc 
)

Use a row to specify an upper boundary and another row to specify a lower boundary, and then pick a pitch in this range.

Parameters:
L1List specifying upper boundary
pos1Current position in L1
L2List specifying upper boundary
pos2Current position in L2
incAmount to increment
Returns:
Random value chosen to lie in the range between indexed elements of L1 and L2

Definition at line 250 of file Row.h.

References Else, If, IRandom(), and Return.

                                                                                                                                                              {
        Integer x = cycle<ElementType,ListType>( L1, pos1, inc );
        Integer y = cycle<ElementType,ListType>( L2, pos2, inc );
        If ( x < y )
                Return( IRandom( x, y ) );
        Else
                Return( IRandom( y, x ) );              
}
template<class Type >
Type Reference Retrograde ( Type Reference  L )

Retrograde a List.

Parameters:
LList to retrograde
Returns:
Retrograde list

Definition at line 84 of file Row.h.

References Return.

                                                                   {
        L.retrograde();
        Return( L );
}
template<class Type >
Type Reference Rotate ( Type Reference  f,
Integer  n 
)

Rotate the elements of a List.

Parameters:
fRow to rotate
nNumber of positions to rotate by

Definition at line 31 of file Row.h.

References Return.

{
        f.rotate(n);
        Return( f );
}
template<class MatrixType , class ListType >
MatrixType SetComplex ( ListType  prime )

Create a set class (matrix) from a List.

Parameters:
primePrime form of the list
Returns:
The set class (matrix)

Definition at line 92 of file Row.h.

References For, Invert(), Length(), Mod(), and Return.

                                                                                   {
        Integer len = Length( prime );
        MatrixType M( len, len );
        ListType inverted = Invert( prime, 12 );
        Integer i;

        For ( i = 0; i < len; i = i + 1 ) {
                 M[0][i] = prime[i];
                 M[i][0] = inverted[i];
        }

        For ( i = 1; i < len; i = i + 1 ) {
                For ( Integer j = 1; j < len; j = j + 1 ) {
                          M[ i ][ j ] = Mod( M[ i ][ 0 ] + M[ 0 ][ j ], len);
                }
        }

        Return( M );
}
template<class ElementType , class ListType >
ListType shuffle ( ListType  L )

Perform swap() operation on every element of List, thereby shuffling it.

Parameters:
LList to shuffle
Returns:
Shuffled list

Definition at line 232 of file Row.h.

References For, Length(), Print(), and Return.

                                                                           {
        // SeedRandom( 788429 );        // Uncomment to test alternative shuffle
        ListType M = RandomRow<ListType>( Length( L ) ); // Determine what elements to swap
        Print( "M=", M );
        For ( Integer i = 0; i < Length( L ); i = i + 1 ) {
                Integer j = M[ i ];
                swap<ElementType,ListType>( L, i, j );
        }
        Return( L );
}
template<class ElementType , class ListType >
ListType stretch ( ListType  L,
ElementType  xMin,
ElementType  xMax,
ElementType  yMin,
ElementType  yMax 
)

Use linear interpolation to map an entire function to a different range.

Parameters:
LList to stretch
xMinMinimum value range of L
xMaxMaximum value range L
yMinMinimum range of resulting stretched list
yMaxMaximum range of resulting stretched list
Returns:
Stretched list

Definition at line 187 of file Row.h.

References For, Length(), linearInterpolate(), and Return.

                                                                                                                                                   {
        For ( Integer i = 0; i < Length( L ); i = i + 1 ) {
                 L[ i ] = ElementType( linearInterpolate( L[ i ], xMin, xMax, yMin, yMax ) );
        }
        Return( L );
}
template<class ElementType , class ListType >
Void swap ( ListType Reference  L,
Integer  from,
Integer  to 
)

Swap two elements in a List.

Parameters:
LList with elements to swap
fromIndex of source
toIndex of destination
Returns:
Modified list

Definition at line 223 of file Row.h.

                                                                                                        {
        ElementType x = L[ to ];                // save the target value
         L[ to ] = L[ from ];           // swap from -> to
         L[ from ] = x;                 // swap to -> from
}
PitchList Transpose ( PitchList  L,
Integer  t 
) [inline]

Transpose the elements of a PitchList.

Transpose performs modulus arithmetic on pitches within the scale. That is, pitches transposed outside the span of the scale are wrapped back into the scale.

Parameters:
LPitchList to transpose
tNumber of degrees to transpose by
Returns:
Transposed list

Definition at line 54 of file Row.h.

References For, List< Type >::length(), and Return.

                                                     {
        For ( Integer i = 0; i < L.length(); i = i + 1 ) {
                L[i].transModuloOctave(t);
        }
        Return( L );
}
template<class Type1 , class Type2 >
Type1 Transpose ( Type1  L,
Type2  t,
Type2  lim 
)

Transpose the elements of a List.

Parameters:
LList to transpose
tNumber of degrees to transpose by
limNumber of scale degrees. E.g., for the equal tempered scale, lim=12 semitones.
Returns:
Transposed list

Definition at line 42 of file Row.h.

References Return.

                                                                                  {
        L.transpose(t, lim);
        Return( L );
}