Page 1 of 1

Developer question: KVO and Undo/Redo

Posted: Mon Dec 29, 2008 6:37 am
by inuwali
Executive summary:
I'm running into problems with a little feature I'm adding; it involves an additional text field in the TrackDrawer.

Background (you can skip this paragraph if you just want to see my question):
I import lots of classical music. I tag in a nonstandard way. Album titles are completely useless to me since most classical albums contain multiple works, and iTunes doesn't let you shuffle or browse by works (e.g. all symphonies). Therefore I've followed Stan Brown's lead and tagged the individual works as albums. They show up when I'm browsing, and they also show up nicely in the iPod display. (I also set the Artist tag to the composer of the work, since I don't often want to browse by the conductor or orchestra, and iTunes won't let me browse by composer.) All this is doable in Max, except tagging different tracks with different album titles.

What I did:
I added an "Album Title" text field to the track drawer so that individual tracks may be set to have different album titles, as can be done for title, artist, date, genre, composer and comment. So far I've modified the following source files:
AudioMetadata.h/mm (added an NSString to this object)
Track.h/m (added track-level album title to this model object to correspond to the view)
UndoRedo.strings (added a specific string for undoing changes to the new text field)
CompactDiscDocument.nib (added the field to the TrackDrawer, set up bindings)

What works:
Everything compiles, I can set a value in the new text field and when I tab out of it, the KVO triggers [track setAlbumTitle:] (which is my new mutator method).

What doesn't work:
If I select a different track and then the one that I was editing, changes I made to the new field do not survive. This is also the case for undo/redo (e.g. set a field to "X", tab away, then set it to "Y" and tab away. Edit->Undo should change it back to "X"; this works for all other fields but for my new field it empties out altogether). This makes me think I've missed something about undo/redo but I can't find any code in the project related to that, and I've combed through the IB stuff and come up with nothing there.

I'm not an experienced OS X coder, so while I have enough of a background to understand generally what's going on and throw in some of my own code, I apparently don't understand enough about KVO or Undo/Redo to get everything hooked up properly. Can anybody point me in the right direction?

Re: Developer question: KVO and Undo/Redo

Posted: Mon Dec 29, 2008 6:53 am
by inuwali

Found my own (1-character) error. Turns out that underscores can be kind of important. :roll:

I'll let you know if encoding actually works. I suspect there are still a few more code changes needed in the classes that manage that process.

Re: Developer question: KVO and Undo/Redo

Posted: Tue Dec 30, 2008 3:44 pm
by inuwali
OK, I got everything to work! I'm going to do some classical album rips with my new little addition. It makes life so much easier.

My question now is about official code. I have my own modified copy of the soucre, and I doubt that the changes would be acceptable in their current form (specifically the UI--the extra field would be very rarely used and likely to be confusing). Do any developers have a suggestion for how to incorporate the changes officially without negative effects? Perhaps a prefs setting?