ALSA MIDI programming with Perl

Programming applications for making music on Linux.

Moderators: khz, MattKingUSA

tux99
Established Member
Posts: 344
Joined: Fri Sep 28, 2012 10:42 am
Contact:

ALSA MIDI programming with Perl

Postby tux99 » Sat Oct 06, 2012 9:51 pm

I just discovered there is a Perl module that gives access to the ALSA MIDI functionality from within Perl:
MIDI::ALSA http://search.cpan.org/~pjb/MIDI-ALSA/ALSA.pm

Since Perl is the only programming language (apart from bash scripting) that I know quite well, I'm rather pleased about this Perl module and I'm planning to experiment with it (I'm thinking of writing some sysex dump apps for some of my hardware synths).

Has anyone used this Perl module? If yes any experience to share, any tips, tricks?

I found this blog that has an example app that uses this Perl module:
http://showmetheco.de/articles/2011/12/ ... -perl.html
Last edited by tux99 on Wed Oct 10, 2012 3:46 pm, edited 1 time in total.

tux99
Established Member
Posts: 344
Joined: Fri Sep 28, 2012 10:42 am
Contact:

Re: ALSA MIDI programming with Perl

Postby tux99 » Mon Oct 08, 2012 6:46 pm

Hmm, given the lack of replies I guess there aren't many (Perl) programmers around here.

Ok, I just did the following mini program that sends a sysex dump request to a Yamaha RM50 rhythm sound module and then receives the sysex dump in return. The program is still very basic, you need to adapt the midi ports and the type of dump request directly in the code, but it works and it's a good example of how easy it is to write ALSA MIDI apps with Perl using the MIDI::ALSA Perl module. Maybe this example will encourage some of you to have a go at ALSA MIDI programming with Perl yourself:

Code: Select all

#!/usr/bin/perl
use strict;
use warnings;

use MIDI::ALSA ('SND_SEQ_EVENT_PORT_UNSUBSCRIBED',
                'SND_SEQ_EVENT_SYSEX');

MIDI::ALSA::client('Perl MIDI test client',1,1,1);
MIDI::ALSA::connectfrom(0,28,0);
MIDI::ALSA::connectto(1,28,0);
MIDI::ALSA::start();

# Yamaha RM50 sysex bulk dump request strings
my $channel_setup_req    = 'C ~LM  0087ML';
my $system_setup_req     = 'C ~LM  0087SY';
my $prg_change_tbl_req   = 'C ~LM  0087PC';
my $int_voice_bank_req   = 'C ~LM  0087VI';
my $wave_card_voices_req = 'C ~LM  0087VW';
my $variation_voices_req = 'C ~LM  0087EP';
my $int_rhythm_kit_req   = 'C ~LM  0087KI';

# define bulk dump request to use
my $req_string = $int_voice_bank_req;

# send bulk dump request delayed by 1 sec
my @alsasysex = MIDI::ALSA::sysex(1,$req_string,1);
MIDI::ALSA::output( @alsasysex );

# sysex data appears to arrive in 256byte chunks so we need
# to loop until we recieve the sysex end byte (F7)
while (1) {
    # read next ALSA event
    my @alsaevent = MIDI::ALSA::input();
    # if the input connection disappears then exit
    if ( $alsaevent[0] == SND_SEQ_EVENT_PORT_UNSUBSCRIBED() ) {
        last;
    }
    elsif ( $alsaevent[0] == SND_SEQ_EVENT_SYSEX() ) {
        # save event data array
        my @data = @{$alsaevent[7]};
        # extract sysex data chunk
        my $sysexdata = $data[0];
        # print sysex data to STDOUT
        print $sysexdata;
        # if last byte is F7 then sysex dump is complete
        if ( substr($sysexdata,-1) eq chr(247) ) {
            last;
        }
    }
}

tux99
Established Member
Posts: 344
Joined: Fri Sep 28, 2012 10:42 am
Contact:

Re: ALSA MIDI programming with Perl

Postby tux99 » Tue Oct 23, 2012 7:39 pm

I'm currently working on a full patch editor for the Yamaha RM50 rhythm sound module using Perl, the Perl MIDI::ALSA module and Perl/Tk for the GUI. I knocked this up in a few hours this afternoon:

Image

This still needs a lot of work, it's far from ready yet, but I thought I post a screenshot to show what's possible with Perl and MIDI::ALSA.

tux99
Established Member
Posts: 344
Joined: Fri Sep 28, 2012 10:42 am
Contact:

Re: ALSA MIDI programming with Perl

Postby tux99 » Tue Nov 13, 2012 4:29 pm

A first 0.1 release of my Yamaha RM50 synth patch editor is now available.

For more details please check out my post about it on the Yamaha Forums:
http://www.yamahaforums.co.uk/forum/vie ... f=9&t=5915


If you own a Yamaha RM50 I highly recommend you to try the patch editor software, it makes editing the sounds soooo much easier!


Return to “Developer's Section”

Who is online

Users browsing this forum: No registered users and 1 guest