tags:

views:

69

answers:

1

I want to write a program that will generate random notes and draw them on the screen on a staff. I want to use Cocoa or Cocoa Touch. What's the best way to go about displaying the notes? Should I somehow use a music font, or pngs of each note, or what? Are there any good tutorials or sources of info out there on this topic?

A: 

I would be very tempted to use a custom music font and render it using the new ability in iOS4 to import custom fonts (I'm pretty sure it's iOS4 in general, and not just the iPad). I also assume that the entirety of CoreText is available on the mac too, but even if not, I'm sure the code wouldn't be vastly different.

Anyway, you can read about loading custom fonts here;

http://www.freetimestudios.com/2010/09/20/ipad-and-ios-4-custom-font-loading/

Or the slightly more hardcore way here;

http://www.freetimestudios.com/2010/09/13/custom-fonts-on-the-ipad-and-ios-4/

John Wordsworth
How about the rendering part? Obviously I couldn't just send it to an NSTextField. how would one position individual notes or symbols in the appropriate places?
TraxusIV
The second link above shows how you would configure a custom CATextLayer to use the font. Once you have created the Core Animation layer (the CATextLayer), you would then place it on the screen with the desired frame settings and then you should be able to add it to your views using the following... [self.view.layer addSublayer:myTextLayer]; I would position the notes on a line-by-line basis and let the font worry about spacing the notes apart as characters in a string. If you need to precisely place the notes at very specific spacings you might want to consider using a series of PNGs instead.
John Wordsworth
Is there any sneaky way to convert a music font into a set of pngs?
TraxusIV
That's a good question! I know that there are a lot of 'Bitmap Font Generators' that convert a font into a single PNG file (all of the characters are embedded in that one image). The 'Heiro Bitmap Font Generator' is one such tool. Just to clarify, are you looking at writing an OSX application or an iPhone app? As where I go from here would be different depending on platform!
John Wordsworth
Probably iphone, but I'd like to be able to use the same resources for a OS X version also. I'm guessing that using OpenGL in one form or another is probably the best way to go?
TraxusIV