Scripting

From kJams Wiki
Jump to navigation Jump to search

Note that kJams 2 uses Python scripting!

You can use AppleScript to cause kJams Pro to export your songs to QuickTime format.

Here is an example script for kJams:

tell application "kJams Pro"
	-- returns the version of kJams that is running
	--version
	
	-- a test property, returns false if kJams is not crashed.  set this to true to make kJams crash
	--crash
	--set crash to true
	
	-- it is okay to add the same song twice from a script, it will only be added once
	-- it is also okay if the song is on a CD, it won't actually add to the library in that case
	-- must pass a POSIX path
	set songID to add to library "/Volumes/SGB0001 - Free Style Jazz Volume 1/7 The Lady Is A Tramp.aiff"
	
	if songID is not 0 then
		-- POSIX path for output folder, tilde is okay for user folder
		export songID encoder "QuickTime Movie" preset "Animation / AAC Best" folder "~/Desktop"
	end if

	-- get or set the volume of mics and speakers.  volume level goes from 0 to 100
	set kSpeakers to 0
	set kMicrophone_1 to 1
	
	set volume kSpeakers level 50
	get volume kMicrophone_1

	-- you can get the current time, the remaining time, or the absolute duration of the currently playing song.
	-- curT is in floating point seconds
	set kCurSongTime_DURATION to 0
	set kCurSongTime_CURRENT to 1
	set kCurSongTime_REMAINING to 2

	set curT to get time kCurSongTime_CURRENT

	-- you can get the current mode too (stopped, playing, paused)
	set kPlayModeType_STOPPED to 0
	set kPlayModeType_PLAYING to 1
	set kPlayModeType_PAUSED to 2

	set playMode to get mode
end tell

Hey! Here's the first application using scripting! The Crossfade Script!

or try this

Simple commands if you want to write your own Remote Control software:

set kScriptCommand_PLAY_PAUSE to 1
set kScriptCommand_STOP to 2
set kScriptCommand_BACK_REWIND to 3
set kScriptCommand_NEXT to 4
set kScriptCommand_VOL_UP to 5
set kScriptCommand_VOL_DOWN to 6
set kScriptCommand_VOL_MUTE to 7
set kScriptCommand_PITCH_UP to 8
set kScriptCommand_PITCH_DOWN to 9
set kScriptCommand_PITCH_NORMAL to 10
set kScriptCommand_SAVE to 11
set kScriptCommand_TEMPO_UP to 12
set kScriptCommand_TEMPO_DOWN to 13
set kScriptCommand_TEMPO_NORMAL to 14
set kScriptCommand_FULL_SCREEN to 15
set kScriptCommand_CAM_POWER to 16
set kScriptCommand_CAM_SHOOT to 17
set kScriptCommand_CRASH to 18
set kScriptCommand_RESCAN_VENUE to 19
set kScriptCommand_SHOW_ROTATION to 20
set kScriptCommand_HIDE_SHOWSCREEN to 21
set kScriptCommand_IS_SHOWSCREEN_SHOWING to 22
set kScriptCommand_GET_SHOW_ROTATION_TIME_REMAIN to 23
set kScriptCommand_TOGGLE_TRANSPARENT_VIDEO to 24
set kScriptCommand_IS_TRANSPARENT_VIDEO to 25
set kScriptCommand_GET_VIDEO_WINDOW_DISPLAY_ID to 26
set kScriptCommand_GET_IND_SONG_ID to 27
set kScriptCommand_GET_PLAY_MODE to 47
set kScriptCommand_GetVolume to 57
set kScriptCommand_SetVolume to 58
set kScriptCommand_Get_ModDate to 63
set kScriptCommand_GET_CUR_SONG_TIME to 64
set kScriptCommand_GET_CUR_SONG_DURATION to 65
set kScriptCommand_GET_CUR_SONG_PROG_PERCENT to 66
set kScriptCommand_SET_CUR_SONG_PROG_PERCENT to 67
set kScriptCommand_CUE to 68
set kScriptCommand_GET_PITCH to 70
set kScriptCommand_GET_TEMPO to 71
set kScriptCommand_IS_MUTED to 72

I haven't tested the "SET" ones, not sure if putting a number after the command will function? The ones with "Str" in them return strings, the rest return a floating point number

set kScriptCommandStr_GetAppVersion to 40

set kScriptCommandStr_GetCurSongName to 41
set kScriptCommandStr_GetCurSongPath to 42
set kScriptCommandStr_GetCurSongCachePath to 43

set kScriptCommandStr_GetNextSongName to 44
set kScriptCommandStr_GetNextSongPath to 45
set kScriptCommandStr_GetNextSongCachePath to 46
set kScriptCommandStr_SHOW_SHOWSCREEN to 69 //  you have to pass the name of the showscreen in as a string
tell application "kJams Pro"
	docommand kScriptCommand_PLAY_PAUSE
	set is_showingB to docommand kScriptCommand_IS_SHOWSCREEN_SHOWING
	if is_showingB
		// do something
	end if

	set myString to docommand_str kScriptCommandStr_GetCurSongPath
	// do something with the path.  check for empty path first!
end tell