I haven't heard anything new from 4ML, so i thought i would write a script that used their efforts. I took the without <CLUSTER> elements example from the samples page, added some "patch changes" and parsed it with XML::Simple. Next, i munged the data and used MIDI to create the MIDI file. The XML file is stored in the script's DATA filehandle for your convenience (well, mine at least ;)).

use strict; use warnings; use MIDI; use XML::Simple; use Data::Dumper; my $xml = XMLin(\*DATA); my $song = $xml->{SONG}; my @note = @{ $song->{NOTE} }; my $title = $song->{title} || 'unknown'; my $author = $song->{author} || 'unknown'; my (@event, $pitch, $duration, $velocity, $instrument); for my $note (@note) { # check for patch changes if (exists $note->{instrument}) { $instrument = $MIDI::patch2number{$note->{instrument}} || 1; push @event,[patch_change => 0, 1, $instrument]; } $pitch = scrub_pitch($note->{pitch},$pitch); $duration = ($note->{duration} || 1) * 96; $velocity = ($pitch eq 'rest') ? 0 : 96; # hacked silence # add note_on/note_off pair push @event,[note_on => 0,1,$MIDI::note2number{$pitch},$velocity]; push @event,[note_off => $duration,1,$MIDI::note2number{$pitch},0]; } my $opus = MIDI::Opus->new({ format => 0, ticks => $song->{bpm}, tracks => [ MIDI::Track->new({ events => [ [text_event => 0, "Title: $title"], [text_event => 0, "Auhtor: $author"], @event, ] })], }); $opus->write_to_file($song->{name}.'.mid'); # this transforms C into C4 and C:5 into C5 (etc.) sub scrub_pitch { my ($next,$prev) = @_; return $prev unless $next; my ($note,$octave) = split(':',$next,2); return $note if lc($note) eq 'rest'; $octave ||= 4; return "$note$octave"; } __DATA__ <?xml version="1.0" standalone="no"?> <!DOCTYPE OPUS SYSTEM "http://4ml.org/4ml.dtd"> <OPUS> <SONG name="mary" title="Mary Had a Little Lamb" bpm="160"> <!-- Define the notes here --> <NOTE pitch="E:5" /> <NOTE pitch="D:5" /> <NOTE pitch="C:5" /> <NOTE pitch="D:5" /> <NOTE pitch="E:5" /> <NOTE /> <NOTE /> <NOTE pitch="rest" /> <NOTE pitch="D:3" instrument="Harpsichord" /> <NOTE /> <NOTE /> <NOTE pitch="rest" /> <NOTE pitch="E:3" /> <NOTE pitch="G:3" /> <NOTE /> <NOTE pitch="rest" /> <NOTE pitch="E" instrument="Sitar" /> <NOTE pitch="D" /> <NOTE pitch="C" /> <NOTE pitch="D" /> <NOTE pitch="E" /> <NOTE /> <NOTE /> <NOTE /> <NOTE pitch="D" instrument="Bagpipe" /> <NOTE /> <NOTE pitch="E" /> <NOTE pitch="D" /> <NOTE pitch="C:3" duration="4" instrument="Church Organ" /> </SONG> </OPUS>

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Creating MIDI from XML by jeffa

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.