Code/AudioClip Recorder: Difference between revisions

From kJams Wiki
Jump to navigation Jump to search
Created page with 'I was inspired by a thread in the forum about the cross fader script. I never use it, mostly because I do not have any free spots to allow for intermission music. But what I DO d…'
 
No edit summary
Line 6: Line 6:


Hope someone finds this useful.
Hope someone finds this useful.
Audio Clip Recorder:
<pre>
tell application "QuickTime Player"
activate
new audio recording
start document 1
set answer to ""
repeat while answer = ""
set question to display dialog "Recording started" buttons {"Stop recording", "Save Recording"}
set answer to button returned of question
end repeat
stop document 1
if answer is equal to "Save Recording" then save document 1
end tell
</pre>
Audio Clip Crossfading Playback:
<pre>
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 QuickTimePlayerMaxVolume to 1
--this is the minimum volume setting
set MinVolume to 0
tell application "QuickTime Player"
set QuickTimePlayerVolume to MinVolume
set kJamsVolume to kJamsMaxVolume
tell application "kJams Pro" to set volume kSpeakers level kJamsMaxVolume
set the audio volume of document 1 to MinVolume
play document 1
repeat until (kJamsVolume ≤ 0 and audio volume of document 1 ≥ QuickTimePlayerMaxVolume)
if QuickTimePlayerVolume is less than QuickTimePlayerMaxVolume then set QuickTimePlayerVolume to (QuickTimePlayerVolume + fadeStep * 0.01)
set kJamsVolume to (kJamsVolume - fadeStep)
set the audio volume of document 1 to QuickTimePlayerVolume
tell application "kJams Pro" to set volume kSpeakers level kJamsVolume
delay fadeDelay
end repeat
set answer to ""
set isPlaying to playing of document 1
repeat until (isPlaying is equal to false or answer is equal to "Stop Playback")
set question to display dialog "Stop Playback" buttons {"Stop Playback", "Continue Playback"}
set answer to button returned of question
if answer is equal to "Stop Playback" then
repeat until (QuickTimePlayerVolume ≤ 0)
set QuickTimePlayerVolume to (QuickTimePlayerVolume - fadeStep * 0.01)
set the audio volume of document 1 to QuickTimePlayerVolume
delay fadeDelay
end repeat
exit repeat
end if
set isPlaying to playing of document 1
end repeat
stop document 1
tell application "kJams Pro"
docommand kScriptCommand_STOP
set volume kSpeakers level kJamsMaxVolume
activate
end tell
end tell
</pre>

Revision as of 07:39, 9 June 2010

I was inspired by a thread in the forum about the cross fader script. I never use it, mostly because I do not have any free spots to allow for intermission music. But what I DO do is record little snippets of people singing, and play them back after they finish, while I am waiting for the next singer to fight their way to the mic. I have to time the recording to give me a buffer so that I can use the mixer to fade them in and out, and sometimes it can get a bit rough, with sudden, loud beginnings or abrupt endings. So I wrote this pair of scripts to automate the process. The first is a simple script to tell QuickTime to record the current input channel. You can set it to internal mic or (preferably) the line in (you'll need to run a line from your mixer to the microphone input of your mac. Sorry, I don't do Windows scripting. Someone else will have to take care of that, once the Windows version comes out!) You have the option after the recording is done to save the recording to disk if you want a permanent copy. This is not necessary, even for the next part.

The second script then automates the playback. Activate the script and it will fade out the current song (usually at the end) in kJams, and fade in the most recent recording. You can either let it play out, or you can stop playback early, in which case it will fade back out, reset the volume in kJams, and bring kJams to the frontmost application.

Hope someone finds this useful.

Audio Clip Recorder:

tell application "QuickTime Player"
	activate
	new audio recording
	start document 1
	set answer to ""
	repeat while answer = ""
		set question to display dialog "Recording started" buttons {"Stop recording", "Save Recording"}
		set answer to button returned of question
	end repeat
	stop document 1
	if answer is equal to "Save Recording" then save document 1
end tell

Audio Clip Crossfading Playback:

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 QuickTimePlayerMaxVolume to 1
--this is the minimum volume setting 
set MinVolume to 0

tell application "QuickTime Player"
	set QuickTimePlayerVolume to MinVolume
	set kJamsVolume to kJamsMaxVolume
	tell application "kJams Pro" to set volume kSpeakers level kJamsMaxVolume
	set the audio volume of document 1 to MinVolume
	play document 1
	repeat until (kJamsVolume ≤ 0 and audio volume of document 1 ≥ QuickTimePlayerMaxVolume)
		if QuickTimePlayerVolume is less than QuickTimePlayerMaxVolume then set QuickTimePlayerVolume to (QuickTimePlayerVolume + fadeStep * 0.01)
		set kJamsVolume to (kJamsVolume - fadeStep)
		set the audio volume of document 1 to QuickTimePlayerVolume
		tell application "kJams Pro" to set volume kSpeakers level kJamsVolume
		delay fadeDelay
	end repeat
	set answer to ""
	set isPlaying to playing of document 1
	
	repeat until (isPlaying is equal to false or answer is equal to "Stop Playback")
		set question to display dialog "Stop Playback" buttons {"Stop Playback", "Continue Playback"}
		set answer to button returned of question
		if answer is equal to "Stop Playback" then
			repeat until (QuickTimePlayerVolume ≤ 0)
				set QuickTimePlayerVolume to (QuickTimePlayerVolume - fadeStep * 0.01)
				set the audio volume of document 1 to QuickTimePlayerVolume
				delay fadeDelay
			end repeat
			exit repeat
		end if
		set isPlaying to playing of document 1
	end repeat
	stop document 1
	
	tell application "kJams Pro"
		docommand kScriptCommand_STOP
		set volume kSpeakers level kJamsMaxVolume
		activate
	end tell
end tell