if its too loud, turn it down

Saturday, February 13, 2010

A pocket audio guide to Peter Matthiessen, E.J. Watson and "Shadow Country"


(click here to skip down to the audio section)

"I don't go looking for trouble...but when trouble comes to me, why, I take care of it."

Sounds like something Clint Eastwood would say in a spaghetti western. Instead, it was uttered by an even more mysterious and enigmatic bad-ass named E.J. Watson, the real-life main character of Peter Matthiessen's epic book entitled "Shadow Country - A New Rendering of the Watson Legend". It truly is the Great American Novel. It consumes you, makes you want to know more...stays with you long after you've finished reading it.

EJ Watson

A rare photo of E.J. Watson himself,
from the PBS documentary "No Boundaries"

E.J. Watson so fascinated Matthiessen that he devoted 30 years (more than a third of his life) to researching, writing, and imagining the Watson character and the myth that surrounded him. Originally, Matthiessen published the story as three separate books, dubbed "The Watson Trilogy" in the 90s. But he was never quite satisfied with it, so he took 10 years to completely re-write it, and published "Shadow Country" in 2008. The book is classified as a work of fiction, but as Matthiessen says, "it's the closest to the truth that anybody's ever come." Unconcerned with plot, Matthiessen kills Watson off in the first few pages of the book, and spends the remainder of the 900-some pages discovering just who this E.J. Watson guy is. Ultimately Matthiessen wanted to answer the very first question he ever had about Watson...why a large group of Watson's neighbors — who admitted they genuinely liked and admired him — felt they needed to kill him with a barrage of bullets. Thirty-three bullets to be exact, not counting buckshot...and the ones that missed.

E.J. Watson's various monikers speak to his diverse personality. His given name was Edgar Artemis Watson, born 1855 in Edgefield County, South Carolina (which Matthiessen claims is the most violent county in American history) where he grew up under the thumb of a abusive, drunken father. Fleeing his father, Watson left home early and bounced between North Florida and the "Nations" of Oklahoma. He developed a reputation as a killer when he was tried (but acquitted) in Oklahoma for the murder of the female outlaw Belle Starr. He later escaped from jail, and likely a lynching, where he was being held on suspicion of horse theivery — a crime considered worse than murder in those days. He fled to the primitive, sparsely-populated wilderness of southwest Florida known as 10,000 Islands, where he changed his name to E.J. ("Jack") Watson, ostensibly to seperate himself from his past. 10,000 Islands (now part of the Florida Everglades National Park) was a haven for outsiders, deserters and men on the run from the law. It was truly a frontier land, even well into the 20th century. A character in the book calls 10,000 Islands "the ass end of hell." Even today, the Florida Everglades and the adjacent 10,000 Islands and Big Cypress is the largest roadless area in the lower 48.

In Southwest Florida, Watson painstakingly hacked out a 40-acre sugarcane farm from the dense mangrove and shell soil, and built a very successful cane syrup business from scratch. His sugarcane farming methods are believed to be the foundation of Florida's large sugarcane industry today. In this frontier land, where he became known as "Planter Watson", he changed his reputation from that of an outlaw to one of a hard-working, entreprenurial businessman who was well-liked and well-respected among his neighbors, associates and, uh...quite a few women. He had three wives (not all at the same time), and a number of other mistresses. He was ruggedly handsome, intelligent (known for quoting Shakespeare), had an affable personality, was very generous, could tell a great story, and had a real sense of humor. People just plain liked him.

Chatham Bend

The approximate location of Watson's cane farm, Chatham Bend
(click to view in larger map)

