ChatGPT can do Lua #553
Replies: 69 comments 107 replies
-
oh dear: something in my original script is causing weird text issues. hopefully you get the general idea. (and when i copied it into the panel, the indents were all good, not as above) and is its comment/explanation: "This uses a table tabValues to map the values of structure to the corresponding uiTabsCurrentTab values for SynPcm1 and SynPcm2. This allows us to eliminate the multiple if statements and reduce the code to just a few lines." |
Beta Was this translation helpful? Give feedback.
-
lol sorry it is isn't it. i'll have another go. |
Beta Was this translation helpful? Give feedback.
-
woo got there in the end. my very bad habit of decorating methods with separators. bear in mind this was my first attempt at doing anything in Lua long before our discussions! - i think chatGPT did pretty well. |
Beta Was this translation helpful? Give feedback.
-
in fact, it looks like it's made a mistake: the first 2 entries are supposed to call the first sub function see(00) eg: result is (0,0) (0,0), not (0,0) (0,1) what would dnaldoog's version be? |
Beta Was this translation helpful? Give feedback.
-
it does correctly identify that using a table is better. |
Beta Was this translation helpful? Give feedback.
-
A slightly more concise version of your code would be to have only one internal function and set it to local: -- Called when a modulator value changes struct12_showGrps_pt1 = function (mod, value) -- sets corresponding option views local structure = panel:getModulatorByName("struct12_pt1"):getValue() local SynPcm1 = panel:getComponent("tabs_SynPcm1_pt1") local SynPcm2 = panel:getComponent("tabs_SynPcm2_pt1") local function see(a,b) SynPcm1:setPropertyInt("uiTabsCurrentTab", a) SynPcm2:setPropertyInt("uiTabsCurrentTab", b) end -- 00_01_SS if structure == 0 then see(0,0) -- 01_02_SS elseif structure == 1 then see(0,0) -- 02_03_PS elseif structure == 2 then see(1,0) -- 03_04_PS elseif structure == 3 then see(1,0) -- 04_05_SP elseif structure == 4 then see(0,1) -- 05_06_PP elseif structure == 5 then see(1,1) -- 06_07_PP elseif structure == 6 then see(1,1) -- 07_08_SS elseif structure == 7 then see(0,0) -- 08_09_PP elseif structure == 8 then see(1,1) -- 09_10_SS elseif structure == 9 then see(0,0) -- 10_11_PS elseif structure == 10 then see(1,0) -- 11_12_SP elseif structure == 11 then see(1,1) -- 12_13_PP elseif structure == 12 then see(1,1) end end |
Beta Was this translation helpful? Give feedback.
-
yes in fact chatGPT mucked it up because was only using [1] & [2] |
Beta Was this translation helpful? Give feedback.
-
oh i understand what that is now: it's the table: is each entry a 'subtable'? so it has index 1 and 2. that must be it. |
Beta Was this translation helpful? Give feedback.
-
and in the original table, it had fetched all the options i had listed - it got them all correct except the second one. |
Beta Was this translation helpful? Give feedback.
-
ok just had another go with something else. got the Lua Beautifier standing by. `-- modulators
-- tvaLevel zero is same as partial Off, AND with partial onoff
-- components
-- ledTextB 2nd row//shows partial is at both inputs//
-- tab OnClick buttons//showhide with partial onoff
-- tab showhide
-- struct12/34/clikStrct12/34//showhide for partial pairs
|
Beta Was this translation helpful? Give feedback.
-
..not having a lot of luck with the formatting, but it's broadly there. so here's what chatGPT did to that:
|
Beta Was this translation helpful? Give feedback.
-
finally, for now, here's another bit, defining colours for a LED pair (i'll explain what it is afterwards). there's quite a nice form here in the first bit:
|
Beta Was this translation helpful? Give feedback.
-
anyway: this is from my old D-110 panel, that i was looking at again yesterday. i was able to optimise a pair of methods very nicely - which made me go through the whole thing again. (i haven't used Ctrlr for ages, since early last year.) (and i was just thinking what fine work i'd done, sorting out those button and LED operations ! :D ) |
Beta Was this translation helpful? Give feedback.
-
i think chatGPT is a scam haha. it's some kind of callcentre with loads of human chatbots, scratching their heads when you ask them to code something. no actually, it was absolutely awesome just now, when i asked it to swap a protracted longform elseif series into a more concise form related to the 4 bit binary count represented by 4 button states, 4 parameters grouped on one parameter number - anyway, it came back with the same reply dasFaker gave me years ago lol. |
Beta Was this translation helpful? Give feedback.
-
it's a bit lazy, can't be bothered to give a full list of midi messages for 00 to 0F, ... just gave me some dots, and 'finish it yourself'. |
Beta Was this translation helpful? Give feedback.
-
here's more context with an earlier workfile. still has old code in. this is building out the structure of the panel, making methods apply to all parts, and doing part1 before fleshing it out. this is where i should start the new thread :-) |
Beta Was this translation helpful? Give feedback.
-
ok started a thread for the D110. have much waffling to do there. meanwhile, new conundrum is how to resolve the 'partial reserve' in the Patch parameters. with a total of 32 partials, it is possible to assign a voice reserve for each part. but it can't allocate more than is available depending on how much is already allocated to other voices. there are 8 parts, and a rhythm part. partial reserve can be from 0-32. (if you set 32 on one part, no reserve is available for other parts) is that a job for math.floor or math.ceiling? (etc not sure what i'm talking about yet) |
Beta Was this translation helpful? Give feedback.
-
with a quite minimal prompt, chat GPT gave me:
i suppose it would look something like this: start file with 9x dropdowns 0-32 and a 'total' display. noted something interesting in the steinberg atari editor for D110, which was a XY mixer with the 4 partials, like k1/tg33. |
Beta Was this translation helpful? Give feedback.
-
just to follow up with this, i've done a bit more prompting with chatGPT and have a functional panel, that does NOT produce the correct results - but it seems to be going in the right direction. to recap, the device in question, D-110 has polyphony of 32 partials, and 9 parts, including the rhythm part, and you can assign a 'partial reserve', same sort of thing as voice reserve, for each part. notionally each part 'reserve' parameter has range of 0-32 but in practice, the control maxes out when the total partial count is assigned, so if each part already has 2, or 3, or 4 reserved, the control you're incrementing might only go up to 10, or less, depending on what remains of the total. i thought about controlling the modulator property "maximum value", and did get it working, but it doesn't update the list on a combo - don't know how one might update a combo list in realtime? nightmare; doable probably but maybe just use a better modulator type - and really, i'm trying to prompt chatGPT for a mathematical solution rather than resorting to Ctrlr parameters ( which won't help with the UI .. i thought dropdown would be fine; fader, knob, meh not really. code below generated by chatGPT, from description prompt only, with minor interference from me:
|
Beta Was this translation helpful? Give feedback.
-
You can write that function with less code :) dynaMaxTest = function(--[[ CtrlrComponent --]] comp --[[ MouseEvent --]], event) local currMax = panel:getComponent("currMax"):getValue() local newList = {} for i = 0, currMax do table.insert(newList, string.format("%d=%d", i, i)) end local dataList = trim(table.concat(newList, "\n")) console(String(dataList)) panel:getComponent("myCombo"):setProperty("uiComboContent", dataList, false) panel:getComponent("myCombo"):setValue(0, false) end function trim(s) return s:match "^%s*(.*%S)" or "" end |
Beta Was this translation helpful? Give feedback.
-
here's what chatGPT suggested, for avoiding addressing properties (such as max value):
really minimal prompting required for this, and i was waffling a bit/being imprecise. ha, it also showed me the syntax for integer and replaced math.floor for me:
and this is the next script i'm going to try out - i'm losing track a bit at this stage - i'm not convinced it should divide by 9 parts tbh; i think that's a false route i created with an earlier prompt. (i don't know how this works yet; i'll do the work a bit later) (yeh we don't know where it's going at this point ... )
|
Beta Was this translation helpful? Give feedback.
-
Here's a panel that might give you a head start on the max = 32 problem. I tried rewriting the function updatePartialReserve(mod, value, source) if panel:getBootstrapState() then return end local n = L(mod:getName()) n = tonumber(n:sub(-1)) counter[n] = value local newsum = 0 for i = 1, 9 do newsum = newsum + counter[i] end if newsum > 32 then mod:setModulatorValue(0, false, false, false) newsum = 32 else local remaining = 32 - newsum panel:getLCDLabelComponent("lcd_rem"):setText(String(remaining)) panel:getLCDLabelComponent("lcd_total"):setText(String(newsum)) end end
counter={} for i=1,9 do counter[i]=0 end |
Beta Was this translation helpful? Give feedback.
-
ok fiddled with that a bit, and have something odd going on displaying last values list - think it needs to initialise on each run but not sure how that should be done. thought i'd try to start working in your combo edit method, to see if that can be got to work (notwithstanding that an edited list comes up blank until a new selection is made - maybe that can be triggered? ) the small shortcoming of the previous panel is that if it goes over (total max), it goes to the last selected value - rather than zero, that's good - and not the last available value. i don't know how that could be achieved. i took out the indiv displays, and made the spare display show a 'reserveValues' table each time, which reveals the erroneous values. haven't actually achieved anything with this one, and the first attempt at messing around with substituting |
Beta Was this translation helpful? Give feedback.
-
just got a little gift from chatGPT to convert Roland preset count 11-88, to decimal 1-64, and back. first, decimal to Roland count (as chatGPT decided to call it) 👍
and then the other way:
|
Beta Was this translation helpful? Give feedback.
-
Hi @subv0x You can streamline that code a little with: rolandPreset = panel:getLCDLabel("rolandPreset") -- declare outside function function converter(mod,decimal,source) local prefix = "A-" if decimal > 64 then prefix = "B-" decimal = decimal - 64 -- Adjust the decimal value for the second part end local row = math.ceil(decimal / 8) local column = (decimal - 1) % 8 + 1 rolandPreset:setText(prefix .. row .. column) end
|
Beta Was this translation helpful? Give feedback.
-
Does this panel do what you are wanting? Timbre Memories_5_0_test_dnaldoog_table_storing_values.zip I create a multidimensional table in --panelInit() recorder={} -- add any modulators to be stored here -- when retrieving from D110 store values in table for i=1,128 do recorder[i]={ assignMode=0, keyshift=0, outAssign=0, toneGrp=0, bendRange=0, toneNmbr=0, fine=0, } end -- store the value changed by user in each modulator storeValue = function(mod,value,source) local dec=decimal:getValue() local n=L(mod:getName()) recorder[dec][n]=value end -- recall the value in the table called from callback function in `decimal` `restoreValue(value)` -- which popup selection also fires function restoreValue(v) for k,v in pairs (recorder[v]) do panel:getComponent(k):setValue(v,false) end end |
Beta Was this translation helpful? Give feedback.
-
here is a rough view of what (i think) a Patch looks like: for each column we see the 11 'Part parameters' (as they are called as part of the 'Patch'), with 'Timbre' as the subset of parameters that are given values by the Timbres loaded to them. the same 7 parameters are saved when you save a new Timbre memory. the others belong to the Patch: pan, level, keyLimitLO, keyLimitHI and here's the fun bit, when you save a Patch, it saves those 11 parameters per part. in the sysex pages: there are 7 Timbre parameters, 11 Part parameters, and 11 Timbre Temporary area parameters. sorry for the long roundabout explanation. thought it was worth clarifying. this is at odds with Sean Luke, author of EdiSyn, who says that 'timbres' are irrelevant and not used - they are not required to write a new Patch; the Patch will save new settings OR the settings and number of the Timbre assigned to a Part. at least this is my current conclusion, and happy to be contradicted. |
Beta Was this translation helpful? Give feedback.
-
I think you mean Now you're getting into the weeds! Think of 04 00 00 as a location in memory on the D110: So in a sysex message the number starting at byte 6 is the memory location (04) for the data Each Tone can hold 246 bytes of data as you rightly calculated, Memory locations for the start of each of 8 tones are therefore: 0 | 0
Common parameters occupy the first 0E 14 bytes 00 - 0D so WG pitch Coarse for Tone No.1 Partial 1 will be F0 41 10 16 12 04 00 0E val cs F7 even though it says offset 00 in No. 5-1-2 in the manual. So at the start of each new table in the manual you need to start with the sum of the previous bytes in the previous table, but see next paragraph. It's not so easy!. But there are four partials each of 58 bytes 3A so: Common parameters occupy the first 0E (14) bytes 00~0D so WG pitch Coarse for Tone No.1 Partial 2 will be F0 41 10 16 12 04 00 48 val cs F7 even though it says offset 00 in No.5-1-2 in the manual.
Common parameters occupy the first 0E (14) bytes 00~0D so WG pitch Coarse for Tone No.2 Partial 1 will be F0 41 10 16 12 04 02 04 val cs F7 even though it says offset 00 in No.5-1-2 in the manual. So at the start of each new table in the manual you need to start with the sum of the previous bytes in the previous table, but see next paragraph. It's not so easy! But there are four partials each of 58 bytes 3A so Common parameters occupy the first 0E (14) bytes 00~0D so WG pitch Coarse for Tone No.2 Partial 2 will be F0 41 10 16 12 04 02 3E 48 val cs F7 even though it says offset 00 in No.5-1-2 in the manual. So for each partial you need to offset by 58 0x3A
It's really difficult to get one's head around but thinking of those numbers in terms of position in memory should help. You can either hard code these numbers into Ctrlr in the SYSEX field or calculate them on the fly using lua (possibly with the help of lookup tables). You could even just have one massive table with static lookups for each byte. It's probably still very efficient and you could basically just copy the manual into the table. I did this with the Yamaha TX81-Z panel I wrote. Have each modulator in a table as a key and have an offset address as a binary string if you like. Make the modulator name exactly the same as in the manual, so you don't go insane, adding an identifying trailing digit, or you could have a table of values that you multiply by the Tone number 1-8. Endless possibilities but as long as you take this top down approach you shouldn't get too lost as is so easily done with a complex machine like this! |
Beta Was this translation helpful? Give feedback.
-
revised view of what is contained in the Patch, and what isn't. ( this isn't the panel, it's just a quick visualisation, to see where i'm going with it). it could have a main view like this, reflecting more how the unit powers on - then you hit Timbre>Edit, and Edit again, to get into the Tone on the selected Part. so i guess i could have a uiTabs, with buttons flipping to the relevant Tone page.
btw (thanks for !) how did you calculate all those intervals in hex so quickly ?! i did it last time around but very laboriously, and it was very offputting contemplating how i'd deal with the parameter number count after Part1 (the easy one lol). |
Beta Was this translation helpful? Give feedback.
-
Here is a panel that accesses the correct (hopefully) sysex for each temporary memory byte. This could be a good starting point for a panel. Instead of creating 100s of modulators. I use two combos so you can check how the sysex would be generated for any modulator. This is kind of a top down approach. All you need to do now is assign modulators and name them according to the names in Edit 8/2023 Corrected a few errors |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
2nd chat with it just now, and i thought i'd show it some verbose crude methods and see if it could condense them, and if they'd still work, pasted over and compiled, into an existing panel. the first one was too long :D and it wouldn't have it. so i tried another one, and this time it gave a really short concise alternative. i put it in place of the original method, and it didn't crash, and seems to be working.
quick explanation of what it is: it's a continuous control, that selects which of 2 views is shown, for 2 lanes. there are 13 possible values.
i'll show what chatGPT wrote first, and then the original:
and here's mine:
(fingers crossed this all displays correctly when it hit Post)
Beta Was this translation helpful? Give feedback.
All reactions