.:: An exploration of exercise plans, weight loss and better workouts. ::.

" Searching begets purpose.. So we keep looking for the better workout plan, the better weight loss strategy, the better version of ourselves.. "

Choose a Topic:

Wed
12
May '10

kJams and Autocross Fading, v2.0

I’ve recently made some modifications to my auto cross fading script for kJams. Instead of querying the lyrics window to see if it’s full screen (and just assuming that karaoke is being played), it now simply queries kJams to see if it’s playing a song or not. Dave, the author of kJams added this functionality in a while back and I finally got around to taking advantage of it. I used it at a party with dual monitors (one displaying lyrics for the singers and the laptop screen displaying the kJams song index), and it worked well the entire night. Here’s the newer version :


-- Modified 05-12-10 by Jim Jones
-- Script now just simply queries kJams to see if it's playing a song or not (thanks Dave!).
-- No more hassles of querying the child video window.

-- 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

set kPlayModeType_STOPPED to 0
set kPlayModeType_PLAYING to 1
set kPlayModeType_PAUSED to 2

repeat

	tell application "kJams Pro"

		set playMode to get mode

	end tell

	tell application "iTunes"

		--  So we're probably playing a karaoke song.  Fade out music
		--  fade in karaoke music
		if (playMode = kPlayModeType_PLAYING) 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
			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

Start discussion »

Leave a Reply