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.

USB MIDI Interface!
Friday September 5, 2003

This morning I rode my bicycle for the first time in Fish Creek Park, which is right behind my backyard. I bought the bicycle last summer, but after I managed to put it together, it was too cold to go outside. It also didn't help that I had a hard time finding a helmet that'll fit. Apparently my head is unusually big :-)! And then I found out that I need a bell to ride in the park. Anyway I went out finally today. Nothing too interesting. Just a couple of deer, geese flying south, and a few beaver dams (no beavers, won't see them in the morning). I'll post some pictures here in the future when I see something interesting.

All my MIDI interfaces require a serial port connection to the Mac, which says something about how old my MIDI equipment is! The thing is I love the sound of my DX7-II and Wavestation, so I'll keep them running for as long as I can. I also run Mac OS classic on a PowerMac 8500 so I can continue to use all my old MIDI software: Vision DSP, Galaxy Plus Editor. Remember Opcode Systems? Hopefully I can write some software on the Mac OS X to replace them. That's what I'm trying to do with this Cocoa thing, and hopefully more.

Anyway I'd rather develop the MIDI programs on my iMac so I need a USB MIDI interface. I ordered a Edirol/Roland UA-20 from Kelly's Music and Computers in Manitoba on Tuesday and it arrived today. Pretty fast!


I played with it a little bit. Downloaded Pete Yandell's SimpleSynth program, hooked up a keyboard controller to the UA-20, and played the iMac like a general MIDI box. The sound was so so (due to Apple's sound fonts), but there really was no noticeable delay. The same cannot be said about the program SynthTest which can also be found on the Web. Perhaps CoreAudio and CoreMIDI were really designed for real-time audio and MIDI, unlike their counterparts in Mac OS classic. My next step will be to read the sample code on Yandell's site and other places and experiment with CoreMIDI. Perhaps a SysEx utility?

A Program that Prints Itself
Thursday September 4, 2003

While we're being nostalgic, here's a C version of a program I wrote in university. My first version was probably in Algol 60. Even this is about twenty years old. It's a good thing I pull it off my 5.25-inch floppies before I don't have access to these drives.

#include <stdio.h>
main()
{ char *s[11], *dq, *nl, *bs; int i;
  dq = "\\""; nl = "\\n"; bs = "\\\\";
  s[0] = "#include <stdio.h>";
  s[1] = "main()";
  s[2] = "{ char *s[11], *dq, *nl, *bs; int i;";
  s[3] = "%s%s";
  s[4] = " dq = %s%s%s%s; nl = %s%sn%s; bs = %s%s%s%s;%s";
  s[5] = " s[%d] = %s%s%s;%s";
  s[6] = " for (i=0; i<3; i++) printf(s[3], s[i], nl);";
  s[7] = " printf(s[4], dq, bs, dq, dq, dq, bs, dq, dq, bs, bs, dq, nl);";
  s[8] = " for (i=0; i<11; i++) printf(s[5], i, dq, s[i], dq, nl);";
  s[9] = " for (i=6; i<11; i++) printf(s[3], s[i], nl);";
  s[10] = "}";
  for (i=0; i<3; i++) printf(s[3], s[i], nl);
  printf(s[4], dq, bs, dq, dq, dq, bs, dq, dq, bs, bs, dq, nl);
  for (i=0; i<11; i++) printf(s[5], i, dq, s[i], dq, nl);
  for (i=6; i<11; i++) printf(s[3], s[i], nl);
}
When run, it prints an exact copy of itself to output. Adding a copyright notice to it will add two lines. So it's easier that I just put this program in the public domain.

Unfortunately (fortunately?), CS students don't work on problems like this any more.

My Ten-Year-Old Chinese Checkers Program
Wednesday September 3, 2003

Ten years ago I wrote a Chinese checkers program to run a contest. I've finished converting it today to run in Cocoa. You can download the resulting PB project MarblesX here. It's nice to know that the C code I wrote then still works, that it requires only a few changes (all due to old Toolbox Ptr type), and that I can still kind of understand it :-)! Here is a screen shot of the old version running in the Classic environment along side the new version.


Once you've downloaded and built MarblesX, here's how you play. Click on the piece you want to move, click its destination, then click the latter again to finalize. Before the last click, change your mind by clicking on another destination or on the piece to cancel.

A few things I notice. Constraints to the aspect ratio of a window are much easier to specify in Cocoa than in the old Mac OS Toolbox. It's also much nicer to draw in colors with alpha values. Also, “green” was a different color then!

Enjoy!

A Baby Scheme Interpreter
Tuesday September 2, 2003

I was studying the execution model of Scheme some time ago, and I thought the best way to learn it is to write a small Scheme interpreter myself. Everyone tells you how easy this is to do. I wonder how many of these people have actually done it :-). So I read the first few chapters of Kent Dybvig's thesis. Then I found some (current standard compliant) Scheme code on the Internet that implements his heap model. I thought it might be interesting to code it up in C++.

I challenged myself to write as small an interpreter as possible that performs call/cc correctly. I found that if C++ operator overloading and conversion operators are used correctly, the Scheme interpreter originally written in Scheme can be translated into C++ quite trivially!

Well, here is the code. The interpreter is quite lame in that it only supports the forms lambda, if, set!, call/cc, and function calls. It doesn't even have let so you'll have to bind variables with lambda instead, for example:

(((lambda (fib)
    ((lambda (k) fib)
     (set! fib (lambda (n)
                 (if (<= n 1)
                     1
                   (+ (fib (- n 1))
                      (fib (- n 2)))))))) '()) 10)

Some day, perhaps someone will add macros.

To build it, just say make. Note, however, that since flex is asked to generate a C++ lexer, a recent version is needed. The latest &laquo;stable&raquo; version (2.5.4) won't work. I'm using version 2.5.31. Please use that if you can.

All programs in my blog are released under Perl Artistic License unless otherwise noted.

Top 10 Types of Questions I (Don't Care to) Get about Emacs
Monday September 1, 2003

From actual questions I've received...

  • Questions about fonts/colors.
  • Reports of bugs long fixed.
  • Questions already answered in the FAQ.
  • Questions that begin “Dude!” or “Yo!”. (Am I suppose to write back the same way?)
  • Short questions written in instant-message style. (If you answer them, you know there'll be more.)
  • Questions that begin “I would have implemented such and such feature myself if I had time, ...”. (Yeah, right.)
  • Questions that begin “I have blank years of experience using Emacs/Unix/blah blah blah, ...”. (I couldn't care less!)
  • Questions from consultants (indicated on their signature lines). (Can you, errrr..., consult yourself?)
  • Questions too stupid to post to newsgroups for fear of ridicule. (But it's OK to send them to me, Emacs hacker?)
  • Questions about someone's (outdated) binary distribution. (Someone put a binary distribution on his company's “Products” page; another guy puts it under “Programs He Has Written!”. No, really!)
Yes, I watch Letterman.

August 2003
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
31

September 2003
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
Jul  Oct

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