4

I have a Pure Data patch that reads some MIDI files and performs an analysis of them and then creates a table with some values. I need to extract the MIN and MAX values of this table and then use them to set the range of a KNOB object. For example, let's say that after the analysis turns out that the min and max values from the table are, say, 3 and 29. Now I have to give a KNOB object these values as min and max range. Is this possible? I know you can change the range on Properties, but the values in the table will vary each time, so I need to set the KNOB's range automatically according to the values obtained from the table.

In that matter, the table always has a 0 on the first position, so the patch always finds this 0 to be the min value. How can I ignore this 0 value? I am computing the min and max from the table using the object list-minmax.

Hec46
  • 181
  • 2
  • 15

2 Answers2

3

To algorithmically define the range of the knob object, you can send a message range <min> <max> to the it:

enter image description here

As for the table having always a 0 in the first position, I don't understand why that's the case. You can have any value at any index in the table. Maybe you are unaware that in Pd the first index of a table is 0, so if you are writing values to it from index 1 onwards then index 0 will have the default value of 0.

gilbertohasnofb
  • 1,984
  • 16
  • 28
0

you could also use the [knob] at a default range (e.g. 0..1 or 0..127) and then apply some scalilng offsetting to the numbers to get the range you desire:

e.g. the following will output values between -2 (knob on the left-side) and -5:

[knob]
|
[/ 127]
|
[* -3]
|
[- 2]
|
[print]

this has the advantage that you see the logic in your patch, rather than having some blackbox (inside [knob] that does all the magic for you. it also makes it easy to apply non-linearities.

umläute
  • 28,885
  • 9
  • 68
  • 122