LUA, switches and bit flags

Home Forums General Programming LUA, switches and bit flags

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #498
    dejf_mk
    Participant
      • Topics: 5
      • Replies: 10
      • Total: 15

      Hi there,
      I’m working on a panel for one of the Midibox synths at the moment and I have got most of the sliders set up for the correct sysex. My current problem is that the synth has switches that relate to bits being set in a single sysex variable. I’ve found a few forums posts related to this, checked the API docs (I found the CtrlrLuaBigInteger reference) and looked at some other panels but I just can’t understand how to handle this in Ctrlr.

      Here is an example from the synth’s MIDI spec:
      [code:8utqt56c]
      | Hex | Description | Range
      ==========+==============================================+==============
      10h | OP1 Flags | 0- 15: val
      | Bit 0: reserved |
      | Bit 1: EGT (enables Sustain phase of EG) |
      | Bit 2: Vibrato |
      | Bit 3: Tremolo |[/code:8utqt56c]

      I understand that each switch should be set to react to the sysex (e.g. 10h above), but I’m not sure how to create a LUA method for then setting the appropriate bit for a switch. Ideally I would like to come up with one method that is usable across multiple switches, but I’m not sure how!

      Would you be able to give me some advice how to handle this?

      Thanks in advance

      David

      #3516
      atom
      Keymaster
        • Topics: 159
        • Replies: 2945
        • Total: 3104
        • ★★★★★

        Well one way is to create a method for the panels incomming event "Called when panel receives a MIDI message", catch that message there (match all the bytes, this method will catch ALL midi comming to the panel). Then extract the bits from the message and set values to modulators on the panel based on those bits.

        #3517
        dejf_mk
        Participant
          • Topics: 5
          • Replies: 10
          • Total: 15

          OK thanks for the idea. However, I’m using the midiMessageReceived method from the monstrum wave XL panel and parsing the whole sysex dump.

          What I did come up with today for the buttons is this, thought I would post it just in case anyone else might find a use for it:

          [code:2xhnvdux]
          — Reacts to a switch being changed onscreen
          function mySwitchOP1Sustain (modulator)

          — get the bit to be modified
          bit1 = modulator:getModulatorValue()

          — get the state of the other bits to be modified
          bit2 = panel:getModulatorByName("OP1-vibrato-on"):getModulatorValue()
          bit3 = panel:getModulatorByName("OP1-tremolo-on"):getModulatorValue()

          — roll the bits together (using as rangebecause no idea how to change int to boolean)
          modToSend = CtrlrLuaBigInteger(0)
          modToSend:setBitRangeAsInt(1,1,bit1)
          modToSend:setBitRangeAsInt(2,1,bit2)
          modToSend:setBitRangeAsInt(3,1,bit3)
          modTSInt = modToSend:getBitRangeAsInt(0,4)

          console(string.format ("modToSend as value = %s, TSInt= %d, as bits = %s",modToSend:toString(10,0),modTSInt,modToSend:toString(2,4)))

          — create the SysEx message
          m = CtrlrMidiMessage({0xF0, 0, 0, 0x7e, 0x49, 0, 0x06, 0, 0, 0x10, modTSInt, 0xF7})
          panel:sendMidiMessageNow(m)
          end
          [/code:2xhnvdux]

          Note: this is currently untested, but the MIDI output looks right so far <img decoding=” title=”Smile” />

          I’m still learning LUA, so if anyone can see something that could be improved I’m open to suggestions….

          David

        Viewing 3 posts - 1 through 3 (of 3 total)
        • The forum ‘Programming’ is closed to new topics and replies.
        There is currently 0 users and 52 guests online
        No users are currently active
        Forum Statistics
        Threads: 2,495, Posts: 17,374, Members: 77,605
        Most users ever online was 12 on January 22, 2019 3:47 pm
        Ctrlr