clipboard_listen()

45 views
Skip to first unread message

Tony

unread,
Nov 24, 2009, 8:13:15 AM11/24/09
to key...@googlegroups.com, t...@nosuch.com
Hi Tim,

I am using Keykit 7.6e, created a liblocal directory in the Keykit
installation dir and created a file clipboard_utils.k there, as written
below, but this implementation of the function clipboard_listen() drives the
cpu consumption quite high, which is bad. Do you know any better strategy
which would relax my CPU in a similar way as with the function
test_listen(port) and in it tcpip_listen as a parameter in sock.k?

If it is not easily possible to listen also to "valid phrase content changes
in the clipboard" I would have to use maybe the test_listen(port) solution
even if I would prefer using a non-telnet solution, at least for this use
case scenario.

Thanks,
Tony




###### begin of clipboard_utils.k

function ClipSet(var)
{
mdep("clipboard","set",string(var))
}

function ClipGet()
{
r = mdep("clipboard","get")
return (r)
}

function clipboard_listen()
{
oldarr = ""
arr = ClipGet()
n = sizeof(arr)


if ( n <= 0 )
return()
while ( n > 0 && arr != "end" )
{
if ( substr(arr,1,1) == "'" && oldarr != arr)
{
print("Got a new phrase into the clipboard: " +
string(arr))
print("arr length=",sizeof(arr))
p = phrase(arr)
realtime(p)
}
oldarr = arr
# delay for some time, e.g. 500 ms
millisleep(500)
arr = ClipGet()
}
}

###### end of clipboard_utils.k

Tim Thompson

unread,
Nov 24, 2009, 11:48:57 AM11/24/09
to Tony, key...@googlegroups.com
> but this implementation of the function clipboard_listen() drives the
> cpu consumption quite high, which is bad.

It does?  On my CPU, even checking every 10 milliseconds shows almost
no measurable CPU usage.  Here's my version of your function, adding a
feature that lets you optionally specify a quantization value.

function clipboard_listen(q)
{
      if ( nargs() == 0 )
               q = 0
       while (1) {
               s = mdep("clipboard","get")
               if ( substr(s,1,1) == "'" ) {
                       mdep("clipboard","set","")
                       print("clipped phrase = ",s)
                       realtime(phrase(s),nextquant(Now,q))
               }
               millisleep(10)
       }
}

    ...Tim...

Tony

unread,
Nov 24, 2009, 3:00:52 PM11/24/09
to Tim Thompson, key...@googlegroups.com
Thanks Tim a lot, I tried your function, it works great, but also here I see
49% CPU consumption on a Dual Core Pentium with 3 GHz while I am running
clipboard_listen(0).

Actually it does exactly what I want, only if it would be possible to let it
run with less CPU consumption would be great.

Could some others from the group maybe also try and see how their CPU
consumption on this function is? Here are three short phrases to try out,
just copy one of them into your clipboard:

'a c e'
'"Tempo=200000" a,c,e,f,g,a'
'a,a,e,e,c,c'

Kind regards,
Tony

Tony

unread,
Nov 26, 2009, 3:35:42 PM11/26/09
to Tim Thompson, key...@googlegroups.com
Hi Tim,

do you have any ideas maybe why we can have so different behaviour of
key.exe on two different machines? I wished I had the same behaviour as in
your pc.

Thanks and kind regards,
Tony

Mike

unread,
Nov 27, 2009, 8:50:38 AM11/27/09
to KeyKit
Try ctrl+alt+delete, find the keykit.exe and change the priority of
the process to lower.

Keykit loops Lock the cpu at 100% on my 14000mhz. It's a shame as this
prevents me from effectively driving soft synths.

Mike

Tim Thompson

unread,
Nov 27, 2009, 12:15:30 PM11/27/09
to Mike, KeyKit
> Keykit loops Lock the cpu at 100% on my 14000mhz. It's a shame as this
> prevents me from effectively driving soft synths.

Any continuously-running loop that contains a sleep() should not be
consuming 100% cpu. What OS and keykit version are you using? Are
you using external (to keykit) syncing? I use keykit with soft
synths all the time, of course. Here's a recent example that uses
keykit to drive eight soft synths and two audio effects, monitors ten
input devices, drives two LCD screens, and implements two five-track
MIDI loopers in the keykit code, all on a lowly Atom (N270) processor,
with cycles (barely :-) to spare:

