示例#1
0
def main():
    cmd = kjams.enum_cmds()

    while True:
        for x in range(0, 20):
            kjams.do_cmd(cmd.kScriptCommand_VOL_UP)
            # same thing:
            # kjams.menu("Controls", "Volume Up")
            time.sleep(0.25)
        for x in range(0, 20):
            kjams.do_cmd(cmd.kScriptCommand_VOL_DOWN)
            # same thing:
            # kjams.menu("Controls", "Volume Down")
            time.sleep(0.25)
示例#2
0
def main():
    print sys.path

    cmd = kjams.enum_cmds()

    print "startup script BEGIN"  # print statements go to the kJams Log File
    # want to see the logs? do this line:
    # kjams.menu("Help", "Reveal Logs")

    resultStr = kjams.do_cmd(cmd.kScriptCommandStr_GetAppVersion)
    print 'App Version: ' + resultStr

    # when you select a script from the menu, if you have the alt key/option down
    # then kjams will tell the OS to open the file, instead of run the script inside kJams.
    # the point is that you want to view or edit the script, rather than have python
    # inside kjams execute it.
    # On windows, opening a .py script will cause the OS to *run* it (and not even inside kjams)
    # so there is the option to reveal it instead so you can right click and pick "edit".
    kjams.pref_set("python: alt key causes reveal instead of open",
                   kjams.is_on_windows())

    # turn this on if you don't want to see the test scripts
    if False:
        kjams.pref_set("python: hide test scripts", True)

    # let's give a key shortcut to the new itunes crossfader
    kjams.menu_set_command_key("SubMenu/Python/itunes_crossfade.py", "\'")

    # if you want assurance that your script ran, have it make a sound
    # when it completes
    # kjams.do_cmd(cmd.kScriptCommand_CAM_SHOOT)

    print "startup script END"
示例#3
0
def do_test(orig_str):
    cmd_enum = kjams.enum_cmds()

    print "---------------"
    print "Original string: " + orig_str
    print "converting..."

    oldstr = orig_str
    newstr = kjams.do_cmd(cmd_enum.kScriptCommand_Unicode_Test, oldstr)
    log_success("string", oldstr == newstr, newstr)

    oldstr = unicode(orig_str, "UTF-8")
    oldstr.encode("UTF-8")
    newstr = kjams.do_cmd(cmd_enum.kScriptCommand_Unicode_Test, oldstr)
    newstr = unicode(newstr, "UTF-8")
    log_success("unicode", oldstr == newstr, newstr)

    print "---------------"
示例#4
0
def main():
    kjams.do_cmd(kjams.enum_cmds().kScriptCommand_CAM_SHOOT)

    enum_play_states = itunes.enum_play_states()
    cur_state = itunes.play_state()

    print "cur_state: " + str(cur_state)
    print "Play state: " + enum_play_states.reverse_mapping[cur_state]

    # or try this
    if False:
        if cur_state == enum_play_states.iTunesEPlSPaused:
            itunes.playpause()

    print "Volume: " + str(itunes.get_volume())

    itunes.set_volume(75)
    itunes.next()

    print "New Volume: " + str(itunes.get_volume())
