Advertisement
Guest User

airblast_tcl

a guest
Apr 19th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
TCL 9.77 KB | None | 0 0
  1. #!/usr/bin/env tclsh
  2.  
  3. # execute in wish from path \
  4. #exec wish "$0" ${1+"$@"}
  5.  
  6. # ==================== AIRWAVE DLL BATCH LINKER ====================
  7. # by an airwave user
  8. #
  9. # READ THIS INTRODUCTION BEFORE ATTEMPTING TO USE IT
  10. #
  11. # ==================== HOW TO USE IT ===============================
  12. # This is a Tcl script. You must have Tcl 8.4.6 or later to use it.
  13. # Older versions of Tcl may work, but I am not sure they will.
  14. #
  15. # First, 'cd' to the directory that contains the DLL files of the
  16. # Windows plugins and run the command. All the *.dll files in the  
  17. # current directory will be found and linked RECURSIVELY. Yes,
  18. # recursively, so make sure you're happy with the directory location
  19. # and structure before you run this script.
  20. #
  21. # Example:
  22. # $ cd /some/directory/with/a/truckload/of/plugins
  23. # $ airblast
  24. #
  25. # Tip: some file managers such as pcmanfm or spacefm let you press F4
  26. # to launch a terminal session in whatever directory it is displaying,
  27. # so you don't even have to 'cd' manually.
  28. #
  29. # After you run the command, a temporary file will be opened in a text
  30. # editor. (I use Vim, but it is easy to edit this script and change it
  31. # to another editor of your preference.) So this is your chance to edit
  32. # the names of the plugins if you don't like the defaults. You can
  33. # change them or not. Your call.
  34. #
  35. # The NAMES ARE ON THE FAR LEFT OF EACH LINE, right BEFORE THE FIRST
  36. # FORWARD SLASH. That is the name you will see in the DAW's list of
  37. # available VST plugins. Be careful not to delete the forward slash.
  38. # It is a delimiter so the entire operation will break if you delete
  39. # the forward slash. Also, don't use the forward slash in the name of
  40. # any plugin. If you do, it will become the first forward slash of the
  41. # line, in a rather expected and inconvenient place, and the script
  42. # will certainly make some bizarre mistake.
  43. #
  44. # Everything after the first forward slash of the line is the path to
  45. # the .dll file of the actual plugin. DON'T CHANGE ANY OF THAT.
  46. #
  47. # When you finish editing, save the file and close it. When the text
  48. # editor exits, the script will continue its job and will create all
  49. # the necessary Airwave bridge links in one fell swoop.
  50. #
  51. # The location where the plugin links will be created is hard wired.
  52. # They will be created in the following directory:
  53. # /usr/lib/vst/airwave/
  54. # Besides, you MUST have at least one *.so plugin link/bridge already
  55. # created by Airwave in that directory, or this script will not work.
  56. # If you don't have any Airwave *.so file in that directory, create at
  57. # least one with the Airwave GUI before running this script.
  58. # If you don't want /usr/lib/vst/airwave/ to be your target directory,
  59. # just edit that option in the script below. Come on, try it. It's not
  60. # rocket science.
  61. #
  62. # After running the script, open your DAW and have it refresh the list
  63. # of plugins (assuming it's already configured to find plugins in the
  64. # /usr/lib/vst directory). That's it. The DAW will detect the new
  65. # plugins in that directory and add them to its internal catalogue with
  66. # the names you chose to edit or leave untouched in the previous step.
  67. #
  68. # Note 1: if you're afraid of running the script, you can test it with
  69. # a dry run first. Just run it with any one or more arguments and see
  70. # what happens: the script will not do anything at all except print
  71. # out what it would have done if it had been run in normal mode.
  72. #
  73. # Example:
  74. # $ cd /some/directory/with/a/truckload/of/plugins
  75. # $ airblast dryrun
  76. #
  77. # Using the word 'dryrun' as argument in this example makes sense, but
  78. # the truth is that the script will run in dry run mode with any one
  79. # or more arguments of your choice. Any word at all will trigger dry
  80. # run mode. It's a safety mechanism against typos.
  81. #
  82. # Note 2: every time you run this script NOT in dry run mode, it makes
  83. # a backup copy of your airwave.conf file in the ~/.config/airwave/
  84. # directory. If something goes terribly wrong, use the backup file to
  85. # clean up the mess.
  86. #
  87. # This script is placed in the public domain.
  88. # No guarantees are included whatsoever. If it blows up in your face,
  89. # eats your files or teaches profanity to your parrot, no one will be
  90. # responsible.
  91. # If you find a bug, fix it for your own good. If you don't find any
  92. # bugs, rejoice. Ignorance is bliss.
  93. #
  94. # ==================================================================
  95.  
  96. # USER OPTIONS. EDIT THESE AT WILL.
  97. set _editor "/usr/bin/vim"
  98. set _airwave_directory "/usr/lib/vst/airwave/"
  99.  
  100.  
  101. # SCRIPT BEGINS HERE. DON'T CHANGE ANYTHING BELOW THIS POINT
  102. # UNLESS YOU KNOW WHAT YOU'RE DOING.
  103.  
  104. set _airwave_directory  [file normalize $_airwave_directory]
  105. set _airwave_config     [file normalize "~/.config/airwave"]
  106. set _found_dlls         [file normalize "$_airwave_config/found_dlls.txt"]
  107.  
  108. if  {[file isdirectory $_airwave_directory] == 0}   {
  109.     puts "ERROR. The target directory '$_airwave_directory' doesn't even exist! Did you ever read the instructions???"
  110.     puts "Please fix that problem and try again."
  111.     puts ""
  112.     exit
  113. }
  114.  
  115. # --------------------------------
  116. proc rw {argRW argFile args}    {
  117.     set _fp [open $argFile $argRW]
  118.     if  {[string range $argRW 0 0] == "r"}  {
  119.         set _slurp [read $_fp]
  120.         close $_fp
  121.         return $_slurp
  122.     }
  123.     for  {set i 0}  {$i <= [llength $args]}  {incr i}  {
  124.         puts -nonewline $_fp [lindex $args $i]
  125.     }
  126.     close $_fp
  127. }
  128.  
  129. # --------------------------------
  130. rw w $_found_dlls [exec find [pwd] -iname "*.dll"]
  131.  
  132. set _fp [open $_found_dlls r]
  133.     while   {-1 != [gets $_fp _line]}  {
  134.         regexp {([^/]+$)} $_line => _pluginfile
  135.         regexp {([^/]+)\.[^/.]+$} $_line => _pluginname
  136.         regsub {.*\.wine\/(.+)} $_line {\1} _fullpath
  137.         append _prettylist "$_pluginname/$_fullpath\n"
  138.     }
  139. close $_fp     
  140.  
  141. if  {[info exists _prettylist] == 0}    {
  142.     puts "ERROR. No DLLs found. Perhaps you're running this in the wrong directory?"
  143.     puts ""
  144.     exit
  145. } else {rw w $_found_dlls $_prettylist}
  146.  
  147. # --------------------------------
  148. # PAUSE TO REVIEW AND POSSIBLY EDIT THE LIST OF PLUGINS
  149.  
  150. proc subreview {}   {
  151.     set _newplugins {}
  152.     set _repeats {}
  153.     set _conflicts {}
  154.  
  155.     eval "exec $::_editor $::_found_dlls <@stdin >@stdout"
  156.  
  157.     set _fp [open $::_found_dlls r]
  158.         while   {-1 != [gets $_fp _line]}  {
  159.             regexp {([^/]+)/.*} $_line => _pluginname
  160.             lappend _newplugins $_pluginname
  161.         }
  162.     close $_fp     
  163.    
  164.     foreach i $_newplugins  {
  165.         if  {[llength [lsearch -all $_newplugins $i]] > 1}      {
  166.             lappend _repeats $i
  167.         }
  168.     }
  169.     if  {[llength $_repeats] > 0}   {
  170.         puts ""
  171.         puts "You are trying to add more than one plugin with the exact same name, which is not possible. "
  172.         puts "Maybe you're adding both the 32-bit and 64-bit versions of the same plugin? In that case, "
  173.         puts "remove one or just rename it, e.g. plugin_name_64-bit."
  174.         puts ""
  175.         puts "Press Enter to continue, Ctrl-c to quit."
  176.         gets stdin _line
  177.         subreview
  178.     }
  179.  
  180.     foreach i [glob $::_airwave_directory/*.so] {
  181.         set i [file rootname [file tail $i]]
  182.         lappend _alreadyexist $i
  183.     }
  184.     if  {[llength $_alreadyexist] == 0}     {
  185.         puts "ERROR. The target directory doesn't have any previously created link."
  186.         puts "Please refer to the instructions, specifically this part:"
  187.         puts ""
  188.         puts "\"The plugin links will be created in the following directory: $_airwave_directory"
  189.         puts "Besides, you MUST have at least one *.so plugin link/bridge already created by Airwave in that directory, "
  190.         puts "or the script will not work. And it must not be empty."
  191.         puts "If you don't have any Airwave *.so file in that directory, create at least one with the Airwave GUI before "
  192.         puts "running this script. If you don't like that choice of directory, just change that option in the script.\""
  193.         puts ""
  194.         exit
  195.     }
  196.     foreach i $_newplugins  {
  197.         if  {[lsearch $_alreadyexist $i] >= 0}      {
  198.             puts "conflict: $i"
  199.             lappend _conflicts $i
  200.         }
  201.     }
  202.     if  {[llength $_conflicts] > 0} {
  203.         puts ""
  204.         puts "Uh-oh! The following names you have chosen for plugins to be added are in conflict with already existing ones. "
  205.         puts "You can't change existing ones, but you can change the ones you're adding now. The list will be opened in the "
  206.         puts "text editor again so you can edit or delete them:"
  207.         puts ""
  208.         foreach k $_conflicts   {
  209.             puts $k
  210.         }
  211.         puts ""
  212.         puts "Press Enter to continue, Ctrl-c to quit."
  213.         gets stdin _line
  214.         subreview
  215.         # eval "exec $::_editor $::_found_dlls <@stdin >@stdout"
  216.     }
  217. }
  218. subreview
  219.  
  220. # --------------------------------
  221. # GOOD. MOVING ON...
  222.  
  223. if  {[llength $argc] == 0}  {
  224.     set _dryrun 0
  225. }   else {set _dryrun 1}
  226.  
  227. if  {$argc == 0}    {
  228.     set timestamp [clock format [clock seconds] -format "%Y-%m-%d_%H:%M"]
  229.     file copy -force "$_airwave_config/airwave.conf" "$_airwave_config/airwave.conf.backup.$timestamp"
  230.  
  231.     set _anyplugin [lindex [glob $_airwave_directory/*.so] 0]
  232.  
  233.     foreach i [split [rw r "$_found_dlls"] "\n"]    {
  234.         if  {$i == ""}  {continue}
  235.         regexp {^([^/]+)/.*} $i -> _pluginname
  236.         regexp {^([^/]+)/(.*)} $i -> -> _dllpath
  237.         file copy "$_anyplugin" "$_airwave_directory/$_pluginname.so"
  238.         eval "exec touch $_airwave_directory/$_pluginname.so"
  239.  
  240.         append _insert "\n      {
  241.      \"loader\" : \"default\",
  242.      \"log_level\" : -1,
  243.      \"path\" : \"$_airwave_directory/$_pluginname.so\",
  244.      \"prefix\" : \"real\",
  245.      \"target\" : \"$_dllpath\"
  246.      },"
  247.         set _oldconf [rw r "$_airwave_config/airwave.conf"]
  248.         regsub {("links" : \[)} $_oldconf "\\1$_insert" _newconf
  249.     }
  250.     rw w "$_airwave_config/airwave.conf" $_newconf
  251.  
  252. } else {
  253.     puts "RUNNING IN DRY RUN MODE. The following changes will NOT be applied:"
  254.     puts ""
  255.     foreach i [split [rw r "$_found_dlls"] "\n"]    {
  256.         if  {$i == ""}  {continue}
  257.         regexp {^([^/]+)/.*} $i -> _pluginname
  258.         regexp {^([^/]+)/(.*)} $i -> -> _dllpath
  259.         puts "CREATE BRIDGE: $_airwave_directory/$_pluginname.so"
  260.         puts "POINTING TO: $_dllpath"
  261.         puts ""
  262.     }
  263.     puts "END OF SIMULATION."
  264.     puts ""
  265. }
  266.  
  267. puts DONE!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement