e dot dot dot
a mostly about the Internet blog by

March 2026
Sun Mon Tue Wed Thu Fri Sat
       


You can buy LG's premium soundbar system for nearly 50% off - Amazon Prime not required

Furnished content.


The LG S95TR sound system comes with a soundbar, two rear surround speakers, and a wireless subwoofer. You can pick one up for a discounted price at Amazon.

Read more here


posted at: 12:00am on 16-Mar-2026
path: /Technology | permalink | edit (requires password)

0 comments, click here to add the first



Musical Rhythms with Math in Perl

Furnished content.


Let’s talk about music programming! There are a million aspects to this subject, but today, we’ll touch on generating rhythmic patterns with mathematical and combinatorial techniques. These include the generation of partitions, necklaces, and Euclidean patterns.Stefan and J. Richard Hollos wrote an excellent little book called “Creating Rhythms” that has been turned into C, Perl, and Python. It features a number of algorithms that produce or modify lists of numbers or bit-vectors (of ones and zeroes). These can be beat onsets (the ones) and rests (the zeroes) of a rhythm. We’ll check out these concepts with Perl.For each example, we’ll save the MIDI with the MIDI::Util module. Also, in order to actually hear the rhythms, we will need a MIDI synthesizer. For these illustrations, fluidsynth will work. Of course, any MIDI capable synth will do! I often control my eurorack analog synthesizer with code (and a MIDI interface module).Here’s how I start fluidsynth on my mac in the terminal, in a separate session. It uses a generic soundfont file (sf2) that can be downloaded here (124MB zip).

