[New Tool] Kazakore Useful Live Functions

V0.2 update:
Added Queue/Move EditPos to “Live” Patterns.
Tidied up Keybinding names. Now there are three categories for them., all in Global. Kazakore’s Tempo Functions, Kazakore’s Send Track Automation Clear and Kazakore’s Section Navigation. Hopefully that makes it look a little tidier and avoids the chosen keybinds going over the function name text.
Added Error Messages in Status Bar for when functions exit without performing any action, to give an idea as to why.
Added Double/Half Tempo (BPM).


Not sure how worth this is posting but here’s a handful of functions that I immediately felt I could do with when setting a controller up for live use. I know there are a lot of larger tools that probably incorporate most of this but I get a little lost exploring the wealth of things out there sometimes and they seemed good functions to remind myself the little knowledge of LUA I had lost.

Keybindings are all listed under Global:Kazakore’s Live Functions:… and I know need some work on the naming due to space limitations in the Prefs menu. Unfortunately I believe the Keys menu is limited three levels but I will try and give it some thought.

I’ve split them into three categories in MIDI Mappings under Global:Kazakore’s Live Functions:…

Clear Send Track Automation
For Send Tracks 1-8. Will Clear all automation in either the Current Pattern, or the “LIVE Patterns” by which I mean the last two patterns of the sequence as might be used for live playing with Tools such as Grid Pie.

Sequence
Jump EditPos with change the pattern being edited, while Queue will queue to play next the Pattern at the start of the Section, for 1-8. 1 being the first Section you have created, automatically creating up to the eighth Section in the Sequence. Naming does not matter.

Tempo
Decrement Tempo Reduce Tempo by 0.1 BPM
Increment Tempo Increase Tempo by 0.1 BPM
Nudge Song Backwards Briefly reduce Tempo (by 5%)
Nudge Song Forwards Briefly increase Tempo (5%)
Tap Tempo Self explanatory…

Unfortunately the function appear to work help with the keyboard but not with the MIDI Mapping. This applies mainly to the Tempo control functions, where you might want to repeat it with a held button.

Any small suggestions appreciated. Sure code could be tidier too! Especially how I’ve done the Song Nudge as I got lost trying to get the Idle Notifier to work…

To Add:

Going to add Loop Section 1-8 and Loop “LIVE” Patterns shortly and do a 0.3 update.

3747 uk.deaddogdisko.KazakoresLiveFunctions-V0.2.xrnx

First of all, great work. I cannot really help you with the held-key keep-nudging thing. Maybe a little bit but I don’t know how to really get it working. The thing is, you can use the idle notifier, but then you do not have a key (bind). You can make a keybind but then you don’t get to see when the key is released (which is called a “Key Up” event in most environments)… The first thing you need to fix is to make the bpm backup-variable (where you save the original bpm) global, that is, a local of the script like you have tt etc. This is because you want both the nudge and keyup_test functions to use the same bpm variable!
The same goes for the kp variable. It’s even worse, if a function gets called two times, the local variables inside that function are reset every new call… So to get around this you sometimes have to create lots of globals (see ugly coding style in Basement tool :P)
Now if you do all this I think you might get ‘held-key’ working by, after the ‘if key.repeated’ putting an else, which extends the time by doing kp=os.clock() again. Also you need to think about what the tool is gonna do ‘in time’, that is, in the key_up_test function you immediately release it from the idle notifier (whether it’s seen it’s .1 milliseconds of fame or not) - I’m guessing you were just trying stuff and left it at this state :D.

My only concern would be with the naming in the key- and midi-binds. While MIDI binds I believe are not bound to some limit in hierarchy levels, the last function you bind to something like “Kazakore’s Live Functions:Sequence:Jump EditPos to Section x” while others all start with “Global:”. I haven’t installed this tool yet so it might just have the exact same effect, but who knows, could be annoying if you leave it like that, somewhere in the future where Renoise gets smart and updates the MIDI bind window or so. My other tip is yes, keybinds with long names are friggin annoying in the small window, so just do some smart abbreviation call it KLF. Which of course solves nothing because it’s about the final parts of the names. ehmm. Clear S#07 Auto (LivePat) and Clear S#07 Auto (CurrPat) ???

This might be a step in the right direction:

  
local bpm,kp  
function key_up_test()  
 if (kp > os.clock() - 0.1) then  
 rns().transport.bpm = bpm  
 if renoise.tool().app_idle_observable:has_notifier(key_up_test) then  
 renoise.tool().app_idle_observable:remove_notifier(key_up_test)  
 end  
 end  
end  
  
function nudgefwdkey(key)  
 nudge(1,key)  
end  
  
function nudgebckkey(key)  
 nudge(-1,key)  
end  
  
