Guest User

airblast_tcl_2.1

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