Executing A Script / Function With Timing ?

Hi there. First post here and quite new to Renoise. I bought it because of the Lua API and I haven’t been let down yet, really cool, loving it day by day.
I’m into live coding and algorithmic composing, and I would like to make a function to be called for example when a pattern starts, or on every 8th beat or something like that.
Is it possible to do this? A kind of callback function or something like that?
I would really love to have a track that changes itself every time it begins. I haven’t found any examples and searched the forums for callbacks and timing and haven’t found anything.
Thanks in advance! :rolleyes:

Timing by lines is not really renoise’s forte. Timing an event to a pattern change, however, might be possible to do accurately. I can’t be sure, because I haven’t really done scripts that would be run while renoise is playing, though.

I think what you need to study for this specific purpose is the observables and notifiers -concept. This is something that threw me off at the start. On the most basic level (and I’m on that level, mind you) it works so that you’ll listen to an ‘observable’ that gives a signal when the parent value gets updated by renoise, and you give a (notifier)function to fire on that signal. On your case I’d say renoise.song().selected_pattern_observable, or maybe renoise.song().selected_sequence_index_observable might be good choices to start fiddling with. The ‘parent values’ would be renoise.song().selected_pattern and renoise.song().selected_sequence_index respectively.

And: Welcome to the forums!

Oh, that’s a good start! I was reading the api documentation and saw that observable/notifiers for the tempo change and so on. I will take a look at your suggestion and see if I can achieve what I’m looking for, at least looks like a way to do it, better than trying to hit cmd+R at the first beat ;)

I also saw the timer, but that would make my idea quite unflexible. I think these notifications are the way to go. I’m used to ‘callback’ function from programming games in lua and so, so that was what I was looking for. Would be kind of nice to have a pre-beat / post-beat function execution hook to just put a func on beat, and pre or post generate the stuff that happened or what is comming :)

Thanks! :)

I think the Formula Device may be your friend more than Scripting Tools for the moment…

Welcome indeed, can’t help you on the scripting side, but looking forward to your algorithmic composition tools :drummer:

So, that Formula Device looks quite nice, pitty I can’t get it working, I have 2.8 beta, would like to try it, but don’t know how to unlock it.
I’ve been playing around with some basic stuff and made this little screencast, so basically I will write a little library for me to set the data in the pattern editor (and maybe sample buffer data too), but I would love to put some functions timed so the track regenerate itself while I code other tracks. That was my idea.

Really happy to be part of this and I’ve been enjoying every € I spent on this nice software and maybe contributing tools in the future :)

Nice start, can imagine this become a powerful way to generate patterns of note content.

for the formula device, post this into a track (right mouse clock menu paste):

Ok that is awesome! But I can’t figure out how it produces notes. It works actually like the signal follower just with 3 variable inputs and self made mathematical expression (which is nice) but seems to act only for the DSP effects of the track, or am I missing something? It is still dependent on the pattern editor content. But still this is a VERY NICE approach to live coding! Just want to use it also in the note domain, and not only for controlling parameters.

Thanks for all your answers, I’ll keep messing around with the observables :)

You’re right, Formula Device is only control data, not note data. So similar to an LFO or Signal Follower but you can give it its own rules based on a lot more parameters, such as song position and combination of inputs.

Tools so far have no real-time component. You could write scripts which generate your notes and enter them (there re already some for chord progressions and the likes) but not to do things live on the fly. Well not 100% perfectly anyway. You’ve not said what you want your Function to do every pattern start of 8th note or whatever… These are things the Formula Device does give you access to but only with control/meta data as output. For programming notes not sure how you’d approach it…

Well, I’m quite happy with the performance at the moment of live scripting. I know it wasn’t intended for this, but if we have an interpreter, why not…? ;)
I would like just to define a function which puts some notes on the grid with certain probabilities, or patterns, so when the player plays the last line (e.g. 64) it regenerates the notes on that column with the same rules/probabilty, therefore conserving some properties but with some changes from repetition to repetition. Another thing I would like to do is to define scales and progressions (as you already mentioned, there are some) and also with some probability (even markov chain analyzed data) generate melodies and rhythms. I have already a small library for ‘trying’ to make chiptune, which defines some scales and rules for the rhythm and the melody and gives me out a midi file. I would like to do this live with renoise, I hate making midi files and importing them again and again…

So yeah, that’s basically my approach. While one or two tracks change themselves on every repetition, I can improvise with the keyboard or write notes on other tracks manually and stuff like that.

