monome / norns

norns is many sound instruments.
http://monome.org
GNU General Public License v3.0
633 stars 147 forks source link

add PSET number to PSET actions + add delete action #1544

Closed dndrks closed 2 years ago

dndrks commented 2 years ago

while writing up examples for saving table data with PSETs (building off of @schollz 's incredible work on this front), i realized that PSET index number is a helpful reporting callback -- since PSETs made via the PSET UI can share names, the index number is often the only differentiator. rather than force authors to extract this from the loaded filename, it made sense to add the PSET's index number (if available) to the actions.

i also realized that a PSET deletion action would be helpful for external data management, so i added that as well.

here's a quick example of usage:

MusicUtil = require 'musicutil' -- see https://monome.org/docs/norns/reference/lib/musicutil
s = require 'sequins' -- see https://monome.org/docs/norns/reference/lib/sequins

function init()
  base_note = math.random(30,50)
  my_seq = s{}
  notes_array = MusicUtil.generate_scale_of_length(base_note, "dorian", 16)
  note_data = {}
  for j = 1,64 do
    -- auto-generate 64 steps of notes:
    note_data[j] = MusicUtil.snap_note_to_array(math.random(base_note, base_note+28),notes_array)
  end
  my_seq:settable(note_data) -- send this table of notes to the sequins
  play = false

  -- here, we set our PSET callbacks:
  params.action_write = function(filename,name,number)
    print("finished writing '"..filename.."' as '"..name.."'", number)
    os.execute("mkdir -p "..norns.state.data.."/"..number.."/")
    tab.save(note_data,norns.state.data.."/"..number.."/note.data")
  end
  params.action_read = function(filename,silent,number)
    print("finished reading '"..filename.."'", number)
    note_data = tab.load(norns.state.data.."/"..number.."/note.data")
    my_seq:settable(note_data) -- send this restored table to the sequins
  end
  params.action_delete = function(filename,name,number)
    print("finished deleting '"..filename, number)
    norns.system_cmd("rm -r "..norns.state.data.."/"..number.."/")
  end
end

in the example:

this is testing well on my side, but please lmk if there's anything i'm missing!

dndrks commented 2 years ago

rad, thank you @tehn! super helpful review, which led to a good cleanup and additional testing. changes are now all documented, all testing well -- plz lemme know if there's any loose ends from your perspective!

tehn commented 2 years ago

aha, the html files are actually autogenerated from the lua via luadoc, so no worries about those. i should've been clearer: i meant https://monome.org/docs/norns/reference/params in case required.

great looking edit, thank you!