New Tool (3.0): Randomize Notes

New version available (requires Renoise 2.6 beta 4).

v0.51:
Global keyboard actions are now processed by Renoise. This is good because you don’t have to click between Renoise and the script to “undo” anymore, for example.

http://tools.renoise.com/tools/randomize-notes

yes, that would work… almost the same thing. don’t know if it’s really needed since one can transpose with advanced edit anyway.

Nice Conner_Bw!

Of course there is a workaround, but it’s slow and painful. Killing any inspiration and quick experimenting with the different settings in the script.
When you know what key you are currently in it would be much easier to be able to select this key in the script. No need to do a lot of transpose voodoo for any adjustment you make.

Can someone explain “key” to me in Lua / Math / Nerdspeak?

Example: This is Pentatonic Blues in C:

  
notes = {'C-','D#','F-','F#','G-'}  
  

So, is Pentatatonic Blues in D simply each note +2? Does it wrap around, or something?

If someone can type out all the Pentatonic Blues “keys” so I can see the “math / pattern” it would be appreciated.

That’s right. It’s twelve different keys in western classical music. So each scale will have 12 keys.

(edit: i’m not explaning key below btw. i’d keep the key concept out of the random tool since it’s rather confusing. as i understand it: playing strictly in “key” is is basically just playing in either major or minor scale but the tool has a lot more scales than that. so that’s just a subset of what the tool can generate.)

yes it wraps around. you have to have this list somewhere in your app. it’s just a list of which note follows which if you go up the keyb without skipping any notes: (sorry if i’m being over explanatory here… it’s hard to do this in text :/)

c ->c# → d → d# → e → f → f# → g → g# → a → a# → b | (LOL, that looks sooo good!!)
^-------------------------------------------------------------------------|

so for example (as written in your code snippet) c to d# is c → c# → d → d# = three semitone steps up. (count only in semi notes. there’s no need to keep track of whether the notes have sharps or not… only which note follows which in a linked list or some data structure like that.)

and then starting from that second note:

d# → e → f is two semi tones jumps
f → f# is one semi tone jump
f# → g is one semi tone jump
g → g# → a → a# → b → c is five semi tone jumps and we are back where we started.

so the jumps for this scale would then be: 3, 2, 1, 1, 5 (is this correct? it looks pretty eastern :))

so, say that the user wants that scale starting on d# then the program has to start on d# and make 3 semi tone jumps and then from that tone (f#) make two jumps to g# and so forth.

hope that wasn’t too bad an explanation (=

There are 2047 scales in the western tonal system. (EDIT: not including stacked multiple scales spanning several octaves).

I use the scale degrees to recall them all, so instead of calling it Pentatonic Blues, I just call it 0 3 5 6 7 o (0 = Key & o = octave). I did it that way because I wasn’t willing to find all the names for all 2047 scales.

I categorized them according to total tones including the Tonic (key) and its octave, meaning Pentatonic Blues is in the 6 note category.

This old chart highlights the Pentatonic Blues (0 3 5 6 7 o).

And here’s all the keys for the Pentatonic Blues (0 3 5 6 7 o).

EDIT: forgot to include in the highlight the Tonic note B

Try method-behind-the-music.com scales and key
for some quick theory of the series of whole and half note steps making up the scales.

You run into problems defining scales in different keys when you have the arrays in explicit notes (C, D etc). If you define the scale
by semi tone note steps (1, 3, 5, 6, 8, 10, 12 e.g for major scale) instead you can easily just start at any note to get any key.

First line is all notes, second line is pentatonic Major in C:

  
1 2 3 4 5 6 7 8 9 10 11 12  
'C-','C#','D-','D#','E-','F-','F#','G-','G#','A-','A#','B-'  
'C-', 'D-', 'F-', 'G-', 'A-'  
1 3 6 8 10  
  

First line is all notes, pentatonic Major in D#:

  
1 2 3 4 5 6 7 8 9 10 11 12  
'C-','C#','D-','D#','E-','F-','F#','G-','G#','A-','A#','B-'  
'C-', 'D#', 'F-', 'G#', 'A#',  
10 1 3 6 8  
  

Is this right?

The way it’s most often thought of is to keep the scale degrees/steps locked. See http://en.wikipedia.org/wiki/Degree_(music)
I.e. not to permutate the scale steps letting it become 10, 1, 3, 6, 8 but letting it stay 1, 3, 6, 8, 10 and then just set the root to the key in question. In this case, before you look up the scale notes, you’d just permutate/shift (wrapping) your notes table from C to D# first. So D# would actually become 1, which is the traditional way of thinking about it. Or you could transpose after which I guess could be easier to do.
The point of doing it the first way is that it’s the scale steps that are the underlying structure, not the notes. The notes could be anything based on where you start but the intervals are always the same.
And it wouldn’t actually be 1, 3, 6, 8, 10 either. It would be 1, 3, 3, 2, 2 in this case. The counter resets with each increment but counts from it’s preceding position. The interval between the current and the preceding value is the important thing, not the actual, accumulated value. If you want to get convoluted think of it as a non-accumulative fibonacci sequence with a hidden accumulator. ;)

This is just the traditional way of thinking about it and not really much more effective than your approach, but might make it easier for users, contributors, etc. And the scale steps are the focal point, which I think is ultimately an easier way of thinking about scales.

what a weird article. didn’t enlighten me one bit tbh.

v 0.6 beta:
Added support for keys

Please test and provide feedback before I put it on the Tools page.
Thanks.

Thnx Conner, will test tonight!

Am I going crazy, or is the first note always the same? Is this a bug in Renoise?

In randomizer.lua, look for this code snippet:

  
-- Random  
local note_prefix_table = Random.note_sets[self.mode]  
prefix = math.random(1, #note_prefix_table)  
prefix = note_prefix_table[prefix]  
  

Add some debugging, e.g.

  
print(#note_prefix_table, prefix)  
  

On my computer the first note is always the first element of the note_prefix_table, the rest are fine.

Doesn’t seem to be any flaws in the code, but Renoise is not producing a random result for the first note?

Hopefully this doesn’t derail the thread, but maybe this one Scale (music) - Wikipedia explains it better.

To sum it up, the intervals are the defining ingredient of a scale. The notes it actually uses are secondary.

What makes a certain scale identifiable across all the keys isn’t the notes, but the intervals it uses.
I.e. the structure of the major is 2,2,1,2,2,2,1 in semitone scale steps, and that applies to all keys.
You can start on any note, say B, and use that structure to make the B major scale.

@Conner, it seems like it’s always the same here too. The root and 5th octave. Apart from that keys seem to work fine though.

In the Lua code, open randomizer.lua near line 48 and change this:

  
function Random:__init(mode)  
 math.randomseed(os.time())  
 self:set_mode(mode or 'Chaos')  
end  
  

To this:

  
function Random:__init(mode)  
 math.randomseed(os.time())  
 local garbage = math.random()  
 garbage = math.random()  
 self:set_mode(mode or 'Chaos')  
end  
  

Does it fix the issue?

Yeah that fixes it. So you have to invoke or reference the math.random() in the init… weird shit! :)

booyah!!! :]/

conner… you rock!

edit… :P

anyhow… this is rrreally awesome. thank you!