I can imagine a device like the formula device that also takes for example: current_note_value, and you can change it or leave it as it is before executing. Maybe should I post this suggestion on the suggestions forum? don’t know if people work like this anyway, but I find it nice to generate content from a script and then change it manually or keep it generating on every repetition or every n ammount of beats/lines/whatever. :)

I also can imagine sending an osc message to another computer on every beat or so, for example for visuals (w/o using midi clock). There is LuaAV which I also like a lot and someone brought me to the idea to writ a script for renoise + LuaAV. Will try this this evening. In that case would be nice an OSC clock, or as I asked, a function on every line change/beat so the video host has also some timing information :)

So, sorry the triple post…

@KMaki: I was trying the observable/notifiers and there are pretty much observables for everything except that what I’m looking for. What you suggested works (fires a function) but when I manually edit something in the pattern.
I think what I looking for is in the transport:

renoise.song().transport.playback_pos  

But it doesn’t has an observable. With this:

renoise.song().transport.playback_pos.line  

I get exactly where the playhead is at the moment, it would be pretty easy to make an observable that check this:

if line == 1 then ... end   

How can I make a feature request for this? I mean, there are observables for everything else, so… why not one for the transport position? ;)

This Tool reverses playback direction. I believe to do so it looks at when playback line increases and then deducts 2 from it, to move back a line rather than forwards. Maybe you can find what you need from within its code. (Not actually delved into it myself, only going on description.)

Oh, that’s a nice example! It uses:

renoise.tool().app_idle_observable  

which isn’t synched to the beat but calls itself in the background depending on the load. From the documentation.

So, yes, this would be a workaround, will try this when I get home. I still think a playback_pos_observable would be good (not only for me) but as I said, for example to send beat synced osc or midi to a device or computer.

I think this has been at least discussed (if not directly requested) before. Try a forum search on ‘playback observable’ or something like that. I recall the reason it is not there is that in practice it puts too much strain on yer CPU… Oh, yeah, and that the observable it would always ‘lag’ a certain amount anyway. Would be awesome to have it, though!

And BTW impressing stuff, you post! :)

EDIT

Hey yes, I think it should come with a warning, like the app_idle_observable. It warns it’s inaccurate and one shouldn’t use heavy functions to spare cpu. So I would practically wouldn’t evaluate on the beat bot one or two lines before. At least less hacky than having a function in the background checking if the play position has changed and then executing a function. I will try the thing later on with the visuals host (also Lua) then people could use this for that kind of thing and not only for my purpose (live coding).

And thanks, I’m glad you liked it, It’s quite basic now, still want to make a library so I need less code and really improvise with this.

*** EDIT: oh yes, I was looking on the forums but only found your post. maybe I should put this on the suggestions forum/thread? I don’t know what is the standard procedure in the community… ;)

Look at the Baguetter.

http://www.mynameiskaneel.com/blog/2011/09/23/the-baguetter-a-renoise-2-7-tool/

It triggers an action every X lines. It uses app_idle_observable.

It’s not perfect timing, but it’s not bad either.

Hey, thanks! I like his approach more, it’s a little bit cleaner. Will be using this approach for the moment.
Quote from his source code comments:

So, I understand we don’t want to load too much the cpu, but as people are complaining about this, would be nice to have a solution for this timing problems.
I know a lot of renoisers don’t use the scripts at all or their tools are OK to work NRT, so I understand if this is not a priority. But it would be actually really cool to have this.
I will post my approach tonight when I have it working, and also to show how nice it could be to send osc on beats for an audiovisual performance :)

Well, it’s been discussed before in other threads, but the first step to solving this problem is for LuaJit 2.0 to come out of beta. The LuaJit repo still gets a lot of action and the devs aren’t willing to implement LuaJit until a final release is stamped with a seal of approval. This “precise” timing issue is exactly why Renoise is written in C++, and not Lua. ;) LuaJit will improve things, and open the door for faster processing, maybe even DSP stuff.

Some clever hack suggestions:

Use: renoise.song().transport.edit_mode_observable (or any other toggle button, like chord mode) to trigger actions, DJ style.

Use: renoise.song().sequencer:sequence_is_start_of_section_observable(sequence_index). Here, you could create sections headers (new feature in Renoise 2.8) and when a certain header is reached durring playback, a script is executed.

And so on. Good luck!

Oh, yes, I’ve been waiting for LuaJit 2.0 too for other projects. Still not compatible with the fresh Lua 5.2, but I guess I can wait for this :)

Very nice! thanks for your suggestions! the sequence_is_start_of_section_observable seems good for my purpose and doesn’t have to be evaluated every line. :) Thanks!