NAME
MIDI::Util - MIDI Utilities
VERSION
version 0.1302
SYNOPSIS
use MIDI::Util qw(
midi_dump
reverse_dump
midi_format
set_chan_patch
set_time_signature
setup_score
dura_size
ticks
timidity_conf
play_timidity
get_microseconds
score2events
);
my $dump = midi_dump('length'); # volume, etc.
$dump = reverse_dump('length');
print Dumper $dump;
my $size = dura_size('dqn'); # 1.5
my $score = setup_score( bpm => 120, etc => '...', );
my $ticks = ticks($score);
my $half = 'd' . ( $size / 2 * $ticks );
set_time_signature( $score, '5/4' );
set_chan_patch( $score, 0, 1 );
my @notes = midi_format('C','C#','Db','D'); # C, Cs, Df, D
$score->n( $half, @notes ); # MIDI::Simple functionality
$score->write_score('some.mid'); # "
my $cfg = timidity_conf('/some/soundfont.sf2');
timidity_conf('soundfont.sf2', 'timidity.cfg'); # save to a file
# Or you can just play the score:
play_timidity($score, 'some.mid');
my $ms = get_microseconds($score);
my $events = score2events($score);
DESCRIPTION
MIDI::Util
comprises handy MIDI utilities.
Nothing is exported by default.
FUNCTIONS
setup_score
$score = setup_score; # Use defaults
$score = setup_score( # Override defaults
lead_in => $beats,
volume => $volume,
bpm => $bpm,
channel => $channel,
patch => $patch,
octave => $octave,
signature => $signature,
);
Set basic MIDI parameters and return a MIDI::Simple object. If given a lead_in, play a hi-hat for that many beats. Do not include a lead_in by passing 0
as its value.
Named parameters and defaults:
lead_in: 4
volume: 120
bpm: 100
channel: 0
patch: 0
octave: 4
signature: 4/4
set_chan_patch
set_chan_patch( $score, $channel ); # Just set the channel
set_chan_patch( $score, $channel, $patch );
Set the MIDI channel and patch.
Positional parameters and defaults:
score: undef (required)
channel: 0
patch: undef
midi_dump
$dump = midi_dump($name);
Return a hash or array reference of the following MIDI, MIDI::Simple, and MIDI::Event internal lists:
Hashes:
volume
length
ticks
note
note2number
number2note
patch2number
number2patch
notenum2percussion
percussion2notenum
Arrays:
all_events
midi_events
meta_events
text_events
nontext_meta_events
reverse_dump
$by_value = reverse_dump($name);
$by_value = reverse_dump($name, $precision); # for name = length
Return the reversed hashref from the midi_dump routine hashes section.
midi_format
@formatted = midi_format(@notes);
Change sharp #
and flat b
, in the list of named notes, to the MIDI::Simple s
and f
respectively.
Also change accidentals and double-accidentals into their note equivalents, e.g. Cb
to B
, C##
to D
, etc.
set_time_signature
set_time_signature( $score, $signature );
Set the score time_signature
based on the given string.
dura_size
$size = dura_size($duration);
$size = dura_size($duration, $ppqn);
Return the duration size based on the MIDI::Simple Length
value (e.g. hn
, ten
) or number of ticks (if given as d###
).
If a ppqn value is not given, we use the MIDI::Simple value of 96
ticks.
ticks
$ticks = ticks($score);
Return the score ticks.
timidity_conf
$timidity_conf = timidity_conf($soundfont);
timidity_conf($soundfont, $config_file);
A suggested timidity.cfg paragraph to allow you to use the given soundfont in timidity. If a config_file is given, the timidity configuration is written to that file.
play_timidity
play_timidity($score_obj, $midi_file, $sf_file, $config_file);
Play a given score named midi_file with timidity
and an optional soundfont sf_file.
If a soundfont is given, then if a config_file is given, that is used for the timidity configuration. If not, timidity-midi-util.cfg
is used. If a soundfont is not given, a timidity configuration file is not rendered and used.
get_microseconds
get_microseconds($score_obj);
Calculate the microseconds of a tick given a score, with tempo and ticks.
score2events
score2events($score_obj);
Return the score as array reference of events.
SEE ALSO
The t/01-functions.t test file and eg/* examples in this distribution.
AUTHOR
Gene Boggs <gene@cpan.org>
COPYRIGHT AND LICENSE
This software is copyright (c) 2019-2024 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.