LUA examples

Home Forums General Programming LUA examples

Viewing 20 posts - 1 through 20 (of 22 total)
  • Author
    Posts
  • #371
    atom
    Keymaster
      • Topics: 159
      • Replies: 2945
      • Total: 3104
      • ★★★★★

      I commited them yesterday but my sleeping pills didn’t allow me to write anything after the commit (it was 4am)

      You will find 3 example panels here: https://ctrlrv4.svn.sourceforge.net/svn … rlrv4/Doc/ they show a small fraction of what can be done, all LUA is edited from a method property for each element (modulator/panel), those look like this:

      [attachment=0:m8fcwptt]lua_property.jpg[/attachment:m8fcwptt]

      So for the example panels have a look at the properties of components and see witch one has an assigned method, click the editor button on the property to see the actual LUA code that makes the magic happen. For now there are just two callbacks (there is a lot more planned) one when a modulator value changes, and one when MIDI is received on the panel (those two enable sending/catching/parsing SysEx dumps as programs witch is what i was aiming for in the first LUA release).

      So check that out, compare that to the API Docs to see what method does what, there is the LUA console that you can experiment with.

      #2875
      fozzie
      Participant
        • Topics: 1
        • Replies: 24
        • Total: 25

        Nice, thank you once again for all the coolness <img decoding=” title=”Smile” />

        I have taken a look at the LUA midi-receive panel example and kind of get the idea, but I’m not really familiar with the object oriented side of programming and corresponding syntax. Would anyone be willing to write an example on how (a) received value(s) could be assigned to one specific modulator that is present in the panel? That would help me in understanding LUA syntaxis. I would like to work on parsing a complex incoming sysex to update the MWXT panel without needing a midiox-script, but am not sure where/how to begin… I don’t mean to be demanding anything here, it would just be cool if someone could help, otherwise it will probably just take me a little longer to figure things out, which is no problem either.

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

          sure i’ll do an example assigning values from program dumps.

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

            I played a bit with these examples this weekend and am getting really excited. They weren’t working on the mac build you had up but I see there is a new nightly osx build I’ll have to check out.

            I’ve already started my list of little tricks I want to script up in Lua and am starting to wrap my brain around what I’ll need to do.
            the added bonus is that Lua can be applied… anywhere. I’m feeling like learning Lua is like taking a math class in elementary school!

            Thanks a lot for these examples atom.

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

            #2878
            Filch
            Participant
              • Topics: 22
              • Replies: 173
              • Total: 195
              • ★★

              Same here. I was going over the examples and at first I was feeling overwhelmed, but after more studying I could see what was what. I just need to learn the syntax and get comfortable.

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

                One important thing to add to the API Docs, are the IDs that are used all across Ctrlr to indicate properties, most of the time you will be doing a set/get on a property to do anything in lua.

                Here is a list of all IDs with descriptions and Human Readable names as they appear in Ctrlr (it’s a c++ include file, but it’s a one-line-one-id thing)
                https://ctrlrv4.svn.sourceforge.net/svn … CtrlrIDs.h

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

                  thanks Atom. I haven’t been able to get anything useful out of the midi example – I noticed you updated that example a bit after I downloaded it again last night – is that midi example supposed to be functioning? The dump request sysex string is something generic, doesnt work with my synths, but doing a sysex dump from the synth does nothing to that midi example either. What am I missing?

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

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

                    That example is for DSI Mopho only, every device has a unique request program sysex (or at least a bit different), so it will work only with a Mopho, but it’s an example it should illustrate how things happen and where.

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

                      right. i definitely understand every synth has a different dump request string. <img decoding=” title=”Smile” />

                      even if the panel is a demo for a synth I don’t have….

                      I see a requestProgram Lua script attached to the request program button that puts together a f0 01 25 05 xx xx f7 message. Fully aware that this bit is pure example and requires the morpho. but this is the only functionality I see scripted into the panel.

                      I see the midiMessageReceived code, what is this attached to? I was expecting it to be attached to output label, but nothing seems to be attached to that field. Like I said, I initiated a dump from my synth (not the panel as obviously that’s different code) and expected some input into the outputLabel field but got nothing. . .

                      None of the knobs have ccs assigned to them, I’d imagine the idea is that you do a dump request, the outputLabel updates w/ the long format sysex message, then the knobs update but how does this function if the knobs aren’t even assigned to controllers?

                      So far all i can tell this panel is good for is putting together a dump request from a morpho for the bank/program you select on the panel, what else can I learn from this demo panel? I don’t need to know how to put together a dump request. I already have that coded.

                      thanks!

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

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

                        the midiMessageReceived is attached to the panel to the incomming midi event, it’s fired for every MIDI Message comming into the panel.

                        #2884
                        netchose
                        Participant
                          • Topics: 15
                          • Replies: 70
                          • Total: 85

                          i’ve beginning to learn LUA. the color change panel is exactly what i need.

                          it seem very powerful !

                          http://www.lua.org/

                          thanks a lot

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

                            the basics http://www.lua.org/manual/5.1/manual.html#2.1

                            there is a load of examples on the net, i think the most i found is in WoW (World of Warcraft) cause LUA is inside there, but a lot of programs use LUA for scripting.

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

                              thanks atom for your efforts. I see now the [i:3gx4h84x]panel [/i:3gx4h84x]is assigned the midiMessageReceived call.

                              great.

                              pardon me for being so persistent… but I am not fully understanding the extent of the demonstrated functionality of your demo midi panel. I’m not just speaking for myself here, either :lol:

                              Suppose I have morpho connected… when I hit that "request program", does the ctrlr panel’s demo knobs and combo box update with all of the settings of the bank/program selected?

                              [b:3gx4h84x]How does that occur if all of the knobs on that panel are set to MIDI message type "NONE" ??[/b:3gx4h84x] is there something further behind the scenes that I’m not seeing?

                              thanks a lot!

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

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

                                no you send a request (actualy at some point the Program Manager will be doing that), you catch the response with the data (usualy some big sysex message), you interpret that message (read the bytes, toggle some bits, decompress, unpack whatever it takes to get the actual numeric values for your modulators), once you got those values you assign them to modulators in the panel, this can be automated in many ways (you can have an array of modulator name->index where the index will be some kind of pointer to a value in the sysex dump, so that when you assign the values you don’t need to access each modulator directly). There are hundreds of possibilites here. But that’s how this will work in general

                                SysEx program request
                                Receive dump data
                                Parse dump data
                                Assign values to modulators

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

                                  Got it.
                                  Imho it would make most sense to allow the modulator’s assigned CC or sysex param change short string be the pointer so you don’t need to duplicate work naming a modulator when it’s already in essence "named" by the value it sends..

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

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

                                    i don’t get it, what property would you like to index modulators by ?

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

                                      rewind a bit…

                                      You said: "…you catch the response with the data (usualy some big sysex message), you interpret that message (read the bytes, toggle some bits, decompress, unpack whatever it takes to get the actual numeric values for your modulators), once you got those values you assign them to modulators in the panel…"

                                      "whatever it takes to get the actual numeric values for your modulators" … The modulators already are indexed by the parameters the modulators send, right? The knob that sends CC13 should inversely be receiving something that looks like CC13 and some sort of value, which is contained within that "usually some big sysex message"… why make more work by requiring some giant array be defined (if your panel has a lot of modulators) when the modulators already are indexed and defined by what parameter they send. .. IE just like if i move my CC13 FM amount knob on my ctrlr panel the parameter is sent to the synth: if i move my [b:1bjircqb][i:1bjircqb]synth’s[/i:1bjircqb][/b:1bjircqb] FM ammt knob, my [b:1bjircqb][i:1bjircqb]panel’s[/i:1bjircqb][/b:1bjircqb] FM ammt knob moves. So you see the modulator already IS indexed…

                                      so why not in that "read the bytes, toggle some bits, decompress, unpack" stage, the long sysex string gets parsed into either a string of cc parameter changes and/or short sysex messages? This is precisely how Fozzie’s midiox script works with my microwaveXT panel. It’s really elegant, contrary to fozzie’s claims that he doesn’t have much programming experience.

                                      typing this on my laptop in blinding sunlight outdoors, I’ve done the best I can to re-read this post and make it as clear as possible.. hopefully this makes sense.

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

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

                                        …maybe this all helps to shed light on why I’m confused about how your example panel updates any of the knobs as none of the knobs are "indexed" (as in none of them are set up to send any parameters!!? <img decoding=” title=”Smile” /> Obviously the point of a ctrlr panel is to control synth parameters so the modulators would need either a cc or a sysex parameter assigned to it.. None of the modulators in your Demo-MIDI panel do, hence my confusion.

                                        You didn’t answer the question above regarding the example panel: assuming I have a morpho connected: DO the modulators update after the "request dump" button is pressed?

                                        Thanks atom.

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

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

                                          no the mopho does not yet update, since i had some more serious bugs to fix, i’ll try to finish that asap.

                                          As for the indexing i can do more accessor methods for now we have 2 getModulatorByName() and getModulatorByIndex(), but i will add getModulatorByMidiMessage() getModulatorByComponentType() and so on. Those two available now are the basic primitives.

                                          #2893
                                          fozzie
                                          Participant
                                            • Topics: 1
                                            • Replies: 24
                                            • Total: 25

                                            Maybe I can join in the confusion <img decoding=” title=”Wink” />

                                            Msepsis, I think what atom means by the indexing of the modulators to get proper values assigned to them is in essence the same activity I have done with my Midiox script, you use the position / index of a value in the long sysex message to link that to the proper controller. I’m guessing you can set that up in combination with assigning short cc or sysex messages to the knobs (as is the case in the MWXT panel). Whether you then parse the long sysex into the short messages or make some array to redirect/parse the long sysex-derived values to the correct knobs using an array or table is about the same amount of work. If this whole scripting is independent from the short sysex / cc message functionality that is already present, you can still turn a knob on your synth and also have your panel update directly.

                                            What is not clear to me yet is how you can take/parse values out of a midi message and assign that to one of the modulators to update its value, but I guess that is what we should use the getModulatorByName() and getModulatorByIndex() methods for? Is that right atom?

                                          Viewing 20 posts - 1 through 20 (of 22 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