Random XY script for latest Zebra 2.9.3

Official support for: u-he.com
Post Reply New Topic
RELATED
PRODUCTS

Post

Hey there, I have been trying for some time to get this "Random XY" script from Urs "Randomizer" pack (from All Device Scripts & Presets page), to work on Zebra, but nothing seems to do it.

I believe this will randomly assign parameters to slots and also randomize its values for the macros handles.

Here is a direct copy of the current script available for download at https://u-he.com/PatchLib/all.html

The only problem seems to not be able to select a valid "Target" for each slot (or any slot at all).

Code: Select all

#defaults=no
<?

int fractionalType = 1;
int first_XY_Target = Core.XY[ 4 ].Down[ 8 ].id + 1;
int last_XY_Target = Global.numParameters - 1;

int iterations = 0;

for ( int xy = 1; xy < 5; xy++ )
{
   for ( int slot = 1; slot < 9; slot++ )
   {      
      int target = -1;
   
      for ( 1; 1; 1) // same as while( true )
      {      
         target = rand( first_XY_Target, last_XY_Target );
            
         if ( Global.Parameter[ target ].type == fractionalType )
         {
            int moduleID = Global.Parameter[ target ].moduleID;
            
            if ( Module[ moduleID ].active )
            {
               Core.XY[ xy ].TargetX[ slot ] = target;
            
               float value = Global.Parameter[ target ];
            
               float minInfluence = Global.Parameter[ target ].min - value;
            
               float maxInfluence = Global.Parameter[ target ].max - value;
         
               Core.XY[ xy ].Right[ slot ] = rand( minInfluence, maxInfluence );
               Core.XY[ xy ].Left[ slot ] = rand( minInfluence, maxInfluence );
            
               break;
            }
         }
         
         iterations++;
      }
      
      for ( 1; 1; 1) // same as while( true )
      {      
         target = rand( first_XY_Target, last_XY_Target );
            
         if ( Global.Parameter[ target ].type == fractionalType )
         {
            int moduleID = Global.Parameter[ target ].moduleID;
            
            if ( Module[ moduleID ].active )
            {
               Core.XY[ xy ].TargetY[ slot ] = target;
         
               float value = Global.Parameter[ target ];
            
               float minInfluence = Global.Parameter[ target ].min - value;
            
               float maxInfluence = Global.Parameter[ target ].max - value;
         
               Core.XY[ xy ].Up[ slot ] = rand( minInfluence, maxInfluence );
               Core.XY[ xy ].Down[ slot ] = rand( minInfluence, maxInfluence );
            
               break;
            }
         }
         
         iterations++;
      }
   }
}

?>

In isolation code, the handles right/down (at least for the first slot of the first XY pad) will move randomly as expected (but fail to stay within adequate values most of the time because they do not have the target parameter value for reference):

Code: Select all

#defaults=no
<?

float value = Global.Parameter[ target ];
            
float minInfluence = Global.Parameter[ target ].min - value;
            
float maxInfluence = Global.Parameter[ target ].max - value;
         
Core.XY[ xy ].Right[ slot ] = rand( minInfluence, maxInfluence );
Core.XY[ xy ].Left[ slot ] = rand( minInfluence, maxInfluence );

?>
Is this still possible to do?
How to fix it ? :)

Thanks!

Post

Ok, I think I got it to work:

Code: Select all

#defaults=no
<?

int fractionalType = 1;
int first_XY_Target = Core.XY[ 4 ].Down[ 8 ].id + 1;
int last_XY_Target = Global.numParameters - 1;

//int iterations = 0; //this is probably not needed in the current Zebra version (2.9.3), see below

for ( int xy = 1; xy < 5; xy++ )
{
   for ( int slot = 1; slot < 9; slot++ )
   {      
      int target = -1;
   
      for(int i = 1; i <100;  i++) // the previous "for ( 1; 1; 1) // same as while( true )" probably was the source of the problem, hence the "break;" below is no more used 
      {      
         target = rand( first_XY_Target, last_XY_Target );
            
         if ( Global.Parameter[ target ].type == fractionalType )
         {
            int moduleID = Global.Parameter[ target ].moduleID;
            
            if ( Module[ moduleID ].active )
            {
               Core.XY[ xy ].TargetX[ slot ] = target;
            
               float value = Global.Parameter[ target ];
            
               float minInfluence = Global.Parameter[ target ].min - value;
            
               float maxInfluence = Global.Parameter[ target ].max - value;
         
               Core.XY[ xy ].Right[ slot ] = rand( minInfluence, maxInfluence );
               Core.XY[ xy ].Left[ slot ] = rand( minInfluence, maxInfluence );
            
               //break; //removed because the for ( 1; 1; 1) no longer is used
            }
         }
         
         //iterations++;
      }
      
      for(int i = 1; i <100;  i++)
      {      
         target = rand( first_XY_Target, last_XY_Target );
            
         if ( Global.Parameter[ target ].type == fractionalType )
         {
            int moduleID = Global.Parameter[ target ].moduleID;
            
            if ( Module[ moduleID ].active )
            {
               Core.XY[ xy ].TargetY[ slot ] = target;
         
               float value = Global.Parameter[ target ];
            
               float minInfluence = Global.Parameter[ target ].min - value;
            
               float maxInfluence = Global.Parameter[ target ].max - value;
         
               Core.XY[ xy ].Up[ slot ] = rand( minInfluence, maxInfluence );
               Core.XY[ xy ].Down[ slot ] = rand( minInfluence, maxInfluence );
            
               //break;  //removed because the for ( 1; 1; 1) no longer is used
            }
         }
         
         //iterations++;
      }
   }
}

?>

I think the previous for (1;1;1) was the main reason for it to crash, because the "break;" seems to make the script not work.

Replaced it with "for(int i = 1; i <100; i++)" to increase the probability of the for loop to work.

Anyway thank you very much for this great script and time!

Best regards,
O.

Post Reply

Return to “u-he”