<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Guitar Chords to MIDI in Objective-C</title>
	<atom:link href="http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/</link>
	<description>Code tidbits and tutorials.</description>
	<lastBuildDate>Sun, 11 Dec 2011 01:51:14 -0500</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: oohmyygoood</title>
		<link>http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/comment-page-1/#comment-16992</link>
		<dc:creator>oohmyygoood</dc:creator>
		<pubDate>Tue, 03 Nov 2009 11:34:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/#comment-16992</guid>
		<description>Hi again,

I figured out what the issue was with your code. In method writeFile you do:

&lt;code&gt;length = [track length]+3;
	[contents appendBytes:&amp;length length:4];
&lt;/code&gt;

You can&#039;t do that. You need to convert it into a char array just like you do in writeVarTime and appendNote.

Calling the following method will fix it:

&lt;code&gt;
- (NSMutableData *)appendUnsignedLong:(NSMutableData *)track longValue:(unsigned long)ul {
	char ch[4];
	
	ch[0] = ul &gt;&gt; 24;
	ch[1] = ul &gt;&gt; 16 &amp; 0xff;
	ch[2] = ul &gt;&gt; 8 &amp; 0xff;
	ch[3] = ul &amp; 0xff;
	
	[track appendBytes:ch length:4];
	
	return track;
}
&lt;/code&gt;

So in your writeFile method you would say:

&lt;code&gt;
contents = [self appendUnignedLong:contents unsignedLong:length];
&lt;/code&gt;

instead of:

&lt;code&gt;
[contents appendBytes:&amp;length length:4];
&lt;/code&gt;

Furthermore when you measure a track&#039;s length, you have to include the 3 bytes in the end of track marker { 0xFF, 0x2F, 0x00}

