Next/Previous Sample in Editor

I’m using A.I. to help me build little tools to hopefully speed up my learning process. So take it easy on me fellas haha.

So here is my attempt at two simple keybinds that when used in the sample editor will check for then cache the directory of the loaded sample and load the previous or next audio file in the directory. So you can scroll through samples without having to go to the disk browser.

com.elcasiino.nextprevsamplecached.xrnx (1.8 KB)

Code is probably off a bit or not functional. I can’t test it right now but I can post the code to it if anyone wanted to have a look. What went wrong here? If anythjng

Hello,

Yes, it is broken. The first thing is that it is poorly packaged from the start.The second is that AI invents non-existent API functions. I would not learn from AI. It is good at explaining things, but I would be very careful about things like “do something for me”. I found it to be a good way to comment on code. Next time I’ll let her work on the manual, I’m too lazy for that.AI is supposed to help us, not replace us.

1 Like

What’s a good starting point? Are those functions even there? Like caching a directory?

On the API docs page, you can download the entire documentation as a PDF. When you give that to the AI, it’ll be less likely to make up random functions. But as far as I know, your idea isn’t doable through the API anyway. I once thought about building a shortcut tool to randomly select a sample from the last directory, but from what I’ve seen, there’s no way to actually access the last path, yet.

I was told that before as well about the api amd accessing the directory, I thought maybe the upfste addrressed this. Either way, I have to continue exploring lua if I’m going to use Renoise, at this point, programming is like 50% of the Renoise haha. Thanks for the responses fellas

here is a good starting point how to read LuaAPI for Renoise. The caching function is fine, but you don’t have the sample directory defined anywhere. You have to write it there hard-coded (I don’t recommend it) or use the gui selection.
Also, the directory scanning only happens at the top level. That is, it doesn’t go recursively into every directory in the specified path.
.xrnx is just a .zip file. Put only the files you need in it, don’t put it in another directory.

com.me.anothertool.xrnx
    main.lua
    manifest.xml

Yeah the problem with GenAI is that it will pretty much never cop to being unable to do something, it’ll just make up a bogus solution if the task is impossible.

Renoise doesn’t store the original filename of a sample. You’d have to write your own custom loader like @esaruoho did in Paketti (I think he’s got a similar feature to this but it’s part of a much bigger thing.)

I’m starting to notice that

@martblek Could you elaborate on what defining a directory is? Could a gui-less sample loader be used to be used to compensatefor that?

I’ll take a look at Paketti and see if this is implemented somewhere

In the cache function that scans the directory, you have as input a variable that defines the path to the samples. In a script that doesn’t have a gui, you have to define the path somewhere. Either do it hard-coded in the code or have a file with settings from which the tool reads it.

The thing with AI and LLMs is that they always need solid context to work well. That’s why, with OpenAI and I think also Claude, you can set up “projects” or a customGPT. In a project, you could, for example, upload the Renoise API documentation and add a “pre-prompt.” In that pre-prompt, you can tell the AI to act as a LUA expert who knows the Renoise API inside out, and if it can’t find specific info, it should look it up online. You can even have the AI help you create these pre-prompts. The key is to clearly define what you want the AI to deliver and how it should behave to get good results.

So like a text file packaged with the tool that needs to be edited before the script is initialized?

saved to preferences.xml

that’s how i do it in Paketti Preferences. it saves the settings to preferences.xml, and the stetings are read.

Okay I see. And Paketti can read and write to the preferences.xml. Does this actually solve the caching isssue? Sounds like it. So what else could theoretically prevent the script from functioning? Aside from the terrible ai code lol

A good starting point is NOT blindly relying on A.I to begin with

Maybe a better way to pick this stuff up would be to take a few simple tools and feed them in to your LLM and ask it to take you through step by step, make your own mods to functions and see what happens in the testpad.lua or a learning xrnx.

e.g. a simple tool I made with a couple of functions linked to key shortcuts. Note: the keybindings wont work from the testpad but you can paste the functions and call them directly, or strip the code out (you would need to keep the status helper function in tact though as it is called by the other two)

Anyway, GPT5 or any of the big models should have no probs walking you through. The advantage being it wont hallucinate on API stuff.

If this is useful I can post some more of my simple tools code here for LLM fodder, just let me know.

EDIT: from this tool: Clear Loops And Play

EDIT 2: I just commented out the status helper and replaced with API calls, should make it simpler to start with


TOOL_NAME = "Clear Loops And Play"


--Renoise Keybinds and menus
-------------------------------

renoise.tool():add_keybinding {
  name = "Global:Tools:".."`CLP` Clear All Loops",
  invoke = function() clear_all_loops()end  
}

renoise.tool():add_keybinding {
  name = "Global:Tools:".."`CLP` Clear All Loops And Play From Start",
  invoke = function() clear_all_loops_and_play_from_start_of_song() end  
}

--------------------------------------------------------------------------------
--helper function : custom status message --prefixes tool name and adds brackets 
--------------------------------------------------------------------------------
--function status(message)
--  renoise.app():show_status(TOOL_NAME.." Tool: ("..message..")")
--end


--------------------------
function clear_all_loops()
--------------------------
  --song
  local song = renoise.song()
  --get renoise.SongPos(sequence,line) objects that are set to 1,1
  local pos = renoise.SongPos(1,1)
  --use SongPos objects to clear looping range in transport sequencer
  song.transport.loop_range = {pos,pos}
  --disable loop block
  song.transport.loop_block_enabled = false
  
  renoise.app():show_status("All Loops Cleared!")
  
  --song.transport.playing = true 
 
end
-----------------------------

-------------------------------------------------
function clear_all_loops_and_play_from_start_of_song()
-------------------------------------------------
  --song
  local song = renoise.song()
  --get renoise.SongPos(sequence,line) objects that are set to 1,1
  local pos = renoise.SongPos(1,1)
  --use SongPos objects to clear looping range in transport sequencer
  song.transport.loop_range = {pos,pos}
  --disable loop block
  song.transport.loop_block_enabled = false
  
  --song.transport:start_at(1)
  song.transport:start_at(pos)
  
  renoise.app():show_status("All Loops Cleared!, Song Playing From Start")
  
  --song.transport.playing = true 
 
end
-----------------------------

I actually have that tool hahaha, at least I can see proper code and go from there. One thing that I noticed is how to properly enter a keybind option in the menus.

I’m slowly going through and trying to dissect which part of the code does what. I’ll start by studying the code to other scripts first and getting familiar with the API. ATP scripting is like half the functionality of Renoise so its time to learn even if it is just the basics

This might be useful for you aswell, not updated to all new API stuff but still relevant and Chatbot pasting friendly. It’s a version of the API with comments taken out for overview and quick scanning:

Also from same thread is a template I use for starting new tools, I’ve updated it a bit since but it should still work to give a simple sample gui, how you can set up prefs etc.

2 Likes

Thanks for this man. My coding journey begins haha. This is like the “Hello World” of Lua scripts for Renoise

Well good luck with it! and remember when you start to get too frustrated, go and stick the kettle on and come back to any problems freshly caffeinated :hot_beverage:, better than throwing blunt objects at the screen which is always tempting! …I was making some rookie errors with tables yesterday which may be coming through!

1 Like