My OS X Programming Blog
Mac OS X Cocoa and CoreMIDI Programming
About Andrew Choi


MIDI Programs

MIDI File Player (External Device)

MIDI Destination Pop-Up Button

MIDI File Player (Internal Synth)

MusicSequence Sample Code

MIDI File Writer

MIDI Name Document Parser

NameConfigSetup

Fish Creek MIDI Framework

MidnamUtility

SysExSenderX

Other Programs

FCBlogEditor

FCBlog and Patch

Chinese Checkers Program

jyut6 ping3 Cantonese Input Method

Cocoa Sample Programs

Syntax Coloring Using Flex

NSTextField and Undo

NSToolbar

Implementing File Import

Launch Application and Open URL

Saving Uncommitted Text Field Edits

Algorithms

Jazz Chord Analysis as Optimization

Optimal Line Breaking for Music

Optimal Chord Spacing

   

A blog where I will write mostly about programming in Cocoa and CoreMIDI, and experiences from my ports of Emacs and XEmacs to the Mac OS.

Chord Spacing Within a Bar
Friday April 16, 2004

Now that we have a dynamic programming algorithm for finding an optimal layout of bars on a page, how should we determine the width of each bar initially? In other words, given a bar containing a number of chords, what should be the spacing between them?

A few principles must be followed:

  • The text box that contains each chord must be large enough for it.
  • The widths of the bars should be equalized as much as possible.
  • Chords should line up on their respective beats as much as possible.
Here're a few examples of the layout of chords within a bar generated by my current code. I still need to improve it but it shows the kind of problems that one encounters.

The chord names in the first example are all quite short. So the text boxes containing them are evenly spaced. In the second and third examples, although the chord names are longer, there is sufficient space for them to line up on their respective beats. The name of the first chord in the fourth example is longer so we adjusted the spacing proportionally to accommodate all four chords. The fifth example shows that when chord names are very longer, the width of the bar needs to be increased to contain them.

Sample Code for Choosing a Font Using the Font Panel
Thursday April 15, 2004

I haven’t posted code on this blog in a while. I’ve been thinking about making a product out of the accompaniment generation program that I’ve been developing. That’s why I’ve not posted any of its code. Some time after the program is released, I will probably release part of its core. I think it would be great for other people to be able to experiment with my jazz theory classes and with accompaniment generation algorithms. I’m also thinking about converting these to Python so they can be “messed around with” more easily. This will tie into mechanisms for writing extendible applications I was working on last year.

In the mean time learning to program on the Mac is made difficult for all by a lack of well-written sample code (that on the Apple developer site notwithstanding). I was looking for code that demonstrates the use of NSFontPanel and failed to find any good one. In any case here’s one I’ve written today.

Build and run it. Choose “ChooseFontTest->Preferences...”, and click Set... to bring up the font panel. The rest is like any other Mac application. This sample code also demonstrates the use of NSUserDefaults to remember the preferences between invocations. The preferences will be stored in the file ~/Library/Preferences/ChooseFontTest.plist in case you’d like to delete it after playing with the program.

Optimal Line Breaking for Music
Tuesday April 13, 2004

How should one determine the layout for displaying a chord sequence in a window? Both BiaB and MiBAC fix the width of the bars. Since bars naturally vary in widths due to differences in the number of chords contained in them and the widths of the chord names, why can’t a chord editor be more like a word processor and display them in “proportional spacing”? Better yet, why can’t it be more like a typesetting system, where spacing is optimized for entire paragraphs? Well, why not?

The line breaking problem in typesetting can be adapted for displaying chord sequences. It’s quite a simple problem and has often been used to illustrate dynamic programming in algorithms books. It’s interesting to note that this excerpt of an online book gives an O(mn^2) time solution. But of course the best time for the problem is O(mn) time (see my formulation for such a solution). Just goes to show how dynamic programming can be useful as well as misused! If we’re using this in an interactive editor, the faster solution will make a big difference.

Chord Editor
Monday April 12, 2004

I need a design for the GUI of the accompaniment generation program. The center of the GUI will be a grid to enter chords. The easiest way to enter chords is probably to play them on a MIDI keyboard. But we need at least a way for the user to type in the chords from the Mac keyboard. Either way we need a grid to display the entered chords.

I find the BiaB GUI quite unappealing. Its menus are cluttered and unwieldy. Chords are edited in a separate text box (why?) before being placed in the grid. A proper GUI should allow the chords to be edited in place.

The MiBAC GUI isn’t a lot prettier (but its design is cleaner) and looks like a System 7 application (which it is!). Also the spacing is wrong when two chords occupy the same bar.

I experimented with displaying chords with the unicode sharp ♯ and flat ♭ instead of the ASCII # and b. I also experimented with different fonts. Here is a sample.

An NSFormatter subclass allows sharps and flats to be typed into a NSTextField using the # and b keys and displayed as their unicode counterparts. It’s all very nice.

April 2004
Sun Mon Tue Wed Thu Fri Sat
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
Mar  May

xml

Search this blog with


Lists

Less-Known Facts About Emacs

Emacs Rants

Chinese Restaurants in Calgary

Calgary/Banff Tourist Attractions

C++ Reading List

Science Fiction Series

Top-10 Reason I Stopped Working on Emacs

Top-10 Types of Questions I Get About Emacs

10 Defining Moments as Programmer


Misc

Carbon XEmacs

Emacs for Mac OS X


Copyright © 2003, 2004, 2005 Andrew Choi (Contact Information). Created with FCBlog