Guest User

airblast-for-airwave

a guest
Aug 10th, 2016
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.82 KB | None | 0 0
  1. #!/usr/bin/env fish
  2.  
  3. # ==================== AIRWAVE DLL BATCH LINKER ====================
  4. # by an airwave user
  5. #
  6. # READ THIS INTRODUCTION BEFORE ATTEMPTING TO USE IT
  7. #
  8. # ==================== HOW TO USE IT ===============================
  9. # This is a fish shell function. Put this file in your function
  10. # directory. If you don't know where it is, you're probably not using
  11. # the fish shell. You can read this script and port it to any other
  12. # shell if you want. That's the spirit of free software. [g]
  13. #
  14. # Next, cd to the directory that contains the DLL files of the Windows
  15. # plugins and run the command. All the *.dll files in the current
  16. # directory will be found and linked RECURSIVELY. Yes, recursively, so
  17. # make sure you're happy with the directory location and structure
  18. # before you run this.
  19. #
  20. # Example:
  21. # $ cd /some/directory/with/a/truckload/of/plugins
  22. # $ airblast
  23. #
  24. # After you run the command, a temporary file will be opened in a text
  25. # editor. I use Vim, but it is easy to edit this script and change it
  26. # to another editor of your preference. So this is your chance to edit
  27. # the names of the plugins. You can change them or not. Your call.
  28. # The NAMES ARE ON THE FAR LEFT OF EACH LINE, right BEFORE THE FIRST
  29. # FORWARD SLASH. Be careful not to delete the forward slash. It is a
  30. # delimiter and the entire operation will break if you delete the
  31. # forward slash. Also, don't use the forward slash in the name of any
  32. # plugin. If you do, it will become the first forward slash of the
  33. # line, in a rather expected and inconvenient place, and the script
  34. # will certainly make some bizarre mistake.
  35. # Everything after the first forward slash of the line is the path to
  36. # the .dll file of the actual plugin. DON'T CHANGE ANY OF THAT.
  37. # When you finish editing, save the file and close it. When Vim exits,
  38. # the script will continue its job and will create all the necessary
  39. # Airwave bridge links in one fell swoop.
  40. #
  41. # The location where the plugin links will be created is hard wired.
  42. # They will be created in the following directory:
  43. # /usr/lib/vst/airwave/
  44. # Besides, you MUST have at least one *.so plugin link/bridge already
  45. # created by Airwave in that directory, or the script will not work.
  46. # If you don't have any Airwave *.so file in that directory, create at
  47. # least one with the Airwave GUI before running this script. If you
  48. # don't like that choice of directory, just change that option in the
  49. # script below. Come on, it's not rocket science.
  50. #
  51. # After running the script, open your DAW and have it refresh the list
  52. # of plugins (assuming it's already configured to find plugins in the
  53. # /usr/lib/vst directory). That's it.
  54. #
  55. # Note 1: if you're afraid of running the script, you can test it with
  56. # a dry run first. Just run it with any one or more arguments and see
  57. # what happens: the script will not do anything at all except print
  58. # out what it would have done if it had been run in normal mode.
  59. #
  60. # Example:
  61. # $ cd /some/directory/with/a/truckload/of/plugins
  62. # $ airblast dryrun
  63. #
  64. # Using the word 'dryrun' as argument in this example makes sense, but
  65. # the truth is that the script will run in dry run mode with any one
  66. # or more arguments of your choice. Any word at all will trigger dry
  67. # run mode. It's a safety mechanism against typos.
  68. #
  69. # Note 2: every time you run this script NOT in dry run mode, it makes
  70. # a backup copy of your airwave.conf file in the ~/.config/airwave/
  71. # directory. If something goes terribly wrong, use the backup file to
  72. # clean up the mess.
  73. #
  74. # This script is placed in the public domain.
  75. # No guarantees are included whatsoever. If it blows up in your face,
  76. # eats your files or teaches profanity to your parrot, no one will be
  77. # responsible.
  78. # If you find a bug, fix it for your own good. If you don't find any
  79. # bugs, rejoice. Ignorance is bliss.
  80. #
  81. # ==================================================================
  82.  
  83. function airblast
  84.  
  85. set -g editor "/usr/bin/vim"
  86. set -g target_directory "/usr/lib/vst/airwave"
  87.  
  88. if test ! -d $target_directory
  89. echo "ERROR. The target directory doesn't even exist! Did you ever read the instructions???"
  90. echo "Please fix that problem and try again."
  91. echo ""
  92. return
  93. end
  94.  
  95. set -g dryrun 0
  96. if test (count $argv) -gt 0
  97. set dryrun 1
  98. end
  99.  
  100. if test -f ~/.config/airwave/found_dlls.txt
  101. rm -f ~/.config/airwave/found_dlls.txt
  102. end
  103.  
  104. # --------------------------------
  105. function dllfindsub
  106.  
  107. for i in (command ls -1a)
  108. if test $i = "." -o $i = ".."
  109. continue
  110. end
  111.  
  112. if test -f "$i"
  113. set extension (echo $i | rev | cut -d"." -f1 | rev)
  114. if test $extension = "dll" -o $extension = "DLL"
  115. set pluginname (echo $i | rev | cut -d"." -f2- | rev)
  116. set fullpath (pwd | sed -r 's/.*\.wine\/(.+)/\1/')
  117. echo $pluginname/$fullpath/$i >> ~/.config/airwave/found_dlls.txt
  118. end
  119. end
  120.  
  121. if test -d "$i"
  122. cd "$i"
  123. dllfindsub
  124. cd ..
  125. end
  126. end
  127.  
  128. end
  129. # --------------------------------
  130.  
  131. dllfindsub
  132.  
  133. if test ! -f ~/.config/airwave/found_dlls.txt
  134. echo "ERROR. No DLLs found. Perhaps you're running this in the wrong directory?"
  135. echo ""
  136. return
  137. end
  138.  
  139. # PAUSE TO REVIEW AND POSSIBLY EDIT THE LIST OF PLUGINS
  140. eval $editor ~/.config/airwave/found_dlls.txt
  141.  
  142. # --------------------------------
  143. function subreview
  144. for i in (cat ~/.config/airwave/found_dlls.txt)
  145. set i (echo $i | cut -d"/" -f1)
  146. for j in (command ls -1a $target_directory/*.so)
  147. if test $j = "." -o $j = ".."
  148. continue
  149. end
  150. set j (basename $j .so)
  151. if test "$i" = "$j"
  152. echo "conflict: $i"
  153. # Note: this is supposed to be an array in fish shell fashion
  154. set -g conflicts $conflicts[(seq (count $conflicts))] "$i"
  155. end
  156. end
  157. end
  158. if test (count $conflicts) -gt 0
  159. echo ""
  160. echo "Uh-oh! The following names you have chosen for plugins to be added are"
  161. echo "in conflict with already existing ones. You can't change existing ones,"
  162. echo "but you can change the ones you're adding now. The list will be opened"
  163. echo "in the text editor again so you can edit or delete them:"
  164. echo ""
  165. for k in $conflicts
  166. echo "$k"
  167. end
  168. echo ""
  169. echo "Press Enter to continue, Ctrl-c to quit."
  170. read
  171. eval $editor ~/.config/airwave/found_dlls.txt
  172. else
  173. return
  174. end
  175. subreview
  176. end
  177. # --------------------------------
  178.  
  179. subreview
  180.  
  181. # --------------------------------
  182. # GOOD. MOVING ON...
  183.  
  184. set timestamp (date +%Y-%m-%d_%H:%M)
  185. if test $dryrun = 0
  186. cp ~/.config/airwave/airwave.conf ~/.config/airwave/airwave.conf.backup.$timestamp
  187. end
  188.  
  189. set tempfile ~/.config/airwave/airblasttemp.txt
  190. sed 1,4!d ~/.config/airwave/airwave.conf > $tempfile
  191.  
  192. set anyplugin (command ls -1a $target_directory/*.so | head -n 1)
  193. if test $anyplugin = "."
  194. echo "ERROR. The target directory doesn't have any previously created link."
  195. echo "Please refer to the instructions, specifically this part:"
  196. echo ""
  197. echo "\"The plugin links will be created in the following directory:"
  198. echo "$target_directory"
  199. echo "Besides, you MUST have at least one *.so plugin link/bridge already"
  200. echo "created by Airwave in that directory, or the script will not work."
  201. echo "It must not be empty."
  202. echo "If you don't have any Airwave *.so file in that directory, create at"
  203. echo "least one with the Airwave GUI before running this script. If you don't"
  204. echo "like that choice of directory, just change that option in the script.\""
  205. echo ""
  206. return
  207. end
  208.  
  209. if test $dryrun = 0
  210. for i in (cat ~/.config/airwave/found_dlls.txt)
  211. set pluginname (echo $i | cut -d"/" -f1)
  212. set dllpath (echo $i | cut -d"/" -f2-)
  213. echo " {" >> $tempfile
  214. echo ' "loader" : "default",' >> $tempfile
  215. echo ' "log_level" : -1,' >> $tempfile
  216. echo " \"path\" : \"$target_directory/$pluginname.so\"," >> $tempfile
  217. echo ' "prefix" : "default",' >> $tempfile
  218. echo " \"target\" : \"$dllpath\"" >> $tempfile
  219. echo ' },' >> $tempfile
  220. cp "$anyplugin" "$target_directory/$pluginname.so"
  221. end
  222. sed '5,$!d' ~/.config/airwave/airwave.conf >> $tempfile
  223. mv $tempfile ~/.config/airwave/airwave.conf
  224. else
  225. echo "RUNNING IN DRY RUN MODE. The following changes will NOT be applied:"
  226. echo ""
  227. for i in (cat ~/.config/airwave/found_dlls.txt)
  228. set pluginname (echo $i | cut -d"/" -f1)
  229. set dllpath (echo $i | cut -d"/" -f2-)
  230. echo "CREATE BRIDGE: $target_directory/$pluginname.so"
  231. echo "POINTING TO: $dllpath"
  232. echo ""
  233. end
  234. echo "END OF SIMULATION."
  235. echo ""
  236. end
  237.  
  238. if test -f ~/.config/airwave/found_dlls.txt
  239. rm -f ~/.config/airwave/found_dlls.txt
  240. end
  241. if test -f ~/.config/airwave/airblasttemp.txt
  242. rm -f ~/.config/airwave/airblasttemp.txt
  243. end
  244.  
  245. end
Add Comment
Please, Sign In to add comment