00001
00002 #ifndef ROW_H
00003 #define ROW_H
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "Musimat.h"
00019
00022
00027
00031 template<class Type> Type Reference Rotate( Type Reference f, Integer n )
00032 {
00033 f.rotate(n);
00034 Return( f );
00035 }
00036
00042 template<class Type1, class Type2> Type1 Transpose( Type1 L, Type2 t, Type2 lim ) {
00043 L.transpose(t, lim);
00044 Return( L );
00045 }
00046
00047
00054 inline PitchList Transpose( PitchList L, Integer t ) {
00055 For ( Integer i = 0; i < L.length(); i = i + 1 ) {
00056 L[i].transModuloOctave(t);
00057 }
00058 Return( L );
00059 }
00060
00065 template<class Type1, class Type2> Type1 Invert( Type1 L, Type2 lim ) {
00066 L.invert(lim);
00067 Return( L );
00068 }
00069
00074 inline PitchList Invert( PitchList L, Integer lim = 12 ) {
00075 For ( Integer i = 0; i < L.length(); i = i + 1 ) {
00076 L[i].invert();
00077 }
00078 Return( L );
00079 }
00080
00084 template<class Type> Type Reference Retrograde( Type Reference L ) {
00085 L.retrograde();
00086 Return( L );
00087 }
00088
00092 template<class MatrixType, class ListType> MatrixType SetComplex( ListType prime ) {
00093 Integer len = Length( prime );
00094 MatrixType M( len, len );
00095 ListType inverted = Invert( prime, 12 );
00096 Integer i;
00097
00098 For ( i = 0; i < len; i = i + 1 ) {
00099 M[0][i] = prime[i];
00100 M[i][0] = inverted[i];
00101 }
00102
00103 For ( i = 1; i < len; i = i + 1 ) {
00104 For ( Integer j = 1; j < len; j = j + 1 ) {
00105 M[ i ][ j ] = Mod( M[ i ][ 0 ] + M[ 0 ][ j ], len);
00106 }
00107 }
00108
00109 Return( M );
00110 }
00111
00119 template<class ElementType, class ListType> ElementType cycle( ListType L, Integer Reference pos, Integer inc ) {
00120 Integer i = PosMod( pos, Length( L ) );
00121 pos = PosMod( pos + inc, Length( L ) );
00122 Return( L[ i ] );
00123 }
00124
00133 template<class ElementType, class ListType> ElementType palindrome( ListType L, Integer Reference pos, Integer Reference inc ) {
00134 Integer curPos = pos;
00135 ElementType x = cycle<ElementType,ListType>( L, pos, inc );
00136 If ( curPos + inc != pos ) {
00137 inc = inc * (-1);
00138 pos = curPos;
00139 }
00140 Return( x );
00141 }
00142
00150 template<class ElementType, class ListType> ElementType permute( ListType L, Integer Reference pos, Integer Reference count, Integer inc ) {
00151 Integer curPos = pos;
00152 ElementType x = cycle<ElementType,ListType>( L, pos, 1 );
00153 count = count + 1;
00154 If ( count == Length( L ) ) {
00155 count = 0;
00156 pos = curPos + inc;
00157 }
00158 Return( x );
00159 }
00160
00169 Integer InterpTendency( Real f, IntegerList L1, Integer Reference pos1, IntegerList L2, Integer Reference pos2, Integer inc );
00170
00178 Pitch LinearInterpolate( Pitch x, Pitch xMin, Pitch xMax, Pitch yMin, Pitch yMax );
00179
00187 template<class ElementType, class ListType> ListType stretch( ListType L, ElementType xMin, ElementType xMax, ElementType yMin, ElementType yMax ) {
00188 For ( Integer i = 0; i < Length( L ); i = i + 1 ) {
00189 L[ i ] = ElementType( linearInterpolate( L[ i ], xMin, xMax, yMin, yMax ) );
00190 }
00191 Return( L );
00192 }
00193
00194
00198 template<class ListType> ListType RandomRow( Integer N ) {
00199 IntegerList L;
00200 ListType M;
00201 Integer i;
00202
00203 For ( i = 0; i < N; i = i + 1 ) {
00204 L[ i ] = 0;
00205 }
00206
00207 For ( i = 0; i < N; i = i ) {
00208 Integer x = IRandom( 0, N - 1 );
00209 If ( L[ x ] == 0 ) {
00210 L[ x ] = 1;
00211 M[ i ] = x;
00212 i = i + 1;
00213 }
00214 }
00215 Return( M );
00216 }
00217
00223 template<class ElementType, class ListType> Void swap( ListType Reference L, Integer from, Integer to ) {
00224 ElementType x = L[ to ];
00225 L[ to ] = L[ from ];
00226 L[ from ] = x;
00227 }
00228
00232 template<class ElementType, class ListType> ListType shuffle( ListType L ) {
00233
00234 ListType M = RandomRow<ListType>( Length( L ) );
00235 Print( "M=", M );
00236 For ( Integer i = 0; i < Length( L ); i = i + 1 ) {
00237 Integer j = M[ i ];
00238 swap<ElementType,ListType>( L, i, j );
00239 }
00240 Return( L );
00241 }
00242
00250 template<class ElementType, class ListType> ElementType randTendency( ListType L1, Integer Reference pos1, ListType L2, Integer Reference pos2, Integer inc ) {
00251 Integer x = cycle<ElementType,ListType>( L1, pos1, inc );
00252 Integer y = cycle<ElementType,ListType>( L2, pos2, inc );
00253 If ( x < y )
00254 Return( IRandom( x, y ) );
00255 Else
00256 Return( IRandom( y, x ) );
00257 }
00258
00259
00261 #endif // ROW_H