示例#5
0
def main():
	cmd = kjams.enum_cmds()

	# pl = play list
	pl_ID = kjams.do_cmd(cmd.kScriptCommand_GetSelectedPlaylist)
	
	# returns an array (list) of PLI_IDs
	pli_id_list = kjams.do_cmd(cmd.kScriptCommand_GET_PLI_LIST, pl_ID)
	
	# the following does NOT dothe same thing: 
	# nameStr, pli_id_list = server_get_plItem_list(enum_server().CWS_Path_SONGS, pl_ID)
	# the above line returns a list of dicts, each being a song, containing strings
	# with name, artist, album strings etc
	
	# selection is also a pli_id_list
	# cur_selection = kjams.do_cmd(cmd.kScriptCommand_GetSelection, pl_ID)
	
	# select first item in the play list	
	if len(pli_id_list) != 0:
		# pli = play list item
		pli_ID = pli_id_list[0]			# take first item 
		single_selection = [ pli_ID ]	# make a new list (array) with just that
		kjams.do_cmd(cmd.kScriptCommand_SetSelection, pl_ID, single_selection)
	
		# always stop before attempting to play the selected song, otherwise you 
		# might just resume a paused song in another playlist
		#kjams.do_cmd(cmd.kScriptCommand_STOP)
		#kjams.do_cmd(cmd.kScriptCommand_PLAY_PAUSE)

		# here's how to pick "Convert Selection To..."  
		# no mater what the encoder string is
		# note that indexes are a bit more fragile because they can  change
		# between releases (tho very unlikely, you should still check each new release)
		# be sure to select something first!
		'''
		kAdvancedMenu = 4
		kConvertSelectionItem = 10
		kjams.menu(kAdvancedMenu, kConvertSelectionItem)
		'''
		
		song_ID = kjams.do_cmd(cmd.kScriptCommand_PLI_TO_SONG_ID, pl_ID, pli_ID)
		songDict = kjams.do_cmd(cmd.kScriptCommand_GetMeta, song_ID)
		#print songDict	# <- will print strings as ASCII
		
		# see https://karaoke.kjams.com/wiki/Xattr for dictionary keys
		zipPathDict = songDict['Sfs2']
		zipPath = zipPathDict['path']
		print zipPath	# <- utf8 now, you're welcome
示例#6
0
def auto_crossfader():
	itunes.initialize();
	cmds = kjams.enum_cmds()
	player = enum_player()

	fade_durationF = kjams.pref_get('Crossfade Duration (seconds)')

	# Number of steps in fade
	fadeSteps = 20
	
	# sets how long in seconds between each step in the fade 
	fadeDelay = fade_durationF / fadeSteps

	# Get current audio volume from kJams	
	kJamsMaxVolume = kjams.get_volume();

	# set iTunes volume maximum.
	iTunesMaxVolume = itunes.get_volume()
	
	# this is the minimum volume setting 
	MinVolume = 0

	# cur_player will be either 0 for kJams or 1 for iTunes
	cur_player = player.kJams
	prev_player = player.kJams

	while True:
		# is kJams playing?
		playMode = kjams.do_cmd(cmds.kScriptCommand_GET_PLAY_MODE)
		
		# Check to see if kJams is playing
		if playMode == kjams.enum_play_modes().kPlayModeType_PLAYING:
		
			# if kJams is playing, set current cur_player to kJams
			cur_player = player.kJams
			
			# If prev_player is not the same as the current state
			# i.e. if kJams is has just started playing, fade in kJams and fade out iTunes
			if prev_player == player.iTunes:
				currentVolume = kjams.get_volume()
				
				if currentVolume != MinVolume:
					kJamsMaxVolume = currentVolume
					
				# sets how much in percentage the volume is decreased per step
				kJFadeStep = kJamsMaxVolume / fadeSteps
				kJamsVolume = MinVolume
				
				# get current starting volume from iTunes
				iTunesVolume = itunes.get_volume()
				
				kjams.set_volume(MinVolume)
				
				while not (iTunesVolume <= MinVolume and kJamsVolume >= kJamsMaxVolume):
					iTunesVolume = iTunesVolume - iTFadeStep
					kJamsVolume = kJamsVolume + kJFadeStep
					
					if kJamsVolume > kJamsMaxVolume:
						kJamsVolume = kJamsMaxVolume
					
					itunes.set_volume(iTunesVolume)
					kjams.set_volume(kJamsVolume)
					time.sleep(fadeDelay)

				# if you do NOT want iTunes to pick up where it left off, un-comment the following line
				# itunes.next()
				itunes.pause()
		else:
			# if kJams is not playing, set current cur_player to iTunes
			cur_player = player.iTunes
			
			#if kJams has just now been paused, cross fade in iTunes
			if prev_player == player.kJams:
			
				currentVolume = itunes.get_volume()
				
				if currentVolume != MinVolume:
					iTunesMaxVolume = currentVolume
					
				iTFadeStep = iTunesMaxVolume / fadeSteps
				
				#Get current audio volume from kJams
				kJamsMaxVolume = kjams.get_volume()
				kJFadeStep = kJamsMaxVolume / fadeSteps
				kJamsVolume = kJamsMaxVolume
				
				#set all volumes to cross fade starting values 
				iTunesVolume = MinVolume
				itunes.set_volume(MinVolume)
				itunes.play()
				
				while not (iTunesVolume >= iTunesMaxVolume):
					iTunesVolume = iTunesVolume + iTFadeStep

					if iTunesVolume > iTunesMaxVolume:
						iTunesVolume = iTunesMaxVolume

					itunes.set_volume(iTunesVolume)
					time.sleep(fadeDelay)

				#Get current audio volume from iTunes
				iTunesMaxVolume = itunes.get_volume()
				iTFadeStep = iTunesMaxVolume / fadeSteps
				kjams.set_volume(MinVolume)
			
		prev_player = cur_player
		time.sleep(0.5)
示例#7
0
def main():
	urlStr = kjams.do_cmd(cmd.kScriptCommand_Get_ServerAddress)
	kjams.do_cmd(cmd.kScriptCommand_Create_QR_Code, "~/Desktop", "qr_server", urlStr)
示例#8
0
def main():
    # get the songID of our song
    norml_song_ID = 535762
    #	sunfly
    media_song_ID = 1106433
    #	producer

    kjams.pref_set("Messenger Rotation size", 3)

    outFolderStr = "~/Desktop/export tests"
    encoderStr = "QuickTime Movie"
    presetStr = "Animation / Lossless"

    options_enum = kjams.enum(
        'MS',  #	no key,	MediaStream
        'SAM',  #			SAMple
        'TRA',  #			TRAnsparent
        'PAD',  #			PADding
        'SLI',  #	no key,	SLIpping
        'HQ',  #			HQX Upscale
        'HD',  #	no key,	HighDef
    )

    options = {}
    #	this is a map (dict)
    for curOption in options_enum.reverse_mapping:
        options[curOption] = [False, ""]

    # those with keys
    options[options_enum.TRA][Option_Key] = "QT Export with transparency"
    options[options_enum.PAD][Option_Key] = "Pad QuickTime Export to 320 x 240"
    options[options_enum.
            HQ][Option_Key] = "Use hq4x upscaling (fast computers only)"
    options[options_enum.SAM][Option_Key] = "QT Export only 30 seconds"

    outName_key = "QuickTime Export Name"
    skipExisting_key = "QuickTime Export Skip Existing"

    kjams.pref_set(skipExisting_key, True)

    loopSize = int(math.pow(2, len(options)))
    kjams.prog_set(0, loopSize)

    for optionBits in range(0, loopSize):

        outName = ""
        i_hdB = False
        i_slipB = False
        i_songID = norml_song_ID

        for curOption in range(0, len(options)):
            testBit = 1 << curOption
            is_onB = (optionBits & testBit) != 0
            options[curOption][Option_Is_ON] = is_onB
            outName += options_enum.reverse_mapping[curOption]
            if is_onB:
                outName += '1'
            else:
                outName += '0'

            outName += '-'

            if is_onB and options[curOption][Option_Key] == "":
                if curOption == options_enum.HD:
                    i_hdB = True
                elif curOption == options_enum.SLI:
                    i_slipB = True
                elif curOption == options_enum.MS:
                    i_songID = media_song_ID

        # pop the last dash
        outName = outName[:-1]

        while kjams.do_cmd(kjams.enum_cmds().kScriptCommand_Is_Exporting,
                           i_songID):
            time.sleep(0.2)

        kjams.prog_set_str(outName)
        kjams.prog_set(optionBits)

        nameStr = "song"
        if i_songID == media_song_ID:
            nameStr = "media song"

        if not legal_options(options_enum, options):
            print "Skipping (invalid): " + outName
        else:
            print outName

            if not is_test():
                # set prefs
                for curOption in range(0, len(options)):
                    optionKey = options[curOption][Option_Key]
                    if optionKey != "":
                        is_onB = options[curOption][Option_Is_ON]
                        print 'setting "' + optionKey + '" to ' + str(is_onB)
                        kjams.pref_set(optionKey,
                                       options[curOption][Option_Is_ON])

                slip_durationT = 0
                if i_slipB:
                    slip_durationT = 73.5

                slipDict = {
                    'Slip': slip_durationT
                }

                print 'setting "slipping" to ' + str(slip_durationT)
                kjams.do_cmd(kjams.enum_cmds().kScriptCommand_SetMeta,
                             i_songID, slipDict)

                print 'setting "' + outName_key + '" to ' + outName
                kjams.pref_set(outName_key, outName)

                definitionStr = "SD"
                if i_hdB:
                    definitionStr = "HD"

                print 'encoder preset is "' + definitionStr + '"'

                curPresetStr = presetStr
                if (i_hdB):
                    curPresetStr += " HD"

                if True:
                    kjams.do_cmd(kjams.enum_cmds().kScriptCommand_EXPORT,
                                 i_songID, encoderStr, curPresetStr,
                                 outFolderStr)
        #------------------------------------------------

    kjams.pref_set(outName_key, "")
    kjams.pref_set(options[options_enum.TRA][Option_Key], False)
    kjams.pref_set(options[options_enum.PAD][Option_Key], False)
    kjams.pref_set(options[options_enum.HQ][Option_Key], True)
    kjams.pref_set(options[options_enum.SAM][Option_Key], False)

    slipDict = {
        'Slip': 0
    }

    kjams.do_cmd(kjams.enum_cmds().kScriptCommand_SetMeta, norml_song_ID,
                 slipDict)

    kjams.do_cmd(kjams.enum_cmds().kScriptCommand_SetMeta, media_song_ID,
                 slipDict)
