HISE Logo Forum
    • Categories
    • Register
    • Login

    BInary numbers

    Scheduled Pinned Locked Moved Scripting
    27 Posts 4 Posters 1.2k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • d.healeyD
      d.healey @ustk
      last edited by

      @ustk said in BInary numbers:

      I'm sure there is a good reason behind it, like for filtering your list

      I'm not always so sure, sometimes I see a path and follow it, but it's not always the right one :)

      In this case I want to use a switch statement. So if button 1 is on, do something, and if button 2 is on do that as well, etc. I figure I can run a switch on a single value more easily than multiple if statements over an array, but I might be wrong.

      Libre Wave - Freedom respecting instruments and effects
      My Patreon - HISE tutorials
      YouTube Channel - Public HISE tutorials

      ustkU 2 Replies Last reply Reply Quote 0
      • ustkU
        ustk @d.healey
        last edited by ustk

        @d-healey So if I understand well, you need a single number representation of the state of all buttons at a time?
        In this case, effectively this is the best solution I can see...

        Can't help pressing F5 in the forum...

        1 Reply Last reply Reply Quote 0
        • ustkU
          ustk @d.healey
          last edited by

          @d-healey You can also switch over an array, it has the advantage of giving easy readable code, but it might not be compatible with what you want to achieve...

          inline function onbtnQueryControl(component, value)
          {
          	if (value)
          	{
          		local state = [];
          		
          		for (i = 0; i < buttons.length; i++)
          			state.push(buttons[i].getValue());
          		
          		Console.clear();
          		
          		switch (state)
          		{
          			case [0,0,0,1]: Console.print("Do this"); 		break;
          			case [0,0,1,0]: Console.print("Do that"); 		break;
          			case [1,0,1,1]: Console.print("Do whatever"); 	break;
          			default:		Console.print("Do nothing");
          		}
          	}
          }
          

          Can't help pressing F5 in the forum...

          d.healeyD Christoph HartC 2 Replies Last reply Reply Quote 1
          • d.healeyD
            d.healey @ustk
            last edited by

            @ustk Oh I didn't know that! For 4 buttons I think that's more readable, when you get up to 10+ buttons I think it might become unpleasant.

            Libre Wave - Freedom respecting instruments and effects
            My Patreon - HISE tutorials
            YouTube Channel - Public HISE tutorials

            ustkU 2 Replies Last reply Reply Quote 1
            • Christoph HartC
              Christoph Hart @ustk
              last edited by

              @ustk that works? I didn‘t knew you can use array literals as switch cases.

              But if this comes in the vicinity of a realtime callback I wouldn‘t trust it not allocating so a bit fiddling might be better suited.

              ustkU 1 Reply Last reply Reply Quote 2
              • ustkU
                ustk @d.healey
                last edited by

                @d-healey Note that it can also be replaced by the string representation of the same binary number.
                I'm not sure to agree with the fact that it can become unpleasant, because it's always easier to debug or maintain a visual representation rather than a state you don't "see", but it's a matter of taste of course...

                Can't help pressing F5 in the forum...

                d.healeyD 1 Reply Last reply Reply Quote 0
                • ustkU
                  ustk @Christoph Hart
                  last edited by ustk

                  @christoph-hart Yep that works! I understand the allocation issue though... This is where using a string would be better

                  Can't help pressing F5 in the forum...

                  1 Reply Last reply Reply Quote 0
                  • ustkU
                    ustk @d.healey
                    last edited by

                    @d-healey @Christoph-Hart

                    inline function onbtnQueryControl(component, value)
                    {
                    	if (value)
                    	{
                    		local state = "";
                    		
                    		for (i = 0; i < buttons.length; i++)
                    			state += Math.round(buttons[i].getValue());
                    		
                    		Console.clear();
                    		
                    		switch (state)
                    		{
                    			case "0001": Console.print("Do this"); 		break;
                    			case "0010": Console.print("Do that"); 		break;
                    			case "1011": Console.print("Do whatever"); 	break;
                    			default:		Console.print("Do nothing");
                    		}
                    	}
                    }
                    

                    Can't help pressing F5 in the forum...

                    Christoph HartC 1 Reply Last reply Reply Quote 0
                    • d.healeyD
                      d.healey @ustk
                      last edited by

                      @ustk said in BInary numbers:

                      a state you don't "see"

                      matric-matrix.gif

                      Libre Wave - Freedom respecting instruments and effects
                      My Patreon - HISE tutorials
                      YouTube Channel - Public HISE tutorials

                      ustkU 1 Reply Last reply Reply Quote 1
                      • ustkU
                        ustk @d.healey
                        last edited by

                        @d-healey 🤣

                        Can't help pressing F5 in the forum...

                        d.healeyD 1 Reply Last reply Reply Quote 0
                        • d.healeyD
                          d.healey @ustk
                          last edited by

                          @ustk You were right, I found a cleaner way to do it without resorting to bit masks :)

                          Libre Wave - Freedom respecting instruments and effects
                          My Patreon - HISE tutorials
                          YouTube Channel - Public HISE tutorials

                          1 Reply Last reply Reply Quote 1
                          • Christoph HartC
                            Christoph Hart @ustk
                            last edited by

                            @ustk nope, that's even worse, you're creating a string in the button callback and it might reallocate it in each loop iteration :)

                            ustkU 1 Reply Last reply Reply Quote 1
                            • ustkU
                              ustk @Christoph Hart
                              last edited by

                              @christoph-hart then using a reg should resolve the issue right? For a better world? :)

                              Can't help pressing F5 in the forum...

                              1 Reply Last reply Reply Quote 0
                              • Dan KorneffD
                                Dan Korneff
                                last edited by

                                Is there a way to use bitwise operators in SNEX?

                                Dan Korneff - Producer / Mixer / Audio Nerd

                                1 Reply Last reply Reply Quote 0
                                • First post
                                  Last post

                                16

                                Online

                                1.7k

                                Users

                                11.8k

                                Topics

                                102.6k

                                Posts