But Watson still had a dark side. He was a heavy drinker with an explosive temper, and considering he was unusually tall, unusually strong and had icy cold blue eyes...he seems like the kind of guy you wouldn't want to mess with. As one character describes him, "He looked like God, and he looked like Satan and he looked like Uncle Sam...all three at once!" He always dressed well, even when he was at work in the fields. Kept a pistol in his pocket at all times and was known to be a deadeye shot with any firearm. Legend has it Watson killed dozens of people who crossed him, though Matthiessen (who's obviously done by far the most exhaustive research on Watson) isn't so generous. He says, "I couldn't seperate him from about seven [killings]". One legend is of the "Watson Payday" where he employed folks — usually loners and drifters — for an entire season of cane growing, and after the harvest when they went to get paid they got killed instead. Not quite the reward they'd hoped for! It was through rumors like this that he earned his most infamous nickname, "Bloody Watson." In one interview, Matthiessen relates how when researching Watson, he came across a family in New York (need to verify) who used to tell their children "now you get to bed, or Mr. Watson's gonna git ya!" Nice parents. But it speaks to the power of the mythical "Bloody Watson"...he became the quintessential boogyman. He was both good and evil, charismatic and dangerous. I can see why Matthiessen would want to solve the enigma of the Watson character. When asked how Matthiessen filled in the gaps of what was known about Watson, he says "I put myself in him." So what we get is a synthesis of the real person of Watson, with elements of the author himself.

The other important character in "Shadow Country" is the land itself. Two common threads in all of Matthiessen's books (not that I've read them all, this is just what he says) are "marginalized people, places and creatures" and "the frayed relationship humans and nature." While not terribly hospitable to people (except the natives), the Everglades hosted a rich and diverse ecosystem of birds, fish, reptiles and other wildlife, and Calusa (now extinct), Seminole and Mikasuki indians who had been there for thousands of years. But commercial fishing and hunting wreaked havoc on the land, and the federal government itself nearly destroyed it entirely by undertaking a massive wetland drainage program in the late 1800s. Three bloody Seminole Wars were fought there between the natives and the US Army, though the indians were never actually subverted. Matthiessen's descriptions of the land and it's trials are a major element in the book, and are in fact a metaphor for the checkered past of the United States as a whole. His alchemy with words sets a sense of place in my mind like no other book has ever done.

For his massive 30-year undertaking, Matthiessen won the 2008 National Book Award. It was his second National Book Award — his first was for "The Snow Leopard" in 1978.

Peter Matthiessen


Peter Matthiessen

Similar to Matthiessen's obsession with the character of Watson, I'm fascinated with Matthiessen himself. I find Matthiessen's story every bit as intriguing as Watson's.

Matthiessen developed his love for nature and wild animals at an early age, having grown up in rural Connecticut (as a child he kept a den of copperhead snakes as pets). He and his brother roamed the Connecticut backcountry hiking, fishing and birding. For school, he boarded and later went to Yale where he presumably cut his chops as a writer. Matthiessen then went on to serve in the Navy in WWII. Afterwards — and this is where it gets interesting — he was recruited by the CIA and sent to Paris to spy on what the CIA deemed to be Communist threats. As cover he began the famous literary magazine, "The Paris Review" with his childhood friend George Plimpton. As cover! Matthiessen calls his 2-year stint with the CIA "the only adventure I've ever regretted." He very obviously does not like to talk about it. He says he quit because he found himself more in line with those who he was trying to spy on than his employers.

He later became a commercial fisherman, then a charter boat captain, and also tried to make a living as a fiction writer. But, by this time he was married with kids and was having a hard time paying the bills. He soon discovered that non-fiction was the way to go for making money. He got hooked up with an editor at the New Yorker who liked his work, and that launched his writing career in earnest.

In total, Matthiessen's written 30-plus books, both fiction and non-fiction. Although he is most well-known for his non-fiction (i.e. "The Snow Leopard"), he is very clear that his heart is in fiction writing. He says he did non-fiction "to pay the bills" and doesn't like writing it because, "you're stuck with the facts...or should be, anyway." His books are usually well-received critically, though he's had only two New York Times bestsellers in his career, "Far Tortuga" and "Killing Mister Watson" (the first book of the "Watson Trilogy").

Not unlike his buddy E.J. Watson, Matthiessen is nothing if not diverse himself. In addition to a successful writing career, Matthiessen is also well-known as an explorer, a political activist, environmentalist, an expert birder, and a Zen Rōshi. His spiritual path that led to Zen Buddhism began in the 60s, when he and his then-wife (who later died of cancer) were heavily into experimental drugs, particularly LSD. To this day he claims that if properly prepared, LSD can offer deep insight into one's mind (he does not still use LSD). Searching for non-checmically-induced methods to achieve altered states of consciousness, he and his wife eventually discovered Zen Buddhism in the 70s, which he still practices and teaches today.