http://www.youtube.com/watch?v=aHZveIJjxJ0

That was my Burning Man project this year.

...Tim...

Tony

unread,
Nov 27, 2009, 7:51:38 PM11/27/09
to Tim Thompson, Mike, KeyKit
Hi Tim,

are you using Keykit 7.6e with its default values for the parameters as
follows

- Clicks = 96
- Clicksperclock = 1 ?


I am using

- Clicks = 768
- Clicksperclock = 64

The reason why I changed those values was to synchronize Keykit as slave via
Midi Clock to other sequencers like Ableton Live and Reaper. In both cases a
ratio of
Clicks/Clicksperclock = 12/1 was required to get a correct synchronization
between Keykit and Ableton Live/Reaper.

I could of course try again the lower requirements setting with

- Clicks = 96
- Clicksperclock = 8

Another reason of setting Clicks to a higher value like 768 is I was
thinking the timing would be tighter.


While experimenting with synchronization between Keykit and Live/Reaper I
also discovered if Keykit is slave to Midi Clock it can not catch the right
ONE or the right phase of a 4/4 measure for example. Only the beats are
synchronized, but not the phase. The only solution I know might be to use
Keykit as master for Midi Clock and Live/Reaper as slaves, at least while
using together with Keykit. Did anybody find a reliable method of
phase-synchronizing Keykit to other sequencers, no matter if as master or
slave? I only would like to have the possibility to hear the Keykit
real-time output in context to what is available in the sequencer,
phase-correct, of course.

Tim, I watched your videos already, they are really cool, as you are!

Kind regards,
Tony



> Any continuously-running loop that contains a sleep() should not be
> consuming 100% cpu. What OS and keykit version are you using? Are
> you using external (to keykit) syncing? I use keykit with soft
> synths all the time, of course.
>
> http://www.youtube.com/watch?v=aHZveIJjxJ0

Tony

unread,
Nov 27, 2009, 8:14:22 PM11/27/09
to Tim Thompson, Mike, KeyKit
This is cool, I just tried the settings below, and now only if I press
repeatedly very fastly some hotkeys which change the Clipboard, key.exe
reaches only up to 7% of CPU, but not more, normally I does not even show
1%, maybe very shortly 1-2% then switching back to almost nothing which is
great!

I think we seem to have the solution here.

Tim, thanks for your always bombastic support. Now the AutoHotkey extensive
clipboard manipulation journey can start! Is anybody else interested in this
topic, we could collect some interesting ideas here, together. The goal
would be to use the pc keyboard as a "master control center" for any "midi
button feature needs" for your target DAW, vsti or effects, sequencer or
step sequencer, anything which can handle midi events. A programmable pc
keyboard with individual RGB LEDs for each key, would be the perfect
supplement for this idea. Imo much more powerful than a Novation Launchpad
or so...

Kind regards,
Tony

Tim Thompson

unread,
Nov 27, 2009, 8:44:52 PM11/27/09
to Tony, Mike, KeyKit
> are you using Keykit 7.6e with its default values for the parameters as follows
> -  Clicks = 96
> -  Clicksperclock = 1 ?

Yes.

> I am using
> -  Clicks = 768
> -  Clicksperclock = 64

I think you've found the reason why you're running at 100% cpu.

> While experimenting with synchronization between Keykit and Live/Reaper I
> also discovered if Keykit is slave to Midi Clock it can not catch the right
> ONE or the right phase of a 4/4 measure for example.

That's because MIDI clock by itself doesn't have any notion of the
downbeat or phase. MIDI start/stop/continue messages are useful for
keeping two sequencers in sync, downbeat-wise. See
http://nosuch.com/keykit/mailarchive/msg02917.html for a description
of something that may be useful. There's no example code that
actually makes use of the value of Nowoffset that is automatically
computed (in the C code of keykit) when a start/continue message is
received - it's an experiment waiting for someone to experiment with
it. If Sync is 1 and MIDI input sees a MIDI start message, you should
actually see a console message reporting that the value of Nowoffset
has been set.

...Tim...
Reply all
Reply to author
Forward
0 new messages