brgds</description>
		<content:encoded><![CDATA[<p>Hi again,</p>
<p>I figured out what the issue was with your code. In method writeFile you do:</p>
<p><code>length = [track length]+3;<br />
	[contents appendBytes:&amp;length length:4];<br />
</code></p>
<p>You can&#8217;t do that. You need to convert it into a char array just like you do in writeVarTime and appendNote.</p>
<p>Calling the following method will fix it:</p>
<p><code><br />
- (NSMutableData *)appendUnsignedLong:(NSMutableData *)track longValue:(unsigned long)ul {<br />
	char ch[4];</p>
<p>	ch[0] = ul &gt;&gt; 24;<br />
	ch[1] = ul &gt;&gt; 16 &amp; 0xff;<br />
	ch[2] = ul &gt;&gt; 8 &amp; 0xff;<br />
	ch[3] = ul &amp; 0xff;</p>
<p>	[track appendBytes:ch length:4];</p>
<p>	return track;<br />
}<br />
</code></p>
<p>So in your writeFile method you would say:</p>
<p><code><br />
contents = [self appendUnignedLong:contents unsignedLong:length];<br />
</code></p>
<p>instead of:</p>
<p><code><br />
[contents appendBytes:&amp;length length:4];<br />
</code></p>
<p>Furthermore when you measure a track&#8217;s length, you have to include the 3 bytes in the end of track marker { 0xFF, 0&#215;2F, 0&#215;00}</p>
<p>brgds</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: oohmyygoood</title>
		<link>http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/comment-page-1/#comment-16985</link>
		<dc:creator>oohmyygoood</dc:creator>
		<pubDate>Sun, 01 Nov 2009 12:26:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/#comment-16985</guid>
		<description>Hi,

This tutorial was very useful in explaining the Midi file specification, so thanks for that.

I&#039;ve tried to follow it to create my own midi file, but I keep getting an error message that the midi file cannot be opened when I try to import the file into Logic Pro.

Below follows my code:

[code]- (void)midiTest {

NSString *fileAtPathName = [[NSString alloc] initWithFormat:@&quot;%@MidiTest.mid&quot;, [mainDelegate documentsDirectoryName:YES]];
	
char header[18] = { &#039;M&#039;, &#039;T&#039;, &#039;h&#039;, &#039;d&#039;, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x40, 0x4D, 0x54, 0x72, 0x6B };
char end[3] = {0xFF, 0x2F, 0x00};
char guitar[3] = { 0x00, 0xC0, 0x19};
int iLength;
	
NSMutableData *contents = [[NSMutableData alloc] init];
NSMutableData *track = [[NSMutableData alloc] init];
	
[contents appendBytes:header length:18];
		
char deltaChar[1] = {0x00};
char noteOn[3] = { 0x90, 60, 100 };
char noteOff[3] = { 0x80, 60, 100 };
	
[track appendBytes:deltaChar length:1];
[track appendBytes:guitar length:3];
[track appendBytes:deltaChar length:1];
[track appendBytes:noteOn length:3];
deltaChar[0] = 0x24;
[track appendBytes:deltaChar length:1];	
[track appendBytes:noteOff length:3];
		
[track appendBytes:end length:3];

iLength = [track length];
[contents appendBytes:&amp;iLength length:4];
[contents appendData:track];
	
[[NSFileManager defaultManager] createFileAtPath:fileAtPathName contents:contents attributes:nil];
	
}
[/code]

What gives?</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>This tutorial was very useful in explaining the Midi file specification, so thanks for that.</p>
<p>I&#8217;ve tried to follow it to create my own midi file, but I keep getting an error message that the midi file cannot be opened when I try to import the file into Logic Pro.</p>
<p>Below follows my code:</p>
<p>[code]- (void)midiTest {</p>
<p>NSString *fileAtPathName = [[NSString alloc] initWithFormat:@"%@MidiTest.mid", [mainDelegate documentsDirectoryName:YES]];</p>
<p>char header[18] = { 'M', 'T', 'h', 'd', 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x40, 0x4D, 0x54, 0x72, 0x6B };<br />
char end[3] = {0xFF, 0x2F, 0x00};<br />
char guitar[3] = { 0x00, 0xC0, 0x19};<br />
int iLength;</p>
<p>NSMutableData *contents = [[NSMutableData alloc] init];<br />
NSMutableData *track = [[NSMutableData alloc] init];</p>
<p>[contents appendBytes:header length:18];</p>
<p>char deltaChar[1] = {0x00};<br />
char noteOn[3] = { 0x90, 60, 100 };<br />
char noteOff[3] = { 0x80, 60, 100 };</p>
<p>[track appendBytes:deltaChar length:1];<br />
[track appendBytes:guitar length:3];<br />
[track appendBytes:deltaChar length:1];<br />
[track appendBytes:noteOn length:3];<br />
deltaChar[0] = 0x24;<br />
[track appendBytes:deltaChar length:1];<br />
[track appendBytes:noteOff length:3];</p>
<p>[track appendBytes:end length:3];</p>
<p>iLength = [track length];<br />
[contents appendBytes:&amp;iLength length:4];<br />
[contents appendData:track];</p>
<p>[[NSFileManager defaultManager] createFileAtPath:fileAtPathName contents:contents attributes:nil];</p>
<p>}<br />
[/code]</p>
<p>What gives?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John</title>
		<link>http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/comment-page-1/#comment-15621</link>
		<dc:creator>John</dc:creator>
		<pubDate>Wed, 24 Jun 2009 18:29:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/#comment-15621</guid>
		<description>I&#039;m trying to get this to work on OS 10.4.11, but having a lot of trouble.  Any tips?</description>
		<content:encoded><![CDATA[<p>I&#8217;m trying to get this to work on OS 10.4.11, but having a lot of trouble.  Any tips?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: paul</title>
		<link>http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/comment-page-1/#comment-738</link>
		<dc:creator>paul</dc:creator>
		<pubDate>Tue, 01 Jan 2008 16:37:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/#comment-738</guid>
		<description>That&#039;s an intriguing idea, Steve... I&#039;ll have to think about that.</description>
		<content:encoded><![CDATA[<p>That&#8217;s an intriguing idea, Steve&#8230; I&#8217;ll have to think about that.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SteveP</title>
		<link>http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/comment-page-1/#comment-737</link>
		<dc:creator>SteveP</dc:creator>
		<pubDate>Tue, 01 Jan 2008 04:17:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.viscerallogic.com/programming/blog/2005/12/03/guitar-chords-to-midi-in-objective-c/#comment-737</guid>
		<description>Now this is cool.... :)   Maybe asking too much, but care to take a stab at the reverse?  Analyzing a MIDI file and pulling the chords out of it?  {smile}</description>
		<content:encoded><![CDATA[<p>Now this is cool&#8230;. <img src='http://www.viscerallogic.com/programming/blog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />    Maybe asking too much, but care to take a stab at the reverse?  Analyzing a MIDI file and pulling the chords out of it?  {smile}</p>
]]></content:encoded>
	</item>
</channel>
</rss>

