<?xml version="1.0"?>
<rss version="2.0">
	<channel>
		<title>Another MIDI Question + 1st Version of VirtualPiano Attached!</title>
		<link>http://www.allegro.cc/forums/view/586224</link>
		<description>Allegro.cc Forum Thread</description>
		<webMaster>matthew@allegro.cc (Matthew Leverton)</webMaster>
		<lastBuildDate>Wed, 05 Jul 2006 00:24:20 +0000</lastBuildDate>
	</channel>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Now that I know how to find out which note the MIDI player is playing, how do I change the tempo?<br />I&#39;m planning to add it as a feature to my virtual piano program.<br />By the way, anyone wants to see the first version? (It&#39;s not 3D yet and there are no hands that play the music, but hey, it&#39;s a start!)<br />I&#39;ll attach a self-extracting .RAR archive to the post.<br />(Includes the compiled .exe, the source code and some old recordings of me!)<br />Watch the program play the third move of the Moonlight Sonata and imagine how fast I had to move my fingers to play it! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Big)</author>
		<pubDate>Sun, 02 Jul 2006 13:50:27 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Quote:</div><div class="quote"><p>
Watch the program play the third move of the Moonlight Sonata
</p></div></div><p>
Ahaa, so you wrote it in C#. Well, C# minor.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Johan Halmén)</author>
		<pubDate>Sun, 02 Jul 2006 15:20:29 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>L0L! <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /><br />So, does it work?<br />Have you spotted any bugs or memory leaks?<br />There were parts in the program that required the usage of pointers, and me and pointers don&#39;t get along too well with eachother.<br />If it kills your system please don&#39;t be angry at me...
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Big)</author>
		<pubDate>Sun, 02 Jul 2006 15:35:10 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I remember slowing down MIDI files by altering one of the bytes in the header with a hex editor.  Might have been byte 0xC?  Global speed or something.  Maybe you can have your program alter how it uses that or alter the value after it&#39;s read into memory so you don&#39;t have to alter the files.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Arthur Kalliokoski)</author>
		<pubDate>Sun, 02 Jul 2006 22:14:59 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>May I suggest that you use something other than a self-extracting RAR archive to distribute your source?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Evert)</author>
		<pubDate>Sun, 02 Jul 2006 22:45:04 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>I&#39;ve included the source code so you could compile and run the program on other platforms and packed it in a .EXE self extractor...<br />How stupid of me! <img src="http://www.allegro.cc/forums/smileys/embarassed.gif" alt=":-[" /><br />I&#39;ll attach a .ZIP instead.</p><p>[EDIT]</p><p>I found this during a Google search:</p><p>&quot;To extract the tempo data of a MIDI file, you must find the metaevent which<br />specifies this. This will look like this in hex:<br />FF 51 03 xx yy zz</p><p>Use filein and then use the match object to find FF 51 03 (247 81 3 in decimal) and<br />then get the next three bytes. These are concatenated to form a 24bit number, xx is<br />the MSB and zz the LSB. This represents the number of microseconds per quarter<br />note. So, if you divide the 24bit number into 60,000,000 the result will be in<br />bpm.</p><p>Bear in mind that this event may be used throughout the MIDI file for dynamic tempo<br />changes.<br />The one you want is most likely (but not always) the first.&quot;</p><p>So I need to modify the next three bytes after FF 51 03.<br />How do I do that?<br />Maybe the &#39;midi_out&#39; function of Allegro could help?<br />This is Chinese to me... <img src="http://www.allegro.cc/forums/smileys/huh.gif" alt="???" /><br />This is not the kind of thing I usually deal with.<br />Could anyone please help?
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Big)</author>
		<pubDate>Mon, 03 Jul 2006 00:00:46 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You need to construct the MIDI command data yourself and send it to midi_out().</p><div class="source-code snippet"><div class="inner"><pre><span class="k1">char</span> mdata<span class="k2">[</span><span class="n">6</span><span class="k2">]</span> <span class="k3">=</span> <span class="k2">{</span><span class="n">0xFF</span>, <span class="n">0x51</span>, <span class="n">0x03</span><span class="k2">}</span><span class="k2">;</span>

mdata<span class="k2">[</span><span class="n">3</span><span class="k2">]</span> <span class="k3">=</span> blah<span class="k2">;</span>
mdata<span class="k2">[</span><span class="n">4</span><span class="k2">]</span> <span class="k3">=</span> blah<span class="k2">;</span>
mdata<span class="k2">[</span><span class="n">5</span><span class="k2">]</span> <span class="k3">=</span> blah<span class="k2">;</span>

<a href="http://www.allegro.cc/manual/midi_out" target="_blank"><span class="a">midi_out</span></a><span class="k2">(</span>mdata, <span class="n">6</span><span class="k2">)</span><span class="k2">;</span>
</pre></div></div><p>

To get the BPM I believe it will be:</p><p>60,000,000 / BPM;</p><p>I don&#39;t know how to construct the 24-bit integer value but I&#39;m sure you could get it with just a couple of tries.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Todd Cope)</author>
		<pubDate>Mon, 03 Jul 2006 03:01:23 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>You have another problem to look at.  Your program doesn&#39;t read the key of the midis.   I know how to play about half of the moonlight sonata myself and it&#39;s playing it incorrectly because it&#39;s reading all the notes as naturals.  I could be reading an arranged piece, but I&#39;m pretty sure it&#39;s correct.  <img src="http://www.allegro.cc/forums/smileys/undecided.gif" alt=":-/" />
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Mon, 03 Jul 2006 20:48:22 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><div class="quote_container"><div class="title">Evert said:</div><div class="quote"><p>
May I suggest that you use something other than a self-extracting RAR archive to distribute your source?
</p></div></div><p>
What&#39;s wrong with .rar archives? Typically smaller filesize than .zip and you can just download a free program to open them. <a href="http://rarlabs.com">RARLabs</a>
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Jeff Bernard)</author>
		<pubDate>Tue, 04 Jul 2006 00:58:17 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>There&#39;s nothing wrong with regular RAR archives. <i>Self-extracting</i> archives, however, are works of the devil.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (gnolam)</author>
		<pubDate>Tue, 04 Jul 2006 01:14:11 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Todd Cope, thanks, now all I have to do is to figure what to put there instead of &quot;blah-blah-blah&quot;. <img src="http://www.allegro.cc/forums/smileys/grin.gif" alt=";D" /></p><p>Brian, everything is fine.<br />It&#39;s just that not every synthesizer has the middle C as key number 60.<br />Set &#39;offset&#39; to -4 and it&#39;ll show the correct keys.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Mr. Big)</author>
		<pubDate>Wed, 05 Jul 2006 00:07:15 +0000</pubDate>
	</item>
	<item>
		<description><![CDATA[<div class="mockup v2"><p>Oh ok I fixed it up, it works now.  Heh.
</p></div>]]>
		</description>
		<author>no-reply@allegro.cc (Paladin)</author>
		<pubDate>Wed, 05 Jul 2006 00:24:20 +0000</pubDate>
	</item>
</rss>
