dnaldoog

Forum Replies Created

Viewing 20 posts - 441 through 460 (of 480 total)
  • Author
    Posts
  • in reply to: randomize a text label? #73376
    dnaldoog
    Participant
      • Topics: 4
      • Replies: 480
      • Total: 484
      • ★★

      How about this?

      
      -- Called when a modulator value changes
      -- @mod   http://ctrlr.org/api/class_ctrlr_modulator.html
      -- @value    new numeric value of the modulator
      --
      function warmUp()
      math.randomseed(os.clock())
      math.random(); math.random(); math.random() -- warmup
      end -- function
      --------------------------------------------------------------
      myMethod = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)
      
      tab={}	
      warmUp() -- generate randomseed 
      
      for i= 1,10 do 
      rnd=math.random(32,127) 
      tab=rnd -- populate table tab with random numbers
      end
      
      shuffleTable = {} -- tab seems to repeat some of the positions with the same number so I re-shuffle them
      
      for i=1,10 do
          shuffleTable = tab[math.random(1,10)]
      end
      
      label="[ "
      
      for i,v in ipairs (shuffleTable) do
      console(String(v))
      label=label..v.." "
      end
      
      label=label.." ]"
      panel:getComponent("modulator-2"):setPropertyString("uiLabelText",label)
      console(String("________________________"))
      end -- function
      --------------------------------------------------------------
      
      Attachments:
      You must be logged in to view attached files.
      in reply to: Demo panel for MIDI receive/transmit routines #73348
      dnaldoog
      Participant
        • Topics: 4
        • Replies: 480
        • Total: 484
        • ★★

        80 characters is 240 bytes? can you clarify
        the obviousness i’m oblivious to? ? i’m obviously
        considering bytes in the wrong way.

        I haven’t gone right into it, but I think lua treats strings as a series of bytes, so the length of a string of 80 sysex values is F+0+” ” (space) that’s 3 bytes: ,multiply 3 by 80 and you get 240, except I was slightly wrong there – there is no trailing space, so the correct length is 239. My panel still divides 239 into 4 strings of 20 sysex values, but there could be a potential bug in there somewhere. I’ve changed the code slightly, from
        local st = mySplitStringIntoFourSegments(a,60)
        to
        local st = mySplitStringIntoFourSegments(a,#a/4)
        but it would need to be tested.

        and [“.. v..”] this is the bit that looks weird to me

        with console() or console(String()) you can mix strings with data:
        console(String(">>"..i.." = my test value= "..(v*3).."\n_____\\n prints a new line!_____"))
        Regards,

        Attachments:
        You must be logged in to view attached files.
        in reply to: Demo panel for MIDI receive/transmit routines #73347
        dnaldoog
        Participant
          • Topics: 4
          • Replies: 480
          • Total: 484
          • ★★

          Hi Human Fly,

          I just put that panel together quickly and maybe there’s a much better way of doing it, but *reverse_nameThemAll* if renamed to *nameThemAll* and *nameThemAll* given a temporary name (say *nameThemAll2*) will return the names back to the original modulator-1,.. modulator-56. If you change a name in the table/array like those typos you spotted, you then run the original *nameThemAll* function again. Bit clumsy I realise, but just cobbled together quickly.

          my earlier observation that some things
          that seemed to need to be ‘known’ earlier in a method, often
          come later

          When you define a function it can reside anywhere in your program (often in another file) and the great thing is you can use that function again anywhere in your program rather than have some code in-line when you need it in one function and repeat that same code in another function, which could lead to more confusion and errors. In other words, if you are going to use that gsub code more than once, then bundle it into a function that you can call anywhere.

          is that a 10 byte dummy header you’ve got?

          That sysex is completely made up from what I thought the D110 should look like, but not fully checked. Have you looked at my JD-990 panel which might function similarly to the D110?

          for i=offset,#t+(offset-1)
          ‘offset=10’ is minus the headers and address locations, but F0 is ignored. You would have to check the real offset in the D110, so from that point (‘offset=10’, which is really 11!!! (remembering we ignore the first byte F0)) we load data into the modulators on Ctrlr.

          #t means the size of table #t=56 – keep looping until you reach #t (56)+(offset-1) (or + 9) so loop through 56 times from position 10 to 65.

          The (offset-1) is unnecessary – it’s just to show you what’s happening. The last two numbers are ‘checksum’ and ‘F7 end sysex’ and so are ignored. Confusing! 🙁

          
          offset=10
          j=1
          for i=10,65 do
          m=midi:getLuaData():getByte(i)
          panel:getModulatorByName(t[j]):getComponent():setValue(m,true)
          j=j+1
          end

          because ‘i’ starts at 10, we can’t use it to reference t[1] through to t[56] so I use another counter ‘j’ instead. You can do this too:

          
          for i=10,65 do
          m=midi:getLuaData():getByte(i)
          panel:getModulatorByName(t[i-9]):getComponent():setValue(m,true)
          end
          
          in reply to: Demo panel for MIDI receive/transmit routines #73345
          dnaldoog
          Participant
            • Topics: 4
            • Replies: 480
            • Total: 484
            • ★★

            Hi Proton,

            The reason why the values are all zero is that in the received() function I had written:
            panel:getModulatorByName(t[j]):getComponent():setValue(m,false)
            Changing it to
            panel:getModulatorByName(t[j]):getComponent():setValue(m,true)
            fixes that!

            Regards,

            Attachments:
            You must be logged in to view attached files.
            in reply to: Demo panel for MIDI receive/transmit routines #73335
            dnaldoog
            Participant
              • Topics: 4
              • Replies: 480
              • Total: 484
              • ★★

              I should have explained that panel more clearly. The green button just a trigger for a script that fills all modulators named modulator-1 … modulator56 with names from a table of D110 parameters or controls. I didn’t have to type each name into Ctrlr, so I thought that might be of interest to you. Once initialized it is no longer needed. What you do is send a sysex message (see attached syx file) from MidiOx to the panel through LoopBe1 (input device in Ctrlr) and it will load each sysex value into each modulator. You don’t do anything with the panel, it is just receiving data.

              s:gsub("^%s*(.-)%s*$", "%1") is a regex expression that looks for space at the beginning or end of a string and removes it (in this case). I don’t think I could come up with that expression.

              console(String(i.."[".. v.."]")) this is just printing the index number “i” of the table and its value “v” to the console. There are four strings printed that were split from the 80 character (240 byte string). The 240 byte string ends with a space, hence the function that strips that space at the end.

              Each process or function that works on the string is broken down into separate functions or methods as they may be called, which makes for easier readability (perhaps?) and easier management of code (perhaps?).

              Attachments:
              You must be logged in to view attached files.
              in reply to: SOLVED: Display Sysex String in Console #73333
              dnaldoog
              Participant
                • Topics: 4
                • Replies: 480
                • Total: 484
                • ★★

                You can just do it this way:

                
                myMidiReceived = function(--[[ CtrlrMidiMessage --]] midi)
                console(midi:getLuaData():toHexString(1))
                end
                

                in reply to: Demo panel for MIDI receive/transmit routines #73331
                dnaldoog
                Participant
                  • Topics: 4
                  • Replies: 480
                  • Total: 484
                  • ★★

                  Hey Human Fly,

                  I finally worked out how to split a 240 byte string (e.g. direct from uiTextLabel) into 4 segments.

                  
                  mySplitString = function(mod,value,source)
                      a=panel:getModulatorByName("stringtosplit"):getComponent():getProperty("uiLabelText")
                      local st = mySplitStringIntoFourSegments(a,60)
                      for i,v in ipairs(st) do
                          console(String(i.."[".. v.."]"))
                          panel:getComponent("string0"..i):setPropertyString("uiLabelText",v)
                      end
                  end --function
                  ------------------------------------
                  function myTrim(s) -- trim leading/trailing whitespace
                      return (s:gsub("^%s*(.-)%s*$", "%1"))
                  end --function
                  -----------------------------------
                  function mySplitStringIntoFourSegments(text, stringSize)
                      local j=1 -- counts to 4
                      local s = {}
                      for i=1,#text,stringSize do
                          s[j] = myTrim(string.sub(text,i,stringSize*j))
                          j=j+1
                      end
                      return s
                  end --function
                  -----------------------------------
                  

                  🙂

                  With regard to that panel I posted, did you unmute loopBe1?

                  in reply to: Demo panel for MIDI receive/transmit routines #73298
                  dnaldoog
                  Participant
                    • Topics: 4
                    • Replies: 480
                    • Total: 484
                    • ★★

                    Hi there Human Fly,

                    I have got that code working from above. See panel. Here I am sending a made-up Sysex string …

                    F0 41 10 16 12 03 00 00 00 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F 10 11 12 13 14 15 16 17 18 19 1A 1B 1C 1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F 30 31 32 33 34 35 36 37 38 41 F7

                    … from MidiOx to trigger the midi received function in the panel using virtual midiports (LoopMidi).

                    Enjoy!

                    🙂

                    Attachments:
                    You must be logged in to view attached files.
                    in reply to: Demo panel for MIDI receive/transmit routines #73293
                    dnaldoog
                    Participant
                      • Topics: 4
                      • Replies: 480
                      • Total: 484
                      • ★★

                      this little demo panel, though,
                      is/was merely a test thing – a ‘paraphrasing’, ..a simili !

                      Oh I see, but it’s all very interesting and for me and leads to greater understanding generally. 🙂

                      in reply to: Demo panel for MIDI receive/transmit routines #73285
                      dnaldoog
                      Participant
                        • Topics: 4
                        • Replies: 480
                        • Total: 484
                        • ★★

                        ok, i see how that last section works – this is ok as long as
                        all values incoming are ‘literal’, and i don’t have to deal
                        with any ‘mapped’ offsets ie: pan with midi value 0-14 where it
                        is displayed as -7<0>+7

                        As you know, in such a case -7 to +7 are actually the values 0-14 so as far as midi and the D-110 are concerned. It’s only at the interface level that you would need to display -7 – +7 and in fact 0 to the D-110 would be 7 for the control at that address (you know this, but someone else reading this might not). That’s where you would use uiFixedSlider etc.

                        I suppose there could be some reason to convert the midi values 0,1 to -7, -6 etc in lua (ie sending text to uiLabel), but for pure sending of midi and receiving I don’t think it is necessary 🙂

                        in practice, i will have to split this read-off of values from
                        the incoming data whenever i…

                        Sometimes you may want to load every byte into a table and then run various functions on the address stored in the table rather than run a series of if/else on every midi-data-byte. But either would work.

                        i wanted to play with it without it being a Ctrlr midi
                        message type – because that seems to require it to be a message
                        incoming on the midi bus.(if you see what i mean..)

                        Do you mean doing all this without being connected to the D-110? No doubt that makes it a bit more difficult to test, but maybe you could set up a program like Midi-Ox to transmit sysex messages to your panel? 😕

                        in reply to: Demo panel for MIDI receive/transmit routines #73283
                        dnaldoog
                        Participant
                          • Topics: 4
                          • Replies: 480
                          • Total: 484
                          • ★★

                          Well I never looked at the reason for this function, just focusing on the errors you were dealing with and offering a way of fixing those (particular issues), but it seems that all you are trying to do is process the data coming in from the synth.

                          I don’t think you need to do all that memoryblock converting or midi:getLuaData():getRange(), gsub() stuff. Needs to be as simple as possible or else all these compilation errors start seeping in as you are finding out.

                          If you know a certain midi dump will be say 65 bytes long then:

                          myMidiReceived = function(--[[ CtrlrMidiMessage --]] midi)
                              local s = midi:getSize()
                           if s == 65 then

                          …now work out a way of writing into the values of a midi:getLuaData():getByte() to various modulator/components (uiSliders uiCombos etc); that magic moment when you see all the sliders change values on screen!

                          You can do this by mapping the position of each byte in midi:getLuaData():getByte() to a table of modulator/Component names.

                          This would be the foundation/core of your whole program!!! Everything else should be designed around this central function of Ctrlr 🙂

                          e.g.

                          
                          t={
                          "WG_PITCH_COARSE", --  0x00 this would be the name of the Modulator/Component
                          "WG_PITCH_FINE", -- 0x01
                          "any_mod_name_I_choose", -- 0x10
                          -- <em>54 more elements to be listed here</em>
                          "TV_ENV_SUSTAIN_LEVEL”, -- 0x39 
                          }
                          --pseudo code follows untested!!
                          j=1
                          for i=5,65-2 do
                          --  5 could be the offset from the sysex header F0 41 ?? ?? ??
                          -- -2 = ignore checksum and F7 (in the case of Roland Synths)
                          m=midi:getLuaData():getByte(i)
                          panel:getModulatorByName(t[j]):getComponent():setValue(m,false)
                          j=j+1
                          end
                          

                          This is all untested, but hopefully it will help you understand the core idea of getting data out of the D-110 and into ctrlr. 🙂

                          in reply to: Demo panel for MIDI receive/transmit routines #73279
                          dnaldoog
                          Participant
                            • Topics: 4
                            • Replies: 480
                            • Total: 484
                            • ★★
                            myMethod = function(--[[ CtrlrModulator --]] mod, --[[ number --]] value, --[[ number --]] source)
                            	extBank = L(panel:getModulatorByName("lcd_bankDataB"):getComponent():getProperty("uiLabelText"))
                            	console("Retrieving external bank : "..extBank)
                            
                            --make a memory block from the string
                            	memB = MemoryBlock(extBank) -- this variable is used to send midi????
                            
                            --check size of received dump
                            	local size = memB:getSize() -- same as size=string.len(extBank)???
                                console("midiMessageReceived: " .. size .. "bytes")
                            
                            		if size == 80 then 	--bank dump
                            		console("bank dump detected!")
                            		end
                            extBank:gsub("(%w+)",function(c) table.insert(tabl_extBank,c) end)
                            for i,v in ipairs(tabl_extBank) do
                            console("i="..i.." v="..v)
                            end
                            console("size of tabl_extBank="..#tabl_extBank)
                            end

                            –convert bank to table tabl_extBank = {} for i=1,80 do s=extBank:toHexString(1) table.insert(tabl_extBank,s) end

                            I think toHexString(1) just dumps a memory block into a string. ‘extBank’ is a string obtained from a uiTextLabel, so it is not a memory block. To convert a string into a table, you would need to split or explode it somehow using a delimiter (like excel does with csv files). The code above gsub(“(%w+)” does a similar thing by ignoring whitespace and just loading the number 0-9 or letter A-F into each element of the table. Not fully tested though 🙂

                            extBank:gsub("(%w+)",function(c) table.insert(tabl_extBank,c) end)
                            I found it here.

                            in reply to: Demo panel for MIDI receive/transmit routines #73278
                            dnaldoog
                            Participant
                              • Topics: 4
                              • Replies: 480
                              • Total: 484
                              • ★★

                              I don’t know why I used ‘s’ 😕 – using an underscore for arrays is a matter of personal style for me, but I think underscore + capital letter should be avoided in Lua from what I read:

                              http://www.lua.org/pil/1.3.html You should avoid identifiers starting with an underscore followed by one or more uppercase letters (e.g., _VERSION); they are reserved for special uses in Lua. Usually, I reserve the identifier _ (a single underscore) for a dummy variable.

                              Maybe I should say table and not array? Maybe table is the more correct term in Lua?

                              i is commonly used as the index and v as the value in looping though arrays tables. If another counter is needed then j is often used and then k for key in associative arrays or tables, but of course generally variable names should have more descriptive titles.

                              in reply to: Demo panel for MIDI receive/transmit routines #73273
                              dnaldoog
                              Participant
                                • Topics: 4
                                • Replies: 480
                                • Total: 484
                                • ★★

                                Glad it worked for you!

                                To change the thumb colour on all sliders, you could put them into an array:

                                _s={"wave","coarse","fine","cutoff","reso","atk","dec","sus","rel","level"} 
                                -- some example properties you can change
                                for _,v in pairs(_s) do -- 'v' is each element in the array _s
                                panel:getModulatorByName(v):getComponent():setProperty ("uiSliderRotaryTextColour","FF00FFFF",true)
                                panel:getModulatorByName(v):getComponent():setProperty ("uiSliderRotaryFillColour","FFffFFFF",true)
                                panel:getModulatorByName(v):getComponent():setProperty ("uiSliderThumbColour","FF00FF00",true)
                                panel:getModulatorByName(v):getComponent():setProperty ("uiSliderValueBgColour","FF00FFFF",true)
                                panel:getModulatorByName(v):getComponent():setProperty ("uiSliderValueTextColour","FF000000",true)
                                panel:getModulatorByName(v):getComponent():setProperty ("uiSliderTrackColour","FF000000",true)
                                
                                end

                                then loop through and change any property you like. There is a full list of constructor?? (property) names in :

                                • panel -> modulator list -> View -> Visible Columns

                                ..scroll down and you will see all the uiSlider constructors (I don’t know if that’s the right term) – looking down the list, you can see uiSliderThumbColour (you already know the name)

                                in reply to: Demo panel for MIDI receive/transmit routines #73268
                                dnaldoog
                                Participant
                                  • Topics: 4
                                  • Replies: 480
                                  • Total: 484
                                  • ★★

                                  You created a Modulator called uiSliderThumbColour (orange) , but uiSliderThumbColour is a Component (blue).

                                  You would need to make a backup and try something like this: 🙂

                                  n = panel:getNumModulators()
                                  for i=0,n-1 do
                                  mod = panel:getModulatorByIndex(i)
                                  mod:removeProperty("uiSliderThumbColour")
                                  end
                                  in reply to: Callback Error #73266
                                  dnaldoog
                                  Participant
                                    • Topics: 4
                                    • Replies: 480
                                    • Total: 484
                                    • ★★

                                    This line needs a ) at the end – Does that fix it?

                                    string.format(“%s”,modulatorRef:getMidiMessage():getProperty(“midiMessageSysExFormula”)

                                    in reply to: Demo panel for MIDI receive/transmit routines #73265
                                    dnaldoog
                                    Participant
                                      • Topics: 4
                                      • Replies: 480
                                      • Total: 484
                                      • ★★

                                      I did that a few times and wrote a function to clear them.

                                      Is this what you mean? You created a new modulator that is now showing on the panel editor menu (or whatever it is called)?

                                      removeComponentsIcreated=function(NAME)
                                          --[[While developing I occasionally accidentally created a component or Modulator -- this code removes that entity--]]
                                          --[[ COMPONENTS --]]
                                          panel:getModulatorByName(NAME):getComponent():removeProperty("uiSliderThumbColour")
                                             --[[ MODULATORS --]]
                                          panel:getModulatorByName(NAME):removeProperty("uiSliderThumbColour")
                                      end --function
                                      in reply to: A little help please #73237
                                      dnaldoog
                                      Participant
                                        • Topics: 4
                                        • Replies: 480
                                        • Total: 484
                                        • ★★

                                        Wow – that’s better and even more concise!

                                        in reply to: A little help please #73231
                                        dnaldoog
                                        Participant
                                          • Topics: 4
                                          • Replies: 480
                                          • Total: 484
                                          • ★★

                                          Hi there Anton,

                                          If ‘list’ can have values ranging from 0-31, then I think this would work:

                                          
                                          My_Knobs_1 = function(value)
                                          list = panel:getModulatorByName("list"):getModulatorValue()
                                          local multiplier = list * 4
                                          local loopEnd = multiplier + 3
                                          k=40
                                          for i=multiplier,loopEnd  do
                                          m1 = panel:sendMidiMessageNow(CtrlrMidiMessage({0xf0, 0x47, 0x00, 0x72, 0x31, 0x00, 0x04, 0x01, 0x03, k, i, 0xf7}))
                                          k=k+7
                                          end
                                          

                                          Note: in the attached panel I mistakenly left in the redundant i=i+2

                                          Regards,

                                          Attachments:
                                          You must be logged in to view attached files.
                                          in reply to: Demo panel for MIDI receive/transmit routines #73218
                                          dnaldoog
                                          Participant
                                            • Topics: 4
                                            • Replies: 480
                                            • Total: 484
                                            • ★★

                                            It looks like sendMidiMessageNow doesn’t like receiving an empty string

                                            if string.len(memB:toHexString(1)) >0 then
                                            	panel:sendMidiMessageNow(CtrlrMidiMessage(memB))
                                            end

                                            Maybe the L() function is an alias for

                                            std::string LGlobalFunctions::stringToLua (const String &string)
                                            {
                                                return (string.toUTF8().getAddress());
                                            }

                                            Looks like it converts the string to utf8.

                                            Regards,

                                          Viewing 20 posts - 441 through 460 (of 480 total)
                                          Ctrlr