Changing BPM using if>then statement

Post Reply
webcentrik
Posts: 22
Joined: Fri Apr 06, 2018 5:18 pm

Changing BPM using if>then statement

Post by webcentrik »

I'm trying to create an effect where a line moves across the matrix but varies its speed based on position. I have tried using the if>then statements examining the xpos of the line but I am getting something wrong in the syntax or use of the SetBPM command when nested in an if>then statement.

Can anyone look at this and point me in the right direction.

// Global Vars
float mw;
float mh;
int xdir;
int ydir;
float xpos;
float ypos;

// Global Colors
color col = {255,255,255,0}; //White
color col2 = {127,127,127,0}; //Gray
color col3 = {255,0,0,0}; //Red


void InitEffect()
{
SetBpm(600.0);
SetAsync(true);

xdir = 1;
xpos = 0.0;


mw = (float)GetMatrixWidth();
mh = (float)GetMatrixHeight();
}

void RenderEffect()
{
//Calc Position and Direction for X
if(xdir == 1)
{
xpos += 1.0;
if(xpos == mw-1.0)
// xdir = -1;
xpos=0;
}
if (xpos == 30)
(SetBPM(900.0);)
else
if (xpos == 60)
(SetBPM(1200.0);)
else
if (xpos == 90)
(SetBPM(600.0);)



//Draw Matrix Black
ClearAlpha(255);

//First Vertical Line
DrawVectorLine(col2,(xpos-1.0)/mw,0.0,(xpos-1.0)/mw,1.0);

DrawVectorLine(col,(xpos+4.0)/mw,0.0,(xpos+5.0)/mw,4.0);

DrawVectorLine(col3,(xpos+8.0)/mw,0.0,(xpos+5.0)/mw,4.0);



}

void MatrixSizeChanged()
{
InitEffect();
}
Guertler
Support
Support
Posts: 880
Joined: Tue Feb 04, 2014 10:47 am

Re: Changing BPM using if>then statement

Post by Guertler »

Hello webcentrik,

There are several issues in the posted MADRIX Script:
    • The function SetBPM isn't correct. If you want to change the BPM value, you will need to use the function SetBpm(float value)
    • In case of working with brackets at the If Statements you will need to use curly brackets instead of round brackets. Example:

      Code: Select all

      if(condition)
      {
          statements
      }
      In your posted code you are working with only one statement per if respectively else if condition so you don't need to add the curly brackets Example

      Code: Select all

      if(condition)
          statement
      
    • In the If condition you are comparing float values but some of the values are still integer.
Post Reply