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.

Printing Page Headers and Footers in Cocoa
Friday October 29, 2004

It really isn’t difficult to print headers and footers (say to show filenames and page numbers) using Cocoa printing. What makes it difficult is the wrong and useless information in mailing list archives! Just try looking up drawPageBorderWithSize in a search engine.

Here’s a sample output with a title in the header and a page number in the footer. Two keys guarantee success:

  1. The view passed to printOperationWithView:printInfo: must not be a subview of another view. My first attempt was to pass the documentView of a scroll view; this result in all sorts of unexpected clipping. I ended up creating a separate NSView subclass just for printing.
  2. Here’s how to implement drawPageBorderWithSize in my NSView subclass (I assume that its isFlipped returns YES):
    
    - (void)drawPageBorderWithSize:(NSSize)borderSize
    {  
      [super drawPageBorderWithSize:borderSize];
    

    NSRect frame = [self frame];

    [self setFrame:NSMakeRect(0.0, 0.0, borderSize.width, borderSize.height)];

    [self lockFocus];

    int page = [[NSPrintOperation currentOperation] currentPage]; NSString *pageNumberString = [NSString stringWithFormat:@"- %d -", page];

    NSMutableDictionary *attribs = [NSMutableDictionary dictionary]; [attribs setObject:[NSFont systemFontOfSize:10.0] forKey:NSFontAttributeName]; NSSize pageNumberSize = [pageNumberString sizeWithAttributes:attribs];

    float bottomMargin = [[[NSPrintOperation currentOperation] printInfo] bottomMargin]; NSPoint pageNumberPoint = NSMakePoint((borderSize.width - pageNumberSize.width) / 2.0, borderSize.height - (bottomMargin + pageNumberSize.height) / 2.0);

    [[NSString stringWithFormat:@"- %d -", page] drawAtPoint:pageNumberPoint withAttributes:attribs];

    [self unlockFocus];

    [self setFrame:frame]; }

Transposition
Thursday October 28, 2004

Implemented a “transpose” function in the chord editor. Unlike BiaB and MiBAC Jazz, in my design the user can transpose chords in the current selection instead of always transposing entire tunes. Of course the transpose operations are recorded in the undo manager and can be undone and redone.

The implementation uses the jazz theory classes to handle enharmonic chord and note “spellings”. Correct spellings will therefore be used automatically for the transposed chords and bass notes. Since the chord editor cannot handle chord and note names that are double sharp or double flat, a dialog is displayed to inform the user that a transposition that results in such a chord or note name cannot be performed.

I’ve also begun to implement printing. This turns out to be quite easy to do. Here’s a PDF file output of one of my test files. I still need to find a way to print the song title and perhaps other useful information. Printing headers and footers seems to be a bit trickier.

On another note, took this picture of a bobcat cub behind my backyard today. I assure you that’s not my neighbor’s domestic cat!

Site Search
Wednesday October 27, 2004

Added a site search form in the right-hand column below the calendar.

Continued to test my program on BiaB files found on the Web. Among them was one that uses a “Cm69” chord, which wasn’t recognized by the import routine. Apparently this chord is only supported in newer versions of BiaB (mine is 6.0). Added that to my program. Also fixed a problem with reading BiaB files in 3/4 time.

Expressive Performance, Humanization, Groove Quantization
Tuesday October 26, 2004

I read a few papers on expressive performance a while ago and I went back today to look at some of them. It’ll take quite a bit of effort to incorporate these techniques into my program so I think I’ll wait until a later version.

I also played with the “groove quantization” function in the Opcode Vision MIDI sequencer a little. Although it does liven the sequence, I feel that it might be tiring to listen to sequences modified by the same groove over and over again.

So I’ve experimented with small changes to make the output of the accompaniment generation algorithms sound less mechanical. I think some of the more effective modifications may be ones that introduce variations. Here’s an accompaniment generated by today’s version of my program for the tune Desafinado. The high-hat is now louder on on-beats. Different drum patterns are played in sections A and B. The pattern for section A has two variations. Also, the durations of chords on the piano have been tweaked.

Bossa Nova!
Monday October 25, 2004

Adding bossa nova to the repertoire of styles that the automatic accompaniment program can handle required the addition of a few new instruments to my existing drum kit (rim shot and toms) and a way to disable “swing” in eighth notes. Implementing the accompaniment generation algorithms for a few styles provides insights into improvements on and streamlining of my jazz theory classes. I won’t make these changes now but will save them for version 2, when I’ll have a Python plug-in mechanism with which users can implement their own accompaniment generation algorithms.

Anyway here’s an example of an accompaniment generated by my program for the tune Desafinado. It sounds mechanical because I haven’t implemented expressive performance/humanization yet. I hope to work on that in the next few days.

October 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
31
Sep  Nov

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