Anybody who knows me knows that I am a huge fan of karaoke. Back in the college days we took it upon ourselves to build a karaoke stage in the living room complete with mounted multi-monitors on the wall. Those were the good ole’ days

In an attempt to recreate these great memories, I have put together a portable karaoke setup that I like to call Karaoke In a Bag ™. KIAB contains a laptop, portable computer speakers, a mixer board, and a library of karaoke music. It works well. I bring it to parties. We sing on the beach. We sing in old folks homes. It’s a blast.
I’ve been using the kJams for playback of my karaoke music. kJams is on the bleeding edge of the karaoke software. Nothing on the PC even comes close to touching it.
Usually when we throw parties we setup the system and just allow people to come up, search for the song they want, double-click it, and away they go. But it’s no fun when the party is just starting. At the beginning of the night no one is drunk and when people are searching for karaoke songs, you can hear crickets chirp.
I have been holding out on registering the software for I want one feature; the ability to automatically cross-fade back and forth between karaoke playback and iTunes playback. In other words, I want music from iTunes to play when the user is searching for their karaoke song, then when the user begins to sing, I want the iTunes music to automatically fade out (karaoke music fade in) and then once the karaoke song is done, the iTunes music should automatically fade back in and continue to play. Constant music is the goal whether it comes from the karaoke singer & kJams or my iTunes library. I never want to hear silence and I want it all to be managed by the computer (there’s important beer drinking to be done, no way in hell I’m going to sit there all night playing DJ switching between iTunes and kJams).
So I set out to write a script to do such a thing. Luckily the user “oss” from the kJams support board gave me a running start with his iTunes crossfade script that he wrote.
Below is my modified version of his script. You will want to start kJams Pro (the Lite version doesn’t have scripting support), iTunes (with the playlist you want it to play through) and then leave the following script running in the background (run it using OS X Script Editor) :
-- Modified 10-27-08 by Jim Jones
-- Script now looks to see if the Video window is full screen. If the video window is full screen
-- it assumes that a karaoke song is playing and fades out iTunes. If the video screen is less
-- than full resolution it assumes that karaoke is not being played and starts playing a track from iTunes.
-- 11-27-07
-- http://karaoke.kjams.com/forum/viewtopic.php?t=265
-- Please have iTunes and kJams running before launching this script and
-- have a playlist selected in iTunes
-- The simple logic of the script assumes that if iTunes is playing and this script is run,
-- you want to cross fade over to kJams.. Alternately, if iTunes is not playing a track,
-- it assumes you want to cross fade over to iTunes.
-- when you are ready to cross fade to kJams, make sure your next song is
-- highlighted/selected. It will NOT automatically go to the next track in
-- your kJams playlist.
-- Although I have tested this code, I make no guarantees with this code,
-- any disasters that occur are not my fault. Use at your own risk!!
tell application "kJams Pro" to set kSpeakers to 0
--sets how much in percentage the volume is decreased per step
set fadeStep to 5
--sets how long in seconds between each step in the fade
set fadeDelay to 0.1
set kScriptCommand_PLAY_PAUSE to 1
set kScriptCommand_STOP to 2
--this is the max volume settings.. iTunes and kJams must share this for proper mixing.. Change to whatever you like.
set MaxVolume to 100
--this is the minimum volume setting
set MinVolume to 0
set appName to "kJams Pro"
set itunesAppName to "iTunes"
-- Playstate will be either 1 for iTunes or 0 for kJams
set playState to 0
set prevPlayState to 0
-- Find the bounds for the current system
set _desktopw to 0
set _desktoph to 0
-- Get max resolution of system
tell application "Finder"
set _b to bounds of window of desktop
set _desktopw to item 3 of _b
set _desktoph to item 4 of _b
end tell
-- Poll the resolution of the Video window and compare it against the max resolution of the system
-- If they are equal, then you can assume the user is playing a karaoke song and you should cross
-- fade out iTunes and crossfade in kJams
repeat
set w to 0
set h to 0
-- Repeatedly get the resolution of kJams Video window and
-- don't progress until the width and height are greater than zero
-- If there's an error, probably means the user just closed the Video window
repeat until w > 0 and h > 0
try
tell application "System Events"
tell process "kJams Pro"
tell window "Video"
set _s to get size
set w to item 1 of _s
set h to item 2 of _s
end tell
end tell
end tell
on error errStr number errorNumber
-- error occurred, Video window was probably closed
end try
delay 0.1
end repeat
tell application "iTunes"
-- Resolution of Video window equal to max resolution
-- So we're probably playing a karaoke song. Fade out music
-- fade in karaoke music
if (w ≥ _desktopw and h > _desktoph) then
set playState to 0
-- If prevPlayState is not the same as the current state
if (prevPlayState = 1) then
set kJamsVolume to MinVolume
set iTunesVolume to MaxVolume
set the sound volume to MaxVolume
tell application "kJams Pro" to set volume kSpeakers level MinVolume
repeat until iTunesVolume ≤ 0
set iTunesVolume to (iTunesVolume - fadeStep)
set kJamsVolume to (kJamsVolume + fadeStep)
tell application "iTunes" to set the sound volume to iTunesVolume
tell application "kJams Pro" to set volume kSpeakers level kJamsVolume
delay fadeDelay
end repeat
--tell application "kJams Pro" to docommand kScriptCommand_PLAY_PAUSE
tell application "iTunes" to next track
tell application "iTunes" to pause
end if
else -- Video window not at max, so fade out kJams and fade in iTunes
set playState to 1
if (prevPlayState = 0) then
set iTunesVolume to MinVolume
set kJamsVolume to MaxVolume
tell application "kJams Pro" to set volume kSpeakers level MaxVolume
tell application "iTunes" to set the sound volume to MinVolume
tell application "iTunes" to play
repeat until kJamsVolume ≤ 0
set iTunesVolume to (iTunesVolume + fadeStep)
set kJamsVolume to (kJamsVolume - fadeStep)
tell application "iTunes" to set the sound volume to iTunesVolume
tell application "kJams Pro" to set volume kSpeakers level kJamsVolume
delay fadeDelay
end repeat
tell application "kJams Pro" to docommand kScriptCommand_STOP
end if
end if
set prevPlayState to playState
delay 0.5
end tell
end repeat
March 24th, 2010 at 2:31 pm
Looks like Dave has added support for querying kJams and whether it is currently playing a song ( http://karaoke.kjams.com/wiki/Scripting ).
I need to rewrite the code above to take poll the following state instead of querying the resolution of the lyric display window.
set kPlayModeType_STOPPED to 0
set kPlayModeType_PLAYING to 1
set kPlayModeType_PAUSED to 2
set playMode to get mode