Perl type library for MIDI
  • Perl 93.2%
  • Raku 6.8%
Find a file
2025-04-10 22:03:22 -05:00
.woodpecker install deps for regular test 2025-04-10 22:03:22 -05:00
lib/Types manually set CPAN authority rather than rely on local config 2025-04-06 16:28:49 -05:00
t fix percussion synopsis and test 2025-03-29 19:52:37 -05:00
xt/author explicit perlcritic and perltidy config 2025-04-06 18:52:02 -05:00
.gitignore git ignore dzil artifacts 2025-03-29 17:29:32 -05:00
.mailmap revise mailmap 2025-03-29 18:37:28 -05:00
Changes v0.601.0 2025-03-30 20:16:31 -05:00
CONTRIBUTING.md add guidelines for contributors 2025-03-29 19:13:48 -05:00
dist.ini explicit perlcritic and perltidy config 2025-04-06 18:52:02 -05:00
LICENSE v0.0.2 2025-03-29 18:07:28 -05:00
README.md v0.601.0 2025-03-30 20:16:31 -05:00
weaver.ini add codeberg.org metadata 2025-03-29 17:43:54 -05:00

NAME

Types::MIDI - Type library for MIDI

VERSION

version v0.601.0

SYNOPSIS

use Moo;
use Types::MIDI -all;

has volume => (
    is      => 'ro',
    isa     => Velocity,
    default => 100,
);
has a440 => (
    is      => 'ro',
    isa     => Note,
    default => 69,
);
has electric_snare => (
    is      => 'ro',
    isa     => PercussionNote,
    coerce  => 1,
    default => 'Electric Snare',
);

DESCRIPTION

This is a type constraint library intended to be useful for those developing music software using the MIDI (Musical Instrument Digital Interface) specification.

It is a work in progress driven by real-world usage, and as such does not yet necessarily have a stable interface. Once it reaches version 1.0, though, the author does not intend to introduce any breaking changes without a corresponding increase in the major version number.

OVERVIEW

Because this leverages Type::Library, it should be usable in a variety of Perl object systems, including Moo and Moose. By default, it exports nothing into the consumer's namespace; however, in addition to specifying individual functions in the "use" in perlfunc statement, you can also provide or combine the following tags to export groups of functions:

  • use Types::MIDI qw(:types);

    Exports all types by name into the namespace.

  • use Types::MIDI qw(:is);

    Exports all is_TypeName functions into the namespace.

  • use Types::MIDI qw(:assert);

    Exports all assert_TypeName functions into the namespace.

  • use Types::MIDI qw(:to);

    Exports all to_TypeName functions into the namespace.

  • use Types::MIDI qw(+TypeName);

    Exports TypeName and all related functions into the namespace.

  • use Types::MIDI qw(:all);

    Exports everything.

This library also inherits from Exporter::Tiny; consult Exporter::Tiny::Manual::Importing for ways to customize how functions are imported, such as renaming or omitting certain names.

Also note that the tags listed above may be preceded with a - (hyphen) instead of a : (colon); Perl's auto-quoting of barewords thus enables you to import a tag group of functions like so:

use Types::MIDI -all;

TYPES

Channel

An integer from 0 to 15 corresponding to a MIDI Channel.

Velocity

An integer from 0 to 127 corresponding to a MIDI velocity.

Note

An integer from 0 to 127 corresponding to a MIDI note number.

PercussionNote

A "Note" from 27 through 87, corresponding to a "Note" number in the General MIDI 2 Percussion Sound Set.

This type can also coerce case-insensitive "NonEmptySimpleStr" in Types::Common::Strings of instrument names in the General MIDI 2 Percussion Sound Set, returning the corresponding "Note".

FUNCTIONS

is_Channel

Returns true if the passed value can be used as a "Channel".

assert_Channel

Returns the passed value if and only if it can be used as a "Channel"; otherwise it throws an exception.

is_Velocity

Returns true if the passed value can be used as a "Velocity".

assert_Velocity

Returns the passed value if and only if it can be used as a "Velocity"; otherwise it throws an exception.

is_Note

Returns true if the passed value can be used as a "Note".

assert_Note

Returns the passed value if and only if it can be used as a "Note"; otherwise it throws an exception.

is_PercussionNote

Returns true if the passed value can be used as a "PercussionNote".

assert_PercussionNote

Returns the passed value if and only if it can be used as a "PercussionNote"; otherwise it throws an exception.

to_PercussionNote

Coerces the passed value to a "PercussionNote".

SEE ALSO

BUGS

Please report any bugs or feature requests on the bugtracker website https://codeberg.org/mjgardner/perl-Types-MIDI/issues

When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.

AUTHOR

Mark Gardner mjgardner@cpan.org

COPYRIGHT AND LICENSE

This software is copyright (c) 2025 by Mark Gardner.

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