Advertisement
nintendoto

MIDI CC to fader script port

Feb 27th, 2023 (edited)
2,206
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AppleScript 13.73 KB | Source Code | 1 0
  1. --CLOSE INSPECTOR BEFORE RUNNING FOR UP TO 10 TIMES SPEED INCREASE
  2. --Script to generate utility cues, 128 cues per controller to translate MIDI cc values to OSC to set slider levels, and cues to feedback current level of sliders of selected cue in dB to MIDI controller as a cc value.
  3. --set MIDI Patch 8 to MIDI controller device
  4. -- set script cue template with 'run in separate process' UNCHECKED
  5. --set Network Cue template to MIDI ch of controller in triggers
  6. --set Script Cue template to MIDI ch of controller in triggers
  7.  
  8.  
  9. --user adjustable variables
  10.  
  11. set encoders to true --(boolean) true if controller has motorized fader or is rotary encoder, false for dumb fader or knob.
  12. set allatonce to true -- if true any encoder switch will update levels on all encoders. If false a switch will only updte it's own encoder (only used for encoders)
  13.  
  14. set theminimum to -60 --minimum audio level as set in settings/audio
  15. set themaximum to 10 --maximum audio level as set in settings/audio
  16. set theMIDIcc to 1 -- MIDI cc of first MIDI cc controller
  17. set theMIDInote to 0 --MIDI note to read levels of selected cue for takeover or note sent when first MIDI encoder touched (0 for Behringer X-Touch compatibility out of box)
  18. set theMIDIch to 11 -- Midi Channel to send feedback to encoders (only needed for encoders) (11 for Behringer X touch compatibility out of box)
  19. set numberOfControllers to 9 -- number of consecutive controllers
  20. set listOfSliders to {1, 2, 3, 4, 5, 6, 7, 8, 0} -- list of sliders controlled by midi controllers. Master is 0. Number of items in list must match number of controllers.
  21.  
  22.  
  23. ---do not change anything below this line-----
  24.  
  25. --error check routines for variables above
  26.  
  27. if (count of items of listOfSliders) is not equal to numberOfControllers then
  28.     display dialog "Slider list does not match number of controllers"
  29.     return
  30. end if
  31.  
  32. --calculate the step value
  33.  
  34. set thestep to (themaximum - theminimum) / 127 --step value for slider in dB in QLab, per increase of 1 in MIDI cc value.
  35.  
  36. --make text formatted list of sliders for use in script sources below
  37.  
  38. set formattedlist to "{"
  39. repeat with x from 1 to numberOfControllers
  40.     set formattedlist to formattedlist & item x of listOfSliders
  41.     if x is not numberOfControllers then set formattedlist to formattedlist & ","
  42. end repeat
  43. set formattedlist to formattedlist & "}"
  44. set thelistofsliders to formattedlist
  45.  
  46. --make text for preflight check dialog display
  47.  
  48. set thechecklist to ""
  49. if encoders is true then
  50.     set thechecklist to thechecklist & "GENERATING CUES FOR ENCODERS" & return & return & "MIDI ch to send to encoders is: " & theMIDIch & return & return
  51.     if allatonce is false then
  52.         set thechecklist to thechecklist & "An encoder's switch only updates its own encoder" & return & return
  53.     else
  54.         set thechecklist to thechecklist & "All encoders updated with any encoder switch" & return & return
  55.        
  56.     end if
  57. else
  58.     set thechecklist to thechecklist & "GENERATING CUES FOR POTS" & return & return
  59. end if
  60.  
  61. set thechecklist to thechecklist & "Minimum audio level as set in settings audio is: " & theminimum & return & return & "Maximum audio level as set in settings audio is: " & themaximum & return & return & numberOfControllers & " controllers starting with cc" & theMIDIcc & return & "Controlling sliders: " & thelistofsliders & return & return
  62.  
  63.  
  64. if encoders is false then set thechecklist to thechecklist & "MIDI note to take over levels: " & theMIDInote & return & return
  65.  
  66. -- main program
  67.  
  68. tell application id "com.figure53.QLab.5" to tell front workspace
  69.    
  70.     --check user actually wants to generate a list and present the preflight check list
  71.    
  72.     --display dialog "QLab will Generate cues to convert MIDI cc messages to OSC" & return & return & "Are you sure you want to do this?" & return & return & "Delete all cues created previously by this script before running" & return & return & "Some settings cannot be managed through scripting!" & return & return & "In settings:" & return & "Set MIDI Patch 8 to MIDI controller device" & return & return & "Set script cue template with 'run in separate process' UNCHECKED" & return & return & "Set Network Cue template Triggers tab to MIDI ch of controller" & return & return & "CUE GENERATOR WILL RUN UP TO 10 TIMES FASTER IF INSPECTOR IS CLOSED" & return & return & thechecklist with icon "warning"
  73.    
  74.    
  75.     --make memo cues to store variables
  76.    
  77.     --Make Memo cue to store data from preflight check list in notes field
  78.     make type "Memo"
  79.     set theselected to last item of (selected as list)
  80.     set the q number of theselected to "SUM"
  81.     set the notes of theselected to thechecklist
  82.     set the q name of theselected to thechecklist
  83.    
  84.     --Make Memo cue to store minimum audio level for use in calculations in notes field
  85.     make type "Memo"
  86.     set theselected to last item of (selected as list)
  87.     set the q number of theselected to "MIN"
  88.     set the notes of theselected to theminimum
  89.     set q name of theselected to theminimum
  90.    
  91.     --Make Memo cue to store step level for use in calculations, in notes field
  92.     make type "Memo"
  93.     set theselected to last item of (selected as list)
  94.     set the q number of theselected to "STEP"
  95.     set the notes of theselected to thestep
  96.     set the q name of theselected to thestep
  97.    
  98.     --make a MIDI cue to feedback current level of a slider to MIDI controller
  99.     make type "MIDI" --set up cue template to set patch etc.
  100.     set theselected to last item of (selected as list)
  101.     set the midi patch id of theselected to 1
  102.     set the q number of theselected to "MOP"
  103.     set the message type of theselected to voice
  104.     set the command of theselected to control_change
  105.     set the channel of theselected to theMIDIch
  106.    
  107.    
  108.     --Create Take cue to store current slider level and script to prepare level takeover
  109.     if encoders is false then
  110.         make type "Script"
  111.         set theselected to last item of (selected as list)
  112.         set the q number of theselected to "TAKE"
  113.         set the q name of theselected to "Prepare level takeover"
  114.         set the midi trigger of theselected to enabled
  115.         set the midi command of theselected to note_on
  116.         set the midi byte one of theselected to theMIDInote
  117.         set the midi byte two string of theselected to ">0"
  118.         set the script source of theselected to "set thelistofsliders to " & thelistofsliders & return & "tell application id \"com.figure53.QLab.5\" to tell front workspace" & return & "try" & return & "set theselected to last item of (selected as list)" & return & "set the armed of cue \"Pick\" to false" & return & "set the armed of cue \"SetS\" to false" & return & "repeat with aSlider from 1 to " & numberOfControllers & return & "set thelevel to getLevel theselected row 0 column (item aSlider of thelistOfSliders)" & return & "set thelevel to round ((thelevel - (notes of cue \"MIN\")) / (notes of cue \"STEP\"))" & return & "set thecue to \"Pcc\" & (aSlider as string) & \"_\" & (thelevel as string)" & return & "delay 0.1" & return & "set the armed of cue thecue to true" & return & "end repeat" & return & "end try" & return & "end tell"
  119.     end if
  120.    
  121.     --make a group cue to enclose all the group cues relating level setting of a MIDI controller
  122.     make type "Group"
  123.     set theselected to last item of (selected as list)
  124.     set the mode of theselected to start_first
  125.     set the q name of theselected to "set slider cues"
  126.     set the q number of theselected to "SetS"
  127.    
  128.     --make a group cue to enclose all the group cues relating to level matching of a current slider position to MIDI controller value for take over
  129.     if encoders is false then
  130.         make type "Group"
  131.         set theselected to last item of (selected as list)
  132.         set the mode of theselected to fire_first_go_to_next_cue
  133.         set the q name of theselected to "Pickup level Mechanism"
  134.         set the q number of theselected to "Pick"
  135.     end if
  136.    
  137.    
  138.     if encoders is true and allatonce is true then
  139.         --make a script that sends all the current slider levels in use, all at once, to the MIDI controllers
  140.         make type "SCRIPT"
  141.         set theselected to last item of (selected as list)
  142.         set the q name of theselected to "Feedback all levels to MIDI controller"
  143.         set the q number of theselected to "AAO"
  144.         set the script source of theselected to "set thesliderslist to " & thelistofsliders & return & "set numberofsliders to " & numberOfControllers & return & "set theCC to " & theMIDIcc & return & "tell application id \"com.figure53.QLab.5\" to tell front workspace" & return & "try" & return & "set theselected to last item of (selected as list)" & return & "repeat with aSlider from 1 to numberofsliders" & return & "set thelevel to getLevel theselected row 0 column (item aSlider of thesliderslist)" & return & "set thelevel to round ((thelevel - (notes of cue \"MIN\")) / (notes of cue \"STEP\"))" & return & "set byte one of cue \"MOP\" to theCC - 1 + aSlider" & return & "set byte two of cue \"MOP\" to thelevel" & return & "start cue \"MOP\"" & return & "end repeat" & return & "end try" & return & "end tell"
  145.        
  146.         --make a start cue for each encoder switch to start the group cue that feeds back all slider levels to the controller.      
  147.         repeat with astartcue from 1 to numberOfControllers
  148.             make type "start"
  149.             set theselected to last item of (selected as list)
  150.             set the cue target of theselected to cue "AAO"
  151.             set the q name of theselected to "Triggered by encoder switch MIDI note " & theMIDInote - 1 + astartcue
  152.             set the q number of theselected to "AAO" & astartcue
  153.            
  154.            
  155.             set the midi command of theselected to note_on
  156.             set the midi byte one of theselected to theMIDInote - 1 + astartcue
  157.             set the midi byte two string of theselected to ">0"
  158.             set the midi trigger of theselected to enabled
  159.         end repeat
  160.        
  161.     end if
  162.     --
  163.    
  164.     repeat with cc from 1 to numberOfControllers
  165.         --make a group cue for 128 cues that will control slider levels
  166.         make type "Group"
  167.         set theselected to last item of (selected as list)
  168.         set the mode of theselected to start_first
  169.         set the q name of theselected to "Controller " & (cc as string)
  170.         set the q number of theselected to "SetS" & (cc as string)
  171.         move cue id (uniqueID of theselected) of parent of theselected to end of cue "SetS"
  172.        
  173.         --make 128 cues triggered by cc values 0-127 to set slider levels via OSC and put them in the newly created group cue
  174.         repeat with x from 0 to 127
  175.             make type "Network"
  176.             set theselected to last item of (selected as list)
  177.             --set the correct triggerfor the new cue
  178.             set the midi command of theselected to control_change
  179.             set the midi byte one of theselected to theMIDIcc + (cc - 1)
  180.             set the midi byte two of theselected to x
  181.             set the midi trigger of theselected to enabled
  182.             --set the parameter values of theselected to custom
  183.             --set the OSC message to be sent by the new cue
  184.             set thelevel to theminimum + x * thestep
  185.             set thelevel to round (thelevel) rounding to nearest
  186.             set the parameter values of theselected to "/cue/selected/level/0/" & item cc of listOfSliders & " " & thelevel
  187.             set the q number of theselected to "cc" & theMIDIcc + (cc - 1) & "_" & x
  188.             move cue id (uniqueID of theselected) of parent of theselected to end of cue ("SetS" & (cc as string))
  189.         end repeat
  190.        
  191.         if allatonce is false then
  192.             -- make a MIDI input script to get current value of QLab parameter and send the equivalent MIDI level to the MIDI controller)
  193.             make type "SCRIPT"
  194.             set theselected to last item of (selected as list)
  195.             set the q number of theselected to "SL" & item cc of listOfSliders
  196.             set the q name of theselected to "send slider" & (item cc of listOfSliders) & " value to MIDI controller"
  197.             set the midi trigger of theselected to enabled
  198.             set the midi command of theselected to note_on
  199.             set the midi byte one of theselected to (theMIDInote + (cc - 1))
  200.             set the midi byte two string of theselected to ">0"
  201.             set the script source of theselected to "set theslider to " & (item cc of listOfSliders) & " -- slider to control, 0 is Master" & return & "set theCC to " & (theMIDIcc + (cc - 1)) & " -- MIDI cc number for this slider" & return & "tell application id \"com.figure53.QLab.5\" to tell front workspace" & return & "try" & return & "set theselected to last item of (selected as list)" & return & "set thelevel to getLevel theselected row 0 column theslider" & return & "set thelevel to round ((thelevel - (notes of cue \"MIN\")) / (notes of cue \"STEP\"))" & return & "set byte one of cue \"MOP\" to theCC" & return & "set byte two of cue \"MOP\" to thelevel" & return & " start cue \"MOP\"" & return & "end try" & return & "end tell"
  202.            
  203.             move cue id (uniqueID of theselected) of parent of theselected to end of cue "SetS"
  204.            
  205.         end if
  206.        
  207.        
  208.         if encoders is false then
  209.             --make 128 cues triggered by cc values 0-127 to enable a group of 128 level setting cues when the encoder level matches the slider level and move to the group numbered Pick
  210.             repeat with x from 0 to 127
  211.                 make type "network"
  212.                 set theselected to last item of (selected as list)
  213.                 --set the correct triggerfor the new cue
  214.                 set the midi command of theselected to control_change
  215.                 set the midi byte one of theselected to theMIDIcc + (cc - 1)
  216.                 set the midi byte two of theselected to x
  217.                 set the midi trigger of theselected to enabled
  218.                 set the parameter values of theselected to custom
  219.                 --set the OSC for the newcue
  220.                 set the custom message of theselected to "/cue/SetS" & (theMIDIcc + (cc - 1)) & "/armed 1"
  221.                 set the q number of theselected to "Pcc" & theMIDIcc + (cc - 1) & "_" & x
  222.                 set q name of theselected to "compare cc" & theMIDIcc + (cc - 1) & " value " & x & " to slider level for takeover"
  223.                 move cue id (uniqueID of theselected) of parent of theselected to end of cue "Pick"
  224.             end repeat
  225.         end if
  226.     end repeat
  227.    
  228.     --disarm all level setting groups and cues
  229.     if encoders is false then set the armed of cue "SetS" to false
  230.    
  231.     --disarm this generator script to guard against accidental operation
  232.     set the armed of cue "GEN" to false
  233.    
  234. end tell  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement