Setting volume control

Need help? Ask your questions here! I'll try to answer every one, but anyone can answer!
Brendan
Posts: 424
Joined: Sun Dec 30, 2007 1:05 pm
Location: Vacaville, CA.

Setting volume control

Post by Brendan »

When using crossfade, how do i set the volume on Kjams and itunes to full? Currently when crossfading the volume control goes about 3/4 of the waay up. Thanks!

dave
Site Admin
Posts: 6687
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: Setting volume control

Post by dave »

I don't know as i've never used the crossfade script. anyone?

jfbiii
Posts: 179
Joined: Tue Jan 15, 2008 3:22 pm

Re: Setting volume control

Post by jfbiii »

Open Script Editor and then open the cross fade script. Your looking for the lines highlighted in red below. Change the max volume to 100 and save. You're all set.

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


tell application "iTunes"
if (player state is playing) then
set kJamsVolume to MinVolume
set iTunesVolume to MaxVolume
set the sound volume to MaxVolume
tell application "kJams Pro" to «event kJamSVol» kSpeakers given «class vLev»:MinVolume
tell application "kJams Pro" to «event kJamdCmd» kScriptCommand_PLAY_PAUSE

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 «event kJamSVol» kSpeakers given «class vLev»:kJamsVolume
delay fadeDelay
end repeat

tell application "iTunes" to pause

else
set iTunesVolume to MinVolume
set kJamsVolume to MaxVolume
tell application "kJams Pro" to «event kJamSVol» kSpeakers given «class vLev»: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 «event kJamSVol» kSpeakers given «class vLev»:kJamsVolume
delay fadeDelay
end repeat
tell application "kJams Pro" to «event kJamdCmd» kScriptCommand_STOP
end if
end tell
From he to whom much liquor is given...much singing is expected.

Brendan
Posts: 424
Joined: Sun Dec 30, 2007 1:05 pm
Location: Vacaville, CA.

Re: Setting volume control

Post by Brendan »

Thanks for that jfbiii!! My first dive into script editor, kinda kewl! Are there other tweaks you can do with this program? Is this called"open source"? Excuse my ignorance :?

jfbiii
Posts: 179
Joined: Tue Jan 15, 2008 3:22 pm

Re: Setting volume control

Post by jfbiii »

LOL. I'm not the author, I just had it available and I had already made that change for myself so knew where to point you. The only other part of this that is customizable is the fade itself--how big each step of the fade is and how quickly each step is taken. Those lines are right above the ones for controlling the upper and lower volume limits.

The only other thing I've scripted (well, used Automator to do actually) is something to delay the song start so I have time to get to the stage when I have to set up far away from it. Much more reliable than recruiting a patron to hit "play" for me at the right time.

Some other folks have done some scripting in the cross-fader area, though. There's a few different threads on the forums here.
From he to whom much liquor is given...much singing is expected.

Brendan
Posts: 424
Joined: Sun Dec 30, 2007 1:05 pm
Location: Vacaville, CA.

Re: Setting volume control

Post by Brendan »

When i use script editor to control the volume of itunes, it also affect the volume of kjams. The problem is when i use crossfade, the volume in itunes is much louder then the volume in kjams. Is there a way to adjust only the volume in itunes to be equal to the volume in kjams? - Brendan

dave
Site Admin
Posts: 6687
Joined: Sun Sep 18, 2005 8:02 am
Location: Seattle
Contact:

Re: Setting volume control

Post by dave »

jfbill do you have any idea here?

jfbiii
Posts: 179
Joined: Tue Jan 15, 2008 3:22 pm

Re: Setting volume control

Post by jfbiii »

I'm sure it's possible, but I don't know how to write that code right off the top of my head. I'm not really proficient in programming.
From he to whom much liquor is given...much singing is expected.

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Setting volume control

Post by DeusExMachina »

Dave asked me to look at this.
I am having a hard time understanding what is being asked, here, since the two things mentioned are mutually contradictory.
But it THINK you are asking if you can have cross fade use a different final volume for kJams and iTunes. The answer is yes, it is possible, and fairly easy. You just need to introduce a new variable for maxVolume (I assume you still want identical minVolumes of 0.) So now you have two variables for Volume, say "iTunesMaxVolume," and "kJamsMaxVolume." In each section of the script, just replace the maxVolume reference with the appropriate reference above.
I can write it out, but I want to make sure this is what you mean before I take the time to hack the code. So let me know here, and I'll see what I can do.

BTW, it may be easier just to leave the script alone, and adjust final volume on your mixer, since songs in kJams are not normalized anyway (yet) so there is no way to guarantee that you will crossfade smoothly.

On a related note:
Dave, could you add a scripts menu? That would make firing these things so much easier. I never use crossfade because it is a PITA to fire.

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Setting volume control

Post by DeusExMachina »

Oh what the heck, I'm not doing anything useful right now. Try this out and see if it works. (I may post a code optimized version later, if it does.)
P.S. I modified the code to match the modified code I posted lower down.

Code: Select all

-- 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 kJamsMaxVolume to 100
set iTunesMaxVolume to 100
--this is the minimum volume setting 
set MinVolume to 0

