-- script Name 			: LipScript
-- Ver					: 1.1
-- Written By			: Shibu Menon, Charles Elwonger and Mark Zartler
-- Home Page			: http://www.annosoft.com/3dsmax_lipsync.htm
-- contact				: mzartler@annosoft.com
-------------------------------------------------------------------------------------------------------
--Usage:
-- To be used along with The Lipsync Tool, a speech recognition program from Annosoft LLC, Texas, USA.
-- Please read the help file for detailed usage info.
-- Please report bugs/comments to mzartler@annosoft.com
-------------------------------------------------------------------------------------------------------
-- Changelog
-- 20060501		Added rotation controller support
-------------------------------------------------------------------------------------------------------


CommonMappingFloater = newRolloutFloater "LipScript" 700 700


rollout CommonVisemeMapperRollout "User Defined Phoneme Combinations" width:686 height:611
(
	
	-------------------------------------------------------------------------------------------------------variable declaraions start
	
	global Default_40_PhonemesList = #("x", "IY", "IH", "EH", "AE", "AH", "UW", "UH", "AA", "AO", "EY", "AY", "OY", "AW", "OW", "L", "r", "y", "w", "ER", "m", "n", "NG", "CH", "j", "DH", "b", "d", "g", "p", "t", "k", "z", "ZH", "v", "f", "TH", "s", "SH", "h") 
	
	global dropdownSelection = 0
	global number_UsedVisemes = #()	
	persistent global usedVisemeSlots = #();
	persistent global unUsedVisemeSlots = #()
	global usedVisemesCounterText = ""
	global xxx = 0;
	global foundPhonemesInCurrentAudio = #()
	global phon_list = #()
	
	-----------------------------------------------------------------------------boneRig Variables start
	persistent global BoneRig_CTRLObjs
	persistent global CTRL_objs_onWhich_posLists_Applied
	
	global New_BoneRig_CTRLObjsNames = #()
	global New_CTRL_objs_onWhich_posLists_Applied = #()
	global BoneRigCTRL_count = 0;
	global CTRL_count = 0;
	global pos_listController_Names = #();
	global def_pos_list_weights = #();
	global temp_pos_list_weights = #();
	global WeightMin = 0.0
	global WeightMax = 100.0
	global setupVisemeText = ""
	
	global temp_curPosList = #()
	global temp_Master_curPosList = #()
	global badCTRL_Obj = #()
	global badCTRL_Obj_PosList = #()
	-----------------------------------------------------------------------------boneRig Variables end
	
	global MorpherObject
	global mappedMorphChannelArray = for i = 1 to 20 collect 0
	global targetChannelNumber = 0
	global number_usedMorphs = 0
	global MorphTargetList = #()
	global UsedMorphTargets
	
	global Lipscript_CustAttribHelperObj
	---------------------------------------------------------------------------------------------------------variable declaraions end

	
	
	----------------------------------------------------------------------------------------------------------all functions defn start
	fn PhonemeStreamToArray visNumber= 
	(
	vis_text = ""
	vis_text += "editBox_Phons_" + visNumber as string + "_stream = CommonVisemeMapperRollout.editBox_Phons_" + visNumber as string + ".text as stringstream\n"
	vis_text += "viseme_" + visNumber as string + "_PhonemeArray = #()\n"
	vis_text += "while not(eof editBox_Phons_" + visNumber as string + "_stream) do\n"
	vis_text +=	"\t(\n"
	vis_text +=	"\t append viseme_" + visNumber as string + "_PhonemeArray (readDelimitedString editBox_Phons_" + visNumber as string + "_stream \",\")\n"
	vis_text += "\n\t)"
	execute vis_text
	)
	
	fn infoBoxtextfn = 
	(
	foundPhonemesInCurrentAudio = #()
	for k = 1 to phon_list.count do
		(
		if (findItem foundPhonemesInCurrentAudio phon_list[k] == 0) then 
			(
			append foundPhonemesInCurrentAudio phon_list[k]
			)
		)
	CommonVisemeMapperRollout.foundPhonemesInfoEditText.text = ""	
	CommonVisemeMapperRollout.foundPhonemesInfoEditText.text = (foundPhonemesInCurrentAudio[1])
	for i = 2 to foundPhonemesInCurrentAudio.count do
		(
		CommonVisemeMapperRollout.foundPhonemesInfoEditText.text += ("," + foundPhonemesInCurrentAudio[i])
		)
	CommonVisemeMapperRollout.RecogPhonemesInfoLabel.text = "Info - Phonemes found in the current .Anno File :"	
	CommonVisemeMapperRollout.NumberPhonemesLabel.text = (foundPhonemesInCurrentAudio.count as string)
	)
	
	
	fn SaveVisPresetfn presetFileName = 
	(
	for i = 1 to 20 where (execute("viseme_" + i as string + "_PhonemeArray")!= undefined and  execute("viseme_" + i as string + "_PhonemeArray.count") != 0) do
			(
			format "%\t%\t" i (execute("viseme_" + i as string + "_PhonemeArray.count")) to:presetFileName
			for j = 1 to (execute("viseme_" + i as string + "_PhonemeArray.count")) do
				(
				format "%," (execute("viseme_" + i as string + "_PhonemeArray[" + j as string + "]")) to:presetFileName
				)
			format "\n" to:presetFileName	
			)
	format "~\n" to:presetFileName		
	)
	
	
	
	fn LoadVisPresetfn LoadedpresetFile = 
	(
	global tempText = "";
	usedVisemeSlots = #();
	global endChar = ""
	for k = 1 to 20 do
		(
		--PhonemeStreamToArray k
		tempText += "CommonVisemeMapperRollout.editBox_Phons_" + k as string + ".text = \"\"\n"
		)
		execute tempText
	
	i = 1
   try(
   		
	while (LoadedpresetFile != undefined and endChar != "~" and (not eof LoadedpresetFile) ) do
		( ------------------------------------------------------------- while loop start
		global PresetVisNummer = 0
		global PresetVisPhoneme = #()
		global PresetNumPhonemes = 0
		
		
		PresetVisNummer = readValue LoadedpresetFile
		PresetNumPhonemes = readValue LoadedpresetFile
		
		for j = 1 to PresetNumPhonemes do
			(
			append PresetVisPhoneme (readDelimitedString LoadedpresetFile ",")
			)
		TempText = ""
		for i = 1 to PresetNumPhonemes do
			(
			tempText += "CommonVisemeMapperRollout.editBox_Phons_" + PresetVisNummer as string + ".text = CommonVisemeMapperRollout.editBox_Phons_" + PresetVisNummer as string + ".text + PresetVisPhoneme[" + i as string + "]"
			if i != PresetNumPhonemes then
			tempText += " + \",\" "
			tempText += "\n"
			)
		execute tempText
		endChar = (readchar LoadedpresetFile)
		PhonemeStreamToArray PresetVisNummer
		
		)------------------------------------------------------------- while loop end
      
	  )catch()
	--print (readline LoadedpresetFile)
	)
	
	
	
	
	fn saveMorphSetupfn =
	(
	try(
		MorphSetupSaveFile = createfile ((getsavefilename caption:"Save Viseme Preset as: ") + ".AnM")
		)catch()
	SaveVisPresetfn MorphSetupSaveFile	
	format "%\n" mappedMorphChannelArray to:MorphSetupSaveFile
	)
	
	
	fn saveBoneSetupfn =
	(
	try(
		BoneSetupSaveFile = createfile ((getsavefilename caption:"Save Viseme Preset as: ") + ".AnB")
		)catch()
	SaveVisPresetfn BoneSetupSaveFile	
	format "#(" to:BoneSetupSaveFile
	for i = 1 to (CTRL_objs_onWhich_posLists_Applied.count) do
		(
		format "\"%\"" (CTRL_objs_onWhich_posLists_Applied[i].name) to:BoneSetupSaveFile
		if i != CTRL_objs_onWhich_posLists_Applied.count then format "," to:BoneSetupSaveFile
		)
	format ")\n" to:BoneSetupSaveFile	
	format "%\n" usedVisemeSlots to:BoneSetupSaveFile
	)

	
	
	
	
	fn dropdownHandler visNumber = 
	(
	dropdownHandlerText = ""	
	dropdownHandlerText +=	"if CommonVisemeMapperRollout.editBox_Phons_" + visNumber as string + ".text == \"\" then\n"
	dropdownHandlerText +=	"CommonVisemeMapperRollout.editBox_Phons_" + visNumber as string + ".text = CommonVisemeMapperRollout.editBox_Phons_" + visNumber as string + ".text + Default_40_PhonemesList[dropdownSelection]\n"
	dropdownHandlerText +=	"else\n"
	dropdownHandlerText +=	"CommonVisemeMapperRollout.editBox_Phons_" + visNumber as string + ".text = CommonVisemeMapperRollout.editBox_Phons_" + visNumber as string + ".text + \",\" + Default_40_PhonemesList[dropdownSelection]\n"
	execute dropdownHandlerText
	)

	
	
	
	fn usedVisemesCounter =
	(
	usedVisemesCounterText = ""
	usedVisemeSlots = #();
	UnusedVisemeSlots = #();
	for xxx = 1 to 20 do
			(
			PhonemeStreamToArray xxx
	usedVisemesCounterText += " if (  ((viseme_" + xxx as string + "_PhonemeArray)!= undefined) and ((viseme_" + xxx as string + "_PhonemeArray.count)!= 0) and ((finditem usedVisemeSlots " + xxx as string + ") == 0)   ) then\n"
	
	usedVisemesCounterText += " (\n"
	usedVisemesCounterText += " append usedVisemeSlots " + xxx as string + "\n"
	usedVisemesCounterText += " )\n"
	usedVisemesCounterText += "else\n"
	usedVisemesCounterText += " (\n"
	usedVisemesCounterText += " append UnusedVisemeSlots " + xxx as string + "\n"
	usedVisemesCounterText += " )\n"

			)
	execute usedVisemesCounterText
	CommonVisemeMapperRollout.UsedVisemesCounterLabel.text = ("Number of used Viseme Slots : " + (usedVisemeSlots.count as string))
	CommonVisemeMapperRollout.pb4.value = (usedVisemeSlots.count)*100/20
	
	
	--CTRL_count = usedVisemeSlots.count
	pos_listController_Names = for i in usedVisemeSlots collect ("AnnoViseme" + i as string)
	def_pos_list_weights = for i in usedVisemeSlots collect (if i == 1 then i*100.0 else i*0.0)
	append def_pos_list_weights 0.0
	CommonVisemeMapperRollout.pb4.text = "" ---- no logical use of this line ...... only to refresh the p-bar
	)

	fn setupVisemefn VisNumber =
	( ------------------------------------------------------------------------------------function setupVisemefn start
	temp_pos_list_weights = #()
		for i = 1 to ((usedVisemeSlots.count) + 1) do
		(
		append temp_pos_list_weights WeightMin
		)
	temp_pos_list_weights[1] = WeightMax
	for CO in CTRL_objs_onWhich_posLists_Applied do
		(
			CO.pos.controller.setactive 1
			CO.rotation.controller.setactive 1
	    )
	
	setupVisemeText = ""
	setupVisemeText += "if CommonVisemeMapperRollout.setup_ckb_vis_" + VisNumber as string +".checked == true then\n"
	setupVisemeText +="(\n"
	setupVisemeText += "for i = 1 to 20 where i != " + Visnumber as string + " do\n"
	setupVisemeText += "	(\n"
	setupVisemeText += "	(execute(\"CommonVisemeMapperRollout.setup_ckb_vis_\" + i as string)).checked = false"
	setupVisemeText += "	)\n"
	
	setupVisemeText += "temp_pos_list_weights[(findItem usedVisemeSlots " + VisNumber as string + " ) + 1] = WeightMax\n"
	
	setupVisemeText += "for CO in CTRL_objs_onWhich_posLists_Applied do\n"
	setupVisemeText += "	(\n"
	setupVisemeText += "	CO.pos.controller.setactive ((findItem usedVisemeSlots " + VisNumber as string + " ) + 1)\n"
	setupVisemeText += "	CO.rotation.controller.setactive ((findItem usedVisemeSlots " + VisNumber as string + " ) + 1)\n"
	setupVisemeText += "	)\n"
	
	setupVisemeText += ")\n"
	execute setupVisemeText
	for CO in CTRL_objs_onWhich_posLists_Applied do
		(
		CO.pos.controller.weight = temp_pos_list_weights
		CO.rotation.controller.weight = temp_pos_list_weights
		--CO.pos.controller.setactive ((findItem usedVisemeSlots VisNumber) + 1)
		)
	
	)------------------------------------------------------------------------------------function setupVisemefn end



	fn checkMorpher obj =
	(
	return_val = false;
	if (try(obj.morpher)catch(undefined)) != undefined	then (return_val = true)
	return return_val;
	)
	
	fn morphmapper Visnumber targetChannelNumber =
	(
	mappedMorphChannelArray[Visnumber] = targetChannelNumber
	
	)
	
	
	fn usedMorphsCounter =
	(
	number_usedMorphs = 0
	for i = 1 to 20 do
		(
		execute ("if CommonVisemeMapperRollout.MorphMapper_ddl_" + i as string + ".selected != undefined then number_usedMorphs += 1\n")
		)
	CommonVisemeMapperRollout.UsedTargetsCounterLabel.text = ("Number of targets Map'd : " + number_usedMorphs as string)
	try(CommonVisemeMapperRollout.pb5.value = number_usedMorphs * 100/(20))catch()
	if number_usedMorphs != 0 then
	CommonVisemeMapperRollout.MorphSetupSaveBtn.enabled = true

	)
	
	
	fn activateMorphDropDownsfn =
	(
	n = 1
	MorphTargetList = #()
	while (WM3_Mc_HasData MorpherObject.morpher n) do
		(
		append MorphTargetList ((n as string) + ". " + (WM3_MC_GetName MorpherObject.morpher n))
		n += 1
		)
	morphTargetDropDownText = ""
		for i = 1 to 20 do
		(
		morphTargetDropDownText += "CommonVisemeMapperRollout.MorphMapper_ddl_" + i as string + ".enabled = true\n"
		morphTargetDropDownText += "CommonVisemeMapperRollout.MorphMapper_ddl_" + i as string + ".items = MorphTargetList\n"
		)
	
	--	for i in usedVisemeSlots do
	--	(
	--	morphTargetDropDownText += "CommonVisemeMapperRollout.MorphMapper_ddl_" + i as string + ".enabled = true\n"
	--	morphTargetDropDownText += "CommonVisemeMapperRollout.MorphMapper_ddl_" + i as string + ".items = MorphTargetList\n"
	--	)
	execute morphTargetDropDownText	
	--CommonVisemeMapperRollout.LoadVisPresetBtn.enabled = false
	--for i in UnusedVisemeSlots do	
	--	(
	--	(execute("CommonVisemeMapperRollout.editBox_Phons_" + i as string)).enabled = false
	--	(execute("CommonVisemeMapperRollout.ddl_phons_" + i as string)).enabled = false
	--	)
	
	)
	
	
	fn compareVisemeSlots_w_PosListsfn =
	(
	temp_Master_curPosList = #()
	badCTRL_Obj = #()
	k = 0
	try(
	for i = 1 to BoneRig_CTRLObjs.count do
		(
		if classof BoneRig_CTRLObjs[i].pos.controller == Position_List then
			(
			temp_curPosList = #()
			for j = 2 to (BoneRig_CTRLObjs[i].pos.controller.count) do
				(
				temp_curPosList[j-1] = (execute(substring (BoneRig_CTRLObjs[i].pos.controller.getname j) 11 (BoneRig_CTRLObjs[i].pos.controller.getname j).count))
				--print temp_curPosList
				)
			
			append temp_Master_curPosList temp_curPosList
			)
		else
			(
			k += 1
			badCTRL_Obj[k] = BoneRig_CTRLObjs[i].name
			)
		)	
	   )catch()
	--print temp_Master_curPosList
	if badCTRL_Obj.count > 0 then messageBox (" Out of the Control Objects selected, " + badCTRL_Obj.count as string + " Objects donot have Position List Controllers :\n" + badCTRL_Obj as string + "\n Click on 'Setup Position Lists' to change the position controllers of these Objects to position lists") title: "Lipscript Warning !!"
	
	
	badCTRL_Obj_PosList = #()
	for i = 1 to temp_Master_curPosList.count do
		(
		compare_temp1 = 0
		for j = 1 to usedVisemeSlots.count do
			(
			if (findItem temp_Master_curPosList[i] usedVisemeSlots[j] == 0) then compare_temp1 += 1
			)
		if compare_temp1 > 0 then append badCTRL_Obj_PosList BoneRig_CTRLObjs[i].name
		)
	if badCTRL_Obj_PosList.count > 0 then messageBox (" Out of the Control Objects which have Position Lists, " + badCTRL_Obj_PosList.count as string + " Objects have Position Lists which donot match the active Viseme Slots :\n" + badCTRL_Obj_PosList as string + "\nThis could result in errors while shaping Visemes") title: "Lipscript Warning !!"

	)
	
	
----------------------------------------------------------------------------------------------------------------all function definitions end
	
	
	
	
	button MorphSetupLoadBtn "Load Map" pos:[377,95] width:67 height:22 enabled:false
	button MorphSetupSaveBtn "Save Map" pos:[448,95] width:67 height:22 enabled:false
	button BoneSetupLoadBtn "Load Map" pos:[538,95] width:64 height:22 enabled:false
	button BoneSetupSaveBtn "Save Map" pos:[608,95] width:64 height:22 enabled:true
	label UsedTargetsCounterLabel "Number of targets Map'd : 0" pos:[376,131] width:139 height:16
	edittext foundPhonemesInfoEditText "" pos:[4,25] width:650 height:19
	label NumberPhonemesLabel "0" pos:[660,27] width:77 height:15
	label RecogPhonemesInfoLabel "" pos:[10,8] width:318 height:13
	button ChooseAnnoFileRefbtn "Choose Exported .Anno File for reference" pos:[6,51] width:354 height:21
	
	label Viseme_1_lbl "Viseme 1 :" pos:[13,164] width:56 height:16
	edittext editBox_Phons_1 "" pos:[73,161] width:178 height:20
	dropdownList ddl_phons_1 "" pos:[265,161] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	
	label Viseme_2_lbl "Viseme 2 :" pos:[13,188] width:56 height:16
	edittext editBox_Phons_2 "" pos:[73,185] width:178 height:20
	dropdownList ddl_phons_2 "" pos:[265,185] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label Viseme_3_lbl "Viseme 3 :" pos:[13,212] width:56 height:16
	edittext editBox_Phons_3 "" pos:[73,209] width:178 height:20
	dropdownList ddl_phons_3 "" pos:[265,209] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	
	label Viseme_4_lbl "Viseme 4 :" pos:[13,236] width:56 height:16
	edittext editBox_Phons_4 "" pos:[73,233] width:178 height:20
	dropdownList ddl_phons_4 "" pos:[265,233] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	
	label lbl13 "Viseme 5 :" pos:[13,260] width:56 height:16
	edittext editBox_Phons_5 "" pos:[73,257] width:178 height:20
	dropdownList ddl_phons_5 "" pos:[265,256] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl14 "Viseme 6 :" pos:[13,283] width:56 height:16
	edittext editBox_Phons_6 "" pos:[73,280] width:178 height:20
	dropdownList ddl_phons_6 "" pos:[265,280] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl15 "Viseme 7 :" pos:[13,307] width:56 height:16
	edittext editBox_Phons_7 "" pos:[73,304] width:178 height:20
	dropdownList ddl_phons_7 "" pos:[265,304] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl16 "Viseme 8 :" pos:[13,331] width:56 height:16
	edittext editBox_Phons_8 "" pos:[73,328] width:178 height:20
	dropdownList ddl_phons_8 "" pos:[265,328] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl17 "Viseme 9 :" pos:[13,355] width:56 height:16
	edittext editBox_Phons_9 "" pos:[73,352] width:178 height:20
	dropdownList ddl_phons_9 "" pos:[265,352] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl18 "Viseme 10 :" pos:[13,379] width:56 height:16
	edittext editBox_Phons_10 "" pos:[73,376] width:178 height:20
	dropdownList ddl_phons_10 "" pos:[265,376] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl19 "Viseme 11 :" pos:[13,403] width:56 height:16
	edittext editBox_Phons_11 "" pos:[73,400] width:178 height:20
	dropdownList ddl_phons_11 "" pos:[265,400] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl20 "Viseme 12 :" pos:[13,427] width:56 height:16
	edittext editBox_Phons_12 "" pos:[73,424] width:178 height:20
	dropdownList ddl_phons_12 "" pos:[265,424] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl21 "Viseme 13 :" pos:[13,451] width:56 height:16
	edittext editBox_Phons_13 "" pos:[73,448] width:178 height:20
	dropdownList ddl_phons_13 "" pos:[265,448] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl22 "Viseme 14 :" pos:[13,475] width:56 height:16
	edittext editBox_Phons_14 "" pos:[73,472] width:178 height:20
	dropdownList ddl_phons_14 "" pos:[265,472] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl23 "Viseme 15 :" pos:[13,499] width:56 height:16
	edittext editBox_Phons_15 "" pos:[73,496] width:178 height:20
	dropdownList ddl_phons_15 "" pos:[265,496] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl24 "Viseme 16 :" pos:[13,523] width:56 height:16
	edittext editBox_Phons_16 "" pos:[73,520] width:178 height:20
	dropdownList ddl_phons_16 "" pos:[265,520] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl25 "Viseme 17 :" pos:[13,547] width:56 height:16
	edittext editBox_Phons_17 "" pos:[73,545] width:178 height:20
	dropdownList ddl_phons_17 "" pos:[265,544] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl26 "Viseme 18 :" pos:[13,571] width:56 height:16
	edittext editBox_Phons_18 "" pos:[73,568] width:178 height:20
	dropdownList ddl_phons_18 "" pos:[265,568] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl27 "Viseme 19 :" pos:[13,595] width:56 height:16
	edittext editBox_Phons_19 "" pos:[73,592] width:178 height:20
	dropdownList ddl_phons_19 "" pos:[265,592] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
	label lbl28 "Viseme 20 :" pos:[13,619] width:56 height:16
	edittext editBox_Phons_20 "" pos:[73,617] width:178 height:20
	dropdownList ddl_phons_20 "" pos:[265,616] width:92 height:21 items:#("x (silence)", "IY (eat)", "IH (it)", "EH (Ed)", "AE (at)", "AH (hut)", "UW (two)", "UH (hood)", "AA (odd)", "AO (ought)", "EY (ate)", "AY (hide)", "OY (toy)", "AW (cow)", "OW (oat)", "L (Lee)", "r (read)", "y (yield)", "w (we)", "ER (hurt)", "m (me)", "n (knee)", "NG (ping)", "CH (cheese)", "j (gee)", "DH (thee)", "b (be)", "d (dee)", "g (green)", "p (pee)", "t (tea)", "k (key)", "z (zee)", "ZH (seizure)", "v (vee)", "f (fee)", "TH (theta)", "s (sea)", "SH (she)", "h (he)") selection:0
		
	pickbutton SelectMorpherObjectBtn "Select Object with Morpher" pos:[377,69] width:137 height:22 filter:checkMorpher
	button LoadVisPresetBtn "Load Preset" pos:[13,95] width:160 height:22
	button SaveVisPresetBtn "Save Preset" pos:[187,95] width:160 height:22
	label UsedVisemesCounterLabel "Number of used Viseme Slots : 0" pos:[13,131] width:189 height:17
	
	button SelectCTRLBoneRigsBtn "Select All Control Objects" pos:[536,69] width:137 height:22
	button SetUp_PosListsBtn "Setup position/rotation lists" pos:[536,122] width:137 height:22 enabled:false
	GroupBox PhonemeCombinationsGrp "Phoneme Combinations :" pos:[5,75] width:358 height:566
	GroupBox MorphTargetMappingGrp "Morph Target Mapping :" pos:[369,49] width:153 height:591
	GroupBox BoneRigMappingGrp "Bone Rig Mapping :" pos:[528,49] width:151 height:591
	progressBar pb4 "" pos:[10,149] width:347 height:6 color:(color 150 250 90)
	progressBar pb5 "" pos:[376,149] width:139 height:6 color:(color 150 250 90)
	progressBar pb6 "" pos:[535,149] width:139 height:6 color:(color 30 10 190)
	
	checkbutton setup_ckb_vis_1 "Shape Viseme 1" pos:[536,161] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_2 "Shape Viseme 2" pos:[536,185] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_3 "Shape Viseme 3" pos:[536,209] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_4 "Shape Viseme 4" pos:[536,233] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_5 "Shape Viseme 5" pos:[536,256] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_6 "Shape Viseme 6" pos:[536,280] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_7 "Shape Viseme 7" pos:[536,304] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_8 "Shape Viseme 8" pos:[536,328] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_9 "Shape Viseme 9" pos:[536,352] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_10 "Shape Viseme 10" pos:[536,376] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_11 "Shape Viseme 11" pos:[536,400] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_12 "Shape Viseme 12" pos:[536,424] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_13 "Shape Viseme 13" pos:[536,448] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_14 "Shape Viseme 14" pos:[536,472] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_15 "Shape Viseme 15" pos:[536,496] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_16 "Shape Viseme 16" pos:[536,520] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_17 "Shape Viseme 17" pos:[536,544] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_18 "Shape Viseme 18" pos:[536,568] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_19 "Shape Viseme 19" pos:[536,592] width:135 height:21 enabled:false
	checkbutton setup_ckb_vis_20 "Shape Viseme 20" pos:[536,616] width:135 height:21 enabled:false
	
	
	GroupBox grp7 "" pos:[5,153] width:674 height:30
	GroupBox grp8 "" pos:[5,176] width:674 height:31
	dropdownList MorphMapper_ddl_1 "" pos:[378,161] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_2 "" pos:[378,185] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_3 "" pos:[378,209] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_4 "" pos:[378,233] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_5 "" pos:[378,256] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_6 "" pos:[378,280] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_7 "" pos:[378,304] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_8 "" pos:[378,328] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_9 "" pos:[378,352] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_10 "" pos:[378,376] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_11 "" pos:[378,400] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_12 "" pos:[378,424] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_13 "" pos:[378,448] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_14 "" pos:[378,472] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_15 "" pos:[378,496] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_16 "" pos:[378,520] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_17 "" pos:[378,544] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_18 "" pos:[378,568] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_19 "" pos:[378,592] width:138 height:21 enabled:false selection:0
	dropdownList MorphMapper_ddl_20 "" pos:[378,616] width:138 height:21 enabled:false selection:0
	
	GroupBox grp11 "" pos:[5,199] width:674 height:32
	GroupBox grp12 "" pos:[5,224] width:674 height:32
	GroupBox grp13 "" pos:[5,248] width:674 height:31
	GroupBox grp14 "" pos:[5,271] width:674 height:31
	GroupBox grp15 "" pos:[5,294] width:674 height:32
	GroupBox grp16 "" pos:[5,318] width:674 height:32
	GroupBox grp17 "" pos:[5,342] width:674 height:32
	GroupBox grp18 "" pos:[5,366] width:674 height:32
	GroupBox grp19 "" pos:[5,390] width:674 height:32
	GroupBox grp20 "" pos:[5,414] width:674 height:32
	GroupBox grp21 "" pos:[5,438] width:674 height:32
	GroupBox grp22 "" pos:[5,462] width:674 height:32
	GroupBox grp23 "" pos:[5,486] width:674 height:32
	GroupBox grp24 "" pos:[5,510] width:674 height:32
	GroupBox grp25 "" pos:[5,534] width:674 height:32
	GroupBox grp26 "" pos:[5,558] width:674 height:32
	GroupBox grp27 "" pos:[5,582] width:674 height:32
	
	
	on ChooseAnnoFileRefbtn pressed do
	(
	msArray = #()
	EnergyValArray = #()
	phon_list = #();
	phnvStart = #()
	phnvEnd = #()
	global All_Anno_ms_Array = #()
	global All_Anno_Energy_Array = #()
	i = 1
	global poslis = 2
	
	try	(LpFileOpened = openFile (getopenfileName caption:"Open Exported Lipsync File" types:"AnnoFile(*.anno)|*.anno|Text(*.txt)|*.txt|All(*.*)|*.*|") mode:"r"
	
		if LpFileOpened != undefined then
			( -------------------------------------------------------------------------- fileopen if start
				while not eof LpFileOpened do
				(
				if (skipTostring LpFileOpened "phn_env") != undefined then
					(	
					--print (filePos LpFileOpened)
					phnvStart[i] = readValue LpFileOpened
					phnVEnd[i] = readValue LpFileOpened
					phon_list[i] = readChars LpFileOpened 2
	
					numb_Keyframes = readValue LpFileOpened
	
					msArray = #()
					EnergyValArray = #()
		
					for j = 1 to numb_Keyframes do 
						(
						msArray[j] = readValue LpFileOpened
						EnergyValArray[j] = readValue LpFileOpened
						)
					fff = phon_list[i]
					if findstring fff " " == 2 then phon_list[i] = substring phon_list[i] 1 1
		
					All_Anno_ms_Array[i] = msArray
					All_Anno_Energy_Array[i] = EnergyValArray
	
					i += 1
					)
				else exit
				) ---------------------------------------------------------------------- while end
			) -------------------------------------------------------------------------- fileopen if end
		ChooseAnnoFileRefbtn.text = filenamefrompath (LpFileOpened as string)
		close LpFileOpened
		infoBoxtextfn()
		)catch()
	)
	
	

	on MorphSetupSaveBtn pressed do
	(
	try(saveMorphSetupfn())catch()
	)
	
	on MorphSetupLoadBtn pressed do
	(
	try(
		MorphSetupOpenedFile = openFile (getopenfileName caption:"Load Morph Mapping File" types:"MorphSetups(*.AnM)|*.AnM|All(*.*)|*.*|") mode:"r"
		LoadVisPresetfn MorphSetupOpenedFile
		mappedMorphChannelArray = (execute(readline MorphSetupOpenedFile))
		usedVisemesCounter()
		for i = 1 to mappedMorphChannelArray.count where mappedMorphChannelArray[i] != 0 do
		(
		execute ("CommonVisemeMapperRollout.MorphMapper_ddl_" + i as string + ".selection = mappedMorphChannelArray[" + i as string + "]")
		morphmapper i mappedMorphChannelArray[i]
		)
	
		activateMorphDropDownsfn()
		close MorphSetupOpenedFile
		usedMorphsCounter()
		)catch()
	)
	
	on BoneSetupSaveBtn pressed do
	(
	try(saveBoneSetupfn())catch()
	)

	on BoneSetupLoadBtn pressed do
	(
	try(
		BoneSetupOpenedFile = openFile (getopenfileName caption:"Load Bone Mapping File" types:"MorphSetups(*.AnB)|*.AnB|All(*.*)|*.*|") mode:"r"
		LoadVisPresetfn BoneSetupOpenedFile
		usedVisemesCounter()
		New_BoneRig_CTRLObjsNames = (execute(readline BoneSetupOpenedFile))
		New_CTRL_objs_onWhich_posLists_Applied = (execute(readline BoneSetupOpenedFile))
		tempy = 0
		--for i = 1 to New_BoneRig_CTRLObjsNames.count do
		--	(
		--	if findItem New_BoneRig_CTRLObjsNames BoneRig_CTRLObjs[i].name == 0 then
		--	tempy += 1
		--	)
		--if tempy > 0 then
		--messageBox " The names of Control Objects in the loaded map file don't match the currently selected Objects"
		
		--if New_BoneRig_CTRLObjsNames.count < BoneRig_CTRLObjs.count then
		--messageBox "The number of Control Objects currently selected is more than that in the loaded Mapping File.\nPlease run 'Setup Position Lists' and try again."
		--else if New_BoneRig_CTRLObjsNames.count < BoneRig_CTRLObjs.count and tempy == 0 then
		--	(		
			
		--	)
			
		for i = 1 to 20 where (findItem New_CTRL_objs_onWhich_posLists_Applied i != 0) do
				(
				execute("CommonVisemeMapperRollout.setup_ckb_vis_" + i as string + ".enabled = true")
				)	
			
		)catch()
	compareVisemeSlots_w_PosListsfn()
	
	)
	
	
	on CommonVisemeMapperRollout open do
	(	
		global variableInitText = ""
		for i = 1 to 20 do
		(
		variableInitText += "global viseme_" + i as string + "_PhonemeArray = #();\n"
		)
		execute variableInitText
		if UnusedVisemeSlots.count != 0 then
		(
		for i in UnusedVisemeSlots do	
			(
			(execute("CommonVisemeMapperRollout.editBox_Phons_" + i as string)).enabled = false
			(execute("CommonVisemeMapperRollout.ddl_phons_" + i as string)).enabled = false
			--(execute("CommonVisemeMapperRollout.setup_ckb_vis_" + i as string)).enabled = true
			)
		)
	)
	
	on editBox_Phons_1 changed text do
	(
	PhonemeStreamToArray 1
	usedVisemesCounter()
	)
	on ddl_phons_1 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 1
	PhonemeStreamToArray 1
	usedVisemesCounter()
	)
	on editBox_Phons_2 changed text do
	(
	PhonemeStreamToArray 2
	usedVisemesCounter()
	)
	on ddl_phons_2 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 2
	PhonemeStreamToArray 2
	usedVisemesCounter()
	)
	on editBox_Phons_3 changed text do
	(
	PhonemeStreamToArray 3
	usedVisemesCounter()
	)
	on ddl_phons_3 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 3
	PhonemeStreamToArray 3
	usedVisemesCounter()
	)
	on editBox_Phons_4 changed text do
	(
	PhonemeStreamToArray 4
	usedVisemesCounter()
	)
	on ddl_phons_4 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 4
	PhonemeStreamToArray 4
	usedVisemesCounter()
	)
	on editBox_Phons_5 changed text do
	(
	PhonemeStreamToArray 5
	usedVisemesCounter()
	)
	on ddl_phons_5 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 5
	PhonemeStreamToArray 5
	usedVisemesCounter()
	)
	on editBox_Phons_6 changed text do
	(
	PhonemeStreamToArray 6
	usedVisemesCounter()
	)
	on ddl_phons_6 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 6
	PhonemeStreamToArray 6
	usedVisemesCounter()
	)
	on editBox_Phons_7 changed text do
	(
	PhonemeStreamToArray 7
	usedVisemesCounter()
	)
	on ddl_phons_7 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 7
	PhonemeStreamToArray 7
	usedVisemesCounter()
	)
	on editBox_Phons_8 changed text do
	(
	PhonemeStreamToArray 8
	usedVisemesCounter()
	)
	on ddl_phons_8 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 8
	PhonemeStreamToArray 8
	usedVisemesCounter()
	)
	on editBox_Phons_9 changed text do
	(
	PhonemeStreamToArray 9
	usedVisemesCounter()
	)
	on ddl_phons_9 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 9
	PhonemeStreamToArray 9
	usedVisemesCounter()
	)
	on editBox_Phons_10 changed text do
	(
	PhonemeStreamToArray 10
	usedVisemesCounter()
	)
	on ddl_phons_10 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 10
	PhonemeStreamToArray 10
	usedVisemesCounter()
	)
	on editBox_Phons_11 changed text do
	(
	PhonemeStreamToArray 11
	usedVisemesCounter()
	)
	on ddl_phons_11 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 11
	PhonemeStreamToArray 11
	usedVisemesCounter()
	)
	on editBox_Phons_12 changed text do
	(
	PhonemeStreamToArray 12
	usedVisemesCounter()
	)
	on ddl_phons_12 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 12
	PhonemeStreamToArray 12
	usedVisemesCounter()
	)
	on editBox_Phons_13 changed text do
	(
	PhonemeStreamToArray 13
	usedVisemesCounter()
	)
	on ddl_phons_13 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 13
	PhonemeStreamToArray 13
	usedVisemesCounter()
	)
	on editBox_Phons_14 changed text do
	(
	PhonemeStreamToArray 14
	usedVisemesCounter()
	)
	on ddl_phons_14 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 14
	PhonemeStreamToArray 14
	usedVisemesCounter()
	)
	on editBox_Phons_15 changed text do
	(
	PhonemeStreamToArray 15
	usedVisemesCounter()
	)
	on ddl_phons_15 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 15
	PhonemeStreamToArray 15
	usedVisemesCounter()
	)
	on editBox_Phons_16 changed text do
	(
	PhonemeStreamToArray 16
	usedVisemesCounter()
	)
	on ddl_phons_16 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 16
	PhonemeStreamToArray 16
	usedVisemesCounter()
	)
	on editBox_Phons_17 changed text do
	(
	PhonemeStreamToArray 17
	usedVisemesCounter()
	)
	on ddl_phons_17 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 17
	PhonemeStreamToArray 17
	usedVisemesCounter()
	)
	on editBox_Phons_18 changed text do
	(
	PhonemeStreamToArray 18
	usedVisemesCounter()
	)
	on ddl_phons_18 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 18
	PhonemeStreamToArray 18
	usedVisemesCounter()
	)
	on editBox_Phons_19 changed text do
	(
	PhonemeStreamToArray 19
	usedVisemesCounter()
	)
	on ddl_phons_19 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 19
	PhonemeStreamToArray 19
	usedVisemesCounter()
	)
	on editBox_Phons_20 changed text do
	(
	PhonemeStreamToArray 20
	usedVisemesCounter()
	)
	
	on ddl_phons_20 selected sel do
	(
	dropdownSelection = sel
	dropdownHandler 20
	PhonemeStreamToArray 20
	usedVisemesCounter()
	)
		
	on LoadVisPresetBtn pressed do
	( 
	try(
		VisPresetOpenedFile = openFile (getopenfileName caption:"Load Viseme Preset File" types:"VisemePresets(*.AnP)|*.AnP|All(*.*)|*.*|") mode:"r"
		LoadVisPresetfn VisPresetOpenedFile	
		usedVisemesCounter()	
		close VisPresetOpenedFile
		)catch()
	)
			
	on SaveVisPresetBtn pressed do
	(
	try(
		VisPresetSaveFile = createfile ((getsavefilename caption:"Save Viseme Preset as: ") + ".AnP")
		SaveVisPresetfn VisPresetSaveFile
		) catch()
	)
			
	on SelectMorpherObjectBtn picked obj do
	(
	
	MorpherObject = obj
	if MorpherObject != undefined then
		(
		CommonVisemeMapperRollout.SelectMorpherObjectBtn.text = MorpherObject.name
		activateMorphDropDownsfn()
		CommonVisemeMapperRollout.MorphSetupLoadBtn.enabled = true
		)
	)
	
	on SelectCTRLBoneRigsBtn pressed do
	(
	BoneRig_CTRLObjs = selection as array
	BoneRigCTRL_count = BoneRig_CTRLObjs.count
	--def_Pos.count = CTRL_count
	messageBox (BoneRigCTRL_count as string + " selected objects have been setup for Lipsync Control") title:"Lipsync Tool Info : "
	SetUp_PosListsBtn.enabled = true
	
	if (CTRL_objs_onWhich_posLists_Applied != undefined and CTRL_objs_onWhich_posLists_Applied.count != 0) then
		for i in usedVisemeSlots do	
				(
				(execute("CommonVisemeMapperRollout.setup_ckb_vis_" + i as string)).enabled = true
				)

	CommonVisemeMapperRollout.BoneSetupLoadBtn.enabled = true
	compareVisemeSlots_w_PosListsfn()
	)
	
	
	on MorphMapper_ddl_1 selected sel do
	(
	morphmapper 1 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_2 selected sel do
	(
	morphmapper 2 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_3 selected sel do
	(
	morphmapper 3 sel
	usedMorphsCounter()
	)

	on MorphMapper_ddl_4 selected sel do
	(
	morphmapper 4 sel
	usedMorphsCounter()
	)

	on MorphMapper_ddl_5 selected sel do
	(
	morphmapper 5 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_6 selected sel do
	(
	morphmapper 6 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_7 selected sel do
	(
	morphmapper 7 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_8 selected sel do
	(
	morphmapper 8 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_9 selected sel do
	(
	morphmapper 9 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_10 selected sel do
	(
	morphmapper 10 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_11 selected sel do
	(
	morphmapper 11 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_12 selected sel do
	(
	morphmapper 12 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_13 selected sel do
	(
	morphmapper 13 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_14 selected sel do
	(
	morphmapper 14 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_15 selected sel do
	(
	morphmapper 15 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_16 selected sel do
	(
	morphmapper 16 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_17 selected sel do
	(
	morphmapper 17 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_18 selected sel do
	(
	morphmapper 18 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_19 selected sel do
	(
	morphmapper 19 sel
	usedMorphsCounter()
	)
	
	on MorphMapper_ddl_20 selected sel do
	(
	morphmapper 20 sel
	usedMorphsCounter()
	)
	
	on SetUp_PosListsBtn pressed do
	with undo "Setup PosLists" on
			(
			CTRL_objs_onWhich_posLists_Applied = #()
			for i =1 to BoneRigCTRL_count where (findItem CTRL_objs_onWhich_posLists_Applied BoneRig_CTRLObjs[i] == 0) do
				(
				BoneRig_CTRLObjs[i].pos.controller = bezier_position()
				BoneRig_CTRLObjs[i].pos.controller = position_list()
				for k = 1 to pos_listController_Names.count do
					(
					BoneRig_CTRLObjs[i].pos.controller.available.controller = position_XYZ()
					BoneRig_CTRLObjs[i].pos.controller.setName (k+1) pos_listController_Names[k]
					BoneRig_CTRLObjs[i].pos.controller.weight = def_pos_list_weights
					)
				BoneRig_CTRLObjs[i].pos.controller[1].controller = position_list()
				BoneRig_CTRLObjs[i].pos.controller[1][2].controller = position_XYZ();
				
				BoneRig_CTRLObjs[i].pos.controller[1].controller.setName 1 "DefaultPos"
				BoneRig_CTRLObjs[i].pos.controller[1].controller.setName 2 "UserKeyFrame_XYZ"
				BoneRig_CTRLObjs[i].pos.controller.weight[1] = 100
				append CTRL_objs_onWhich_posLists_Applied BoneRig_CTRLObjs[i]
				
				)
			-- MRZ ADDED create rotation controller and rotation list
			CTRL_objs_onWhich_posLists_Applied = #()
			for i =1 to BoneRigCTRL_count where (findItem CTRL_objs_onWhich_posLists_Applied BoneRig_CTRLObjs[i] == 0) do
				(
				BoneRig_CTRLObjs[i].rotation.controller = Euler_xyz()
				BoneRig_CTRLObjs[i].rotation.controller = rotation_list()
				for k = 1 to pos_listController_Names.count do
					(
					BoneRig_CTRLObjs[i].rotation.controller.available.controller = Euler_xyz()
					BoneRig_CTRLObjs[i].rotation.controller.setName (k+1) pos_listController_Names[k]
					BoneRig_CTRLObjs[i].rotation.controller.weight = def_pos_list_weights
					)
				BoneRig_CTRLObjs[i].rotation.controller[1].controller = rotation_list()
				BoneRig_CTRLObjs[i].rotation.controller[1][2].controller = Euler_xyz();
				
				BoneRig_CTRLObjs[i].rotation.controller[1].controller.setName 1 "DefaultPos"
				BoneRig_CTRLObjs[i].rotation.controller.weight[1] = 100
				append CTRL_objs_onWhich_posLists_Applied BoneRig_CTRLObjs[i]
				
				)
			-- MRZ 
			for i in usedVisemeSlots do	
				(
				(execute("CommonVisemeMapperRollout.setup_ckb_vis_" + i as string)).enabled = true
				)
			for i in UnusedVisemeSlots do	
				(
				(execute("CommonVisemeMapperRollout.editBox_Phons_" + i as string)).enabled = false
				(execute("CommonVisemeMapperRollout.ddl_phons_" + i as string)).enabled = false
				)
			
			SetUp_PosListsBtn.enabled = false
			CommonVisemeMapperRollout.LoadVisPresetBtn.enabled = false
			)----- event end
	

on setup_ckb_vis_1 changed state do
	(
	try(setupVisemefn 1)catch()
	)

on setup_ckb_vis_2 changed state do
	(
	try(setupVisemefn 2)catch()
	)

on setup_ckb_vis_3 changed state do
	(
	try(setupVisemefn 3)catch()
	)

on setup_ckb_vis_4 changed state do
	(
	try(setupVisemefn 4)catch()
	)

on setup_ckb_vis_5 changed state do
	(
	try(setupVisemefn 5)catch()
	)

on setup_ckb_vis_6 changed state do
	(
	try(setupVisemefn 6)catch()
	)

on setup_ckb_vis_7 changed state do
	(
	try(setupVisemefn 7)catch()
	)

on setup_ckb_vis_8 changed state do
	(
	try(setupVisemefn 8)catch()
	)
	

on setup_ckb_vis_9 changed state do
	(
	try(setupVisemefn 9)catch()
	)

on setup_ckb_vis_10 changed state do
	(
	try(setupVisemefn 10)catch()
	)
	
on setup_ckb_vis_11 changed state do
	(
	try(setupVisemefn 11)catch()
	)

on setup_ckb_vis_12 changed state do
	(
	try(setupVisemefn 12)catch()
	)

on setup_ckb_vis_13 changed state do
	(
	try(setupVisemefn 13)catch()
	)

on setup_ckb_vis_14 changed state do
	(
	try(setupVisemefn 14)catch()
	)
	
on setup_ckb_vis_15 changed state do
	(
	try(setupVisemefn 15)catch()
	)


on setup_ckb_vis_16 changed state do
	(
	try(setupVisemefn 16)catch()
	)	

on setup_ckb_vis_17 changed state do
	(
	try(setupVisemefn 17)catch()
	)

on setup_ckb_vis_18 changed state do
	(
	try(setupVisemefn 18)catch()
	)

on setup_ckb_vis_19 changed state do
	(
	try(setupVisemefn 19)catch()
	)
	
on setup_ckb_vis_20 changed state do
	(
	try(setupVisemefn 20)catch()
	)	
	
)

addrollout CommonVisemeMapperRollout CommonMappingFloater

	
rollout ApplyLipsyncRollout "Apply Lipsync" width:686 height:284 rolledUp:true
(
	
	button ChooseAnnoFilebtn "Choose Exported Anno File for Lipsync" pos:[190,105] width:255 height:20
	
	spinner StartTimespn "StartTime" pos:[259,134] width:101 height:16 range:[-10000,10000,0]
	label Framelbl "(frame #)" pos:[364,134] width:49 height:17
	button SYNCbtn "SYNC" pos:[250,200] width:157 height:27 enabled:false
	GroupBox ApplyLipsyncgrp "Apply Lipsync Tools Data" pos:[47,88] width:590 height:160
	progressBar SYNCpb "" pos:[68,234] width:526 height:8 value:0 color:(color 220 120 20)
	radiobuttons ImportRadioBtn "Import Options :" pos:[161,156] width:380 height:30 labels:#("donot shift/modify keys", "shift keys to occur at frames") default:1 columns:2
	label LessAccuratelbl "(less accurate)" pos:[470,173] width:90 height:18
	radiobuttons SyncRadio "Apply Lipsync To" pos:[280,3] width:102 height:78 labels:#("BoneRig", "MorphRig","CustomAttributes") columns:1
	
	
	global allComboVisemes_Energy_Array = #()
	global allComboVisemes_MS_Array = #()
	
	global syncOption = 1
	global ticksOnOff = 1.0	
	global SyncStartTime = 0.0
	global LipscriptCA
		
	fn lipsyncBoneRigfn = 
	(
	poslis = 2
	with animate on with undo "SYNC - BoneRig" on
	for v = 1 to 20 do
		(--- v loop start
		--if allComboVisemes_MS_Array[v].count != 0 then
		if (finditem usedVisemeSlots v) != 0 then	
			(
			for j = 1 to allComboVisemes_MS_Array[v].count do
				(---j loop start
				for CO in BoneRig_CTRLObjs do
					( --- control object loop start
					at time (SyncStartTime + (allComboVisemes_MS_Array[v][j]*framerate/(1000*ticksOnOff) ) )
						(
						CO.pos.controller.weight[poslis] = (allComboVisemes_Energy_Array[v][j]*100)
						CO.rotation.controller.weight[poslis] = (allComboVisemes_Energy_Array[v][j]*100)
						)
					) --- control object loop end
				)--- j loop end
			
			print poslis
			poslis += 1
			)
		ApplyLipsyncRollout.SYNCpb.value = (v*100/20)	
		)--- v loop end
	
	)
	

	fn lipsyncMorphRig = 
	(
	with animate on with undo "SYNC - MorphRig" on
	for v = 1 to 20 do
		(--- v loop start
		if (finditem usedVisemeSlots v) != 0 then	
			(
			for j = 1 to allComboVisemes_MS_Array[v].count do
				(---j loop start
				if mappedMorphChannelArray[v] != 0 then
					(
					at time (SyncStartTime + (allComboVisemes_MS_Array[v][j]*framerate/(1000*ticksOnOff)))
						(
						try(MorpherObject.morpher[(mappedMorphChannelArray[v])].value = (allComboVisemes_Energy_Array[v][j]*100))catch()
						)
					)
				)--- j loop end
			)
		ApplyLipsyncRollout.SYNCpb.value = (v*100/20)	
		)--- v loop end
		
	)
	
	fn lipsyncCustomAttributesfn = 
	(
	with animate on with undo "SYNC - CustomAttrib" on
	for v = 1 to 20 do
		(
		if findItem UsedVisemeSlots v != 0 then
		for j = 1 to allComboVisemes_MS_Array[v].count do
			(
			at time (SyncStartTime + (allComboVisemes_MS_Array[v][j]*framerate/(1000*ticksOnOff)))
				(
				try(Lipscript_CustAttribHelperObj.LipSyncToolData[v].value = (allComboVisemes_Energy_Array[v][j]*100))catch()
				)
			)
		ApplyLipsyncRollout.SYNCpb.value = (v*100/20)	
		)		
		

	)
	
	
	
	fn CreateLipScriptCustomAttributesfn =
	(
	Lipscript_CustAttribHelperObj = Point()
	Lipscript_CustAttribHelperObj.name = uniquename "Lipscript_Helper"
	Lipscript_CustAttribHelperObj.box = true
	Lipscript_CustAttribHelperObj.cross = false
	
	CA_Text = ""
	CA_Text += "LipscriptCA = attributes LipSyncToolData\n"
	
	CA_Text +=	"	(\n"
	
	CA_Text +=	"	parameters main Rollout:params\n"
	CA_Text +=	"		(\n"
	
	for i = 1 to usedVisemeSlots.count do
		(
	CA_Text +=	"		Viseme_" + usedVisemeSlots[i] as string + " type:#float ui:Viseme_" + usedVisemeSlots[i] as string + " default:0.0\n"
		)	
	CA_Text +=	"		)\n"
		
	CA_Text +=	"	rollout params \"LipScript Viseme Values\" \n"
	CA_Text +=	"		(\n"
	for i = 1 to usedVisemeSlots.count do
		(
	CA_Text +=	"		spinner Viseme_" + usedVisemeSlots[i] as string + " \"Viseme_" + usedVisemeSlots[i] as string + "\" type:#float\n"
		)
	CA_Text +=	"		)\n"
		
	CA_Text +=	"	)\n"
	
	execute CA_Text
	custAttributes.add Lipscript_CustAttribHelperObj LipscriptCA baseObject:true

	
	)
	
	
	fn deactivateFurtherMappingfn = 
	(
	for i = 1 to 20 do	
		(
		execute("CommonVisemeMapperRollout.MorphMapper_ddl_" + i as string + ".enabled = false")
		(execute("CommonVisemeMapperRollout.editBox_Phons_" + i as string)).enabled = false
		(execute("CommonVisemeMapperRollout.ddl_phons_" + i as string)).enabled = false
		)

	)
	
	
	
	
	on ChooseAnnoFilebtn pressed do
	(
	msArray = #()
	EnergyValArray = #()
	global phon_list = #();
	
	phnvStart = #()
	phnvEnd = #()
	global All_Anno_ms_Array = #()
	global All_Anno_Energy_Array = #()
	i = 1
	global poslis = 2
	
	
	try(LpFileOpened = openFile (getopenfileName caption:"Open Exported Lipsync File" types:"AnnoFile(*.anno)|*.anno|Text(*.txt)|*.txt|All(*.*)|*.*|") mode:"r")catch()
	
	if LpFileOpened != undefined then
	( -------------------------------------------------------------------------- fileopen if start
	
	while not eof LpFileOpened do
	(
	
	
	if (skipTostring LpFileOpened "phn_env") != undefined then
	(	
	--print (filePos LpFileOpened)
	
	phnvStart[i] = readValue LpFileOpened
	phnVEnd[i] = readValue LpFileOpened
	phon_list[i] = readChars LpFileOpened 2
	
	numb_Keyframes = readValue LpFileOpened
	
	msArray = #()
	EnergyValArray = #()
	
	for j = 1 to numb_Keyframes do 
	(
		msArray[j] = readValue LpFileOpened
		EnergyValArray[j] = readValue LpFileOpened
	)
	
	
		(
		fff = phon_list[i]
		if findstring fff " " == 2 then phon_list[i] = substring phon_list[i] 1 1
		)
	
	
	All_Anno_ms_Array[i] = msArray
	All_Anno_Energy_Array[i] = EnergyValArray
	
	
	
	
	i += 1
	)
	else exit
	)
	
	
	-----------------------------------------------------------combining visemes start 
	allComboVisemes_MS_Array = #()
	allComboVisemes_Energy_Array = #()
	
	
	
	ComboText = ""
	global xxx = 0
	global yyy = 0
	--global usedVisemeSlots = #();
	
			for xxx = 1 to 20 do
			(
			
	ComboText += " if ((viseme_" + xxx as string + "_PhonemeArray)!= undefined) then\n"
	ComboText += " (\n"
	
	ComboText += "	viseme_" + xxx as string + "_list_MS = #();\n"
	ComboText += "	viseme_" + xxx as string + "_list_EN = #();\n"
	ComboText += "		for i = 1 to phon_list.count do\n"
	ComboText += "			(\n"
	ComboText += "			for yyy = 1 to viseme_" + xxx as string + "_PhonemeArray.count do\n"
	ComboText += "				(\n"
	ComboText += "				if (phon_list[i] == (viseme_" + xxx as string + "_PhonemeArray[yyy])) then\n"
	ComboText += "					for j = 1 to All_Anno_ms_Array[i].count do\n"
	ComboText += "					(\n"
	ComboText += "					append viseme_" + xxx as string + "_list_MS All_Anno_ms_Array[i][j]\n"
	ComboText += "					append viseme_" + xxx as string + "_list_EN All_Anno_Energy_Array[i][j]\n"
	ComboText += "					)\n"
	ComboText += "				)	\n"
	ComboText += "			)\n"
	
	ComboText += " allComboVisemes_MS_Array[" + xxx as string + "] = (viseme_" + xxx as string + "_list_MS)\n"
	ComboText += " allComboVisemes_Energy_Array[" + xxx as string + "] = (viseme_" + xxx as string + "_list_EN)\n"
	ComboText += " )\n"
	
	ComboText += " else\n"
	ComboText += " (\n"
	ComboText += " allComboVisemes_MS_Array[" + xxx as string + "] = #()\n"
	ComboText += " allComboVisemes_Energy_Array[" + xxx as string + "] = #()\n"
	
	ComboText += "  )\n"
			
			)
	
	execute ComboText
	
	ChooseAnnoFilebtn.text = filenamefrompath (LpFileOpened as string)
	
	
	-----------------------------------------------------------combining visemes end 
	
	close LpFileOpened
	
	ApplyLipsyncRollout.SYNCbtn.enabled = true
	deactivateFurtherMappingfn()
	CommonVisemeMapperRollout.MorphSetupLoadBtn.enabled = false
	CommonVisemeMapperRollout.BoneSetupLoadBtn.enabled = false
	)-------------------------------------------------------------------------- fileopen if end
	else 
		(
		)
	
	)---------------------------------------------------------------------------ChooseAnnoFile End
	
	
	on StartTimespn changed val do
	(
	SyncStartTime = val;
	)
	
	
	on SYNCbtn pressed do
	( --- butn press start
	if syncOption == 1 and BoneRig_CTRLObjs != undefined then
	lipsyncBoneRigfn()
	
	if  syncOption == 1 and BoneRig_CTRLObjs == undefined then
	messageBox "No Control Objects defined in the Facial Setup" title:"Lipscript Warning!!"
	
	if syncOption == 2 and MorpherObject != undefined then 
	lipsyncMorphRig()
	
	if syncOption == 2 and MorpherObject == undefined then
	messageBox "No Morpher Object Specified " title:"Lipscript Warning!!"
	
	if syncOption == 3 then
		(
		CreateLipScriptCustomAttributesfn()
		lipsyncCustomAttributesfn()
		select Lipscript_CustAttribHelperObj
		)
	)--- butn press end

	
	on SyncRadio changed state do
	(
	syncOption = state
	)
	
		
	on ImportRadioBtn changed state do
	(
	if ApplyLipsyncRollout.ImportRadioBtn.state == 1 then ticksOnOff = 1.0
	else ticksOnOff = 1
	
	)
	
	
	
)
addrollout ApplyLipsyncRollout CommonMappingFloater


