Best way to assign values to modulator

Home Forums General Programming Best way to assign values to modulator

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

      I have two ways of assigning values to modulators after a dump request; one way is to assign one by one the value to each modulator (with a lot of lines of code), and the other way is to loop thru modulators more or lees like this

      [code:3v1mkfjw]for n = 0,73,1 do

      if panel:getModulatorWithProperty("modulatorCustomIndexGroup",n) ~= nil then
      panel:getModulatorWithProperty("modulatorCustomIndexGroup",n):setValue(patchCommonData:getByte(n), false)
      end
      end[/code:3v1mkfjw]

      I’ve observed (but not in the same panel) that the first way is much faster once you make the dump. Is this true or it is my imagination?

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

        Well linear programming (instead of using loops) is always faster, but loops are just easier to use. I spent some time on this some time ago and tried to address the performance issue by adding hash tables with modulator names, but that wasn’t very helpful.

        What you have to keep in mind, that when you do getModulatorByName() Ctrlr iterates through the entire list of modulators and tries to find the one with the name provided, if the modulator is at the end of the list then it might take a while. I should provide some faster examples that are possible, and i’ll do that asap.

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

          I suspected that, thx.

          I have another question: after receiving the dump request, I set the modulators with [i:1m9bquvb]setValue(value,false)[/i:1m9bquvb]. What I want is that the modulator don’t send it’s value via midi, so I set [i:1m9bquvb]false[/i:1m9bquvb], but the modulator always send it’s value via midi.

          Have I to use [i:1m9bquvb]setModulatorValue [/i:1m9bquvb]instead?

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

            That issue is a bit problematic due to Threading issues, the only work around for now is to use setModulatorValue(value, false, false, false) (only the 2nd false/true works anyway and indicates MIDI event), but this might also not work always (the call is not syncrhonus and might sometimes miss the dont-send-midi flag). This is something i know about but have no idea how to fix for now.

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

              Ok. I’ll don’t change anything for now, I think [i:sr9vttxz]setModulatorValue [/i:sr9vttxz]didn’t worked in the midiMessageReceived method.

              #4611
              dasfaker
              Keymaster
                • Topics: 80
                • Replies: 793
                • Total: 873
                • ★★★
                "atom":v7dmhoxn wrote:
                Well linear programming (instead of using loops) is always faster, but loops are just easier to use. I spent some time on this some time ago and tried to address the performance issue by adding hash tables with modulator names, but that wasn’t very helpful.

                What you have to keep in mind, that when you do getModulatorByName() Ctrlr iterates through the entire list of modulators and tries to find the one with the name provided, if the modulator is at the end of the list then it might take a while. I should provide some faster examples that are possible, and i’ll do that asap.[/quote:v7dmhoxn]

                If you have a little time it would be cool to see those examples

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

                  One way to go through all the modulators in the panel quickly:
                  [code:1zwt7e6x]
                  n = panel:getNumModulators()

                  for i=0,n-1 do
                  mod = panel:getModulatorByIndex(i)
                  end
                  [/code:1zwt7e6x]

                  You can use it to quickly send patches for users, to change properties on the panel to all modulators/components (i’ll be doing a patch manager with a web repository so that i can distribute simple patches quickly, like the bug with the mouse cursor beeing None should be fixed by a small snip of code like that)

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

                    It makes a huge difference, thx.

                    #4614
                    Synthetech
                    Participant
                      • Topics: 13
                      • Replies: 70
                      • Total: 83

                      This is something I wish to do with my project.

                      I want it so that when I do a program/patch change, the Ctrlr panel will do a single patch dump request from my Korg and get something like this back:

                      F0 42 21 06 00 00 01 00 00 00 00 00 00 00 00 00 04 01 0f 00 00 00 01 00 00 00 00 00 00 00 00 00 07 01 0F 00 00 00 00 00 02 00 00 04 0B 00 0A 00 0A 01 00 00 00 05 05 00 00 00 01 00 00 00 00 00 0C 00 0C 00 01 00 00 01 0B 01 0F 01 0F 01 0F 00 03 00 00 00 00 00 00 01 0F 01 0F 01 0F 01 0F 00 03 00 00 00 00 01 03 00 05 01 0F 00 00 01 0F 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 00 00 00 09 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 06 00 00 00 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 03 F7

                      The patch parameter values start with byte’s 6&7. So this patch’s first parameter value is 00 01.

                      Problem is.. the Ctrlr modulator/controls are set for values 0-127(as they should/need be). But the above patch dump is giving the values in a format/# that the Korg understands/displays.
                      So say Parameter#1 has a value of 1-2.. two numbers. The above example shows 00 01 and the Korg interprets it as value "2".. if it was 00 00, the Korg would interpret it as a "1".

                      So since each parameter in the patch dump can vary in max. number size.. like 1-2, 0-15, 0-31, 0-62, 0-99… I have to somehow run the raw data thru a formula that will change the raw number into a number that will span 0-127 that will be appropriate for each parameter’s actual range.

                      The example above of only two numbers would have to equate as 0=0, 1=127.
                      That way when the dump is received and translated to the modulator/control, it will display a 0 for 1 and 127 for a two.

                      The reason behind all this chaos is because the Korg will accept on the fly parameter edits.. but it receives those edits via a multi CC#(like NRPN) with values of 0-127 (just like the modulators default values).. and inside the Korg it changes the 0-127 value into an appropriate number for that parameter before it saves it to it’s proper parameter value memory location and finally update that parameter value to be displayed on the Korg and heard by the change in the patch’s sound (like a VCF opening up).

                      Cliff notes- I want to make Ctrlr do a dump request, read the raw data, starting at byte 6.. convert the numbers with varying formulas, then send the formulated # to set each modulator/control with a number that falls between 0-127.
                      It will be a way to update all the modulators values each time I change the patch.. so I can instantly see what each parameter’s value in a patch is the moment it is called.

                      I’ve never programmed in C or JUCE.. but I think I can catch on quickly if given some hints/tips.

                      -Blaine

                      #4615
                      Synthetech
                      Participant
                        • Topics: 13
                        • Replies: 70
                        • Total: 83

                        Ok.. msepsis has been helping me out with this-

                        I’m trying to build a script to read the hex dump from my synth so it can setup all the controls in a patch when I change patches using Ctrlr.

                        Here’s the code

                        [code:3iz871mr]– Called when a modulator value changes
                        — @modulator http://ctrlr.org/api/class_ctrlr_modulator.html
                        — @newValue new numeric value of the modulator
                        — Patch Configure = function(modulator, newValue)
                        — end

                        FilterMsb = midiMessage:getLuaData():getByte(54)
                        FilterLsb = midiMessage:getLuaData():getByte(55)

                        FilterValue = (FilterMsb*16)+(FilterLsb)

                        panel:getModulatorByName("VCF Cutoff"):setModulatorValue(FilterValue, false, false, false)[/code:3iz871mr]

                        when I goto save/compile it, it tells me it has errors…

                        [quote:3iz871mr]Compile of Patch Configure at 10/28/12 19:12:43:
                        ERROR: [string "–…"]:10: attempt to index global ‘midiMessage’ (a nil value)[/quote:3iz871mr]

                        I’m not sure what I’m doing wrong.
                        I can get the synth to do a patch dump.. I see it show up on OX’s monitor.. it’s even the correct patch#.
                        But the script evidently is not altering the value of my cutoff filter knob.

                        I’m sure I have the correct bytes.. it’s just that error makes no sense to me.

                        The Filter Values in the previous post’s dump are "05 05" the first byte is my msb and it is the 54th byte in my dump.. the 2nd 05 is my lsb and it is the 55th byte in my dump… if that helps.

                        #4616
                        msepsis
                        Participant
                          • Topics: 219
                          • Replies: 732
                          • Total: 951
                          • ★★★

                          You commented out the name of your script and the "end".. Those two elements should be like the bun of your sandwich, so to speak, and they shouldn’t be commented out with double dashes. One goes at the top, one goes at the bottom. This concept is important to grasp. When you start a function you must end a function.

                          it should be something like:

                          [code:1jfd3aiv]Patch Configure = function(modulator, newValue)

                          FilterMsb = midiMessage:getLuaData():getByte(54)
                          FilterLsb = midiMessage:getLuaData():getByte(55)

                          FilterValue = (FilterMsb*16)+(FilterLsb)

                          panel:getModulatorByName("VCF Cutoff"):setModulatorValue(FilterValue, false, false, false)

                          end[/code:1jfd3aiv]

                          Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

                          #4617
                          Synthetech
                          Participant
                            • Topics: 13
                            • Replies: 70
                            • Total: 83

                            I tried your code and got this..

                            ERROR: [string "Patch Configure = function(modulator, newValue)…"]:1: ‘=’ expected near ‘Configure’

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

                              [code:1212z05c]
                              — this is how you declare a function
                              myFunction = function(parameter1, parameter2, parameter3)
                              — function body goes here
                              console ("this is my function")
                              console ("parameters: parameter1=%d parameter2=%s parameter3=%d", parameter1, parameter2, parameter3)
                              end
                              [/code:1212z05c]

                              to call the function
                              [code:1212z05c]
                              value = 30
                              myFunction(1, "i love britney spears", value)
                              [/code:1212z05c]

                              #4619
                              msepsis
                              Participant
                                • Topics: 219
                                • Replies: 732
                                • Total: 951
                                • ★★★

                                Well.. I said your code should look "something like…" <img decoding=” title=”Very Happy” />
                                You’re very close.. That first line, as the error indicates is malformed.
                                Try looking at a new script and notice how the name you give the script must be declared in that first line.

                                Also.. No spaces in lua script names <img decoding=” title=”Smile” />

                                Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

                                #4620
                                Synthetech
                                Participant
                                  • Topics: 13
                                  • Replies: 70
                                  • Total: 83

                                  I cleaned up my code and it appears to compile with "Success"

                                  but when I goto use it in my Patch combobox, it fails.

                                  My Patch Select Box is used to not only make my synth select a patch, it also sends a sysex command to get that patch’s dump.

                                  Midi message type is Multi.
                                  I have the sysex command first, then the patch select.
                                  The sysex command works.. it even selects the same single Patch Dump as the Patch# I select as verified in OX’s monitor.

                                  But when I try to use it, I get this..

                                  [attachment=0:3j4d8pwu]luaerror1.jpg[/attachment:3j4d8pwu]

                                  #4621
                                  msepsis
                                  Participant
                                    • Topics: 219
                                    • Replies: 732
                                    • Total: 951
                                    • ★★★

                                    The error message tells you what line the error is, and what the problem is on that line. You’re using a nil global on line 7 name ‘midiMessage’. What are you actually trying to do on line 7?

                                    Just a reminder again, you want the function to set modulator values from the patch dump attached to the panel, not to the same combobox you’re requesting patch dumps from. A combobox requests a program and forms a patch dump request to send to the synth based on the program selection. The synth sends the patch dump. The panel receives the patch dump as a midi message. What does the panel do when it receives a midi message? It does what you tell it to do in the "Called when panels receives a MIDI message" script slot.

                                    Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

                                    #4622
                                    Synthetech
                                    Participant
                                      • Topics: 13
                                      • Replies: 70
                                      • Total: 83

                                      Ok,

                                      so I took this code

                                      [code:2l8rvc4p]PrgChange = function(modulator, newValue)

                                      FilterMsb = midiMessage:getLuaData():getByte(54)
                                      FilterLsb = midiMessage:getLuaData():getByte(55)

                                      FilterValue = (FilterMsb*16)+(FilterLsb)

                                      panel:getModulatorByName("VCFCutoff"):setModulatorValue(FilterValue, false, false, false)

                                      end[/code:2l8rvc4p]

                                      Called it PrgChange, set to be called when Panel receives a midi message.

                                      The Patch change combobox is set to multi midi message. First one is "ProgramChange,Direct,Direct,-1,-1,F0 00 F7", the other is a sysex message that shows up as "SysEx,Direct,Direct,-1,-1,F0 42 21 07 xx F7" in the multimessage listbox after I’ve added it in.

                                      Right below that, Sysex Formula shows as "F0 00 F7"

                                      When I try to change a patch after a fresh load, I get the error msg,

                                      Callback error: PrgChange
                                      at line 6 and a nil value when it attempts to index global "midimessage"

                                      then it disables the script and I’m back to square one.
                                      The synth is sending the dump… I have the combobox setup so it sends the synth a Program Change first, then the sysex dump req.
                                      I tried using the midi program change features you can check off in Panel, but it doesnt seem to help.

                                      I thought I was on the right track… but evidently I’m not.

                                      #4623
                                      msepsis
                                      Participant
                                        • Topics: 219
                                        • Replies: 732
                                        • Total: 951
                                        • ★★★

                                        change that first line to:

                                        function PrgChange(midiMessage)

                                        that should do it.. report back if not.

                                        Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

                                        #4624
                                        Synthetech
                                        Participant
                                          • Topics: 13
                                          • Replies: 70
                                          • Total: 83

                                          OK, I finally have my Filter Knob changing position/value when I do a dump call.

                                          But, I have to set the uiImageslider to a min. of 1 . If I set it to 0, it wont stay at the dump adjustment value… I see the knob try to set/move, and then it just snaps back to 0.
                                          I dont have the snap feature on.

                                          Same thing happens to a uiButton. I see it change, then it goes back to 0.. WTF?

                                          It’s always something..

                                          #4625
                                          msepsis
                                          Participant
                                            • Topics: 219
                                            • Replies: 732
                                            • Total: 951
                                            • ★★★

                                            Do you have MIDI thru turned on at the synth? Turn it off, and/or make sure you’re coming out of your synth’s MIDI out port, not MIDI thru port if it has one.
                                            That’s a weird one. I haven’t experienced that. You need to just troubleshoot this down. Maybe, unless you’ve already tried this put nothing on the panel but the midiMessageReceived script, a combobox which does the program change and sends the dump request and a knob on the panel that gets assigned a value. Strip it down to the basic functionality and go from there. You don’t have any other scripts in your panel that contain any setModulatorValue calls, do you? Do you happen to have any linked modulators? Disable them if so. I also recommend opening up the MIDI monitor and enable monitoring of both In and Out. Watch the MIDI monitor when you do a program change. Also you can insert lines in your lua script that print messages in the Lua console. This can be helpful to verify you’re getting the correct values for things and to print a message in the console at different steps of the script.
                                            Here are some examples:

                                            console ("this text will print in Lua console")
                                            console (string.format ("my modulator’s value is=%", modulatorsUniqueName))

                                            You’re getting there, you’ll look back at this soon and laugh.. just keep working it.

                                            Monstrum Media | Music, Sound & Software Design, Chicago / San Francisco listen

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