How do I do the stuff you can do in Sonic Pi? (gimmie homework please)


(g8tr1522) #21

Wasn’t sure if I should post this in the xStream thread or not. Sorry if it needs to be.

I’m confused about the random seed in xStream. I.e., I can’t reproduce the same sequence of random numbers. Pls help me Danoise.

_ PS: Now, thinking about it I see a reason to introduce a couple more xStream events - because, you would also want to reset the seed when output is first started. _So, if you can wait until the next release I will introduce a set of features to make pseudo/seeded random numbers fully usable :slight_smile:

I’m assuming your PS will address these questions, but maybe I just did something wrong with that event handler? Anyways,

I create a new model, and simply give it one line:xline.note_columns[1].note_value = math.random(36,48) .I keep applying to the selected track, but I’ll get a new random sequence every time**.

If I give the model a second line,math.randomseed(0),and I apply to the track, every note is the same note***. I’m guessing this is because of the behavior of xLine*?

So I get rid of that second line. But now I was clever and thought about setting the random seed in the scripting console; maybe that can set Renoise’s global random seed? So I enter the commandmath.randomseed(0)directly into the terminal. A satisfyingly greenmath.randomseed(0)appears in the console. After I played around with that, I realized that I_could_ reproduce the same random sequence. But I have to entermath.randomseed(0)into the terminal every single time before I apply the model to the track. If I don’t, I get a new sequence every time I apply**. (I explain further below at the footnote**)

Is that event handler supposed to take care of that? I did exactly as you said, but I still get a new sequence every time I apply**.

I’m so confused :frowning:


*I wish I could confidently say I got that behavior because xLine re-applies the model at every line in the track; if I reset the seed at every line, of course I’ll get the same note over and over.
But that’s the thing, I have no exact idea how xLine operates. I tried to read the lua code, but I couldn’t make heads or tails of it. I wish your documentation would describe it better. I wish it said something like, “xLine has two methods, note_columns and effect_columns”, “See renoise.NoteColumn for details on editing note values”, “here’s an example on how to blah blah blah”. Instead, I’m faced with these cryptic function names with cryptic descriptions that mean nothing to me. I have no exact idea how xLine or xinc works. Only a confident guess [of their behavior] after experimenting around with them. (I don’t even know what xpos does).
This is why I’m having such a hard time. There’s no “xStream for Dummies” that I can pour over. All I have is the many examples, with no line-by-line comments, and the cryptic documentation with “functions” that aren’t even used in the examples. I hate being a whiner, but I seriously am so confused because of this.

**Well, I don’t exactly get a new sequence every time. I get areproduciblesequence of sequences. If I reset the seed in the terminal, and apply the model three times, I get three different sequences. But If I reset the seed, and apply the model three times, I’ll get the same sequences (but they’ll all be different). I made this picture (at bottom) for clarification, and in case you need to reproduce this behavior.
I get the same behavior if I use the event handler you described. If I set the “rnd_seed” argument value to 0, I can get the same sequence of sequences. But the only way I can reproduce the sequences is if I change the argument value to something else, apply the model to the track, and then I change the argument value back to 0 (and apply to track). So am I doing something wrong?

***I don’t really care about an answer for this one, but I thought I’d let you know. In this situation, I’d expect xStream to fill the column all with the same, but a different note if I change the seed value. If I set the seed to 0,1,2,3… (and apply after changing) I keep getting “C-4”. But if I type in an arbitrary number, I get something different. But if I increment this arbitrary number and apply again, it’s the same note value. No matter how much I increment the seed.

This is the picture which clarifies what I mean by “sequence of sequences”.

renoise_forum_question.jpg

^ Right here, it should say “step 3”, not “step one”.


(g8tr1522) #22

WHOOOOOOOOOOPSSSSSsssssssies

Well I just realized immediately after posting that last one why I get the “sequence of sequences”.

