Help with String:replace

Home Forums General Programming Help with String:replace

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #43829
    dasfaker
    Keymaster
      • Topics: 80
      • Replies: 793
      • Total: 873
      • ★★★

      I’m trying to copy the sysex formula of a modulator to a string and manipulate some bytes, so I’m doing this:

      syxFormula = mod:getMidiMessage(0):getPropertyString("midiMessageSysExFormula")
      if syxFormula:contains("k0") == true then
           syxFormula1 = syxFormula:replace("k0",tostring(panel:getModulatorByName("GLOBAL Part"):getValue()),false)
           end
      if syxFormula1:contains("k1") == true then
           syxFormula2 = syxFormula1:replace("k1",tostring(panel:getModulatorByName("GLOBAL Tone"):getValue()),false)
           end

      syxFormula is a String (Juce string?) but syxFormula1 is a string(lua string?), so I cannot use replace with syxFormula1. How can I convert this string into a String?

      #43833
      zeoka
      Participant
        • Topics: 73
        • Replies: 466
        • Total: 539
        • ★★★

        I’ve done this longtime ago and worked

        mp1mid1 = panel:getModulatorByName("PartSamplNb-1"):getMidiMessage()
        mp1mid2 = panel:getModulatorByName("Volume-1"):getMidiMessage()
        mp1mid3 = panel:getModulatorByName("Pan-1"):getMidiMessage()
        p1m1 =(string.format("%s %s %s",prfix1,map1val[newValue+1],sufix1)) 
        p1m2 =(string.format("%s %s %s %s",prfix1,map1val[newValue+1],mpbyt2,sufix2))
        p1m3 =(string.format("%s %s %s %s",prfix1,map1val[newValue+1],mpbyt3,sufix2))
         prfix1 = "f0 41 10 00 1d 12 12 00" 
         sufix1 = "00 MS LS z6 f7"
         sufix2 = "xx z5 f7"
        map1val ={"00","01","02","03","04","05","06","07","08","09","0a","0b"}
         mpbyt2 = "02"
         mpbyt3 = "03"  pbyt2 = "04"  
        mp1mid1:setProperty("midiMessageSysExFormula",(p1m1),false)
        mp1mid2:setProperty("midiMessageSysExFormula",(p1m2),false)
        mp1mid3:setProperty("midiMessageSysExFormula",(p1m3),false)

        getMidiMessage() is wrong now ,I notice you enter a 0 in it why ?

        Did you try string.gsub(syxFormula,”k0″,””..panel:getModulatorByName(“GLOBAL Part”):getValue()) ?

        #43848
        dasfaker
        Keymaster
          • Topics: 80
          • Replies: 793
          • Total: 873
          • ★★★

          getMidiMessage() is wrong now ,I notice you enter a 0 in it why ?

          Because otherwise it doesn’t work for me. With this 0 I get the sysex formula as a String.

          Did you try string.gsub(syxFormula,”k0″,””..panel:getModulatorByName(“GLOBAL Part”):getValue()) ?

          Yes, but string.gsub is for lua strings, not for juce Strings. It’s weird that function String:contains() return a lua string, so I can’t use again String:contains() with this string because it only works with juce Strings.

          #43877
          zeoka
          Participant
            • Topics: 73
            • Replies: 466
            • Total: 539
            • ★★★

            I’ve done this

            myMethod = function( mod, value)
            
             jj =panel:getModulatorByName("modulator-3"):getMidiMessage(0):getProperty("midiMessageSysExFormula")
            
            console(jj)
            --f0 41 10 00 1d 12 k0 00 50 4b xx z5 f7
            if string.find(jj,"k0") ~= nil then 
               hh = string.gsub(jj,"k0","f7") 
            console(hh)
            --f0 41 10 00 1d 12 f7 00 50 4b xx z5 f7
            panel:getModulatorByName("modulator-3"):getMidiMessage(0):setProperty("midiMessageSysExFormula",hh,false)
            
            end 
            
            end

            EDIT2 : corrected
            WORKING !

            I notice that you replace with something that looks like not an hexstring….

            • This reply was modified 9 years ago by zeoka.
            • This reply was modified 9 years ago by zeoka.
            #43884
            dasfaker
            Keymaster
              • Topics: 80
              • Replies: 793
              • Total: 873
              • ★★★

              Thanks Zeoka, it worked!!

              I didn’t realized that I was using getPropertyString instead of getProperty to get the midi message when I tried string.find and string.gsub.

            Viewing 5 posts - 1 through 5 (of 5 total)
            • The forum ‘Programming’ is closed to new topics and replies.
            There is currently 0 users and 77 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