local debug = true local function debug_print(msg) if debug then Printf(msg) end end local function tablelength(T) local count = 0 for _ in pairs(T) do count = count + 1 end return count end local song_name = "" local song_bpm = 120 local song_page_num = 1 local main_sequence_location = 1 function CreatorMenu() local inputs = { {name = "Song Name", value = song_name, maxTextLength = 50}, {name = "BPM", value = tostring(song_bpm), whiteFilter = "0123456789"}, {name = "Main Sequence Location", value = main_sequence_location, whiteFilter = "0123456789"} } local resultTable = MessageBox( { title = "Song tool - Create a song", message = "Fill in the song details:", message_align_h = Enums.AlignmentH.Left, message_align_v = Enums.AlignmentV.Top, commands = {{value = 1, name = "Apply", backColor = "Green"}, {value = 0, name = "Cancel"}}, inputs = inputs, backColor = "Global.Default", icon = "logo_small", titleTextColor = "Global.Text", messageTextColor = "Global.Text", autoCloseOnInput = true } ) if resultTable.result == 0 then main() elseif resultTable.result == 1 then local song_name = "Name" local song_bpm = 60 local main_sequence_location = 1 for var_name, var_val in pairs(resultTable.inputs) do if var_name == "Song Name" then song_name = var_val elseif var_name == "BPM" then song_bpm = tonumber(var_val) elseif var_name == "Main Sequence Location" then main_sequence_location = tonumber(var_val) end end Cmd('Store Sequence '..main_sequence_location..' "'..song_name..'" /Overwrite') Cmd('Store Sequence '..main_sequence_location..' Cue 1 "Start commands" /Overwrite') Cmd([[Set Sequence ]]..main_sequence_location..[[ Cue 1 "Command" 'Select Sequence "]]..song_name..[["; Plugin "setSpeed" "1,]]..song_bpm..[["; Call Macro "Go to next song"']]) Cmd("Set Sequence "..main_sequence_location.." 'Appearance' 'Main'") end end local function AddStartPoint(cueNo, main_sequence_no) debug_print("Add StartPoint for cue "..tostring(cueNo)) local resultTable = MessageBox( { title = "Song Tool - Start Point", message = "Do you want to add cue "..tostring(cueNo).." as a Start Point?", message_align_h = Enums.AlignmentH.Left, message_align_v = Enums.AlignmentV.Top, commands = { {value = 1, name = "Yes"}, {value = 0, name = "Cancel"} }, backColor = "Global.Default", icon = "logo_small", titleTextColor = "Global.Text", messageTextColor = "Global.Text" } ) local m_selection = resultTable.result if m_selection == 0 then StartPointerCueSelectionMenu(main_sequence_no) elseif m_selection == 1 then Cmd('Assign Appearance "Start Point" at Sequence '..main_sequence_no..' Cue '..tostring(cueNo)) StartPointerCueSelectionMenu(main_sequence_no) else do return end end end local function RemoveStartPoint(cueNo, main_sequence_no) debug_print("Remove StartPoint for cue "..tostring(cueNo)) local resultTable = MessageBox( { title = "Song Tool - Start Point", message = "Do you want to remove cue "..tostring(cueNo).." as a Start Point?", message_align_h = Enums.AlignmentH.Left, message_align_v = Enums.AlignmentV.Top, commands = { {value = 1, name = "Yes"}, {value = 0, name = "Cancel"} }, backColor = "Global.Default", icon = "logo_small", titleTextColor = "Global.Text", messageTextColor = "Global.Text" } ) local m_selection = resultTable.result if m_selection == 0 then StartPointerCueSelectionMenu(main_sequence_no) elseif m_selection == 1 then Cmd('Set Sequence '..main_sequence_no..' Cue '..tonumber(cueNo)..' Property "Appearance" "None"') StartPointerCueSelectionMenu(main_sequence_no) else do return end end end local function LimitReachedMenu(main_sequence_no) debug_print("Limit of Start Points reached for sequence "..tostring(main_sequence_no)) local resultTable = MessageBox( { title = "Song Tool - Limit reached", message = "You have reached the current limit of possible Start Points in sequence "..main_sequence_no..".\nRemove a Start Point first to create a new one.\nThis limit might get expanded in future versions.", message_align_h = Enums.AlignmentH.Left, message_align_v = Enums.AlignmentV.Top, commands = { {value = 0, name = "Ok"} }, backColor = "Global.Default", icon = "logo_small", titleTextColor = "Global.Text", messageTextColor = "Global.Text" } ) local m_selection = resultTable.result if m_selection == 0 then StartPointerCueSelectionMenu(main_sequence_no) else do return end end end function StartPointerCueSelectionMenu(main_sequence_no) local cues = ObjectList('Sequence '..main_sequence_no..' Cue Thru') local cueTable = {} for i = 1, tablelength(cues) do local cueName = tostring(cues[i].name) cueTable[cueName] = cues[i].no end local selectorButtons = { {name = "Cues", type = 0, values = cueTable}, } local resultTable = MessageBox( { title = "Song tool - Start Points", message = "Select a cue from the main sequence that should be a Start Point:", message_align_h = Enums.AlignmentH.Left, message_align_v = Enums.AlignmentV.Top, commands = {{value = 1, name = "Edit this cue", backColor = "Global.GreenBackground"}, {value = 0, name = "Cancel"}}, selectors = selectorButtons, backColor = "Global.Default", icon = "logo_small", titleTextColor = "Global.Text", messageTextColor = "Global.Text", autoCloseOnInput = true } ) if resultTable.result == 0 then main() elseif resultTable.result == 1 then local spCues = 0 for var_name, var_val in pairs(resultTable.selectors) do if var_name == "Cues" then cueNo = var_val local cues = DataPool().Sequences[main_sequence_no]:Children() for i = 1, tablelength(cues) do if cues[i]:Children()[1].appearance then if tostring(cues[i]:Children()[1].appearance.name) == "Start Point" then spCues = spCues + 1 end end end debug_print(tostring(spCues)) if spCues >= 9 then LimitReachedMenu(main_sequence_no) else for i = 1, tablelength(cues) do if tonumber(cues[i].no) == cueNo then cue = cues[i] end end cueParts = cue:Children() if cueParts[1].appearance then debug_print("Has App") if tostring(cueParts[1].appearance.name) == "Start Point" then RemoveStartPoint(cueNo/1000, main_sequence_no) else AddStartPoint(cueNo/1000, main_sequence_no) end else debug_print("Has no App") AddStartPoint(cueNo/1000, main_sequence_no) end end end end end end function StartPointMenu() local sequences = ObjectList('Sequence Thru') local main_sequences = {} for i = 1, tablelength(sequences) do if sequences[i].appearance then if tostring(sequences[i].appearance.name) == "Main" then local sequence_name = tostring(sequences[i].name) main_sequences[sequence_name] = sequences[i].no end end end local selectorButtons = { {name = "Main sequence", selectedValue = 1, type = 0, values = main_sequences}, } local resultTable = MessageBox( { title = "Song tool - Start Points", message = "Select a song main sequence to continue:", message_align_h = Enums.AlignmentH.Left, message_align_v = Enums.AlignmentV.Top, commands = {{value = 1, name = "Edit", backColor = "Green"}, {value = 0, name = "Cancel"}}, selectors = selectorButtons, backColor = "Global.Default", icon = "logo_small", titleTextColor = "Global.Text", messageTextColor = "Global.Text", autoCloseOnInput = true } ) if resultTable.result == 0 then main() elseif resultTable.result == 1 then for var_name, var_val in pairs(resultTable.selectors) do if var_name == "Main sequence" then main_sequence_no = var_val StartPointerCueSelectionMenu(main_sequence_no) end end end end local function Installer() Cmd('Store Appearance "Main"') Cmd('Set Appearance "Main" "BackG" "255"') Cmd('Set Appearance "Main" "BackAlpha" "255"') Cmd('Set Appearance "Main" "ImageAlpha" "0"') Cmd('Store Appearance "Start Point"') Cmd('Set Appearance "Start Point" "BackR" "255"') Cmd('Set Appearance "Start Point" "BackG" "97"') Cmd('Set Appearance "Start Point" "BackAlpha" "255"') Cmd('Set Appearance "Start Point" "ImageAlpha" "0"') Cmd('Store Macro "Go to next song"') Cmd('ChangeDestination Macro') Cmd('ChangeDestination "Go to next song"') for i = 3, 1, -1 do Cmd('Insert') end Cmd('Set 1 Property "Command" "Previous Page"') Cmd('Set 2 Property "Command" "Off Page"') Cmd('Set 3 Property "Command" "Next Page"') Cmd("ChangeDestination root") for i = 1, 10, 1 do Cmd('Store Macro 80'..tostring(string.format("%0.2i", i))..' "Start Point '..tostring(i)..'"') Cmd('ChangeDestination Macro') Cmd('ChangeDestination "Start Point '..tostring(i)..'"') Cmd('Insert') Cmd([[Set 1 Property "Command" "Plugin 'Song tool' 'goto_sp]]..tostring(i)..[["]]) Cmd("ChangeDestination root") Cmd('Assign Appearance "Start Point" at Macro 80'..tostring(string.format("%0.2i", i))) end main() end -- Main menu function main(display_handle, args) debug_print(tostring(args)) if args then local cues = SelectedSequence():Children() local spCues = {} for i = 1, tablelength(cues), 1 do cue = cues[i]:Children()[1] cueNo = cues[i].no if cue.appearance then if cue.appearance.name == "Start Point" then table.insert(spCues, tonumber(cueNo)) end end end for i = 1, 10, 1 do if args == "goto_sp"..tostring(i) then Cmd("Goto Cue "..tostring(spCues[i]/1000)) end end -- args = nil else local resultTable = MessageBox( { title = "Song Tool - Main Menu", message = "Select what you want to do:", message_align_h = Enums.AlignmentH.Left, message_align_v = Enums.AlignmentV.Top, commands = { {value = 2, name = "Create a song"}, {value = 1, name = "Entry Point"}, {value = 3, name = "Install"}, {value = 0, name = "Exit"} }, backColor = "Global.Default", icon = "logo_small", titleTextColor = "Global.Text", messageTextColor = "Global.Text" } ) local m_selection = resultTable.result if m_selection == 0 then do return end elseif m_selection == 1 then StartPointMenu() elseif m_selection == 2 then CreatorMenu() elseif m_selection == 3 then Installer() else do return end end end end return main