[cc65] A midi player for the cc65 targets ;)

From: Karri Kaksonen <karri1sipo.fi>
Date: 2005-09-06 10:31:56
As you may remember from 2004 I tried to start a discussion about a
simplified abc music library for the cc65 compiler.

During the last few days I have experimented with a package called abcMIDI.
It contains midi2abc and abc2midi. The cool thing is that it also contains a
reformatting package called abc2abc. This allows you to transpose the tune
and change the time base etc.

The sources are all available at sourceforge.net and they are quite modular.
Every tool uses the same parser and the output module is just one c-file
that can easily be changed to create new tools.

So I actually created an output module tocc65.c that outputs the tune as
a c-file that can be compiled by the cc65 and included in a project.

The steps required to play a midi-tune is then:

midi2abc Austin_Powers.midi > austin.abc
abc2c austin.abc > austin.c
compile austin.c and link it to your cc65 application.

The file austin.c will then contain the same number of instruments that
the original midi file had. Depending on your hardware you can then
play just the melody or perhaps the melody and a few other voices.

Ok. This was not a real midi player. But as the internet is swamped
with midi files this is an easy way of playing music on a cc65 target.

Here is what the Austin Powers theme looks like in 4 voices.
No editing by hand. This is what these tools produce.
Playing time is 2 minutes 34 seconds. The original midi file was 21k
and the resulting abc byte array is 3.7k. The original midi file played
on a multitimbral synthesizer sounds better than the abc file on the
Lynx. But the Lynx version is not bad either.

char voice1[] = {
// Flute 1
//MIDI program 73
// intro
"z16|z16|z16|z16|"
"z16|z12 zaf'f'|"
// Main tune (a)
"d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' d'd'z3af'f'|"
"d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' d'd'z3f'f'd'|f'f'z3f'f'd' 
f'f'z3af'f'|d'2z8z3af'f'|"
// Main tune (b)
"d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' 
d'd'z3af'f'|d'd'z3af'f' d'd'z3f'f'd'|"
"f'f'z3f'f'd' f'f'z3af'f'|d'2z12z2|"
// Flute bridge
"^fa6z ^fdzB edz2|^fa6z ^fdzB edz2|"
"^fa6z ^fdzB edz2|z12 zaf'f'|"
// Main tune (b)
"d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' d'd'z3af'f'|"
"d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' d'd'z3f'f'd'|f'f'z3f'f'd' 
f'f'z3af'f'|d'2z12z2|"
"z"
// Trumpet Bridge
"A2>B2B3 Az6z|zA2>B2B3 cz6z|zA2>B2B3 Az6z|zA2>B2B3 d2Be d2B2|"
// ad lib. solo
"d2=fd gfdd2ddA c2dA|c2dA c2dc2ddc dfgf|a2a2 c'a2c' d'd'd'c' agfc|dAcA 
c2^cd z8|"
// Flute bridge (DS)
"^fa6z ^fdzB edz2|^fa6z ^fdzB edz2|^fa6z ^fdzB edz2|z12 zaf'f'|"
// Main tune (b) (DS)
"d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' d'd'z3af'f'|d'd'z3af'f' 
d'd'z3af'f'|d'd'z3af'f' "
// Coda
"d'd'z3f'f'd'|"
"f'f'z3f'f'd' f'f'z3af'f'|d'2z8z3f'f'd'|f'f'z3f'f'd' f'f'z3af'f'|d'2z6 d'2"
};

char voice2[] = {
// Trumpet 1
//MIDI program 56
// intro
"z16|z16|z16|z16|"
"z16|a2za az2a aza2 z4|z16|z16|"
"z16|z12 z"
// Main tune (a)
"=ffd|ffz3ffd ffz3Aff|d2z12z2|"
"z3"
// Main tune (b)
"d z12|z3d z12|z3g z12|z3d z8 zffd|"
"ffz3ffd ffz3Aff|d2z12z2|z2"
// Flute bridge
"dz ddz2 dzdd z4|z2dz ddz2 dzdd z4|"
"z2dz ddz2 dzdd z4|zc'^c'^d' e'^f'g'^g' a'z6z|z3"
// Main tune (b)
"d z12|z3d z12|"
"z3g z12|z3d z8 zffd|ffz3ffd ffz3Aff|d2z8a2 gfdB|"
// Trumpet Bridge
"d6-dz2dfg2fdB|d6-dz3a2 gfdB|d6-dz2dfg2fdB|d6-dz8z|"
"z16|z16|z16|z16|"
"z2"
// ad lib. solo
// Flute bridge (DS)
"dz ddz2 dzdd z4|z2dz ddz2 dzdd z4|z2dz ddz2 dzdd z4|z=c'^c'^d' 
e'^f'=g'^g' a'z6z|"
"z3"
// Main tune (b) (DS)
"d z12|z3d z12|z3g z12|z3d z8 z"
// Coda
"ffd|"
"ffz3ffd ffz3Aff|d2z8z3ffd|ffz3ffd ffz3Aff|d2z6 f2"
};

