NAME

MIDI::RtController::Filter::Drums - Generic RtController drum filter

VERSION

version 0.0402

SYNOPSIS

use curry;
use Future::IO::Impl::IOAsync; # because ScorePlayer is async
use MIDI::RtController ();
use MIDI::RtController::Filter::Drums ();

my $controller = MIDI::RtController->new(
  input   => 'keyboard',
  output  => 'usb',
  verbose => 1,
);

my $filter = MIDI::RtController::Filter::Drums->new(rtc => $controller);

$filter->bars(8);
$filter->phrase(\&my_phrase);
$filter->common({ foo => 42 });

# for triggering with a note_on message:
$filter->trigger(99); # note 99 (D#7/Eb7)

# or for triggering with a control_change:
# $filter->trigger(25); # CC 25
# $filter->value(127);

$controller->add_filter('drums', note_on => $filter->curry::drums);

$controller->run;

sub my_phrase {
  my (%args) = @_;
  if ($args{foo} == 42) {
    $args{drummer}->metronome4;
  }
  else {
    $args{drummer}->metronome5;
  }
}

DESCRIPTION

MIDI::RtController::Filter::Drums is a generic MIDI::RtController drum filter.

ATTRIBUTES

bars

$bars = $filter->bars;
$filter->bars($number);

The number of measures to set for the drummer bars.

Default: 1

bpm

$bpm = $filter->bpm;
$filter->bpm($number);

The beats per minute.

Default: 120

phrase

$filter->phrase(\&your_phrase);
$part = $filter->phrase();

The subroutine given to this attribute takes a collection of named parameters to do its thing. Primarily, this is a MIDI::Drummer::Tiny instance named "drummer."

common

$common = $filter->common;
$filter->common($common);

These are custom arguments given to the phrase.

A MIDI::Tiny::Drummer instance, named "drummer" is added to this list when executing the phrase.

Default: {} (no arguments)

METHODS

drums

Play the drums.

If trigger is set, a note_on event only fires this filter when its note matches trigger. If value is set, a control_change event only fires this filter when its value matches value. When the filter fires, the full phrase is played.

SEE ALSO

The eg/*.pl program(s) in this distribution

MIDI::RtController::Filter

List::SomeUtils

MIDI::Drummer::Tiny

MIDI::RtController

MIDI::RtMidi::ScorePlayer

Moo

Types::Common::Numeric

Types::Standard

AUTHOR

Gene Boggs <gene.boggs@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2025-2026 by Gene Boggs.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.