示例#9
0
def crossfade():
    itunes.initialize()
    cmds = kjams.enum_cmds()

    fade_durationF = kjams.pref_get('Crossfade Duration (seconds)')

    # Number of steps in fade
    fadeSteps = 20

    # sets how long in seconds between each step in the fade
    fadeDelay = fade_durationF / fadeSteps

    # Get current audio volume from kJams
    kJamsMaxVolume = kjams.get_volume()

    # set iTune volume maximum.
    iTunesMaxVolume = itunes.get_volume()

    # sets how much in percentage the volume is decreased per step
    kJFadeStep = kJamsMaxVolume / fadeSteps
    iTFadeStep = iTunesMaxVolume / fadeSteps

    # this is the minimum volume setting
    MinVolume = 0

    if itunes.play_state() == itunes.enum_play_states().iTunesEPlSPlaying:
        # set all volumes to cross fade starting values
        kJamsVolume = MinVolume
        iTunesVolume = iTunesMaxVolume

        kjams.set_volume(MinVolume)
        kjams.do_cmd(cmds.kScriptCommand_PLAY_PAUSE)

        while not (iTunesVolume <= 0 and kJamsVolume >= kJamsMaxVolume):
            iTunesVolume = iTunesVolume - iTFadeStep
            kJamsVolume = kJamsVolume + kJFadeStep
            itunes.set_volume(iTunesVolume)
            kjams.set_volume(kJamsVolume)
            time.sleep(fadeDelay)

        itunes.pause()
        itunes.set_volume(iTunesMaxVolume)

    else:
        # set all volumes to cross fade starting values
        iTunesVolume = MinVolume
        kJamsVolume = kJamsMaxVolume
        kjams.set_volume(kJamsMaxVolume)
        itunes.set_volume(MinVolume)

        itunes.play()

        while not (kJamsVolume <= 0 and iTunesVolume >= iTunesMaxVolume):
            iTunesVolume = iTunesVolume + iTFadeStep
            kJamsVolume = kJamsVolume - kJFadeStep
            itunes.set_volume(iTunesVolume)
            kjams.set_volume(kJamsVolume)
            time.sleep(fadeDelay)

        kjams.do_cmd(cmds.kScriptCommand_STOP)
        kjams.set_volume(kJamsMaxVolume)