<div dir="ltr">I got some problems with the linux builds also, and my final solution was using wine and the windows version of miniAudicle (the windows ChucK standalone also would work) and everythings just goes fine, In fact I wrote and tested the above code with it :)<br>
</div><div class="gmail_extra"><br><br><div class="gmail_quote">2013/12/5 Manuel Bärenz <span dir="ltr"><<a href="mailto:manuel@enigmage.de" target="_blank">manuel@enigmage.de</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div>Hey Moisés,<br>
<br>
Thanks again for this more sophisticated example. I'm having
problems with HIDs, I constantly get this error:<br>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px">HidIn:
couldn't open keyboard 0...<br>
I get the error for all values from 0 to 5. I'm using Gentoo
Linux. For tonight's presentation, I'm going to stick with KBHit
probably.<br>
</p>
<p style="margin-top:0px;margin-bottom:0px;margin-left:0px;margin-right:0px;text-indent:0px"><br>
Best, Manuel<br>
</p>
<br>
<br>
Am 05/12/13 17:43, schrieb Moisés Gabriel Cachay Tello:<br>
</div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr">Hi, I'm a coursera's ChucK course student, in the
lectures, Ge used HIDs to handle keyboard input, so this snippet
should help (I'm commenting the code for clarity).<br>
<br>
// HID stands for human-interface-device, also this is an event,<br>
// see below for more info<br>
Hid hid;<br>
<br>
// This is a message, this will hold the event's (keypress)
information.<br>
HidMsg msg;<br>
<br>
// We should define a device number since we would have multiple
keyboards <br>
// attached to our computer, 0 would do on most cases but you
can try 1, or 2 <br>
// if that doesn't work.<br>
0 => int device_number;<br>
<br>
// We check if the device attach with ChucK was successful,
otherwise the program <br>
// would end inmediately<br>
if(!hid.openKeyboard(device_number)) me.exit();<br>
<br>
<<<"Keyboard:", <a href="http://hid.name" target="_blank">hid.name</a>(), " ready!">>>;<br>
<br>
// We setup a simple sound chain for demonstration pruposes only<br>
BeeThree organ => JCRev rev => dac;<br>
.05 => rev.mix;<br>
<br>
// And repeat forever, see how the keyboard input is something
that would happen <br>
// *forever*, a keypress can occur anytime so we need to stay
alert until a new <br>
// event comes in<br>
while(true) {<br>
// Events are things that happens sometime, in ChucK this
mains basically <br>
// hold ourselves until the event appears (thats why we wain
for the event <br>
// ChucKing it to now)<br>
hid => now;<br>
<br>
// When our wait finishes: check all the messages that came
from the keyboard<br>
// using the recv function, and passing msg as the holder of
the information<br>
while(hid.recv(msg)) {<br>
<br>
// we check if the message is a buttondown message, in
that case:<br>
if(msg.isButtonDown()) {<br>
// We show the ascii value of the key pressed<br>
<<< "Button down:", msg.ascii >>>;<br>
<br>
// and make our generator sound, see how we check if
the<br>
// frequency too much high we simply discard this
message<br>
msg.ascii => Std.mtof => float freq;<br>
if(freq > 20000) continue;<br>
<br>
freq => organ.freq;<br>
1 => organ.noteOn;<br>
<br>
// this will make sure the sound will keep for a
minimum amount of <br>
// time, otherwise, concurrent events may stop
before even commencing<br>
80::ms => now;<br>
} else {<br>
// If we're not in a buttondown event, just assume
it's a key has been<br>
// left out and shut down the sound.<br>
<<< "Button up:", msg.ascii >>>;<br>
1 => organ.noteOff;<br>
}<br>
}<br>
<br>
}<br>
<br>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">2013/12/5 Manuel Bärenz <span dir="ltr"><<a href="mailto:manuel@enigmage.de" target="_blank">manuel@enigmage.de</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
<div>Hi Julien,<br>
<br>
No, this is not the case. KBHits are only key down
events. I tried to include several kb => now, but it
didn't help.<br>
See also this example here:<br>
<a href="http://chuck.cs.princeton.edu/doc/examples/event/kb2.ck" target="_blank">http://chuck.cs.princeton.edu/doc/examples/event/kb2.ck</a><br>
Apparently, the solution is emptying the event queue by
calling kb.getchar() until kb.more() returns false:
<div><br>
<br>
KBHit kb;<br>
<br>
me.sourceDir() + "/bum.wav" => string filename;<br>
<br>
adc => WvOut b => blackhole;<br>
filename => b.wavFilename;<br>
kb => now;<br>
</div>
while(kb.more()) kb.getchar();
<div><br>
b.closeFile();<br>
<br>
SndBuf buf => dac;<br>
filename => buf.read;<br>
kb => now;<br>
<br>
</div>
The important line is "while(kb.more()) kb.getchar();",
apparently. So I guess kb => now; doesn't wait at all
if there are still unprocessed keys in the queue.<br>
<br>
Best, Manuel<br>
<br>
Am 05/12/13 12:18, schrieb Julien Saint-Martin:<br>
</div>
<div>
<div>
<blockquote type="cite">
<div dir="ltr">
<div>
<div>
<div>
<div>Hi Manuel,<br>
<br>
</div>
Maybe your problem is as follow:<br>
For each key press there is two kb events:
key down and key up.<br>
<br>
</div>
A simple solution maybe to write "kb =>
now;" twice.<br>
<br>
</div>
Cheers,<br>
</div>
Julien<br>
<div>
<div><br>
<br>
<div><br>
</div>
</div>
</div>
</div>
<div class="gmail_extra"><br>
<br>
<div class="gmail_quote">2013/12/5 Manuel Bärenz <span dir="ltr"><<a href="mailto:manuel@enigmage.de" target="_blank">manuel@enigmage.de</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello again,<br>
<br>
I also wanted to demonstrate a simple
sequencer prototype that lets me<br>
record a file and then plays it back to me.
I've come this far:<br>
<br>
KBHit kb;<br>
<br>
me.sourceDir() + "/bum.wav" => string
filename;<br>
<br>
adc => WvOut b => blackhole;<br>
filename => b.wavFilename;<br>
kb => now;<br>
b.closeFile();<br>
<br>
SndBuf buf => dac;<br>
filename => buf.read;<br>
kb => now;<br>
<br>
But strangely, the program doesn't wait for
the second kb event, but<br>
exits directly after the first key that I hit.
Any ideas what I'm doing<br>
wrong?<br>
<br>
Best, Manuel<br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
chuck-users mailing list
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a>
</pre>
</blockquote>
</div>
</div>
</div>
<br>
_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br>
</blockquote>
</div>
<br>
<br clear="all">
<br>
-- <br>
-Moisés
</div>
<br>
<fieldset></fieldset>
<br>
<pre>_______________________________________________
chuck-users mailing list
<a href="mailto:chuck-users@lists.cs.princeton.edu" target="_blank">chuck-users@lists.cs.princeton.edu</a>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a>
</pre>
</blockquote>
</div></div></div>
<br>_______________________________________________<br>
chuck-users mailing list<br>
<a href="mailto:chuck-users@lists.cs.princeton.edu">chuck-users@lists.cs.princeton.edu</a><br>
<a href="https://lists.cs.princeton.edu/mailman/listinfo/chuck-users" target="_blank">https://lists.cs.princeton.edu/mailman/listinfo/chuck-users</a><br>
<br></blockquote></div><br><br clear="all"><br>-- <br>-Moisés
</div>