Code/AudioClip Recorder: Difference between revisions

From kJams Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 4: Line 4:


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 either case, it will fade back out, reset the volume in kJams, close the audio recording window, and bring kJams to the frontmost application.
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 either case, it will fade back out, reset the volume in kJams, close the audio recording window, and bring kJams to the frontmost application.
(Note: There are still some issues, namely the fact that QT currently does not remove the item after it is recorded, but instead saves it as "audio recording <x>.mov" in the Movies folder. I have tried to remove this file in the playback script, but have yet to figure it out, so the option to save is almost redundant. Even so, having that option allows you to name the file, and just go in and delete all the "audio recording <x>.mov" files without previewing them. I hope to fix this shortly.


Hope someone finds this useful.
Here is the code. Hope someone finds this useful.


Audio Clip Recorder:
Audio Clip Recorder:
Line 13: Line 14:
new audio recording
new audio recording
start document 1
start document 1
set answer to ""
set question to display dialog "Recording started" buttons {"Stop recording", "Save Recording"}
repeat while answer = ""
set answer to button returned of question
set question to display dialog "Recording started" buttons {"Stop recording", "Save Recording"}
set answer to button returned of question
end repeat
stop document 1
stop document 1
if answer is equal to "Save Recording" then save document 1
if answer is equal to "Save Recording" then save document 1

Revision as of 11:00, 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 either case, it will fade back out, reset the volume in kJams, close the audio recording window, and bring kJams to the frontmost application. (Note: There are still some issues, namely the fact that QT currently does not remove the item after it is recorded, but instead saves it as "audio recording <x>.mov" in the Movies folder. I have tried to remove this file in the playback script, but have yet to figure it out, so the option to save is almost redundant. Even so, having that option allows you to name the file, and just go in and delete all the "audio recording <x>.mov" files without previewing them. I hope to fix this shortly.

Here is the code. Hope someone finds this useful.

Audio Clip Recorder:

tell application "QuickTime Player"
	activate
	new audio recording
	start document 1
	set question to display dialog "Recording started" buttons {"Stop recording", "Save Recording"}
	set answer to button returned of question
	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 isPlaying to playing of document 1
	set secondsToFade to (kJamsMaxVolume / fadeStep) * fadeDelay
	set endingTime to (duration of document 1) - 2 * secondsToFade
	set question to display dialog "Stop Playback?" buttons {"Stop Playback"} default button 1 giving up after endingTime
	repeat while isPlaying
		repeat until (QuickTimePlayerVolume ≤ 0)
			set QuickTimePlayerVolume to (QuickTimePlayerVolume - fadeStep * 0.01)
			set the audio volume of document 1 to QuickTimePlayerVolume
			delay fadeDelay
		end repeat
		stop document 1
		set isPlaying to playing of document 1
	end repeat
	close document 1
	tell application "kJams Pro"
		docommand kScriptCommand_STOP
		set volume kSpeakers level kJamsMaxVolume
		activate
	end tell
end tell