OK so it's not gonna be easy!
PureData patches run but getting any sort of input or output to them means learning some more languages!
Is there a list of other PD commands that are not supported?
I have a couple of non-vanilla objects that I need to find work-around fors as well....
USB keyboard vs Analogue in/outs key matrix
- Edited
As far as I know the only unsupported objects are [sigmund~] [bonk~] [netreceive] [netsend] [key] [keyup] [keydown] [keyname]
, but I have not tested everything else yet. I am working on a replacement for [netreceive] [netsend]
.
Also, I should look into how to dynamically load externals for libpd so that you can compile your own (or someone else's) external for Bela.
may be relevant, I pin it here: http://stackoverflow.com/questions/20943322/accessing-keys-from-linux-input-device
Thanks for the info.
If I compile with Heavy is it still the case that I can't use [key] etc?
yes, even more so. Heavy as a limited number of objects supported, full list here
nuromantix
If you end up skipping the keyboard hack and go with buttons connected to I/O. I would recommend using a multiplexer IC instead of reading different analog voltages. A multiplexer would allow you to expand the digital inputs greatly and is pretty easy to use.
Something like this one perhaps: http://www.nxp.com/documents/data_sheet/74HC_HCT4067.pdf
I actually have a couple lying about but I am a total beginner.... I understand what they do in theory but in practice how do you use it with Bela? How do you get your 8 or 16 values into Bela without using lots of inputs?
You have to write some code that cycles very quickly through all the inputs on the multiplexer to get all the inputs all the time ??
I think I get it but it seems complicated compared to just using a couple of analogue ins and a handful of resistors.
using muxers on the digital inputs would allow to increase the number of digital inputs at the expense of lowering their sampling rate. Using muxers generally requires loads of wires and using a bespoke pcb would be ideal. This would also cause troubles if you were to use rotary encoders, in which case you would need some shift registers.
Additionally, if you were to use some of the digital IOs to drive the muxer, you would then lose some of the available IOs.
If you need more than 16 digital inputs, an option could be to use the Bela multiplexer capelet, which has a 8x multiplexer connected to the analog inputs. This uses a custom PRU code to drive the multiplexer logic.
I'll leave this here as a starting to point to answer the original question (it's actually the first result when googling for "dev keyboard", but the research token itself is not very obvious)
http://stackoverflow.com/questions/2775461/linux-keyboard-event-capturing-dev-inputx
giuliomoro I'm curious about the net receive replacement for libpd...
Did you get it to work?
- Edited
Apologies for the delay. What stopped me so far is that I wanted to find a unified solution for libpd and heavy, which would not use [netsend]
and [netreceive]
, but instead something like:
[r bela_netreceive]
|
| [r bela_netereceive_port]
| /
|/
[print]
[r bela_netsend]
|
| [r bela_netsend_destination]
| /
|/
[print]
I plan to do this by the end of the week.
- Edited
In order to capture the keys from an usb-kbd and send yo Pd, I tried this and I think it work:
render.cpp
#include <fcntl.h>
#include <linux/input.h>
// Task for read the qwerty kbd
AuxiliaryTask gInputTask;
void read_kbd();
// global variables to receive keys from the auxiliary thread
bool newKeyEvent = false;
int keyValue = 0;
int keyType = 0;
in setup()
// start qwerty kbd capture thread
if((gInputTask = Bela_createAuxiliaryTask(&read_kbd, 50, "bela-read-input")) == 0)
return false;
in render()
if (newKeyEvent)
{
if(keyType == 0)
libpd_float("keyup", (int)keyValue);
if(keyType == 1)
libpd_float("key", (int)keyValue);
newKeyEvent = false;
}
Bela_scheduleAuxiliaryTask(gInputTask);
and
void read_kbd(){
// Variables keyboard control
struct input_event ev;
ssize_t n;
const char *dev = "/dev/input/event0";
int fd;
// qwerty keyboard capture
fd = open(dev, O_RDONLY);
if (fd == -1) {
fprintf(stderr, "Cannot open %s:.\n", dev);
return;
}
bool shouldStop = false;
int n;
while (!shouldStop && !gShouldStop)
{
n = read(fd, &ev, sizeof(ev));
if (n == (ssize_t)-1) {
shouldStop = true;
} else if (n != sizeof(ev)) {
shouldStop = true;
} else
{
if (ev.type == EV_KEY && ev.value == 0 && ev.value <= 2)
{
keyType = 0; // key released
keyValue = (int)ev.code;
newKeyEvent = true;
}
if (ev.type == EV_KEY && ev.value == 1 && ev.value <= 2)
{
keyType = 1; // key pressed
keyValue = (int)ev.code;
newKeyEvent = true;
}
// I'm filtering key repetitions
}
}
}
alexBarrachina Thanks for sharing your solution.
NOTE: I reformatted your post, you should use triple backtick (```) to enclose lines of code.
Wow amazing! Wish I knew this 6 months ago..........
To copy that file you could:
- copy the
core/default_libpd_render.cpp
file into your project. Assuming you have a project called PROJECT_NAME, you can do this by pasting this in the console at the bottom of the IDE:
and hit enter.cp /root/Bela/core/default_libpd_render.cpp /root/Bela/projects/PROJECT_NAME/render.cpp
- then you can edit the newly created
render.cpp
file using the IDE editor following the instructions above. - last, the Pd patch in the same project will need receivers such as
[receive keyup]
and `[receive key]