How do I round to the nearest value in a list?

BLAIR
BLAIR Member Posts: 47 Member

I think I'm the first person to ever ask a question on the new forum haha.

Basically, I want to have some sort of list, maybe stored in an array or table, with a bunch of numbers between 1 and 127 which represent a scale e.g. Cmajor (so, therefore, it will have some gaps in the list of numbers like 1, 2, 4, 5, 8, 9 etc). How would I execute this?


P.s. just to be super clear, I am aware that the round macro in core exists, but its not what I need :(, because whilst the chromatic scale would be midi numbers 1, 2, 3, 4, 5, 6, 7 and so on without any gaps, the major and minor scales will not include all 127 midi numbers :)

Best Answer

  • ANDREW221231
    ANDREW221231 Member Posts: 296 Advisor
    Answer ✓

    this gets really hairy if you are trying to just automatically round. the surefire way to do this is to have a table of size 127, and for every entry there is an output. so, for instance in your example, reading from index position 6, there would be an entry which would give the output of 5

Answers

  • ANDREW221231
    ANDREW221231 Member Posts: 296 Advisor
    Answer ✓

    this gets really hairy if you are trying to just automatically round. the surefire way to do this is to have a table of size 127, and for every entry there is an output. so, for instance in your example, reading from index position 6, there would be an entry which would give the output of 5

  • BLAIR
    BLAIR Member Posts: 47 Member

    Ah okay! Thats so smart, I will try this out, thanks!

  • colB
    colB Member Posts: 795 Guru

    That's a good approach, however you are just moving the tricky bit from searching for the correct value to correctly populating a lookup table. Unless the list to be searched is a fixed constant thing...

    Which pproach is correct depends on the specific use case. Choose the table approach if each lookup needs to be extremely efficient.. e.g. if it's an audio process. Choose a search based approach if it's a rare thing like responding to user input.

    Generally, for the search, you would use either brute force - just iterate through all possible values until you get to the position where your value fits... or use a binary search to cut down the iterations.

  • BLAIR
    BLAIR Member Posts: 47 Member
  • colB
    colB Member Posts: 795 Guru

    Well, that's the kind of information that should be in your initial post ;)

    Why does it do it 512 times?

    Are the scales being searched fixed during runtime, or are the editable by the user? and if so, how?

  • darkwaves
    darkwaves Member Posts: 342 Guru
    edited January 2022
    I'm a reaktor newbie; but I'd want to do math to drop it down to 12 options.  I mocked up an example, but can't seem to post the ensemble here :(


    If you do something like that, the 'base' output will be 0-11; those are the only values you need to worry about.  Modify as needed and then add "shift" to get back to the right octave.  If you want C# to play D, it doesn't matter if it's note 1 or 13 or 25 or 121.  Find what the note would be in octave 0, modify it and then go back up to the right octave.

    All of that said; I'm not sure if this is horrible design in reaktor or how it would perform

  • BLAIR
    BLAIR Member Posts: 47 Member
    darkwaves said:
    I'm a reaktor newbie; but I'd want to do math to drop it down to 12 options.  I mocked up an example, but can't seem to post the ensemble here :(


    If you do something like that, the 'base' output will be 0-11; those are the only values you need to worry about.  Modify as needed and then add "shift" to get back to the right octave.  If you want C# to play D, it doesn't matter if it's note 1 or 13 or 25 or 121.  Find what the note would be in octave 0, modify it and then go back up to the right octave.

    All of that said; I'm not sure if this is horrible design in reaktor or how it would perform

    Thanks!!!
  • Studiowaves
    Studiowaves Member Posts: 453 Advisor

    I don't have a clue what you're up to but the LIST under panel can contain any number you like in each entry. I'm not sure if you can access it via IC send/receive from an internal source. It has 1024 entries, maybe enter the scale modes in it, major minor etc.in using 12 entries for each mode. You can also round to any area by dividing the input before the math round. Example 0 to 11 divided by 12 then rounded will produce 0 or 1 but adding .5 after the divisor will result in a 1, although .5 can go either way. So 12 to 23 will round to 2 and so on. The round out could indicate which note is in what octave, or perhaps the base of an index for a mode select if accessing the LIST module. Food for thought, about it.

Back To Top