If you stream the model to the track, it repeats this “sequence of sequences”. More specifically:
I reset the seed to 0 in the console, and_stream_ my example model. ThenI’ll get the output in Step 4.Until the stream reaches the top again. Then I’ll get the output in Step 5. When it reaches the top again, I’ll get the output in step 6 (and so on).

But the problem still persists; I still have to entermath.randomseed(0)into the console if I want those same sequences to be streamed.


(danoise) #23

I create a new model, and simply give it one line:xline.note_columns[1].note_value = math.random(36,48) .I keep applying to the selected track, but I’ll get a new random sequence every time**.
If I give the model a second line,math.randomseed(0),and I apply to the track, every note is the same note***. I’m guessing this is because of the behavior of xLine*?

So I get rid of that second line. But now I was clever and thought about setting the random seed in the scripting console; maybe that can set Renoise’s global random seed? So I enter the commandmath.randomseed(0)directly into the terminal. A satisfyingly greenmath.randomseed(0)appears in the console. After I played around with that, I realized that I_could_ reproduce the same random sequence. But I have to entermath.randomseed(0)into the terminal every single time before I apply the model to the track. If I don’t, I get a new sequence every time I apply**. (I explain further below at the footnote**)
Is that event handler supposed to take care of that? I did exactly as you said, but I still get a new sequence every time I apply**.

Yes, you nailed it. The random seed has to be set at the right moment to work like expected. And the right time (in this case, anyway) would be when output is first started.
That would be the purpose of the event handler - it would simply be a “hook” which you hang your randomseed statement on.

So please don’t be confused. It’s certainly true that xStream documentation is rather scarce, but that just makes it so much easier to improve :slight_smile:

But that’s the thing, I have no exact idea how xLine operates. I tried to read the lua code, but I couldn’t make heads or tails of it. I wish your documentation would describe it better. I wish it said something like, “xLine has two methods, note_columns and effect_columns”, “See renoise.NoteColumn for details on editing note values”, “here’s an example on how to blah blah blah”. Instead, I’m faced with these cryptic function names with cryptic descriptions that mean nothing to me. I have no exact idea how xLine or xinc works. Only a confident guess [of their behavior] after experimenting around with them. (I don’t even know what xpos does).

xLine is a ‘virtual’ representation of the renoise.Patternline, accepting exactly the same input - note_string, instrument_value, etc. But, unlike renoise.PatternLine it doesn’t have to existing in an actual pattern somewhere. Having a virtual representation is required for a tool like xStream to work, because the final line on which output is written might change during playback (for example, if you enable pattern loop near the end of a pattern the tool will redirect it’s output to the top of the pattern instead of the next pattern). Also, it allows us to capture things in a buffer and optimize the output in various ways.

xpos is also a virtual representation of a fundamental Renoise API component - the renoise SongPos. It contains the current sequence index and line number.

(remember, you can always use print(), rprint() and oprint() to output various debug information to the console)

xinc is the ever-increasing counter that doesn’t care about patterns but simply keeps increasing for as long the tool is streaming.

So you should use xpos if you somehow wanted your model to rely on the pattern structure, or xinc if you don’t.

All I have is the many examples, with no line-by-line comments, and the cryptic documentation with “functions” that aren’t even used in the examples.

In one of the last released I renamed a bunch of models to “Demo-something” since they are less complex than the rest. Not with line-by-line comments, but that should certainly be doable. So, not saying that the documentation can’t be improved - it always can.

And when you refer to the cryptic documentation, I guess you found the xLib documentation, contained somewhere deep in the source of xStream? Well, that’s the framework powering all of my newer tools: xRules, PhraseMate, Noodletrap, etc. This is definitely not meant to be a entry point into xStream, rather it should be hidden from plain sight. I’m sorry - seeing now that the README does refer to the xLib documentation. instead, I’ll change it to use the description above + add a mention of how to make good use of xinc in the ‘Getting started’ section of the readme :ph34r: