This is about live beat following using a signal analyser called [bonk~]. Here I'm going to be using it under a Linux sound environment with Jack and Hydrogen, but you should be able to substitute another audio patcher and drum machine on different platforms if you experiment.
The Pd unit [bonk~] is a very useful musical tool for performance and composition. It processes a stream of audio on its input and produces messages when it thinks the signal matches certain patterns. It doesn't have an audio output, just messages. What [bonk~] does is analyse the incoming signal.
Why might this be useful? For many ideas we want to be able to take the properties of one thing and force those properties onto another similar thing. An example might be following the pitch of a live flute player or singer and using that value to drive a synthetic string accompaniment, or another might be listening for only the vowel sounds in speech to better encode it. For music, analysis is often used to extract timing events between beats. Programs to perform automatic beat slicing operations use similar methods to find the start and end of drum sounds.
The [bonk~] unit recognises two kinds of thing on its left inlet, an audio signal, or some messages. The messages are specifically to do things like write some settings to a file or change an analysis parameter. Internally [bonk~] recognises a bunch of things, which stay in its own memory unless you save them to a file. These are enumerated 1, 2, 3 etc, and are called templates, but really they refer to a sound, a sound that [bonk~] has learned somehow. When an incomming sound closely matches a template [bonk~] already has in its memory it outputs a message, either 1 or 2 or whatever number represents the template. How does [bonk~] learn new template sounds? You have to teach it by putting it into learn mode. When you do this each new sound that bonk hears it assigns to a new template thing to look for later. We will train it to follow the beats from a drum machine by playing it each drum sound separately first, then playing the whole beat.
What can we process with [bonk~] to get our event signals? How about a drum machine? Detecting beats with accurate timing is one good test to do and we can play at making new beats from old. One of my favorite drum machines is Hydrogen so it's time to plug the Hydrogen drum machine to Pd, but first start Puredata so you will have both to patch together.
Start Hydrogen and go to the File->Preferences menu. Your version of Hydrogen should support Jack connectivity, so change the audio driver to Jack and save if it isn't already. Notice you need to restart the driver, but this works fine while Jack is running, you should see a new audio cable for Hydrogen pop up in the Jack connections list immediately.

We want the output of Hydrogen to go to Pd, so we disconnect it from its default destination and patch it to Puredata input. Then we connect the Pd output to the soundcard driver. It's important when deciding if something is to be used as an effect (in parallel) or a processor (inline) to know what it does to a signal. If at any time the answer to that question is "nothing" then you should never use the unit as an effect. In other words if a signal is merely copied don't run it in parallel. Look at the patching below and notice the audio driver now appears as Jack in the Hydrogen audio info panel.

So, we don't like to have Hydrogen going to the soundcard through two routes, one through Pd and one directly because when that happens any phase change in one signal just messes up the other one, so that's why we patched it that way. What our Pd patch is doing to the drums is "absolutely nothing" (because all we want to do is monitor the signal that [bonk~] is getting). Here it is.

Switch on the audio engine in Pd and start Hydrogen playing a pattern, you should now be able to hear your drums coming through Pd. Try disconnecting and swapping the audio connections in the patch to check it all works.
Here is an interface I made that wraps [bonk~]. It still needs some work to be useful, but it gives easy access to the unit for simple musical experiments. The [bonker] patch outputs messages from [bonk~] so there is a corresponding [bonkdrum] patch that catches those messages and makes some simple drum sounds. When you load both patches together it's possible to have beats following another drum pattern.
Inside the patch the audio signal just gets passed right through as above, but we tap off the signal to analyse and include some niceities like a level indicator and volume control. The signal that feeds [bonk~] is the left right sum, both channels of the stereo. The remaining controls to [bonk~] are supplied by an [interface adaptor] that deals with messages from the sliders and formats them nicely.


Stop Hydrogen from playing and toggle [bonker] into learn mode. Now fire off three or four of the drum sounds from Hydrogen by clicking on the instrument name in the pattern editor. In the diagram I have just pressed the "Tom Hi" sound. Now untoggle the learn button and start Hydrogen playing. If you turn up the bonk slider you should hear a simple synth noise tracking templates at different pitches, this is left as a debug utility, not really for mixing in to your music necessarily.
If you press forget a few times the stack of templates will disappear. It forgets one for each time you press forget. Now start retraining it with new sounds. It's possible to give several training examples to [bonk~] so it gets better at recognising a sound generally, but you need to read the documentation and modify this patch to do that, here we just give [bonk~] one sound to recognise at a time in a sequence.
Each template that matches causes the [bonker] patch to output an integer message. The [drumbonk] patch is a very simple drum sound generator with three instruments. Therefore it only recognises the numbers 1, 2 and 3. You could build much more sophisticated instruments to respond to the bonk data, or convert it to midi to drive other synths, our simple drum synthesiser just demonstrates the principle.
All we've done is assign the first three things [bonker] recognises to be the bass, hihat and snare of the [drumbonk] synth.
The jungle rythmn is driving three instruments but the thresholds are changing so new beats are picked up by the analogue drum machine (which is following). As you can hear the tracking latency isn't too shoddy, just a few milliseconds. The high vibe sound is the test signal mixed in so you can hear how it tracks the beat.
Here are the Pd patches.