Following the midi crash course written by Daniel White, and using a table of midi note numbers, it is rather easy to write a Maple procedure producing midi files. Here is an example that I posted in Simple Sounds thread, slightly modified by adding an instrument as a 3rd parameter:

midi:=proc(f,L,instr:=1)
local m,n,c;
n:=nops(L);
c:=[60, 62, 64, 65, 67, 69, 71, 72];
m:=[77, 84, 104, 100, 0, 0, 0, 6, 0, 0, 0, 1, 0, 128, 77, 84, 114, 107, 
ListTools:-Reverse(convert(2^32+7*n+8,base,256))[2..-1][], 
0,192,instr-1, 0, 144, c[L[1]+1], 96,
seq([129,0,c[L[i]+1],0,0,c[L[i+1]+1],96][],i=1..n-1),
129,0,c[L[-1]+1],0,0,255,47,0];
writebytes(f,m);
close(f)
end;

midi("filename.mid", L) produces a midi file "filename.mid" from a list L containing numbers from 0 to 7 corresponding to middle C for 0, D for 1 etc.

For example, one can listen to a music of octal digits of pi or e,

pi:=ListTools:-Reverse(convert(round(evalf(Pi*2^63,21)),base,8));

  pi := [3, 1, 1, 0, 3, 7, 5, 5, 2, 4, 2, 1, 0, 2, 6, 4, 3, 0, 2, 1, 5, 2]

midi("pi.mid",pi);

e:=ListTools:-Reverse(convert(round(evalf(exp(1)*2^63,21)),base,8));

  e := [2, 5, 5, 7, 6, 0, 5, 2, 1, 3, 0, 5, 0, 5, 3, 5, 5, 1, 2, 4, 6, 5]

midi("e.mid",e);

The third parameter allows to change the instrument from the piano (default), to a guitar (a number from 25 to 32), a violin (41), a clarinet (72) etc. according to the standard patch map.

For example, for the list L from Robert Israel's post in the Simple Sounds thread,

L := [3,2,1,2,3,3,3,2,2,2,3,5,5];

midi("tenorsax.mid",L,67);

produces a Tenor Sax music fragment.

You can provide the complete path to the file - like "C:/temp/tenorsax.mid" for example, in Windows, instead of "tenorsax.mid" in the example above. If the path is not provided, it is located in Maple's working directory, which can be found using curentdir(). The working directory can be also changed using currentdir.

To play it in Windows, one can just (double)-click the file in Windows Explorer, and it will play in Windows Media Player.

Alec


Please Wait...