A little information on the grain/fragment properties scripting

THIS POST IS WORK IN PROGRESS

The grain scripting code is essentially just one function that is executed for each new grain that the engine generates. The limitations of the underlying code evaluation engine make it hard to allow things like user defined functions inside the code. Anyway, for most needs how it works is enough.

The C++ side adds variables to the user code to read and/or modify. These are :

Variable name Valid range Will appear modified to the grain engine Additional notes
texturelen 0.1…600.0 No Duration of the texture, in seconds
count 0-some big number No
time 0.0…texture duration No Time position of the grain in seconds in the texture
pitime 0.0…blah No Convenience variable suitable for direct input into trigonometric functions (time*3.141592653*2)
meta_a 0.0…1.0 No Read only variable dedicated for scripts to use as they like
meta_b 0.0…1.0 No Read only variable dedicated for scripts to use as they like
sound 0…number of samples loaded-1 Yes Which sound the grain plays from the loaded samples list
offset 0.0…1.0 Yes Where the grain starts playing the source sound file material
pan -1.0…1.0 Yes Stereo pan position of the grain. -1.0 is full left, 0.0 is middle, 1.0 is full right
transpose -48.0…48.0 Yes Pitch transposition of the grain in semitones. The allowed range is larger than in the GUI, where it is -24.0…24.0
length 0.001…1.0 Yes Duration of the grain in seconds
volume -96.0…12.0 Yes Overall volume of the grain in decibels

The variables that get read back on the C++ side are forced to valid ranges, so extensive care doesn’t need to be taken on what values are set to the variables in the script code, but the sounding results could of course be surprising/undesired.

Info on mathematical functions supported. (For full list look at Cockos Jesusonic documentation, in the “Basic math functions” section.)

Function Description Use example 

sin(x) Returns the Sine of the angle specified (specified in radians) pan=sin(pitime*4.0);
sign(x) Returns the sign of the parameter (-1, 0, or 1).
floor(x) Rounds the value to the lowest integer possible (i.e. 3.9 becomes 3). steps=11; offset=(1.0/steps)*floor(offset*steps);
rand(1) Returns a uniform random number (from a Mersenne Twister generator) in range 0.0…1.0. Note the (1) must be present! transpose=-12.0+24.0*rand(1);
Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

2 Responses to A little information on the grain/fragment properties scripting

  1. robenestobenz says:

    Thanks for the explanation, looking forward to experimenting with this. Any plans on envelopes for the sample weight parameters?

    • xenakios says:

      Note some of the info on the scripting doesn’t apply to the latest publically available build of HourGlass. I try to get a new one posted soonish, that has things like the sample selection variable available in the scripting code.

      I need to think some nice solution to the sample weight automation/morphing. I think a separate envelope for each sample would not work too well.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s