char voice3[] = {
// Trombone 1
//MIDI program 57
// intro
"D,z2D z2D,z3D,z2Dz2|D,zD,D zDD,z D,zD,D zDD,z|D,zD,D zDD,z D,zD,D 
zDD,z|D,zD,D
zDD,z D,zD,D zDD,z|"
"D,zD,D zDD,z D,zD,D zDD,z|z16|z16|z16|"
"z16|z12 z"
// Main tune (a)
"B,B,^G,|B,B,z3B,B,^G, A,A,z3A,FF|D2z12z2|"
"z8 z2"
// Main tune (b)
"D,2 z4|z8 z2D,2 z4|z8 z2=G,2 z4|z8 z2B,2 zB,B,^G,|"
"B,B,z3B,B,^G, A,A,z3A,FF|D2z8z3^F,=G,^G,|"
// Flute bridge
"A,3z2^G,A,_B, =B,3z2^F,=G,^G,|A,3z2^G,A,_B, =B,3z2^F,=G,^G,|"
"A,3z2^G,A,_B, =B,3z2^CD^D|E6-Ez3A,,4-A,,z|z8 z2"
// Main tune (b)
"D,2 z4|z8 z2D,2 z4|"
"z8 z2=G,2 z4|z8 z2B,2 zB,B,^G,|B,B,z3B,B,^G, A,A,z3A,FF|=D2z12z2|"
"z"
// Trumpet Bridge
"A,2>B,2B,3 Dz6z|zD2>B,2B,3 A,z6z|zA,2>B,2B,3 Dz6z|zD2>B,2B,3 A,z6z|"
// ad lib. solo
"=G,zG,G zGG,z G,zG,G zGG,z|D,zD,D zDD,z D,zD,D zDD,z|A,zA,A zAA,z 
G,zG,G zGG,z|
D2z8z3^F,G,^G,|"
// Flute bridge (DS)
"A,3z2^G,A,_B, =B,3z2^F,=G,^G,|A,3z2^G,A,_B, 
=B,3z2^F,=G,^G,|A,3z2^G,A,_B, =B,3z
2^CD^D|E6-Ez3A,,4-A,,z|"
"z8 z2"
// Main tune (b) (DS)
"D,2 z4|z8 z2D,2 z4|z8 z2=G,2 z4|z8 z2"
// Coda
"B,2 zB,B,^G,|"
"B,B,z3B,B,^G, A,A,z3A,FF|=D2z8z3B,B,^G,|B,B,z3B,B,^G, A,A,z3A,FF|D2z6 D2"
};

char voice4[] = {
//MIDI channel 10
// Drums
// intro
"=G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|"
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,z2G, G,z2G, G,z^Cz4z|"
// Main tune (a)
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|"
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, 
^F,,^F,,^F,,^F, ^F,^F,,E,^F,,|"
// Main tune (b)
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|"
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|"
// Flute bridge
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|"
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,^F,,^F,,^F,, ^F,,^F,,^F,,^F,, 
^F,,z^Cz2=F,,F,,F,,|"
// Main tune (b)
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|"
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G, G,G,G,G,G,G,G,G,G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|"
// Trumpet Bridge
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G
, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|"
// ad lib. solo
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G
, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|"
// Flute bridge (DS)
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G
, G,G,G,G, G,G,G,G, G,G,G,G,|G,^F,,^F,,^F,, ^F,,^F,,^F,,^F,, 
^F,,z^Cz2=F,,F,,F,,
|"
// Main tune (b) (DS)
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G
, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, "
// Coda
"G,G,G,G, G,G,G,G,|"
"G,G,G,G, G,G,G,G, G,G,G,G, G,G,G,G,|G,G,G,G, G,G,G,G, G,G,G,G, 
G,G,G,G,|G,G,G,G
, G,G,G,G, G,G,G,G, G,G,G,G,|"
};

--
Karri
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Tue Sep 6 10:29:35 2005

This archive was generated by hypermail 2.1.8 : 2005-09-06 10:29:38 CEST