Audio of Peter Matthiessen

I've found the best way to get into the mind of Peter Matthiessen is to listen to him talk. Preferably, on my iPod. So, for myself, and any other Matthiessen fans who'd like to partake, I've compiled a complete set of Peter Matthiessen interview/lecture/monologue mp3s for your iPod listening pleasure. Many of these were ripped from video (with WireTap), and in those cases I included the link to the video in case you want to watch that as well, which you should.

Listening to Matthiessen speak is a unique experience. At 82 years of age, he has a deep, wise, gravelly voice...you can almost hear the Zen within it. Some of the topics covered in the interviews are repetitive, he appears to have had "talking points" when making the media rounds promoting his books (mostly "Shadow Country"). However, there are distinct nuggets of goodness in each and every one. No interview is exactly the same as another. If you listen to all of these, you'll end up feeling like you know him pretty well.

As serene as he comes across, an interesting thing I discovered is that he is also somewhat of a crank (his words). He is an exceedingly private person. Dislikes it when people recognize him in public and hates it when devotees of his writing visit his house. Virtually nothing is known about his Tanzanian-born second wife, and he rarely mentions her in interviews. When sitting on planes, the first thing he does is give his seat-mate a icy cold look as if to say "I am not chatty." He also says being a Zen Rōshi does not preclude him from feeling rage about what he perceives as injustices. He speaks quite strongly against George Bush, Big Oil, the FBI (who actually sued him) and various other people or organizations that antagonize the causes he's invested himself in.

The files are in the order of the most recent first. I've included a brief synopsis of the forum and topic for each mp3 below. I also bolded the ones I think are of particular interest. Enjoy the words of one of America's most gifted and prolific living authors!

Forum : WPSU Conversations at Penn State - Author's Reflections
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 56:16
Air Date: Thursday, January 21, 2010
Description : This one's interesting because it doesn't talk much about Shadow Country. He talks about his life and the highlights include his 2-year stint as a spy for the CIA, his LSD usage with his first wife, and his path to Zen.

Forum : 2008 National Book Awards
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 10:32
Air Date: February 2, 2009
Description : Gail Godwin presents the 2008 National Book Award in Fiction to Peter Matthiessen, for "Shadow Country." Eric Bogosian introduces Godwin.

Forum : PBS NewsHour's "Art Beat" segment
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 14:12
Air Date: December 31, 2008
Description : Jeffery Brown interviews Matthiessen, mostly about Shadow Country. Matthiessen also reads from his book. I included both segments in the audio.

