Skip to content

Instantly share code, notes, and snippets.

@ology
Last active October 21, 2023 22:11
Show Gist options
  • Save ology/91b3c4593e2733efd23c65451508e1ee to your computer and use it in GitHub Desktop.
Save ology/91b3c4593e2733efd23c65451508e1ee to your computer and use it in GitHub Desktop.
Replacing static pitches with VoiceGen
#!/usr/bin/env perl
use 5.26.0;
use List::Util qw(shuffle);
use MIDI ();
use Music::Factory ();
use Music::Scales qw(get_scale_MIDI);
use Music::VoiceGen ();
use Object::Pad;
my $srand = time();
srand $srand;
my $scale_name = shift || 'pminor';
my $octave = shift || 3;
my @pitches = (
get_scale_MIDI($scale_name, $octave),
get_scale_MIDI($scale_name, $octave + 1),
);
my @intervals = (-4 .. -1, 1 .. 4);
my $voice = Music::VoiceGen->new(
pitches => \@pitches,
intervals => \@intervals,
);
my @pitchselect = map { [ $voice->rand, $voice->rand ] } 1 .. 7;
class DoubleBeat :isa(Music::Factory::Generator) {
field $chan :param = 0; # MIDI channel
field $mul :param = 1;
# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment