kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Mar 2, 2019 22:06:45 GMT
Curious if it is important to use else if in this case? I'm gonna have a lot of script here and I think It may even need to be divided up into 2 functions... \
if (m_cc == 0) d.Bass__Volume.x = m_ccv; if (m_cc == 1) d.Snare__Volume.x = m_ccv; if (m_cc == 2) d.Clap__Volume.x = m_ccv;
if (m_cc == 0) d.Bass__Volume.x = m_ccv; else if (m_cc == 1) d.Snare__Volume.x = m_ccv; else if (m_cc == 2) d.Clap__Volume.x = m_ccv;
How hard to i need to optimize is the question...
|
|
|
Post by xPsycHoWasPx on Mar 2, 2019 22:36:29 GMT
if (m_cc == 0) d.Bass__Volume.x = m_ccv; if (m_cc == 1) d.Snare__Volume.x = m_ccv; if (m_cc == 2) d.Clap__Volume.x = m_ccv;
and
if (m_cc == 0) d.Bass__Volume.x = m_ccv; else if (m_cc == 1) d.Snare__Volume.x = m_ccv; else if (m_cc == 2) d.Clap__Volume.x = m_ccv;
is mostly the same and both is ok to use but.... lets make it like this to better explain:
if (m_cc == 0) d.Bass__Volume.x = m_ccv; else 'do something else 1' if (m_cc == 1) d.Snare__Volume.x = m_ccv; else 'do something else 2' if (m_cc == 2) d.Clap__Volume.x = m_ccv; else 'do something else 3'
lets say m_cc is 2
it does the first "if m_cc==0" and its not so it does the else instead (do something 1) now it tries "if m_cc==1" and its still not so it does the else (do something 2) .......... now it tries "if m_cc==2" and bingo m_cc is 2 so "d.Clap__Volume.x = m_ccv;" is now triggered but it won't do else (do something 3)
does that make sense to you ?
|
|
|
Post by xPsycHoWasPx on Mar 2, 2019 22:38:07 GMT
but this can be done much easier by using the
setexpression(object, expression_name, value);
setexpression(findobject('d.Bass__Volume'), 'x' , m_ccv);
decl list={'d.Bass__Volume','d.Snare__Volume','d.Clap__Volume'}
setexpression(list[0], 'x' , m_ccv);
it will pick the first item in the created list ('d.Bass__Volume') and insert it as a string in the findobject command that makes it into a real object target
by using your m_cc your list pointer u can now skip all the if rules
decl list={'d.Bass__Volume','d.Snare__Volume','d.Clap__Volume'}
setexpression(list[m_cc], 'x' , m_ccv);
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Mar 3, 2019 2:20:04 GMT
but this can be done much easier by using the setexpression(object, expression_name, value);
setexpression(findobject('d.Bass__Volume'), 'x' , m_ccv);
decl list={'d.Bass__Volume','d.Snare__Volume','d.Clap__Volume'}
setexpression(list[0], 'x' , m_ccv); it will pick the first item in the created list ('d.Bass__Volume') and insert it as a string in the findobject command that makes it into a real object target by using your m_cc your list pointer u can now skip all the if rules if (m_cc == 0) d.Bass__Volume.x = m_ccv; else 'do something else 1' if (m_cc == 1) d.Snare__Volume.x = m_ccv; else 'do something else 2' if (m_cc == 2) d.Clap__Volume.x = m_ccv; else 'do something else 3' This makes 100% sense. Its actually how I'm scripting the rest of my device! i just missed that i could do that here! THANK YOU! The main reason i had it this way is because i needed to insert some custom code at each point to convert x to the right value. I can make that array a little more dense... but... there is no way to store and call a function ref is there? decl list={{'d.Bass__Volume', data_func},{'d.Snare__Volume', data_func},{'d.Clap__Volume', data_func}
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Mar 3, 2019 2:48:17 GMT
decl list={{'d.Bass__Volume', data_func},{'d.Snare__Volume', data_func},{'d.Clap__Volume', data_func}}; This doesn't work. Not allowed to do nested Lists like this I guess... or maybe my syntax sucked. I dunno... I'm just gonna go for a double index here and multiply my index by two. decl list={'d.Bass__Volume', data_func,'d.Snare__Volume', data_func,'d.Clap__Volume', data_func}; and then for the function call. I'm just sticking a variable in there that can be evaluated to determine what function to be called. if(func == 'float') x = t_cc_to_x(m_ccv);
if(func == 'list') x = t_cc_to_list(m_ccv);
|
|
|
Post by xPsycHoWasPx on Mar 3, 2019 3:29:52 GMT
{{1,2},{3,4},{5,6}} in lemur will just end up as {1,2,3,4,5,6} so list inside a list cant be done.
+ the list in example with setexpression is only to tell findobejct() what object to target. The list is static and contains no possibility to store anything outside the script So wouldnt make sense to start mix things into that list If u want to store/recall variables when triggering the setexpression, you should create an expression outside the script. And run it with same index number as the other one.
But forget about trying to combine one object target with another and store it in a variable. You can combine 2 text strings into one and use that in findobject to run setattribute, getattribute, setexpression, getexpression. Nothing more or less..
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Mar 3, 2019 4:51:48 GMT
{{1,2},{3,4},{5,6}} in lemur will just end up as {1,2,3,4,5,6} so list inside a list cant be done. + the list in example with setexpression is only to tell findobejct() what object to target. The list is static and contains no possibility to store anything outside the script So wouldnt make sense to start mix things into that list If u want to store/recall variables when triggering the setexpression, you should create an expression outside the script. And run it with same index number as the other one. But forget about trying to combine one object target with another and store it in a variable. You can combine 2 text strings into one and use that in findobject to run setattribute, getattribute, setexpression, getexpression. Nothing more or less.. Right... the main reason I want to mix things like this in the list is for legibility. I can access them this way... I get that I'm stuck here if i double down on the indexes I can only have 128 items. But it makes for formatting the data much easier to read. decl linn_data_map = {d.Bass__Volume, 'float', d.Snare__Volume, 'float', d.Clap__Volume, 'float', d.Rim__Volume, 'float', d.HiHat__Volume, 'float', d.Cabasa__Volume, 'float', d.Tamb__Volume, 'float', d.Tom__Low__Volume, 'float', d.Tom__High__Volume, 'float', d.Conga__Low__Volume, 'float', ...}; otherwise its multiple lists and then me trying to match up the indexes. I know i will have so many bugs this way. I could even see wrapping this up in a function like storing indexes 0-64 in a part and 64-127 in another. So many insights you've brought me today. Thanks!!!!!!!!!!
|
|
|
Post by xPsycHoWasPx on Mar 3, 2019 16:24:47 GMT
Well I don't know what your main goal of project is or how the rest of scripts are done. Or how much experience you have with lemur so hard for me to tell where the different ppl are in terms of lemur experiance. So I just start my suggestions like ppl only have limited knowledge(just based on how limited Support I hat access to myself, when I was the clueless one). Then ppl can always tell me that "Hey I'm not that clueless" and me like "Ok I STFU" hehe :-)
So if you feel this is best way for you, then no problem doing like that. .
I will just remind you that as long this is done inside a script then arrays are thx God only limited to 256 items and not 256 bytes. So your method is fine to do, but I really don't recommend doing the same with external expressions since they limited to freaking bytes (why o why o why o why liine???) I did some of my first more advanced scripts in lemur where I hat expressions like this, [0] the name of the item [1] midi Val, and it was cool until I started use all knobs n parameters I was like WTF why are only half the values being recalled... and turned out before even half the parameters was stored it eaten up the whole expressions array because some names took more bytes than others.
That's the only reason I said that other thing.
In the end I just found it easier to have separate settings lists, that stores /recall With the same index vals as the name index. I'll explain later below:
The funny experience for me was Lemur was my first programming lang to learn until then I was more a script kiddie type. So for me my programming knowledge was only based on what lemur could do, picture how mind blowing it has been for me learning Python and I can fucking pack all settings name whatever under a single value and just call them with sub calls or make dynamic strings to call functions and save them as value and do that value with a .name whatever. Booooooooooooooooooooooom.......
Looking back at all this I can only say that maybe lemur do needs a bit of an upgrade in its scripting lang. Lmao. But I still like the nature of lemur where half if it can be done by GUI and rest done by coding. Vs almost full time coding. + when it comes to recalling and storing variables then it is possible with dynamic strings in complex ways like the other programmings langs, without 2000 if rules.
|
|
|
Post by xPsycHoWasPx on Mar 3, 2019 16:40:13 GMT
But stuff like packing a large amount of expressions into a single object type in lemur can easy be done, and handled with subcall ish function. this post is just used a temp place to write this tutorial so I will properly copy paste this and post it as a tutorial for advanced expression management I just figured I use this reply post to write the base for it :First I create a ”Container" then I make a init script that just tells it to hide the container show(getobject(), 0); you can delete the init script after it has hidden the itemSo I don't have to move it around because it blocks the view when selecting other objects in the editor. Then it becomes more like a list container. That can be called with the findobject(), and all ”subexpressions” are called when mixed with get/setexpression(). - Let's say I want to store 64-128 fader positions and each fader also have a curve setting and they also have custom names I created on the fly.
- Then I create a container and call it Faders
- Then I create an expression for each type of data I wanna store/recall, like name, pos, midi_cc_target inside ”Faders”.
- Let's say I want to be able to save and recall 32 different presets of the Faders.
- Then I create a new container and call it ”Preset_0”.
- Then I move Faders inside Preset_0.
- Then I move Preset_0 into a last container called “Memory”
- Now i take Preset_0 and start duplicating it and lemur will auto rename the duplicated item to Preset_1, Preset_2 etc.
- If I later on figure out I want same deal for 64 knobs I of course have to go back to the step where I moved Faders” into Preset_0
- But I just duplicate Faders and rename it to Knobs
- Then delete Preset_1 and up and duplicate Preset_0, again inside the Memory Container.
- The last thing to do is making a script inside Memory container, running the code that will hide Memory so it now acts like list object, and won't be in your way.
Now I just collapse the Memory container and I don't have to look at all those expressions anymore So if I want 1st preset and the 1st fader and knob data fader1.name = Memory.Preset_0.Faders.name[0] fader1.x = Memory.Preset_0.Faders.pos[0] fader1.cc_target = Memory.Preset_0.Faders.midi_cc_target[0] knob1.name = Memory.Preset_0.Knobs.name[0] knob1.x = Memory.Preset_0.Knobs.pos[0] knob1.x = Memory.Preset_0.Knobs.midi_cc_target[0] or with getexpression and dynamic text string in findobject()fader1.name = getexpression( findobject('Memory.Preset_' + 0 + '.Faders'), 'name' )[0]; fader1.x = getexpression( findobject('Memory.Preset_' + 0 + '.Faders'), 'pos' )[0]; fader1.cc_target = getexpression( findobject('Memory.Preset_' + 0 + '.Faders'), 'midi_cc_target' )[0];
if you don't feel like writing the whole text string for findobject then u can just save the dynamic text string as a variable: object = findobject('Memory.Preset_' + 0 + '.Faders'); fader1.name = getexpression( object, 'name' )[0]; fader1.x = getexpression( object, 'pos' )[0]; fader1.cc_target = getexpression( object, 'midi_cc_target' )[0]; so a lemur script(loop based) that calls 64 faders/knobs based on what preset index picked (preset 0): And each fader /knob you are calling to have besides the ’x’ also a name and cc_target expression. decl a, b, c, val; decl preset = 0; decl source = { '.Faders', '.Knobs' }, list_1 = { ' name', 'pos', 'midi_cc_target' }; decl target = { ' fader', 'knob' }, list_2 = { 'name', 'x', 'cc_target' }; for (a = 0; a < sizeof (target); a++) { for (b = 0; a < sizeof (list); b++) { for (c = 0; c < 64; c++) { val = getexpression(findobject ('Memory.Preset_' + preset + source), list_1[b]) [c]; setexpression(findobject (target + c), list_2[b], val); } } } You can easy extract the 2 expression lines to a external callable script (but there is a limit to name length, so I guess shorten the var names) my_script(pre,src,trg,list,idx) executed like this:
my_script(0,'.Faders','fader',{'name','name'},0); my_script(0,'.Faders','fader',{'pos','x'},0); my_script(0,'.Faders','fader',{'midi_cc_target','cc_target'},0); my_script(pre,src,trg,list,idx):decl val; val = getexpression(findobject ('Memory.Preset_' + pre + src), list[0]) [idx]; setexpression(findobject (trg + idx), list[1], val); Run it as a loop, to load 64 faders/knobs:
decl a, b, c; decl preset = 0; decl src = { '.Faders', '.Knobs' }, list_1 = { 'name', 'pos', 'midi_cc_target' }; decl trg = { 'fader', 'knob' }, list_2 = { 'name', 'x', 'cc_target' }; for (a = 0; a < sizeof (trg); a++) { for (b = 0; a < sizeof (list_1); b++) { for (c = 0; c < 64; c++) { my_script(preset, src, trg, {list_1[b],list_2[b]}, c); } } } how to do all this could be done with calling scripts is still beyond me, other than an ass load of IF rules and mini scripts. but at least u kill the need for loads of if rules with the method I explained.. but I hope you also find this useful
|
|
kirkwoodwest
Junior Member
Building Lemur Templates for Live and Studio
Posts: 47
|
Post by kirkwoodwest on Mar 4, 2019 5:51:29 GMT
Yup very useful. tbh seeing any script other than my own is super useful. I like that you dumped a lot of code and expressions in a container object to tidyness!
|
|