• ### Creating a large number combining several numbers

Hi everyone! This is my first post here, be kind

I don't know if this is in front of me and I'm blind but I cant find a solution for this without using externals, and other stuff (even though). I've tried lists, pack, etc... and I prefer not to use any external, just core pd 0.51

Problem: I cant generate a number, let's say 101 from three separate numbers: 1 0 1.

Situation:
I need to take three numbers (boolean states from 3 toggles: 0 or 1) and create a "3 bit" number so a [select] object can decide accordingly: If number is 100 do X, if 101, do Y, if 110 do F, if 001 do K, and so on...

I, knowing a little bit of other programming languages, though it was as easy as "combine all integers from a list creating a string and then apply something like string.ToInteger"... but looks like is not that simple.

I appreciate any input!

• Posts 23 | Views 2203
• Oh and if you are using boolean values, this would be more efficient: bool_combine.pd

• Muchas gracias Bocanegra!

You have the "mathematician approach" and that is what I lack of! It's so good to have a second pair of neurons to look at your problems This is not exactly what I was thinking of but it will do the trick.

I'm working on an instrument where you have 3 push buttons (that gives you ones and zeros), and like a trumpet, you play different "notes" with the combination of the three, that is why I was thinking of Ones and Zeros. But for example if you have 011, as a number, pd will read just 11, so thanks to your approach, I think I will work with Ones and Twos, as a workaround.
Gracias de nuevo!

• De nada

If you want to replicate a trumpets behavior it becomes way simpler: Button one lowers the pitch by two semitones. Button two by one semitone. And button three by 3 semi tones, so you could just multiply each boolean with the corresponding (negative) interval, and add them up to a fundamental pitch:

• the arithmetic method from boca is perfect for 3 digits.

however, what you were thinking of originally is this

(sorry maybe pd-extended content, i dont know the different packes by heart)

that will also work for "numbers" longer than the 32 bit limit, because it outputs a symbol.

...

then there is a third method for such things - i dont know the proper terminology, let´s just pretend it is called "binary encoding" or "flags"

1 0 1 1 0 stands for true false true true false

now you give the positions of these numbers names like that:

1 2 4 8 16 32 ...

now you just accumulate the names of the positions which are true:

1 0 1 1 0 == 1 + 4 + 8 == 13

each possible combination of true/false positions will end up in a different decimal number, which can be converted back into a list of 0 and 1.

finding the math for this is left as an excercise.

• Hi.
I will just try to set a similar question under this thread as the answers given before had a good input to me.

I want to have 6 different notes played by having 3 buttons (each one single + the three combination pressing two keys)

So far my patch works. But when I press a key-combinations (in my example "s + d" it jumps back to the frequency of one or the other of the key but it is not staying with the frequency I set the key-combination.

It would be wonderful if somebody can give a hint.
Thank you
Tilman

• The thing is that the OS will send key up and key down events when a key is pressed. Another thing is that i get nothing out of [key] when i press three keys at once on Linux which is not expected.

• This works better:

keyupdown.pd

• @ingox Thank you for the reply and your post. The number box (at the end of the patch ) from 1-6 works fine. But to transfer it to the right sound is still tricky for me.
Press d = c1 ,
Press s= d1
Press ds= e1 (notes)
is what I want. but as soon I press ds together it reads as well each key individual and change the sound back to c1 or d1 and is not staying on e1.
I am trying around with a metro which is triggered by "ds" and with a Spigot object, blocks d + s to function.
As soon I am a functional step further I will post it here. Tricky control situation + I am quite new with Pure data.
Thanks again

• @atk90x @Tilman You can also you message arguments to combine numbers

Edit: Should mention that this can create a great number of symbols quickly, which can fill up the hash table and slow down pd. In cases like OP it is not much of an issue, just a few symbols are being created and it will have no real negative impact on speed, but in some situations you could quickly create thousands of unique symbols and this will slow things down.

• For anyone that finds that will not work......... [f] only converts symbols since Pd 0.48.0....... and unfortunately will still not convert text 123 so it must first be defined as a symbol as @oid says.
David.

• @Tilman Using the computer keyboard will never give you the same responsiveness as a midi keyboard, as the computer keyboard produces many key down and up events when a key is pressed like aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.

So this has to be mitigated somehow. I find it surprisingly hard.

I built a buffer with [text] but it still has some fluctuations at least on my macbook + linux: keyplay.pd

• @ingox on mac you can turn repeats off in system preferences

• Here is a nicer and cleaner approach that seems mostly stable: keyplay.pd

@Tilman You can adjust the delay so that it works with your keyboard.

50 milliseconds is enough on my keyboard.

I still have some weird effects that sometimes when i hit three keys at once, the release of a single key is not detected, but it mostly works.

• @ingox A little patch to solve the problem when repeats cannot be turned off (virtual keyboard midi chord debounce)..... chord_debounce.zip
I am pretty sure it has no ill effects....... you get the chord immediately.......
It doesn't use [delay].
You asked me once whether [clone] was necessary for this. Probably not as it can probably be done with lists but this is a simple solution (I am not the @list-master).
The number of clones could be reduced to 128 I think but this allows for clumsy fingers.
David.

• Wow that is an incredible help. Thank you all so much. What a joy.

I will need a bit more time to go though all different objects to have a max. learning input.

Very great:)

• @whale-av I can't get it to work...

If i do
[chord_debounce]
|
[print]
i still get key ups and downs for pressed keys.

How should it be implemented and what should it do?

• @ingox Yes...... but it suppresses all repeats generated by the OS from key presses held down........ your "aaaaaaaaaaaaaaaaaaa" problem...... while still outputting the intended events instantaneously.
You would need to compare it to the actual outputs of [key] and [keyup] to see it work.
I suppose that if repeats are turned off in system preferences you would see no difference.
I don't think there is such a setting for widows....... but I am often wrong...... and can be again.
You can adjust the repeat rate in windows but not turn the repeats off.
Anyway its a pita to have to change such settings for different uses.
David.

• @whale-av Hm, it doesn't work on linux. Repeats are not turned off.

debounce-test.zip

Or this, shows same behavior for [chord_debounce] and [key] and [keyup] combined: debounce-test.pd.

• @ingox In windows the bang directly after [key] (right hand side in debounce_test.pd) shows bangs all the time that a key is pressed and held down.
test.pd
Does [key] suppress repeats in the Linux Pd distro? maybe.........
David.

Posts 23 | Views 2203
Internal error.

Oops! Looks like something went wrong!