fluidsynth -a coreaudio -m coremidi -g 2.0 ~/Music/soundfont/FluidR3_GM.sf2
So, how does Perl know what output port to use? There are a few ways, but with JBARRETT’s MIDI::RtMidi::FFI::Device, you can do this:
use MIDI::RtMidi::FFI::Device ();my  = RtMidiIn->new;my  = RtMidiOut->new;print "Input devices:\n";->print_ports;print "\n";print "Output devices:\n";->print_ports;print "\n";
This shows that fluidsynth is alive and ready for interaction.Okay, on with the show!First-up, let’s look at partition algorithms. With the part() function, we can generate all partitions of n, where n is 5, and the “parts” all add up to 5. Then taking one of these (say, the third element), we convert it to a binary sequence that can be interpreted as a rhythmic phrase, and play it 4 times.
#!/usr/bin/env perluse strict;use warnings;use Music::CreatingRhythms ();my  = Music::CreatingRhythms->new;my  = ->part(5);# [ [ 1, 1, 1, 1, 1 ], [ 1, 1, 1, 2 ], [ 1, 2, 2 ], [ 1, 1, 3 ], [ 2, 3 ], [ 1, 4 ], [ 5 ] ]my $p = ->[2]; # [ 1, 2, 2 ]my  = ->int2b([$p]); # [ [ 1, 1, 0, 1, 0 ] ]
Now we render and save the rhythm:
use MIDI::Util qw(setup_score);my  = setup_score(bpm => 120, channel => 9);for (1 .. 4) {    for my  (->[0]->@*) {        if () {            ->n('en', 40);        }        else {            ->r('en');        }    }}->write_score('perldotcom-1.mid');
In order to play the MIDI file that is produced, we can use fluidsynth like this:
fluidsynth -i ~/Music/soundfont/FluidR3_GM.sf2 perldotcom-1.mid
Not terribly exciting yet.Let’s see what the “compositions” of a number reveal. According to the Music::CreatingRhythms docs, a composition of a number is “the set of combinatorial variations of the partitions of n with the duplicates removed.”Okay. Well, the 7 partitions of 5 are:
[[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 3], [1, 2, 2], [1, 4], [2, 3], [5]]
And the 16 compositions of 5 are:
[[1, 1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 2, 1], [1, 1, 3], [1, 2, 1, 1], [1, 2, 2], [1, 3, 1], [1, 4], [2, 1, 1, 1], [2, 1, 2], [2, 2, 1], [2, 3], [3, 1, 1], [3, 2], [4, 1], [5]]
That is, the list of compositions has, not only the partition [1, 2, 2], but also its variations: [2, 1, 2] and [2, 2, 1]. Same with the other partitions. Selections from this list will produce possibly cool rhythms.Here are the compositions of 5 turned into sequences, played by a snare drum, and written to the disk:
use Music::CreatingRhythms ();use MIDI::Util qw(setup_score);my  = Music::CreatingRhythms->new;my  = ->compm(5, 3); # compositions of 5 with 3 elementsmy  = ->int2b();my  = setup_score(bpm => 120, channel => 9);for my  (->@*) {    for my  (@) {        if () {            ->n('en', 40); # snare patch        }        else {            ->r('en');        }    }}->write_score('perldotcom-2.mid');
A little better. Like a syncopated snare solo.Another way to play the MIDI file is to use timidity. On my mac, with the soundfont specified in the timidity.cfg configuration file, this would be:
timidity -c ~/timidity.cfg -Od perldotcom-2.mid
To convert a MIDI file to an mp3 (or other audio formats), I do this:
timidity -c ~/timidity.cfg perldotcom-2.mid -Ow -o - | ffmpeg -i - -acodec libmp3lame -ab 64k perldotcom-2.mp3
Okay. Enough technical details! What if we want a kick bass drum and hi-hat cymbals, too? Refactor time
use MIDI::Util qw(setup_score);use Music::CreatingRhythms ();my  = Music::CreatingRhythms->new;my  = ->compm(4, 2); # snaremy  = ->int2b();my  = ->compm(4, 3); # kickmy  = ->int2b();my  = setup_score(bpm => 120, channel => 9);for (1 .. 8) { # repeats    my  = ->[ int rand @ ];    my  = ->[ int rand @ ];    for my $i (0 .. $#) { # pattern position        my @notes = (42); # hi-hat every time        if (->[$i]) {            push @notes, 40;        }        if (->[$i]) {            push @notes, 36;        }        ->n('en', @notes);    }}->write_score('perldotcom-3.mid');
Here we play generated kick and snare patterns, along with a steady hi-hat.Next up, let’s look at rhythmic “necklaces.” Here we find many grooves of the world.World rhythmsImage from The Geometry of Musical RhythmRhythm necklaces are circular diagrams of equally spaced, connected nodes. A necklace is a lexicographical ordering with no rotational duplicates. For instance, the necklaces of 3 beats are [[1, 1, 1], [1, 1, 0], [1, 0, 0], [0, 0, 0]]. Notice that there is no [1, 0, 1] or [0, 1, 1]. Also, there are no rotated versions of [1, 0, 0], either.So, how many 16 beat rhythm necklaces are there?
my  = ->neck(16);print scalar @, "\n"; # 4116 of 'em!
Okay. Let’s generate necklaces of 8 instead, pull a random choice, and play the pattern with a percussion instrument.
use MIDI::Util qw(setup_score);use Music::CreatingRhythms ();my  = shift || 75; # clavesmy  = Music::CreatingRhythms->new;my  = ->neck(8);my  = ->[ int rand @ ];my  = setup_score(bpm => 120, channel => 9);for (1 .. 4) { # repeats    for my  (@) { # pattern position        if () {            ->n('en', );        }        else {            ->r('en');        }    }}->write_score('perldotcom-4.mid');
Here we choose from all necklaces. But note that this also includes the sequence with all ones and the sequence with all zeroes. More sophisticated code might skip these.More interesting would be playing simultaneous beats.
use MIDI::Util qw(setup_score);use Music::CreatingRhythms ();my  = Music::CreatingRhythms->new;my  = ->neck(8);my  = ->[ int rand @ ];my  = ->[ int rand @ ];my  = ->[ int rand @ ];my  = setup_score(bpm => 120, channel => 9);for (1 .. 4) { # repeats    for my $i (0 .. $#) { # pattern position        my @notes;        if (->[$i]) {            push @notes, 75; # claves        }        if (->[$i]) {            push @notes, 63; # hi_conga        }        if (->[$i]) {            push @notes, 64; # low_conga        }        ->n('en', @notes);    }}->write_score('perldotcom-5.mid');
And that sounds like:How about Euclidean patterns? What are they, and why are they named for a geometer?Euclidean patterns are a set number of positions P that are filled with a number of beats Q that is less than or equal to P. They are named for Euclid because they are generated by applying the “Euclidean algorithm,” which was originally designed to find the greatest common divisor (GCD) of two numbers, to distribute musical beats as evenly as possible.
use MIDI::Util qw(setup_score);use Music::CreatingRhythms ();my  = Music::CreatingRhythms->new;my  = 16;my  = ->rotate_n(4, ->euclid(2, )); # snaremy  = ->euclid(2, ); # kickmy  = ->euclid(11, ); # hi-hatsmy  = setup_score(bpm => 120, channel => 9);for (1 .. 4) { # repeats    for my $i (0 ..  - 1) { # pattern position        my @notes;        if (->[$i]) {            push @notes, 40; # snare        }        if (->[$i]) {            push @notes, 36; # kick        }        if (->[$i]) {            push @notes, 42; # hi-hats        }        if (@notes) {            ->n('en', @notes);        }        else {            ->r('en');        }    }}->write_score('perldotcom-6.mid');
Now we’re talkin’ - an actual drum groove! To reiterate, the euclid() method distributes a number of beats, like 2 or 11, over the number of beats, 16. The kick and snare use the same arguments, but the snare pattern is rotated by 4 beats, so that they alternate.

So what have we learned today?

  1. That you can use mathematical functions to generate sequences to represent rhythmic patterns.
  2. That you can play an entire sequence or simultaneous notes with MIDI.

References:



Read more here

posted at: 12:00am on 16-Mar-2026
path: /Programming/Perl | permalink | edit (requires password)

0 comments, click here to add the first



Amazon is selling Jackery's Explorer 2000 power station for 50% right now - and I can vouch for it

Furnished content.


Save $750 on the Explorer 2000 v2, Jackery's compact LiFePO4-powered backup power unit, perfect for in-home use, camping, and outdoor work.

Read more here


posted at: 12:00am on 16-Mar-2026
path: /Technology | permalink | edit (requires password)

0 comments, click here to add the first



Are free VPNs legit? I asked security experts to learn the true cost (and what services to avoid)

Furnished content.


You want to protect your privacy, but you don't want to pay. Is the solution a free VPN? Here's what to know before subscribing to one.

Read more here


posted at: 12:00am on 16-Mar-2026
path: /Technology | permalink | edit (requires password)

0 comments, click here to add the first



JD.com takes on Amazon in Europe as China's e-commerce titans expand globally

Furnished content.


JD.com is pushing same-day delivery and international brands as a way to help it compete with Amazon.

Read more here


posted at: 12:00am on 16-Mar-2026
path: /Technology | permalink | edit (requires password)

0 comments, click here to add the first



March 2026
Sun Mon Tue Wed Thu Fri Sat
       







RSS (site)  RSS (path)

ATOM (site)  ATOM (path)

Categories
 - blog home

 - Announcements  (0)
 - Annoyances  (0)
 - Career_Advice  (0)
 - Domains  (0)
 - Downloads  (3)
 - Ecommerce  (0)
 - Fitness  (0)
 - Home_and_Garden  (0)
     - Cooking  (0)
     - Tools  (0)
 - Humor  (0)
 - Notices  (0)
 - Observations  (1)
 - Oddities  (2)
 - Online_Marketing  (0)
     - Affiliates  (1)
     - Merchants  (1)
 - Policy  (0)
 - Programming  (0)
     - Bookmarklets  (1)
     - Browsers  (1)
     - DHTML  (0)
     - Excel  (1)
     - Javascript  (4)
     - PHP  (0)
     - PayPal  (1)
     - Perl  (44)
          - blosxom  (0)
     - Unidata_Universe  (22)
 - Random_Advice  (1)
 - Reading  (0)
     - Books  (0)
     - Ebooks  (0)
     - Magazines  (0)
     - Online_Articles  (3)
 - Resume_or_CV  (1)
 - Reviews  (2)
 - Rhode_Island_USA  (0)
     - Providence  (1)
 - Shop  (0)
     - Test-Store  (1)
 - Sports  (0)
     - Football  (0)
          - Cowboys  (0)
          - Patriots  (0)
     - Futbol  (0)
          - The_Rest  (0)
          - USA  (0)
 - Technology  (4869)
 - Windows  (1)
 - Woodworking  (0)


Archives
 -2026  March  (87)
 -2026  February  (164)
 -2026  January  (189)
 -2025  December  (171)
 -2025  November  (172)
 -2025  October  (168)
 -2025  September  (157)
 -2025  August  (169)
 -2025  July  (161)
 -2025  June  (155)
 -2025  May  (157)
 -2025  April  (149)
 -2025  March  (164)
 -2025  February  (151)


My Sites

 - Millennium3Publishing.com

 - SponsorWorks.net

 - ListBug.com

 - TextEx.net

 - FindAdsHere.com

 - VisitLater.com