jump to navigation

Audacity mods August 6, 2007

Posted by samwyse in Scripting.
trackback

This post will record my initial findings as I investigate modifications to Audacity to support some common use-cases. In particular, I’m interested in implementing the first bullet point of the section “Books on tape, field recordings, etc.”, and also all of the bullets listed under ” Looping and Dictation Aids”. All of these involve handling short-cut keys during the playing of an audio stream.

I’ll start my investigation at the top, AudacityApp.cpp. This file defines the like-named class, which is the primary control point for Audacity. It seems to handle most of the items found in the “File” menu, but of particular interest to me is that it filters all events, passing the raw key-up and key-down events to the active project.

In Project.cpp, the HandleKey{Down,Up} methods do three things. First, they respond to the Shift keys, swapping the “Play” and “Loop” functions on the control tool bar. Next, they forward all printable characters to the selected label track, if one exists. Finally, they pass the remaining events to the command manager.

The trail grows cold in CommandManager.cpp (cleverly hidden in the “command” sub-directory). This is where a hash table is searched for the key event and, if found, the appropriate call-back function is invoked. Unfortunately, I don’t know where the hash table is initialized. However, I do know that what I want will be very similar to the “Add Label At Playback Position” function, so I’ll grep for that string and see if I can find where the menu item is initialized.

I’m in luck! Menu.cpp is the place I’m looking for; there the item is associated with the OnAddLabelPlaying function, which gets the current audio stream position and creates a label at that point. I’ll just need to add a third parameter to the DoAddLabel method (defaulting to an empty string) and pass it along to the label track’s AddLabel method.

LabelTrack.cpp is where I’ll pause for now. The AddLabel method already accepts an optional string, so I won’t need to change anything here. However, it also leaves the new label selected, which means it will process any following key-press event. I don’t want that, so I’ll have to de-select the label once I’ve added it.

P.S. I just spotted an apparent bug in CommandManager.cpp:
if (!entry && entry->menu)
Unless I’ve forgotten everything I know about operator precedence, this will trigger a null pointer exception if entry is ever null. I suspect that they mean if (!(entry && entry->menu))

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: