Author Topic: user_defined $maxFrame questions  (Read 1255 times)

Offline injury

  • Sr. Member
  • ****
  • Posts: 191
user_defined $maxFrame questions
« on: October 22, 2012, »
I am playing around trying to devlop a chase down each strand individually across an entire grid to teach myself user_defined and make some things I have in mind (like the more random different delayed meteor I mentioned earlier). So current goal is change color of strand 1 pixel 1, then pixel 2 all the way to 8 then strand 2 pixels 1-8 etc. I noticed my code is only called 960 times for a 200 sec sequence (doing it locally so going long). Doing the math and some error checking I noticed it's only cycling through the entire grid 8 times ( this grid is made up of 15 strands of 8 pixels so 120 nodes I need to chase).

I notice in f_user_defined.php line 61
$maxFrame=$maxPixel;

is that length intentional? I was expecting something more in the range of total miliseconds/frame delay or something similar to be the number of frames in an animation. Unless I'm misunderstanding how the animation works that means in my case any user_defined animation I want on this object can only have 8 steps correct? Otherwise in the case of a chase like I am trying is there a different method to know when it's safe to illuminate the next light and set back the previous?

Offline smeighan

  • Moderator
  • Sr. Member
  • *****
  • Posts: 2285
    • Nutcracker RGB Sequence Builder
Re: user_defined $maxFrame questions
« Reply #1 on: October 22, 2012, »
You are not allowed to view links. Register or Login
I am playing around trying to devlop a chase down each strand individually across an entire grid to teach myself user_defined and make some things I have in mind (like the more random different delayed meteor I mentioned earlier). So current goal is change color of strand 1 pixel 1, then pixel 2 all the way to 8 then strand 2 pixels 1-8 etc. I noticed my code is only called 960 times for a 200 sec sequence (doing it locally so going long). Doing the math and some error checking I noticed it's only cycling through the entire grid 8 times ( this grid is made up of 15 strands of 8 pixels so 120 nodes I need to chase).

I notice in f_user_defined.php line 61
$maxFrame=$maxPixel;

is that length intentional? I was expecting something more in the range of total miliseconds/frame delay or something similar to be the number of frames in an animation. Unless I'm misunderstanding how the animation works that means in my case any user_defined animation I want on this object can only have 8 steps correct? Otherwise in the case of a chase like I am trying is there a different method to know when it's safe to illuminate the next light and set back the previous?

what target and effect name are u doing these with and i will take a look

thanks
Sean
Littleton, CO
Latest releases You are not allowed to view links. Register or Login
xLights/Nutcracker Forum You are not allowed to view links. Register or Login
Fbook You are not allowed to view links. Register or Login

Offline injury

  • Sr. Member
  • ****
  • Posts: 191
Re: user_defined $maxFrame questions
« Reply #2 on: October 22, 2012, »
Alright, had to copy my local test up and lower the duration to be more reasonable (then I realised duration doesn't matter since it executes the same).

user injury, model VERL, effect class user_defined name:ChaseTest

Offline injury

  • Sr. Member
  • ****
  • Posts: 191
Re: user_defined $maxFrame questions
« Reply #3 on: October 23, 2012, »
Kind of thinking on this as I presume the current limit I was running into was a) this was considered more megatree so $maxPixels would be the longer of the two and b) possibly delay in processing from having too many frames.

Would a compromise be making $maxFrames = $maxPixels * $maxStrands as a default starting point and adding a box for a way to specify how many times you'd want to process $maxFrames. Or I could see if I really planned something out more times than not being able to calculate beforehand the number of frames I want to use in an effect and manually entering it in a text box.

One thing I haven't tried that just occured to me but probably is not advisable, setting refrence to the global $maxFrames  and modding it to how I'd like it. My main concern before trying it is if would bust anything else in the wrapped or if I a coding error would hang something bad.

Offline kgustafson

  • Coop Manager
  • Sr. Member
  • *
  • Posts: 1120
    • Lost Weekend Productions
Re: user_defined $maxFrame questions
« Reply #4 on: October 23, 2012, »
You are not allowed to view links. Register or Login
Kind of thinking on this as I presume the current limit I was running into was a) this was considered more megatree so $maxPixels would be the longer of the two and b) possibly delay in processing from having too many frames.

Would a compromise be making $maxFrames = $maxPixels * $maxStrands as a default starting point and adding a box for a way to specify how many times you'd want to process $maxFrames. Or I could see if I really planned something out more times than not being able to calculate beforehand the number of frames I want to use in an effect and manually entering it in a text box.

One thing I haven't tried that just occured to me but probably is not advisable, setting refrence to the global $maxFrames  and modding it to how I'd like it. My main concern before trying it is if would bust anything else in the wrapped or if I a coding error would hang something bad.

