MADRIX Forum • Changing BPM using if>then statement
Page 1 of 1

Changing BPM using if>then statement

Posted: Tue Sep 13, 2022 8:40 am
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();
}

Re: Changing BPM using if>then statement

Posted: Wed Sep 14, 2022 10:38 am
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.