Help with conditional presets #UnO2


Jim B
 

Great! Glad it helped you out.
I just received and installed my chip on Thursday! But to be fair, I had practiced coding my setup with the online editor for a few weeks while waiting for the chip. And I have several programming languages (and various iterations of html) under my belt - so I’ve been writing programs for nearly 40 years! It’s always the simple things that trip me up. I’m still learning all this too. The last time I did anything with MIDI was just Sysex dumps to store program patches from my Korg poly to cassette tape in the late 80s! Now I’m using the foot controller for my EWI5000 and SWAM instruments. 

Glad you’re up and running.

Cheers,
Jim B 


wanttobelieve42@...
 

All of the above!! Thank you for catching that. I swore that I had tried the parentheses at one point, but I ALSO needed to make the "if" lowercase. Plus, double parentheses inside parentheses for multiple conditionals with "&&" between. Had to double check the manual for that one.

Okay! Seems to be working now. I am learning, slowly but surely. Thanks everybody for the help. =)


Jim B
 

SYNTAX!

if (condition) … else (condition) … else if (condition) … etc.
The “condition” must be surrounded with “(…)”.
I fall for the a lot!
Also, I’ve noticed that some commands are “case specific” - upper/lower case sometimes matters.

Hope that helps!


Cheers,
Jim B


wanttobelieve42@...
 

Huh. So I applied your suggestion, took out the multiple PC commands and made a single one after the last ELSE IF block. I also took ninjaatwork's suggestion and added a dummy variable to try a command at the beginning of the preset. Still getting the same error. I even tried typing it all over from scratch. As soon as I enter the IF command I get a message: Error parsing the programming code on line 53: unknown command : IF. The error stays on that line until I put the brackets in, at which point the error jumps to the PRESET line where you see it in the picture.

Is it just not possible to use conditionals in presets, or I am I still missing something?



Also, I really appreciate the general notes as well. I can see where I might save myself future headache by thinking about readability and consistency with how I use the variables, plus constricting the range just in case. Thanks for all the help!


ninjaatwork@...
 

Or simply put an: else { $dummy = 0 } after the last else if {} to satisfy the compiler.
 


chrisw_63
 

Ergh.. Minor point on programming stuff I should have mentioned earlier:  Always consider every value a variable could have, even if your code would 'never' *** assign those values.  Here's what I mean:  $miniprog is checked for being less than 99, equal to 99, and equal to 0.  It is never checked for being greater than 99.  While your current code would probably never let it go over 99, shtuff happens.  Hardware glitch.  Later addition to the code.  Using the same variable name elsewhere in the code, whether you realize it or not...  Or just plain coding errors.  Always check, and make sure a variable can only be the range you need it to be.

The easiest and most logical way to do that is in the two ELSE IF $miniprog = 99... statements.  Since they are checking for the upper boundary of the variable, and reset it to zero, it would make sense that any value higher than 99 should be reset as well.  Just change it to ELSE IF $miniprog >= 99...  and every eventuality is taken care of.  Except less than zero, but I'll leave it to you to find out if that check is needed.

*** If you ever hear a programmer say, "That variable could never have that value", and they don't say "..because my code checks for it and corrects it if needed", then they need to get some more experience under their belt.  Unless your code constricts a variable to the values that make sense for your code, you're opening up the possibility of a bug.  The kind of programming needed for the Uno2 isn't so serious that you need all the tenets of this burned into your brain, but it's still a good thing to keep in mind.


chrisw_63
 

Also, Ossandust, if possible, please consider changing this error into a Warning, so it can still compile when the only commands are inside conditionals and the compiler can't be sure any of them will be called.


chrisw_63
 
Edited

Hmm... it would seem that the compiler doesn't consider the commands inside the conditionals.  The easy solution is to move one or more of them outside the conditionals.  Since the PC command is common for all of the conditions, just move that one outside the IF block, after all the conditions.  Setting $miniprog to zero is great, but then you didn't use the variable in the last two PC commands, which may have left you thinking they weren't the same as the first one (it may save a couple bytes in the written program, but it won't change what the compiler puts out).  Always be consistent with the use of your variables.  You did well naming it with what it's used for, so use it consistently and when you look at the code later, it'll be clear exactly what that zero means.

Since both of those zeroes represent $miniprog anyway, remove the PC command, and put one call to it just before the closing brace.  The compiler will see it and be happy.

PRESET Mini PC Up =
{
   IF $miniprog < 99
   {
    ...
   }
   ELSE IF..
   {
   ...
   }
   ELSE IF..
   {
   ...
   }
   SendMidi Minilogue ProgChange $miniprog
}


wanttobelieve42@...
 

I am trying to create a preset that will send program change commands to advance the patch selection on my Minilogue, which seems to organize its patches into 4 banks of 100 patches each, numbered 0-99. So the preset needs to keep track of what bank and patch number I'm on, so that it knows when it advance the bank and return the patch number back to zero, etc. The problem that I'm having is that whenever I put IF and ELSE statements in my preset, I get a message that I still need to specify a command for the preset. I attached a picture of the error message and full code below (I'm new to this, so feel free to point out anything else I'm doing wrong). Thanks!