function nudge(dir, key)  
 local bpm = rns().transport.bpm  
  
 -- Refresh the time for the inital keystroke as well as all repeats.  
 kp = os.clock()  
  
 -- Key is initially pressed  
 if not key.repeated then  
 if bpm > 949 then return end  
 rns().transport.bpm = bpm + rns().transport.bpm * nudge * dir  
 if not (renoise.tool().app_idle_observable:has_notifier(key_up_test)) then  
 renoise.tool().app_idle_observable:add_notifier(key_up_test)  
 end  
 end   
end  
  
tool:add_keybinding {  
 name = "Global:Kazakore's Live Functions:Nudge Song Forward",  
 invoke = nudgefwdkey  
}  
tool:add_keybinding {  
 name = "Global:Kazakore's Live Functions:Nudge Song Backward",  
 invoke = nudgebckkey  
}  
  

Thanks Cas, I’ll try and break that down and understand when I’ve woken up properly. In fact I might try and have a couple of hours more sleep first to be honest… Couldn’t sleep this morning so just doing a quick forum and FB check ;)

But you were correct in that I left it in a broken state from (almost) randomly trying slight changes from the initial bit of code I was given and know it was left in nowhere near the correct state.

All the MIDI Mappings do start the same, with Kazakore’s blah blah… But sometimes I have the MIDI Mappings first, sometimes the Keybindings first, so maybe that confused you on a skim read.

Going to add Loop Section 1-8, plus Jump To/Queue “LIVE” Pattern and Loop “LIVE” Patterns shortly and do a 0.2 update along with some Keybinding name tidying.

Been trying to avoid having to use Global variables. In part because I wanted each section to be like a chunk which could just be lifted and used in isolation by people who might only want some of the functions I have written. I did consider having a global BPM variable and then having a Notifier on it, so that changes from within the GUI would also be registered, and thus not having to read it each time the related Functions are called… Maybe I should have attempted to go that way but with such small functions the overhead should be so small and I try and not have loads of notifiers listening for changes. Although I admit I don’t really know why…

(EDIT: Typo)

That’s a nice bunch of functionality. Especially tempo-nudge seems wicked cool

I will be sure to give it a spin :slight_smile:

Well indeed, some cool stuff in there, nudge seems cool functionality. And you were right about my confusing kb and midi binds with e/o. It’s just that you have to declare the variable in the right scope, you don’t have to declare their existence at the top of your file per se… (like I was also a bit confused since my style is always putting kb binds, midi binds, and menu entries at the bottom of the main.lua but you don’t really need to do that :D)

Each section has it’s keybindings and midi at the bottom of it’s section, so if somebody wanted just that functionality it’s a single copy and paste ;)

I think I’m gonna be lazy and leave the Nudge using the method it is (at least for now.) At only 100mS I don’t think it should impact too much else and if you’re holding down the nudge forwards/back button you’re unlikely to be at the same time trying to do any of the others…

On a related note I’ve been told it’s good practice to always check that the track you are about to work on is the type of track you expect. When doing this I have used a Return to get out of the Function. Problem is there in then no way to know what is going wrong and why.

How do a use a callback (is that the right term?) variable so I can produce a pop-up with an error message on anything but a Return(0) {or however it is done}?

Sorry can’t help you here because this is not in the code you posted in firstpost??

From the code that is in the first post (I’ve actually not yet put in the Type check but this illustrates the same point.)

[/i][/i]

This is a safely check and stops the script attempting to do something which is illegal. The thing is I do not know that somehow you attempted to do something that is not possible.

So if Return carried with it the Error Code, so return(0) would be a normal return, whereas return(x>0) would return a code which I could then reference against a table entry for display in a dialogue why the function doesn’t work as expected.

Would wrapping all the functions within an error checking function do it? Is there a neater way?

You can do

  
return 0  
  

or ```
return 1

  
  
[quote="kazakore, post:10, topic:37267"]  
Would wrapping all the functions within an error checking function do it? Is there a neater way?  
[/quote]  
I wouldn't advise doing too much for exception throwing/catching. You'll primarily code stuff for yourself, and as you probably know very well in which situation to press which shortcut, more than a status bar line saying "Wrong" is rarely needed. If you want to really spew up a whole modal dialog, messing up your music making workflow, well there of course are calls for that, for instance  

renoise.app():show_error(message)

  
So really a neater way would be, build a small function (let's say you call it display_error or throw_error) that just takes a string 'message' and in there you can decide (and change in 1 edit everytime!) whether it'll show stuff on statusbar or in terminal or in a dialog or all 3 at once, ;D

Really need to start remebering to click on Watch Topic of threads I know I want to work from or take ideas (especially my own threads like this one.)

Going to try and add Clear ALL Sent Track Automations and tidy up how it is displayed in the Keybindings dialogue over the weekend :)

V0.2 added to first post.

Added Queue/Move EditPos to “Live” Patterns.
Tidied up Keybinding names. Now there are three categories for them., all in Global. Kazakore’s Tempo Functions, Kazakore’s Send Track Automation Clear and Kazakore’s Section Navigation. Hopefully that makes it look a little tidier and avoids the chosen keybinds going over the function name text.
Added some Status Bar messages for when functions exit without performing any action, to give an idea as to why.