maxPixels and MaxStrands are calculated from the model you created.  The algorithm that sets these two values walks the model definition file and looks at the 2 and 4th value in your model definition file (The format is S X P X) .  So basically it is the max value found for S and max value found for P.  maxFrames is determined based on two factors (neither of which are related to maxPix or maxStrand) : duration and frame delay.  This is something that is checked vigorously when submitting a project to make sure you have congruous effects created that can be joined by the project program.  maxFrames is the number of 'columns' you will have in your grid.  maxPix*maxStrand*3 is the number of 'rows' you will have in your grid (note this may be a broken concept in the future when we introduce starting addresses.  When we intro start addresses, number or rows in the grid = startaddress + maxPix*maxStrand * 3 or something similiar.)  The general formula for maxFrames = duration (in seconds) * 1000 / frame delay (in millisecs).  So with a 1 second song with a 50 millisecond rate would produce a maxFrames of 1 * 1000 / 50 or 20 frames.

I HIGHLY recommend against changing the values of these three as it can have serious side-effects when trying to use the other applications within Nutcracker.  The reason for these values is in the generation of the Nutcracker (NC) file and is our way to ensure that a given effect will match another effect if they have the same target (model).
------
Visit at: You are not allowed to view links. Register or Login

Offline injury

  • Sr. Member
  • ****
  • Posts: 191
Re: user_defined $maxFrame questions
« Reply #5 on: October 23, 2012, »
You are not allowed to view links. Register or Login
maxPixels and MaxStrands are calculated from the model you created.  The algorithm that sets these two values walks the model definition file and looks at the 2 and 4th value in your model definition file (The format is S X P X) .  So basically it is the max value found for S and max value found for P.  maxFrames is determined based on two factors (neither of which are related to maxPix or maxStrand) : duration and frame delay.  This is something that is checked vigorously when submitting a project to make sure you have congruous effects created that can be joined by the project program.  maxFrames is the number of 'columns' you will have in your grid.  maxPix*maxStrand*3 is the number of 'rows' you will have in your grid (note this may be a broken concept in the future when we introduce starting addresses.  When we intro start addresses, number or rows in the grid = startaddress + maxPix*maxStrand * 3 or something similiar.)  The general formula for maxFrames = duration (in seconds) * 1000 / frame delay (in millisecs).  So with a 1 second song with a 50 millisecond rate would produce a maxFrames of 1 * 1000 / 50 or 20 frames.

Then it's intended purpose is more what I expected in the first place which makes sense. So the fact that no matter the length I enter 5,10, or 200 secs with 50 ms timing all produce the same $maxFrame of 8 (which is $maxPixel for this model) and the line I mentioned in the first post in f_user_defined which is the upper limit of the for loop which reads in user_defined code would be considered a bug correct?

You are not allowed to view links. Register or Login
I HIGHLY recommend against changing the values of these three as it can have serious side-effects when trying to use the other applications within Nutcracker.  The reason for these values is in the generation of the Nutcracker (NC) file and is our way to ensure that a given effect will match another effect if they have the same target (model).

Message received loud and clear.

Offline smeighan

  • Moderator
  • Sr. Member
  • *****
  • Posts: 2285
    • Nutcracker RGB Sequence Builder
Re: user_defined $maxFrame questions
« Reply #6 on: October 23, 2012, »
The user defined funtion is called like this

