NAME

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

VERSION

version 0.0400

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)

Default: 120

METHODS

All filter methods must accept the object, a MIDI device name, a delta-time, and a MIDI event ARRAY reference, like:

sub drums ($self, $device, $delta, $event) {
  my ($event_type, $chan, $note, $value) = $event->@*;
  ...
  return $boolean;
}

A filter also must return a boolean value. This tells MIDI::RtController to continue processing other known filters or not.

drums

Play the drums.

If trigger or value is set, the filter checks those against the MIDI event note or value, respectively, to see if the filter should be applied.

SEE ALSO

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

MIDI::RtController::Filter::Tonal - Related module

MIDI::RtController::Filter::Math - Related module

MIDI::RtController::Filter::CC - Related module

List::SomeUtils

MIDI::Drummer::Tiny

MIDI::RtController

MIDI::RtMidi::ScorePlayer

Moo

Types::Standard

AUTHOR

Gene Boggs <gene.boggs@gmail.com>

COPYRIGHT AND LICENSE

This software is copyright (c) 2025 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.