Forum : Salt Lake City Public Library
Media : Article | MP3 (right-click and choose "save as" or "save target as"
Stream :
Length : 1:43:41
Air Date: November 13, 2008
Description : Peter Matthiessen and photographer Subhankar Banerjee talk about their collaboration on the Arctic. Unless you're REALLY into the arctin, skip right to Matthiessen, who comes in at 38:10. Skip to 51:00 if you want to get right to the "Shadow Country" material. A very good segment because he reads quite a bit from the book, it's interesting to hear him speaking the character's parts in the southern vernacular.

Forum : KUER RadioWest (NPR)
Media : Article | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 52:02
Air Date: November 12, 2008
Description : Doug Fabrizio talks with Peter Matthiessen about "revealing the world through words"

Forum : WBUR's "On Point" (NPR)
Media : MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 45:18
Air Date: Wednesday, October 8, 2008
Description : Tom Ashbrook talks with Peter Matthiessen about "The Snow Leopard", Zen and environmental issues. Very little about Watson. Has a nice call-in portion except for the first call, she's a fruitcake.

Forum : Leonard Lopate Show WNYC (NPR)
Media : Article | MP3 (right-click and choose "save as" or "save target as"
Stream :
Length : 21:34
Air Date: Monday, June 09, 2008
Description : Leonard Lopate interviews Peter Matthiessen mostly about Shadow Country. A great place to start if you haven't read it yet.

Forum : The Charlie Rose Show
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 22:04
Air Date: May 27, 2008
Description : Charlie Rose interviews Peter Matthiessen about Shadow Country. He is quite obviously irritated at Charlie's questioning about his experience as a spy for the CIA.

Forum : The Free Library of Philadelphia
Media : Article | MP3 (right-click and choose "save as" or "save target as"
Stream :
Length : 58:29
Air Date: April 17, 2008
Description : Perhaps the best interview with Matthiessen I could find. He's has a good rapport with the interviewer, also an author. He wanders quite a bit in his answers, it's interesting to see where his mind takes him. Nice Q&A bit with the audience at the end.

Forum : Writer's Symposium by the Sea
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : Dean Nelson interview's Peter Matthiessen at a writer's forum. This one is distinct from the others because he tells personal stories I've heard nowhere else. He talks about nearly getting killed in the Sudan, encountering old men in the swamp backcountry, and there's an allusion to when he came across a dead guy in an alley when he was a young man. He is actaully quite jovial.
Air Date: April 1, 2005
Description : 28:45

Forum : "Web Exclusive" on Orion Magazine Website
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 13:36
Air Date: September 1, 2004
Description : Sort of a monologue about Politics and the Environment, Globalization, Resources, and Ethics and Corporate Profits and Common Sense. Not terribly interesting (to me, anyway), but does give some insight into his political views.

Forum : The Charlie Rose Show
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 18:33
Air Date: December 9, 2003
Description : Discussion with Matthiessen, about his book "At The End of the Earth: Voyages to Antarctica". Tells Rose that his favorite book to date is "Far Tortuga" but hints that it might be replaced by the book he's working on (which will become "Shadow Country")

Forum : The Charlie Rose Show
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 16:43
Air Date: March 21, 2002
Description : Interview about his book "Birds of Heaven" about Cranes. Bet you didn't know there's a Crane sanctuary in the DMZ between North and South Korea. Not a terribly interesting interview otherwise, though he does talk a bit about Antarctica.

Forum : The Charlie Rose Show
Media : Video | MP3 (to download, right-click and choose "save as" or "save target as")
Stream :
Length : 10:19
Air Date: April 26, 2000
Description : From Charlie Rose site: "Peter Matthiessen, nature writer and co-founder of "The Paris Review", discusses his book "Tigers in the Snow", which explores the efforts being made to save the species and contemplates the impact of their majesty and grace on our collective imagination."

Forum : The Charlie Rose Show
Media : Video | MP3 (right-click and choose "save as" or "save target as"
Stream :
Length : 15:55
Air Date: June 3, 1999
Description : Charlie Rose interviews Peter Matthiessen about "Bone by Bone". Interesting because even though Bone by Bone had just been released, he hyas already resolved to synthesize the "Watson Trilogy" into one book. He tosses out "The Labyrinth" as a speculative title (refernce to the everglades). He also discusses EJ Watson in depth, the Columbine shootings, and the dark side of humanity. Good interview.

Forum : The Charlie Rose Show
Media : Video | MP3 (right-click and choose "save as" or "save target as"
Stream :
Length : 23:10
Air Date: November 26, 1997
Description : A great interview because of its age, done at the time the second book of the Watson Trilogy, "Lost Man's River" was released.

Friday, January 29, 2010

Top 10 OS X tools & utilities I couldn't live without

These are either free, cheap, or not super cheap but worth every penny. All of these have made my life easier. I often wonder how I got by before I discovered each one of these. This is not a paid advertisement! (free ones are noted with an asterisk *, though donating to the developers is a nice idea!)
  1. Quicksilver * - It's hard to define Quicksilver because it does so many things. Basically, you can configure it to perform tasks on your Mac with keystrokes. Launch apps (obviosuly), but also launch searches on commonly-used websites, do math, pause iTunes, add an event to your calendar, etc. It's magic. I couldn't live without it. Seriously.
  2. SubEthaEdit - This is the greatest text editor I've ever found - and I've tried alot. It's fast and simple, yet has all the functions you'd ever need. I have it open all the time to use as my scratch pad, do regex on data, or convert characters or line endings. I don't do much actual coding in it, for that I use Eclipse, You certainly could, as it has syntax highlighting for all big languages.
  3. WireTap Studio - This is my go-to app for almost all audio work. It's primary function is to rip audio from any source (mac audio, or from any app specifically), but it has a great audio editor built in. It's not as functional as Audacity's but it's so much easier to use. OK, it's no Logic Studio but sometimes you just need a fast, quick and dirty audio editor.
  4. Default Folder X - OS X's built-in file system navigation is decent, but leaves something to be desired. If you open/close/save lots of files each day like I do, this app is incredible. It integrates seamlessly into the OS.
  5. SuperDuper! - I'm a backup freak (learned the hard way), and this app makes it a cinch. There's no backup scenario that SuperDuper! can't handle. It's saved my ass several times and besides that, it makes transitioning to new hardware a breeze.
  6. iTerm * - Best terminal app I've ever used. Tabbed terminals, and so much more.
  7. X11 * - This little piece of genius is actually part of the OS X distribution (optional install, Xcode tools). The wonder of it is, it allows you to run graphical *NIX applications (like GnuCash) natively. OS X is itself a UNIX distribution, after all. Of course, you'll also need a slick package manager like MacPorts or Fink to install your apps (I've used them both and they are both pretty nice).
  8. VLC * - Plays pretty much any media file that's playable. Soooooo much better than Quicktime. Even comparing it to Quicktime is insulting to VLC, because it does so much more. There are so many neat, tweakable functions I continue to discover. And it's a joy.
  9. Disk Inventory X * - I am also a disk cleanup freak. When your hard drive is full, or approaching full, sometimes it's hard to see where huge chunks of data are located in the filesystem. This lays it all out for you visually so you can go in and delete, delete, delete.
  10. Reggy * - Super handy little regular expression tester.

Thursday, January 28, 2010

The three things I would need to actually get work done on the iPhone

I love my iPhone, it has freed me quite a bit from my desktop computer. But there are many instances that I am out, and I am unable to complete simple work tasks on the iPhone because multiple applications are needed. The hardware and OS tools that a computer has available to allow you to synthesize your workspace to get tasks done, are just not available on the iPhone...even though all the apps I need are. It's not a huge deal, but I think the barriers to actually being able to get work done are small(ish). I've narrowed it down to these three simple things:
  1. An External Keyboard - The touchscreen keyboard just isn't workable for alot of typing. I'd love something external that either folds up, or is very small and can "cradle" the iPhone. Keyboard shortcuts (like Command-C, Command-V) would need to be incorporated into the OS.
  2. A Pointer (Mouse/Clickable Trackpad) - This is in conjunction to, or perhaps even part of the keyboard. This would allow for much easier editing of text, and easier highlighting of text for copy/paste. The copy/paste function on the iPhone now is OK, but very cumbersome.
  3. Multiple Applications Open/Fast Application Switching - Right now iPhone seems to have limited support for multiple apps to be open. For example, you can listen to music while using Safari. I'd love if you could open as many as 4 applications at a time, and have a keyboard (see #1) shortcut to switch quickly between them. If I could have Mail, Safari, a simple text editor and TouchTerm open all at once, switch between them easily, and cut/copy/paste text between them, I'd be in heaven.
Of course, these three things are all dependent on one another. And the big issue here would be RAM. Supporting external hardware and multiple running applications would really slow the iPhone down. However, I think the gain in productivity would be worth the cost of the slowdown.

Sunday, January 10, 2010

Record an early broadcast of "This American Life" to listen to at your leisure

If you're like me, you don't like to be tied to your local NPR station's schedule for "This American Life" each weekend, and you don't want to wait until Sunday for the This American Life podcast to become available.

Solution! Time-shift an early broadcast of This American Life on the internet. That way, it's available for you to listen to when it's convenient for you. For me that's usually on my iPod, on my Saturday run.

The earliest reliable and listenable stream I've found is on WUIS in Springfield, IL. It airs on Friday evening at 7pm Central time. They provide a quite listenable 56k stream at this URL:
http://war.str3am.com:7780/wuis.mp3
It's great for me because I am on the west coast, so it comes on at 5pm my time and is available at 6pm. There are earlier internet broadcasts of This American Life on east coast NPR stations, but I have found their streams to be too low-quality or unreliable.

If you know of an earlier broacast that's of decent quality, let me know in the comments. Whatever stream you use, be sure to donate to the station to compensate for the bandwidth. And of course, donate to This American Life!

Thursday, December 31, 2009

Applescript to apply mp3gain to iTunes playlists from the Script Menu

First off, if you use iTunes "Sound Check" and like it you may not need this. I disabled it because with iTunes 9, because I had alot of problems importing large mp3 files. It would often hang when determing the mp3's volume. Also, I was never able to tell the difference one way or the other. Playlists with songs from different albums still sounded un-even when Sound Check was enabled. If you love Sound Check and don't have any problems with it, this tip is not for you.

There are a couple other options for "normalizing" MP3 volume on OS X. One is iVolume which I've never tried. I read good things about it...but it costs money. Another is what I am going to focus on here: MacMP3Gain which is a port of the open source command-line program mp3gain for OS X (they also added a GUI).

mp3gain does more than just normalization, it does analysis to determine how quiet or loud an mp3 will sound to the human ear. If you really want to get technical, mp3gain does its analysis based on the Replay Gain algorithm. mp3gain applies lossless adjustment - it does not re-encode the mp3. However, MacMP3Gain offers this caveat about mp3gain, "MacMP3Gain modifies MP3 and unprotected AAC files with no provision provided to undo the changes." I haven't had any trouble after using extensively.

The MacMP3Gain application does have a GUI, which allows you to process by folder or by iTunes playlist. However, in the spirit of efficiency, I wanted a way to be able to normalize playlists right from iTunes. So I wrote this script which can be run right from the iTunes script menu. The other advantages of this script vs. the MacMP3Gain GUI is that it gives you a proper progress bar (important because it can take a long time to process), and it shows you the output when its done (so you can see exactly what changes were made to each file).

Prerequisites

MacMP3Gain - Install MacMP3Gain on your Mac. To use this applescript, you'll need to create a symlink from the command-line binary to somewhere in your path. This can be done with this command:
sudo ln -s /Applications/MacMP3Gain.app/Contents/Resources/aacgain /usr/bin/mp3gain
You can now use mp3gain on the command line. For a complete list of switches, open up Terminal and type:
mp3gain -?
mp3gain is also available via MacPorts, if you use that. Though at the time of writing, the newest version was 1.7.0 while the version rolled into the Intel MacMP3Gain is 1.8.0. To install via ports do this:
sudo port install aacgain
sudo ln -s /opt/local/bin/aacgain /usr/bin/mp3gain
Note: if you don't want to use any symlinks then just update the "mp3gain" reference in the applescript to point to the full path of your installed aacgain program.

BP Progress Bar - mp3gain takes roughly 30 seconds to process each mp3. Therefore, it can take a while to process an entire playlist. So, I've configured this script with a handy progress indicator. Applescript has no "native" progress indicator method, but you can access an external app to do this for you. Download BP Progress Bar (download link), unzip it and mount the disk image. Then, copy the app "BP Progress Bar" to your "Applications" folder, and the "BP Progress Bar Controller.scpt" to your Scripts folder /Users/YOU/Library/Scripts/ (create if it doesn't exist) and you're all good to go!

Please Note: The first time you run this script, you might get the rainbow wheel for 10-20 seconds, and you'll probably get the "BP Progress Bar was downloaded from the internet" security warning. Both of these things happen only the first time.

Now, copy the script below to Script Editor, and save it as "normalize_playlist.scpt" in your iTunes scripts directory /Users/YOU/Library/iTunes/Scripts/ (create if it doesn't exist). This will allow you to run it from the iTunes script menu like below:

iTunes Script Menu

Upon launch, you're prompted to enter a playlist to normalize.

Enter Playlist

As long as you enter a good one, you should see a progress bar come up.

Progress Bar

Upon completion you can view the log, which is written to /tmp/mp3gain_output.log.

MP3Gain Log

Enjoy!

(* 

Normalize Playlist

Accepts an itunes playlist as text input,
and normalizes all mp3 files on the playlist
with mp3gain -r (mp3gain itself decides how 
best to normalize).

Prerequisities:

* mp3gain on command-line
* http://homepage.mac.com/beryrinaldo/AudioTron/MacMP3Gain/
* BP Progress Bar
* http://scriptbuilders.net/files/bpprogressbar1.0.html

*)

--Ask the use for the playlist
set myList to the text returned of (display dialog "Enter playlist to normalize " default answer "")

--exit if they didn't enter anyting
if the myList is "" then
 display dialog "No playlist entered" giving up after 2
 return
end if

--make sure itunes is running
--SHOULD BE if it's run from the itunes script menu
--but it could be executed directly
set itunesOK to my itunes_is_running()
if itunesOK is false then
 tell application "iTunes"
  activate
 end tell
end if

tell application "iTunes"
 set oldfi to fixed indexing
 set fixed indexing to true
 
 --see if the playlist exists
 if exists user playlist myList then
  --do nothing for now
 else
  --show error if the playlist doesn't exist
  display dialog "Playlist does not exist" giving up after 2
  return
 end if
 set currentList to playlist myList
 
 --initialize progress bar
 set ProgressBar to load script alias (((path to scripts folder) as text) & "BP Progress Bar Controller.scpt")
 set myTitle to "Normalizing " & myList & " - may take several minutes"
 tell ProgressBar to initialize(myTitle) -- title of progress bar
 -- Start of Script to use ProgressBar Controller
 tell ProgressBar
  barberPole(true)
  setStatusTop to "Initializing Volume Adjustment"
  setStatusBottom to ""
 end tell
 
 --get the number of items on the playlist
 set eop to index of last track of currentList
 
 -- Stop the barber pole, set up for the progress bar
 tell ProgressBar
  barberPole(false)
  setMax to eop -- to match the items to be processed below
  setStatusTop to "Examining playlist"
 end tell
 
 --add a little progress so it doesn't start at 0
 tell ProgressBar to increase by 1
 
 with timeout of 10800 seconds --avoid "event timed out" error
  
  --delete the logfile if it already exists
  do shell script "if [ -e /tmp/mp3gain_output.log ]; then rm -f /tmp/mp3gain_output.log; fi;"
  
  repeat with i from 1 to eop
   
   --write current track to log
   do shell script "echo \"------------ Track " & i & " of " & eop & " ------------\" >> /tmp/mp3gain_output.log"
   
   --get the mac path to the mp3 file, name of the track, and extension
   set i_location to (get location of track i of currentList)
   set i_name to (get name of track i of currentList)
   set theFileInfo to info for i_location
   set ext to name extension of theFileInfo as string
   
   --only do this if it's an mp3
   if ext is "mp3" then
    
    --convert mac path to POSIX path, quote it so we
    --can use it on the cmd line
    set mypath to POSIX path of i_location
    set posixpath to quoted form of mypath
    
    --create our command
    --mp3gain is CPU-intensive, so pass thru nice
    --write output of mp3gain to log
    --this will allow us to report on what changes were made
    set myCmd to "nice mp3gain -r -k -c -q " & posixpath & " >> /tmp/mp3gain_output.log"
    
    --update progress window with status
    tell ProgressBar
     setStatusTop to "Processing file " & i & " of " & eop & " : " & i_name
     setStatusBottom to "Full path: " & mypath
    end tell
    
    --execute the shell command
    do shell script myCmd
   else
    --if track is not an mp3, don't process it
    do shell script "echo \"Track " & posixpath & "is not an mp3...not processing\" >> /tmp/mp3gain_output.log"
    
   end if --end if for is an mp3
   
   tell ProgressBar to increase by 1
   
  end repeat
 end timeout
 
 set fixed indexing to oldfi
end tell

tell ProgressBar to quit

--tell them we're done and ask if they want to see log
set seeLog to (display dialog ¬
 "Done. Would you like to see the log? " with title ¬
 "Normalization Complete" buttons {"Yes", "No"} ¬
 default button "Yes")
set button_name to button returned of seeLog
if button_name is "Yes" then
 --open log in textedit
 tell application "TextEdit"
  activate
  open "/tmp/mp3gain_output.log"
 end tell
end if

--be nice and clean up
do shell script "if [ -e /tmp/mp3gain_output.log ]; then rm -f /tmp/mp3gain_output.log; fi;"

return

--subroutine checks if itunes is running
on itunes_is_running()
 tell application "System Events" to return (exists process "iTunes")
end itunes_is_running