September 10th, 2009
I use a tail command alias (from FlashApe) to constantly output the contents of my flashlog file to the terminal which makes reading output very useful. However, if you use FlexBuilder/FlashBuilder at all, you’ll notice it will dump millions of useless comments such as
-> Begin call to AS: getSelectedItems()
<- End call to AS: getSelectedItems, Result = Text23
==> Begin AS external call: designViewComplete()
<== End AS external call: designViewComplete, Result =
Just resizing the design view is enough to dump tons of these statements into your trace output, which gets very annoying. While working on a project, a friend of mine had the idea of somehow removing these statements, which got me thinking. The dirty solution I came up with is to grep -v the flashlog before you send it to the tail command using a regex that will match any line starting with one of the four arrow characters (->, <-, ==>, <==). As a consequence, you will also remove any traces that begin with these characters, so be mindful of how you write your trace statements. I'm sure there's a way to modify this to search for 'Begin call to AS' and so on.
Anyway, the command is a bash alias called trace. How-to:
1. First, you'll need the Flash debug player if you don't already have it. Go to playerversion.com - if you don't see (Debug Player) by the version number, go here, and download the appropriate debug players for your browser/OS.
2. Next, go to the terminal and open your ~/.bash_profile
nano ~/.bash_profile
3. Then, add the following line somewhere within the file:
alias trace='tail -f /Users/YOUR-USER/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt | grep -v "^\->\|^<\-\|^\=\=>\|^<\=\="'
4. Be sure to replace YOUR-USER with your username, or, if your flashlog.txt file is in a different location (I'm using OS X, linux will be different) change the command to point wherever your flashlog.txt file is located. If you don't have a flashlog.txt file, you can create one.
5. If you don't have it, create a file in your home directory called 'mm.cfg'. Add the following:
TraceOutPutFileName=/Users/YOUR-USER/Library/Preferences/Macromedia/Flash Player/Logs/flashlog.txt
ErrorReportingEnable=1
TraceOutputFileEnable=1
MaxWarnings=9999
6. Make sure TraceOutPutFileName is the same as the directory you put in your .bash_profile.
Now you should be able to type trace in the terminal to see the trace output, minus the pesky FlashBuilder comments! Yay!
Categories: flex
Tags: alias, bash, comments, flash, flashbuilder, flashtracer, flex, flexbuilder, grep, terminal, trace
September 10th, 2009
I have made a slight update to the earlier post at Automatically Ripping FLAC Files to mp3s Via Shell Script. I have updated the script so that it will automatically make the database directory the first time you run it. Without that change, the script wouldn’t work as expected unless you manually created the directory.
In addition, I attempted to get the script working on my OS X machine with much success. Installing the Apple Developer Tools (available on your OS X install disc) will provide you with the ‘make’ command line utility. This will allow you to compile id3 mass tagger. MacPorts and/or Fink will provide you with the other tools you’ll need – lame, flac, and metaflac. I was able to compile and install id3 mass tagger without any problems (much to my surprise).
Once you have these tools, the script should work as expected. Let me know if you have any problems and I may be able to help you out.
Categories: music
Tags: apple, automation, database, diff, easytag, encoding, flac, genre, genres, id3, lame, lossless, mac, macintosh, metadata, metaflac, mp3, music, os x, ripping, script, shell
August 22nd, 2009
I use Cog on OS X as my primary music application which I’m pretty happy with – It’s very lightweight and plays FLAC files. Still, I prefer how Rhythmbox and iTunes manages your music in one large library. Cog, on the other hand, gives you a directory listing and requires you to drag and drop files into a library to listen to them.
This post describes a way to make Cog work more like iTunes. The library for Cog is simply a m3u playlist file on the filesystem. I wrote a script that would overwrite the m3u file with list of files in my music directory whenever you run Cog. To do this:
1. Rename the actual Cog application (within the /Applications/Cog.app folder). In the terminal,
mv /Applications/Cog.app/Contents/MacOS/Cog /Applications/Cog.app/Contents/MacOS/Cog-Application
2. Create a shell script to masquerade as Cog. This will first update the Cog m3u file, then run Cog. Copy the script below in a file called ‘Cog’ and place it at /Applications/Cog.app/Contents/MacOS/
#!/bin/sh
######################
#Update Library File:#
######################
LIBRARY_FILE=~/Library/Application\ Support/Cog/Default.m3u #Location of Cog playlist file (Shouldn't need to change this)
LIBRARY_FOLDER=/Volumes/Music/collection/tagged/ #The folder that keeps all of the music you want to listen to
echo ' ' > $LIBRARY_FILE #Clear out library
find $LIBRARY_FOLDER -type f -name "*.flac" > $LIBRARY_FILE #Add flac files
find $LIBRARY_FOLDER -type f -name "*.mp3" >> $LIBRARY_FILE #Add mp3 files
### Add other file types here
#find $LIBRARY_FOLDER -type f -name "*.ogg" >> $LIBRARY_FILE #Add ogg files
#find $LIBRARY_FOLDER -type f -name "*.wav" >> $LIBRARY_FILE #Add wav files
#########
#Run Cog#
#########
/Applications/Cog.app/Contents/MacOS/Cog-Application
You will want to modify the script. Change the LIBRARY_FOLDER to point to a directory where all of your music files are located. You’ll also want to add or remove the find statements to find the type of music files you are looking for (flac, mp3, ogg, etc).
3. Set the permissions on the script to make it executable
chmod 755 /Applications/Cog.app/Contents/MacOS/Cog
Now whenever you run Cog, the library will be updated with your music files. If you add music files to your music directory, you will need to restart Cog.
Categories: music
Tags: apple, cog, iTunes, library, m3u, mac, macintosh, mp3, music, os x, player
August 5th, 2009
For a project, we’ve been meaning to implement some accessibility features such as providing the ability to resize all of the text in the application. The problem with this is that it requires a lot of overhead to build your application so that it can handle dynamic text sizes. I wanted instead to try some scaleX and scaleY action on the entire Flex application, emulating the way Firefox (and other similar browsers) now handle page resizing.
For the most part, this worked really well. You need some UI to set the scale value (for example, a slider component). Then, in your application you can just set the scaleX and scaleY values to the value of that component.
Things get slightly more tricky when you include the PopUpManager. When you rescale the Application, any pop-ups (which are placed a layer above the Application clip) remain unscaled. Attempting to cast systemManager to a DisplayObject, and rescaling that ended up breaking the application since the content would no longer fill the entire stage.
A less elegant solution was to simply rescale the pop-ups as they are added via PopUpManager. While working it out, a friend suggested to add an event listener for when popups are added, and to rescale the pop-ups then (so there’s no need to manually rescale the pop-ups). That’s what I came up with. The important caveat here is that you need to add/create your pop-ups in the PopUpManagerChildList.POPUP child list. I was having fun so I added keyboard commands just because I’m that kind of guy. A… keyboard command adding… guy.
Instructions: Click somewhere on the flash movie to give it focus. Move the slider (or press Ctrl & - or Ctrl & = ) (or Command for OS X) to rescale the content. The flex movie has view source enabled, so right click and select ‘View Source’ to peer into the un-ending black darkness.
This movie requires Flash Player 9
Or, view in a new window. (View Source won’t work in the new window, click on the embedded movie instead to view source).
A few flaws with this method:
- Images will look trashy when scaled. The only thing you can do about this is stick with vector graphics. Unless having the image in perfect clarity is critical to your application, I think it’s fine to let the user gain the functionality to rescale the application at the sacrifice of image clarity.
- The text in buttons (that don’t explicitly define a size) will sometimes get truncated (ie, “Cancel” becomes “Can…”). If the buttons are allowed to auto size, I don’t see why the text would truncate. Annoying. I still want to play with this and see if I can figure it out.
- If you are focused in a TextField, pressing Ctrl & – or Ctrl & = will input – and = characters into the TextField! You can’t prevent this, unfortunately, but you could provide a work around if you really wanted to.
Categories: flex
Tags: accessibility, events, flash, flex, keyboard, modal, popupmanager, rescale, resize, systemmanager
August 3rd, 2009
Disclaimer: These instructions are for Ubuntu (or other Linux distro) – I will be doing an updated post later on to cover OS X.
Being somewhat of an audiophile, I’ve been encoding my music in lossless FLAC format for a while now – which is great, except when you want to put them on an iPod (which of course, won’t play FLAC files). One option would be to convert these files to Apple Lossless, however, I don’t mind sacrificing some quality to be able to put more music on my iPod. Plus, I probably couldn’t tell the difference while I’m listening to the iPod anyway.
Therefore, I wanted a shell script that I could run that would find out which files I had recently added to my collection and convert them to mp3s (preserving metadata). Then, I could grab those mp3s and put them into gtkpod or iTunes.
I created the shell script below borrowing liberally from other similar scripts I found online. The key thing about this script is that it keeps a simple flat text file database so that it can remember which files it has already converted.
The biggest problem I stumbled on was handling genres. For whatever reason, many command line and GUI tools refuse to let you write in your own genres – you pick from a pre-defined list. This boggles my mind – it seems presumptuous to me that some group would be tasked with coming up with all of the possible labels to all music. I listen to a lot of Electronic music, which alone covers ‘Drum and Bass’, ‘House’, ‘Techno’, ‘Electro’, ‘Progressive Trance’, ‘Microhouse’ and a trillion other tiny genres. In addition to sub-genres, you also have the problem of your cousins band which plays an Acoustic Goth-Country “experience” that defies categorization, and cannot simply be lumped into ‘Alternative’.
I found two solutions to this problem. For ripping from CDs to FLAC, I use EasyTag which will let you enter in genres by hand. EasyTag’s not my favorite program in the world, but it gets the job done and you can get it from your package manager. For decoding the FLAC files and encoding them to mp3s, I found id3 mass tagger by squell. My script below uses this program (simply called id3), so you’ll need to install that first.
In addition to the id3 mass tagger, you’ll need to have lame (for encoding mp3s), flac (for decoding flacs) and metaflac (for handling the flac metadata). On linux, all of these should be obtainable through your package manager.
Next, grab this script and save it somewhere that is in your path (for example, /usr/bin). Personally, I like making a bin folder in my home directory to keep all of my scripts. You do whatever tickles your fancy. Make sure to give the script executable permissions:
chmod 755 name-of-the-script
The script:
#!/bin/bash
#flac-to-mp3 will search FLAC_SOURCE_DIR for all flac files added since last time you've run flac-to-mp3. These files will be converted to mp3s and placed in MP3_OUTPUT_DIR. This script can be useful when maintaining a flac music collection along with a mp3 player like the iPod.
#Dependencies: lame, flac, metaflac, ID3 mass tagger (id3)
#Directory settings:
FLAC_SOURCE_DIR=/path/to/your/flac/files
MP3_OUTPUT_DIR=/path/to/where/you/want/to/output/the/mp3s
DB_DIR=/home/YOUR-USER-NAME/.flac-to-mp3
#You probably don't need to set these. These specify the files that keep track of changes:
CURRENT="$DB_DIR"/current
INDEXED="$DB_DIR"/indexed
DIFF=/tmp/flac-to-mp3-dif
TMP_FILE="$DB_DIR"/tmp.tmp
IFS=" ";
if [ ! -d "$DB_DIR" ]; then
mkdir "$DB_DIR"
fi
if [ ! -f "$CURRENT" ]; then
touch "$CURRENT"
fi
if [ ! -f "$INDEXED" ]; then
touch "$INDEXED"
fi
#Update index of flac files
find "$FLAC_SOURCE_DIR" -type f -name "*flac" > "$CURRENT"
#Get a list of files that have been newly added
if [ -f "$DIFF" ]; then
rm "$DIFF"
fi
#Sort the database files so the diff won't have problems with files being in a different order:
sort "$INDEXED" > "$TMP_FILE"
cat "$TMP_FILE" > "$INDEXED"
sort "$CURRENT" > "$TMP_FILE"
cat "$TMP_FILE" > "$CURRENT"
touch "$DIFF"
diff "$INDEXED" "$CURRENT" | grep ">" | cut -c 3- > "$DIFF"
#Reset IFS so that our for loop won't die on spaces
IFS="
";
#Encode the flac files that are new into mp3s into the MP3_OUTPUT_DIR directory.
for FLAC in `cat "$DIFF"`
do
#We first have to detect for duplicates. If an mp3 file of the same name exists in the MP3_OUTPUT_DIR then we should append (2), (3), and so on to the filename. Otherwise mp3 files would be overwritten. This situation arises when there are two or more flac files with the same name.
echo "${FLAC%.flac}" | sed 's/.*\///' > "$TMP_FILE"
TMP=`cat "$TMP_FILE"`
NUM_FILES=`ls "$MP3_OUTPUT_DIR" | sed 's/.mp3//' | grep "$TMP" | wc -l`
if [ "$NUM_FILES" -gt 0 ]; then
V=`expr $NUM_FILES + 1`
MP3_PATH="${FLAC%.flac} ($V).mp3"
else
MP3_PATH="${FLAC%.flac}.mp3"
fi
#Encode flac file to mp3 file.
echo "$MP3_PATH" | sed s/^.*\\///g > "$TMP_FILE"
MP3=`cat "$TMP_FILE"`
[ -r "$FLAC" ] || { echo can not read file \"$FLAC\" >&1 ; exit 1 ; } ;
metaflac --export-tags-to=- "$FLAC" | sed 's/=\(.*\)/="\1"/' >"$TMP_FILE"
cat "$TMP_FILE" > /dev/null 2>&1
. "$TMP_FILE"
flac -dc "$FLAC" | lame --preset standard --tt "$TITLE" \
--tn "$TRACKNUMBER" \
--ty "$DATE" \
--tc "$COMMENT" \
--ta "$ARTIST" \
--tl "$ALBUM" \
--add-id3v2 \
- "$MP3_OUTPUT_DIR"/"$MP3"
#We use ID3 mass tagger to write the genre tag - this will allow us to write non-standard genres. ID3 can be found at http://home.wanadoo.nl/squell/id3.html
id3 -2 -g "$GENRE" "$MP3_OUTPUT_DIR"/"$MP3"
#Update the database:
echo "$FLAC" >> "$INDEXED"
done
#Cleanup
rm "$DIFF"
rm "$TMP_FILE"
IFS=" "
MP3_PATH=
MP3=
FLAC=
FLAC_SOURCE_DIR=
MP3_OUTPUT_DIR=
CURRENT=
INDEXED=
DIFF=
DB_DIR=
NUM_FILES=
TMP=
V=
TMP_FILE=
Note that you’ll need to edit a few things, namely, the first three lines. FLAC_SOURCE_DIR should point to where you store your flac files. MP3_OUTPUT_DIR should point to a folder where you want the encoded mp3 files will end up. DB_DIR will be the folder that will hold the flat file databases. My script has a folder (.flac-to-mp3) in my home directory.
You may also want to modify the encoding options. Line 72 uses the –preset standard option – you might want to change this.
Outside of that, you probably don’t need to modify the script much. Read on if you want to know more about the inner workings of the script.
The script keeps two flat text database files – indexed and current. indexed lists all of the files that you have already encoded. When you run the script, current is rebuilt which is simply a list of all of the flac files in your FLAC_SOURCE_DIR. These two files are sorted, then a diff is performed to see which files exist in current that are missing from indexed. These are the files that (assumed) you have added since you last ran the script.
Next, a check is performed to make sure that a file of the same name doesn’t already exist in the MP3_OUTPUT_DIR. If it does, then a (2), (3) and so on are appended to the file name. After that, the script exports the flac metadata into a temporary file. Then, it decodes the flac file (line 72: flac -dc) and pipes that into lame. Next, id3 (the id3 mass tagger application) writes the id3 tag information into the newly created mp3. If all of these steps work, then the indexed file is appended with the name of the file (since it has already been encoded).
One final mega disclaimer: You’re at your own risk. I wrote this for my personal use and I haven’t tested it thoroughly, so backup your files or run the script on a small sample to make sure it works first!
Categories: music
Tags: automation, database, diff, easytag, encoding, flac, genre, genres, id3, lame, lossless, metadata, metaflac, mp3, music, ripping, script, shell
August 2nd, 2009
Jello!
Since I’m starting a blog, I have to get the introductions out of the way. I’m Zachary Berry, a web developer with a leaning towards Flex and Flash work. Since the end of 2004 I’ve been working as a Web Application Designer & Developer at the University of Central Florida under the New Media team. Before that, all of my web development work was simply various experiments, home-pages, angelfire sites, and the like.
I also enjoy synthesizers, music and long walks on the beach. Two of those passions will also drive some of the content for the blog.
There, now that that’s out of the way, we can get to the rest of the blog! :)
Categories: Uncategorized
Tags: intro, introduction, introductions