for($frame=1;$frame<=$maxFrame;$frame++)
   {
      if($frame>5000) exit ("Too many frames in sequence");
      $x_dat = $base . "_d_". $frame . ".dat"; // for spirals we will use a dat filename starting "S_" and the tree model
      $dat_file[$frame] = $path . "/" .  $x_dat;
      $dat_file_array[]=$dat_file[$frame];
      $fh_dat [$frame]= fopen($dat_file[$frame], 'w') or die("can't open file");
      fwrite($fh_dat[$frame],"#    " . $dat_file[$frame] . "\n");
      for($s=1;$s<=$maxStrand;$s++)
         for($p=1;$p<=$maxPixel;$p++)
      {
         //      if(in_array($s,$window_array)) // Is this strand in our window?,
         {
            $i = array_search($s,$window_array)+1;
            srand();
            $rgb_val=user_functon($frame,$i,$p,$maxFrame,$maxStrand,$maxPixel,$param1,$param2,$start_color,$end_color);

So maxFrame is calculated , like Kurt said.

You changing it inside of your user function will NOT modify how many times you get called. You should treat all parameters passed to you as read only variables.

The only thing you need logic to do is decide what color you will return.

So if you have a 10 second duration with 50ms frame timing , there will be 200 frames.

so if you have a 32x50 tree, folded in two means 64 strands x 25 pixels.

the loops look like

for (f=1;f<=200;f++)
   for(s=1;s<=64;s++)
      for(p=1;p<=25;p++)
       $rgb_val=user_functon($frame,$i,$p,$maxFrame,$maxStrand,$maxPixel,$param1,$param2,$start_color,$end_color);

your use function will be called 320,000 times in this example.

a simple one liner
if($s%2==0) $color = hexdec("#FF0000"); else $color=hexdec("0000FF");
return $color;

will make every other strand be RED/GREEN. Notice, no animation effects. You need to include $frame in order to make things change frame to frame.

so change the above to
$s_new = intval($s/$frame);
if($s_new%2==0) $color = hexdec("#FF0000"); else $color=hexdec("0000FF");
return $color;


here is another code snippet

if($frame%4==0) $rgb=hexdec("#FFFFFF");
if($frame%4==1) $rgb=hexdec("#FF0000");
if($frame%4==2) $rgb=hexdec("#00FF00");
if($frame%4==3) $rgb=hexdec("#0000FF"); 






if you want to write more complicated code, pm me and i will set you up.

thanks
sean
Sean
Littleton, CO
Latest releases You are not allowed to view links. Register or Login
xLights/Nutcracker Forum You are not allowed to view links. Register or Login
Fbook You are not allowed to view links. Register or Login

Offline injury

  • Sr. Member
  • ****
  • Posts: 191
Re: user_defined $maxFrame questions
« Reply #7 on: October 23, 2012, »
I'm not sure how you fellows are missing what I'm saying, as the effect I mentioned above have the results. I echo out $maxFrames and several variables for a 8/15 grid and it is always 8 no matter the length I associate to it, and echoing $frame is always 1-8. I am not changing them, I have never changed them. If you notice I supposed about it, but thought it would be a bad idea which was confirmed by kurt.

If you look about 10 lines above where you pasted you will see where I believe what I'm running into is coming from. This is f_user_defined.php which is refrenced from user_defined.php in a require_once. This is not my code.

   $maxFrame=$maxPixel;
   //$maxTrees=6;   // how many tree to draw at one time
   $seq_number=0;
   $window_array = getWindowArray($minStrand,$maxStrand,$window_degrees);
   $include_file = $path . "/$effect_name.inc";
   write_user_functon($php_program,$include_file);
   ob_start();
   echo "
include $include_file
\n";
   require_once $include_file;
   ob_get_clean();
   for($frame=1;$frame<=$maxFrame;$frame++)
   {
      if($frame>5000) exit ("Too many frames in sequence");
      $x_dat = $base . "_d_". $frame . ".dat"; // for spirals we will use a dat filename starting "S_" and the tree model
      $dat_file[$frame] = $path . "/" .  $x_dat;
      $dat_file_array[]=$dat_file[$frame];
      $fh_dat [$frame]= fopen($dat_file[$frame], 'w') or die("can't open file");
      fwrite($fh_dat[$frame],"#    " . $dat_file[$frame] . "\n");
      for($s=1;$s<=$maxStrand;$s++)
         for($p=1;$p<=$maxPixel;$p++)
      {
         //      if(in_array($s,$window_array)) // Is this strand in our window?,
         {
            $i = array_search($s,$window_array)+1;
            srand();
            $rgb_val=user_functon($frame,$i,$p,$maxFrame,$maxStrand,$maxPixel,$param1,$param2,$start_color,$end_color);
            //echo "
user_functon($i,$p,$maxStrand,$maxPixel,$frame,$param1)
\n";
            // user_functon(\$frame,\$s,\$p,\$maxFrame,\$maxStrand,\$maxPixel,\$param1,\$param2,$\$start_color,\$end_color)\n\n"));
            $string=$user_pixel=0;
            $xyz=$tree_xyz[$s][$p];
            $seq_number++;
            if($rgb_val <> 0)
               fwrite($fh_dat[$frame],sprintf ("t1 %4d %4d %9.3f %9.3f %9.3f %d %d %d %d %d\n",$s,$p,$xyz[0],$xyz[1],$xyz[2],$rgb_val,$string, $user_pixel,$strand_pixel[$s][$p][0],$strand_pixel[$s][$p][1],$frame,$seq_number));
         }
      }
      fclose($fh_dat[$frame]);

« Last Edit: October 23, 2012, by injury »

Offline smeighan

  • Moderator
  • Sr. Member
  • *****
  • Posts: 2285
    • Nutcracker RGB Sequence Builder
Re: user_defined $maxFrame questions
« Reply #8 on: October 23, 2012, »
ok, Injury.

you were right.

I had some old debug code that was not setting the maxFrame as we stated.

try it again.

thanks

BTW, i would not try 50 ms and 200 seq duration (4000 dat files).

if you have a local install , you can have these big.

Sean
Littleton, CO
Latest releases You are not allowed to view links. Register or Login
xLights/Nutcracker Forum You are not allowed to view links. Register or Login
Fbook You are not allowed to view links. Register or Login

Offline injury

  • Sr. Member
  • ****
  • Posts: 191
Re: user_defined $maxFrame questions
« Reply #9 on: October 23, 2012, »
Ya my long ones were intended to be local, I had just pasted code up and such since you had wanted to see the effect.

Edit:
Just tested it out and it's working like you intended now. Thanks! Now I get to tweak the length and the logic I use so that my effect ends where they loop seamlessly.
« Last Edit: October 23, 2012, by injury »