tell application "iTunes"
	if (player state is playing) then
		--set all volumes to cross fade starting values 
		set kJamsVolume to MinVolume
		set iTunesVolume to iTunesMaxVolume
		set the sound volume to iTunesMaxVolume
		tell application "kJams Pro" to set volume kSpeakers level MinVolume
		tell application "kJams Pro" to docommand kScriptCommand_PLAY_PAUSE
		
		repeat until (iTunesVolume ≤ 0 and kJamsVolume ≥ kJamsMaxVolume)
			set iTunesVolume to (iTunesVolume - fadeStep)
			if kJamsVolume is less than kJamsMaxVolume then 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 "iTunes" to pause
		
	else
		--set all volumes to cross fade starting values 
		set iTunesVolume to MinVolume
		set kJamsVolume to kJamsMaxVolume
		tell application "kJams Pro" to set volume kSpeakers level kJamsMaxVolume
		tell application "iTunes" to set the sound volume to MinVolume
		tell application "iTunes" to play
		repeat until (kJamsVolume ≤ 0 and iTunesVolume ≥ iTunesMaxVolume)
			if iTunesVolume is less than iTunesMaxVolume then 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 tell
Last edited by DeusExMachina on Tue Jun 08, 2010 3:55 pm, edited 2 times in total.

Brendan
Posts: 424
Joined: Sun Dec 30, 2007 1:05 pm
Location: Vacaville, CA.

Re: Setting volume control

Post by Brendan »

Yes, i am talking about the final volume. What do i do with this, delete the original script and replace it with this one? I can open script editor but dont know much more about it. :oops: Thanks in advance

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Setting volume control

Post by DeusExMachina »

Well, keep in mind that I am VERY lazy (i.e. I did not actually test this rigorously) but if it works correctly, all you should have to do is open it in AppleScript editor, and then save it named whatever you want. Alternately, you can just open the crossfader script, select all, paste this code in, and save.
All you have to do is edit the value for whichever max volume you want to change. For instance, if you want iTunes always at 75%, just change iTunesMaxVolume to, um, 75. You can even change both values.

Addendum:

OK, I lied, I am not that lazy after all. I tested it, and it DOES work (not bad for first time around) but there IS a logical error that causes the volume to jump around a bit, and not be exactly precise. I have fixed that in the version below. Just follow the same directions above.

Code: Select all

-- 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 kJamsMaxVolume to 100
set iTunesMaxVolume to 100
--this is the minimum volume setting 
set MinVolume to 0

tell application "iTunes"
	if (player state is playing) then
		--set all volumes to cross fade starting values 
		set kJamsVolume to MinVolume
		set iTunesVolume to iTunesMaxVolume
		set the sound volume to iTunesMaxVolume
		tell application "kJams Pro" to set volume kSpeakers level MinVolume
		tell application "kJams Pro" to docommand kScriptCommand_PLAY_PAUSE
		
		repeat until (iTunesVolume ≤ 0 and kJamsVolume ≥ kJamsMaxVolume)
			set iTunesVolume to (iTunesVolume - fadeStep)
			if kJamsVolume is less than kJamsMaxVolume then 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 "iTunes" to pause
		
	else
		--set all volumes to cross fade starting values 
		set iTunesVolume to MinVolume
		set kJamsVolume to kJamsMaxVolume
		tell application "kJams Pro" to set volume kSpeakers level kJamsMaxVolume
		tell application "iTunes" to set the sound volume to MinVolume
		tell application "iTunes" to play
		repeat until (kJamsVolume ≤ 0 and iTunesVolume ≥ iTunesMaxVolume)
			if iTunesVolume is less than iTunesMaxVolume then 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 tell
OK, Dave, where is my million dollars?

jfbiii
Posts: 179
Joined: Tue Jan 15, 2008 3:22 pm

Re: Setting volume control

Post by jfbiii »

Oh good...I was dreading taking a stab at this myself. :) Nice though. Firing it isn't so bad...I ended up dragging the script into the dock between the kJams and the iTunes logos so I don't have to dig through a menu for it. I don't use it so often because I normally don't play music in between songs but when I need it it's easier to find in the dock than digging through the script folder on the right side of the menu bar for it.
From he to whom much liquor is given...much singing is expected.

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Setting volume control

Post by DeusExMachina »

Glad people are finding it useful.

My reason for wanting a scripts menu is that I have a number of script ideas for kJams, and having a scripts menu would make it easier to launch them. Having 15 scripts in the dock would be cumbersome.

Currently, I use QuickSilver to launch things, so it is not that big a deal, except when I mistype, and launch "Crash kJams" instead of "Crossfade!" Whoops!

What I really want to be able to do is crossfade between kJams and audio clips I make while a singer is singing. I am trying to avoid GUI-based macros, but I can't seem to get my recording app to respect my authority. So I may start looking into quicktime (though that has it's own interface usability issues.)

DeusExMachina
Posts: 1293
Joined: Sun Apr 20, 2008 9:57 am
Location: Pittsburgh, PA
Contact:

Re: Setting volume control

Post by DeusExMachina »

OK, I couldn't resist! I rewrote the whole thing to fix a few issues. Instead of the user having to edit the script to set max volume levels, the script is now intelligent, and polls iTunes and kJams to get their current volume levels. They do NOT any longer need to be the same. Rather, the script fades each at different speeds such that both reach their end points at the same time. I also redid some of the algorithm logic so it was more compact, and so it should run smoothly.
Here is a link to the code:
http://karaoke.kjams.com/wiki/Code/new_ ... Crossfader
Last edited by DeusExMachina on Wed Jun 09, 2010 5:54 pm, edited 1 time in total.

Post Reply