Re: Hydrogen for live accompaniment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 24, 2006 at 11:25:11PM +0100, Frank Barknecht wrote:
> Hallo,
> Joshua Boyd hat gesagt: // Joshua Boyd wrote:
> 
> > A lot of devices and software systems (of the commercial type at least)
> > seem to have a tap tempo system where two taps are all that is needed to
> > set the tempo of an effect or sequence.

> Two tabs normally aren't enough IMO, however that really is easy to do
> in, guess it: Pd. Attached is the naive idiom which just spits out the
> time interval between two events.

Heh, I have an old tossed-off python script that may be handy too.
Just run it from the command line, tap any key any number of times,
hit "q" when you're done and it prints estimated BPM.

But it's ancient and uses a deprecated library module;
so it only works in Python < 2.4.

It's at http://www.slinkp.com/code/tempotool.py

-- 

Paul Winkler
http://www.slinkp.com
#!/usr/bin/python

print  """
Tap a steady beat on any key.
Hit 'q' to stop and print the estimated tempo of your beat.
"""

## This is almost entirely based on the 'keypress' entry in python FAQ, by
## Andrew Kuchling.

import termios, sys, os, time

fd = sys.stdin.fileno()
# Get 2 copies of termios info... one to modify, one to restore
old = termios.tcgetattr(fd)
new = termios.tcgetattr(fd)
# turn off "canonical mode" & "echo"
new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
# I have no idea what these do-- not in python docs or 'man termios'
new[6][termios.VMIN] = 1
new[6][termios.VTIME] = 0
termios.tcsetattr(fd, termios.TCSANOW, new)

times = [] # save the time when keys are pressed.
try:
    while 1:
        c = os.read(fd, 1)
        when = time.time()
        if c == "q": break
        else:
            times.append(when)
            print "%s %f" % (c, when)
finally:
    # be sure to restore tty attributes no matter what!
    termios.tcsetattr(fd, termios.TCSAFLUSH, old)

diffs = []
for i in range(len(times)):
    try:
        diffs.append(times[i + 1] - times[i])
    except IndexError: pass #

sum = 0
## print "diffs:"
for d in diffs:
##      print d,
     sum = sum + d

estimate = 60.0 / (sum / len(diffs)) 
print "\n\nestimate is: %f" % estimate











[Index of Archives]     [Linux Sound]     [ALSA Users]     [Pulse Audio]     [ALSA Devel]     [Sox Users]     [Linux Media]     [Kernel]     [Photo Sharing]     [Gimp]     [Yosemite News]     [Linux Media]

  Powered by Linux