Cocoa

I learned Ruby on Rails without knowing Ruby by using the language as if it were made up of Rails idioms. When I needed a language construction, I would look elsewhere in my project source and in Rails tutorials, and copy it.

I'm hoping to do the same thing with Cocoa and Objective-C. My first project is to create an application that uses the WiiRemoteFramework by using the included DarwiinRemote project as an example. (Open Source can be so nice.)

Handy Resources

CocoaDev
It's a wiki that links to full guided Cocoa tutorials, and has many recipe-like pages like "HowToCreateAControllerClass" and "HowToUseOutlets." It's a good resource for Cocoa and Objective-C in general.
Cocoa Dev Central
Lots of Cocoa-specific guided tutorials for beginners who don't know how to code through advanced programmers who want to know how to do something specific, like make an application multi-threaded, or create a preference pane.

Wiimote Project

I've made progress on the Wiimote project! By brutally tearing out bits of code from the DarwiinRemote application, and connecting wires in Interface Builder as I saw appropriate, I now have something that detects the presence of the Wiimote and gets streaming updates about its current acceleration and button state changes.

Next, to learn me some MIDI...

MIDI

Okay, so I'm doing little more than throwing copy-pasted lines into my file and hoping they work... but I'm having issues!

-(void)awakeFromNib{
	[...]

	MIDIClientCreate(CFSTR("MIDI Tom"), NULL, NULL, &client);
	MIDIOutputPortCreate(client, CFSTR("Output port"), &outPort);
	dest = MIDIGetDestination(0);
	if(dest == NULL)
		[log setString:[NSString stringWithFormat:@"%@\n===== No MIDI =====", [log string]]];
	else
		[log setString:[NSString stringWithFormat:@"%@\n===== Sending MIDI =====", [log string]]];
}

… and later …

- (void) buttonChanged:(WiiButtonType)type isPressed:(BOOL)isPressed wiiRemote:(WiiRemote*)wiiRemote{
	if (type == WiiRemoteAButton){
		[log setString:[NSString stringWithFormat:@"%@\n===== BOING! =====", [log string]]];

		Byte buffer[1024];
		MIDITimeStamp timeStamp;
		MIDIPacketList *pktlist = (MIDIPacketList *)buffer;
		MIDIPacket *curPacket = MIDIPacketListInit(pktlist);
		Byte noteOn[] = { 0x90, 60, 64 };
		curPacket = MIDIPacketListAdd(pktlist, sizeof(buffer), curPacket,
									  timeStamp, 3, noteOn);
		MIDISend(outPort, dest, pktlist);
	}
}

When I start the program with SimpleSynth started, I get the "Sending MIDI" message in my text box "log," but when I press the button, I don't hear anything and don't see anything that would suggest that my MIDI message was sent. I do see "BOING!" though.

When I start the program without SimpleSynth running, I get the "No MIDI" message, as expected. So I'm fairly sure it's finding SimpleSynth all right. The MIDISend call later doesn't fail, though I hope I can look into why that is later…


Comments

Click here to view the comments on this post.