While Statement issue with Uno2 #UnO2


Jack Fenton
 

Hi this segment works but I had to add the if statement otherwise the "SendMidi Nord 0 0" still executes even if $Device = "Hammond"

TRIGGER_CLICK AllNotesOffPanic =
{
   switch($Device)
   {
   case "Hammond":
      SendMidi Hammond CtrlChange $HammondAllSoundsOff 127
      break
   case "Nord":
      // Nord does not recognize all notes off so we need to send them manually
      $currentnote=127
      while ($currentnote > 0)
      {
         SendMidi Nord NoteOff $currentnote 0
         $currentnote--
        //Wait 1
      }
      // I had to add this. I think it is a bug with while statement 
      if ($Device == "Nord")
      SendMidi Nord NoteOff 0 0 // This line always executes if the above line is not there
      break
   default:
      break
   }
}



ossandust
 

Will look into it - probably an issue with using a while loop within a switch statement. 
But it would be simpler to just say while($currentnote >= 0)  ... 


Jack Fenton
 

Yes, I tried that at first but it continues to send notes 0 forever  because  integers in Uno2 cannot go below 0. 


ossandust
 
Edited

ok, I tried it out myself now and I can confirm these are 2 bugs : 
- arithmetic functions on variables should always keep the value between 0 and 127, also in case of "overflow"
- when using a "while" loop within a switch statement, the "case" condition is not correctly evaluated on statements following the while loop. 

Following version works correctly, because it doesn't have statements after the "while" :
(for your info : the "default:" statement within a switch statement is optional, so if it doesn't contain any commands you can omit it) 

TRIGGER_CLICK AllNotesOffPanic =
{
   switch($Device)
   {
      case "Hammond":
         SendMidi Hammond CtrlChange $HammondAllSoundsOff 127
         break
      case "Nord":
         SendMidi Nord NoteOff 127 0
         $currentnote=127
         while ($currentnote > 0)
         {
            $currentnote--
            SendMidi Nord NoteOff $currentnote 0
         }
         // don't add any more commands here...
         break
   }
}