Norns: scripting

norns

#283

not currently possible, but we did have this feature on the aleph. i’ll get it on the list


#284

Notification/Callback on storing a Parameter Set?

In a Lua script, is there a way to be “notified” when the user manually stores a parameter set via norns’s parameter page (via holding down key1, turning enc2/3 and pressing knob3)? Or in other words: How can I create a function that is automatically executed when saving via norns’s parameter page, but that is executed prior to the actual save being executed (i.e. prior to the new parameter set being written to the SSD)?

Related: When loading a parameter set via norns’s parameter page (via holding down key1, turning enc2/3 and pressing knob3), I assume that automatically a params:bang() is executed, correct? Is there a way via Lua script to create an additional function that is being automatically executed when loading a parameter set via norns’s parameter page?

Thanks in advance!


#285

there’s no mechanism to execute a script-defined callback when the ParamSet:write() method is called, but i suppose you could add one.

s there a way via Lua script to create an additional function that is being automatically executed when loading a parameter set via norns’s parameter page?

the relevant method there is ParamSet:read(). it calls :set()for the parameter referenced in each line of the pset file; which, yes, then calls bang() to execute the action associated with the parameter by the script.

so, if i understand correctly, you’re asking if the parameter action can be defined differently for when it’s set from loading a pset file versus set by some other means. to which the answer is, ParamSet doesn’t support that currently (it doesn’t seem like an obvious thing to want to do.)

depending on what you’re actually trying to do, you could add some parameter(s) that are only meant to be interacted with from a pset file, and set the appropriate actions for them.


#286

Thanks. Please pardon a noob’s curious question: Does this mean that saving (or loading) via norns’s parameter page also calls ParamSet:write() (or ParamSet:read() respectively), i.e. the same commands that a user uses in a Lua script?

My apologies for the long explanation following, but here’s why I ask: I’d like to store the current state of a connected monome grid (when used as a 16 step sequencer) as a parameter, so that I can store and recall grid states together with all the other parameters appearing on norns’s parameter page.

As far as I know, such a parameter has to be number, not an array, but luckily, when used as a simple step sequencer, each of the grid’s 16 columns can have one of its 8 buttons lit (1 to 8) or no button lit at all (0), which means I can express the grid’s state as an integer number with 16 digits. As far as I understand, such a large number is still within the boundaries of norns’s number space, so I could use this number to store and recall the grid’s state via norns’s parameter system (although I know that it does not make sense to edit this “grid state” parameter on norns’s parameter page).

But this means that when I store a parameter set on norns’s parameter page, I have to convert the current grid state to a 16 digit integer number after the save has been initiated, but before the actual number is being written to memory.

And on loading a parameter set the 16 digit integer number needs to be converted back to the grid state. This one can be accomplished by an according action triggered by bang().

But for saving it means that I have to constantly update the 16 digit integer number whenever the grid state is changed. I guess this is possible, but it seems unnecessary.

Of course, the whole concept falls apart the moment more than one LED can be lit per column, and/or when using variable LED brightness. So my thinking is a workaround until the complete grid state (128 LED each with 15 brightness levels and one off state) can be stored & recalled as one variable via norns’s parameter system.

Thanks for reading so far.


#287

I’d suggest that this use case might be easier outside of the current params system. In tabutils there is a handy method for saving any simple table that I’ve used for this kind of thing. :+1:


#288

perhaps this would be useful as a reference point:

I’m storing drum patterns (sequences) as arrays in a text file and then loading the patterns dynamically. Then there’s a parameter id that’s mapped to pattern select.

so - maybe you could store your sequencer patterns in a text file instead of params?


#289

Thanks for these hints, but I had hoped to save both sound & notes together, initiated with one command invoked at the place norns already offers for saving user data: the parameters page.


#290

To the user it could appear like that (a saved param to choose a pattern as @okyeron mentions) but the actual pattern data would be elsewhere for ease/flexibility.


#291

I have to admit I do not understand @okyeron’s script completely – but from all that I understand (which is pretty limited), @okyeron’s script uses a set of preset pattern data stored in the text file okyeron/drumpattrns.txt, and which of preset pattern desribed in this text file shall be loaded is determined by a parameter called pattern select. And this parameter’s value (amongst all other parameters) is stored when the user initiates a “store parameter set” (go to norns’s PARAMETERS page, hold down KEY1, scroll parameters set with ENC3, hit KEY3), and also on cleanup().

