Help for scale object needed!


#1

Hey guys!

Been bumpping my head all day, trying to find out how to do this function, so now I am going to ask here.

I have a "bin12" parameters, which is used to form a set of values, between 0 and 11 that I need to round an input to.

As it is now, it works like this:

Each step represents one of the values from 0-11, as seen on the picture. If a step is on that number of that step is output. So if step 3 is on and you select step 3, it will output 3. If step 6 is on and you select step 6, it will output 6. And so on, as seen on the picture. (The display object on the right also shows each value of each step, so you can see what is going on).

But if you for example select step 2, which is not on, it will output a 0. And if you select step 7, which is also not on, it also output a 0. As shown on the picture.

Summed up shortly, if a step is on, it will output the value of that step, if a step is not on, then it outputs 0.

This is where I got to now and now I am stuck, I don't know how to build the next step of the object, but I am assuming it might need to be done with a for loop that checks some values against each other. So here is what I want to add to this algorithm:

If I for example select step 2, which is NOT on, the the algorithm should select the first step below step 2 that is on and output that value. In this case step 2 is selected and the nearest step BELOW 2 that is on, is step 0, so it will output 0.

Another example:

In this care step 9 is selected from the input, but step 9 is not on, so the algo should scan the parameter and select the first value BELOW 9 that is on, which in this case is step 6. Then output will be 6.

So you probably get it by now:
If you select a step that is NOT on, the algo should output the value of first step below the selected step.

I probable need to scan/evaluate the parameter every time a new step is selected and I am thinking it can be done with a for loop, but not sure where to start at all.

Does anyone have an idea how to do this?

Here is the patch is anyone of the more code save guys are up for a challenge:
Scale Com 1 .axp (4.2 KB)

I am just learning about for loops and I looked at some exercises and a lot of stack overflow, but did not find anything I think could be used to do this and I am really not that comfy using for loops yet.

Any tips and help appreciated.


#2

maybe look at this code ?
its in the contribution Library
a773/quantizer
quantizes to nearest note in selected scale, outputs pulse when the output note changes


#3

I have used the a773/quantizer object, but I am not too fond of the way it handles the scaling.
Maybe I can hack it to do what I want, but not sure where to start.

The issue I am having with that object is that if you feed it a random vaue between 0 and 11 is that if you only have 3 notes on in the scale it will behave like this:
If you have only 3 notes active and you send it a value of 4, it will play the first active note, but an octave higher. If you send it a value of 5 you will the second value, but an octave higher. Which means that the range can vary drastically, depending on how many notes is active in the scale. Sending the object random value, even at low range can mean that the scale is being spread out over several octaves., which is not always wanted.

I would like to keep the same range no matter how many notes is active in the scale. I want it to just round to closest value with out the drastical range changes. The way I described it above should do what I think is the right way for a scale object to work. I am pretty sure it's the same way that the quantizer object in Nord modular works, where it just rounds to closest active value.

But yeah, I will check up on it, maybe I can make something out of that object, I am just not expert on for loops yet, hehe :wink:


#4

You just wrote you want rounding to the closest active value, a few posts earlier, you wrote you'd want it to round to the next lower active value. Which?

And what should happen if there is no active value?


#5

Ah sorry :slight_smile:

I would like it to playback the closest active value from the scale. To be honest it does not have to be the closest active lower value, it could also be the closest active higher value if that is easier to do. Or it could check if the closest value is either higher or lower and then use the closest one. In my head it just made most sense to use the closest lower value, but I am not set on that.

Here are a few examples The input is the blue square, in this case we send it a value of 9:

If we use closest lower value, then playback the closest active lower value from the scale, in this case the closest lower value is 6:

If closest higher value: then playback the closest active higher value from the scale, in this case the closest higher value is 11:

And if we just want to get the closest value form the active notes, the result would be 11 again, as it is the closest value, in both lower and higher direction.

Actually after thinking about it I think that the closest value in general is the best way to go. So closest value on either one of the direction is probably the best.

It doesn't really matter that much, cause there is always going to be an active note. But IF I have to choose, I would say:

Anything you send through it, would result in a 0, cause there are no active notes.

I hope that made it a bit clearer :slight_smile:


#6

Nearest active value, or 0 if there’s no active value.

That’s clear.

If you post what you’ve got so far, this should be easy.


#7

@tele_player

The patch is above in the first post, called "Scale Com 1 .axp"

Thanks for taking the time to understand the issue, I appreciate it :slight_smile:


#8

Ahhh , I missed that... I’ll look at it tomorrow


#9

This will do it.

Scale Com 1 .axp (2.8 KB)


#10

Thanks @tele_player, will try it out tonight :slight_smile:


#11

Just tried it out, works exactly as I was hoping.

I highly appreciated it, @tele_player :wink:


#12

Note: there is one case I missed in my simplified spec yesterday - what happens when the input falls exactly between two ON notes?

My implementation will choose the HIGHER. Changing one test from ‘<‘ to ‘<=‘ will cause it to choose the LOWER. I leave that as an exercise for the reader.


#13

Cool, nice to know that is can be changed easily.

For now it seems to work pretty well :slight_smile:


#14

Cool , Please contribute , and name it something with Quantizer cheers


#15

@philoop

Here is the final version:
Draw Scale Com .axp (2.5 KB)

It's very efficient, it only uses 4 cycles to process it and very low dsp too.


#16

name it something with Quantizer
please and contribute

I have a lot of patches to update now.....


#17

I made it into an object and saved it to the library.

It is called jaffa/scale/drawscale


#18

isnt it easier to find it as quantizer draw?


#19

@jaffasplaffa - how are you counting cycles?

The bit of code I added definitely doesn’t consume much CPU, but it should also vary a bit depending on specific conditions.

Interestingly, I don’t know what it would be used for.

Edit: I just looked at what jaffasplaffa checked in, and I see what it does, but...

The idea of quantizing Note numbers seems unuseful. This is different from quantizing pitch, as in Autotune.


#20

@tele_player

Like this :slight_smile:

Insert the object that you want to check how many cycles uses between the "before" and "after" object.

It subtracts "before" from "after" = how many cycles used to process the object (approximately).