But there’s seems to be (at least not to my beginner’s eyes) no place in the script where user-edited pattern data is written into okyeron/drumpattrns.txt (or into any other place), let alone that this would happen when the user initiates a “store parameter set” from norns’s PARAMETERS page. All potential pattern save functions are either commented out or not called, as far as I understand.

Please, can somebody be so kind and explain to me what I am missing here?


#292

Yes - I’m not saving the pattern here yet. The pattern is defined as a preset and I edited the text files manually.

But… I think you could do something to save a file the same as loading one with params:set_action? Something like…

 params:set_action("pattern save", function(n) patternsave(n) end)
 local function patternsave(pid)
 -- save your pattern code
 end

Not sure if that actually solves your particular query tho.


#293

@wolfgangschaltung I think you’re overthinking the process. Find whatever data you have available to store your grid-state, then loading parameters and grid data is as simple as writing a function to do both at once.


#294

I was just referencing @okyeron’s mention of using a param to select. My suggestion is to use the tabutils function to save your data. I don’t know a simple way to tie it to saving params but you could fire it, for example, during script cleanup, when the user switches pattern, or maybe even every time a pattern is edited.


#295

I guess you are right. My problems disappears the moment I let go of the wish to store all data (sound & sequence) via initiating the store action from norns’s PARAMETERS page (hold down KEY1, scroll parameters set with ENC3, hit KEY3).

When I say initiating the store action from within the Lua script is fine, I am free to come up with any store action I want.

Hope this makes sense. Thanks to all for being so patient with me!


#296

Confusion reg. parameters vs variables

I have to admit I feel I still have not completely understood the difference between parameters and variables. I’ll try to explain my confusion.

Imagine I’ve added a parameter “pattern_length”:
params:add{type="number",id="pattern_length",name="pattern length", min=1,max=16,default=8}

Does this mean I’ve also created a variable pattern_length that I can use in an array like
array = {pattern_length, other_value_2, other_value_3}
or do I have to write
array = {params.get("pattern_length"), other_value_2, other_value_3}

And can I manipulate pattern_length like this:
pattern_length = 9
or do I have to use
params:set("pattern_length", 9)
?

Sorry if this is stupid, thanks in advance for any help.


#297

Strange alert on Floor Division in norns’s Lua

I’m on norns 181008, when I use the Lua arithmetic expression for floor division, maiden shows an alert, but norns does the correct calcuation and returns the correct results:
lua%20division%201

When I remove the second / as requested by the alert, I get the standard division (which is not what I need):
lua%20division%202

I guess it is time for me to learn how to file a bug in git, no?


#298

I noticed this in one of my scripts as well, the code actually works error-free, but the alert doesn’t go away.


#299

this is an unfortunate limitation of the lua support baked into the editor framework we’re using in maiden, which doesn’t support lua 5.3 ops. (@tehn noticed this a while ago; tracked in: https://github.com/monome/maiden/issues/9.) . it’s an easy fix but should really happen upstream (or we should get off the web-worker parser and get on to something more robust – e.g., https://github.com/monome/maiden/issues/135).


#300

Are there a best practices for using key 1 within scripts? I’ve been using long presses with it and as a modifier w/ encoders, but don’t want to accidentally override/mask system behavior for accessing the menu with the normal short press.


#301

you actual can’t override the system behavior. it’s built-in to the scripting system, so you’re always safe to get back to the menu despite what your script does. what you’re doing is correct— KEY1 is really only good as a modifier or long-hold. keep in mind you can also track the release which can be useful.


#302

following up on my earlier (in retrospect massively misguided) attempt to ‘fix’ maiden on ios to reclaim table space.

i have discovered the ‘obvious’ solution of coding with vim via ssh and bypassing the ios issues entirely. the vim learning curve for a novice is a bit ‘ehhhh’ but the space saving results are undeniable:

i am still trying to wrap my head around the workflow for this kind of coding and would appriciate any thoughts/links about how to approach doing norns scripts via ssh.

i can google vim shortcuts etc, but version control, testing/debugging, and general order of operations are a bit of a mystery since up until now i have just been mashing save/run in maiden and staring at the REPL for errors.

someday i will use norns to make a song. maybe a 2019 new years resolution.