Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env tclsh
- # execute in wish from path \
- #exec wish "$0" ${1+"$@"}
- # ==================== AIRWAVE DLL BATCH LINKER ====================
- # by an airwave user
- #
- # READ THIS INTRODUCTION BEFORE ATTEMPTING TO USE IT
- #
- # ==================== HOW TO USE IT ===============================
- # This is a Tcl script. You must have Tcl 8.4.6 or later to use it.
- # Older versions of Tcl may work, but I am not sure they will.
- #
- # First, 'cd' to the directory that contains the DLL files of the
- # Windows plugins and run the command. All the *.dll files in the
- # current directory will be found and linked RECURSIVELY. Yes,
- # recursively, so make sure you're happy with the directory location
- # and structure before you run this script.
- #
- # Example:
- # $ cd /some/directory/with/a/truckload/of/plugins
- # $ airblast
- #
- # Tip: some file managers such as pcmanfm or spacefm let you press F4
- # to launch a terminal session in whatever directory it is displaying,
- # so you don't even have to 'cd' manually.
- #
- # After you run the command, a temporary file will be opened in a text
- # editor. (I use Vim, but it is easy to edit this script and change it
- # to another editor of your preference.) So this is your chance to edit
- # the names of the plugins if you don't like the defaults. You can
- # change them or not. Your call.
- #
- # The NAMES ARE ON THE FAR LEFT OF EACH LINE, right BEFORE THE FIRST
- # FORWARD SLASH. That is the name you will see in the DAW's list of
- # available VST plugins. Be careful not to delete the forward slash.
- # It is a delimiter so the entire operation will break if you delete
- # the forward slash. Also, don't use the forward slash in the name of
- # any plugin. If you do, it will become the first forward slash of the
- # line, in a rather expected and inconvenient place, and the script
- # will certainly make some bizarre mistake.
- #
- # Everything after the first forward slash of the line is the path to
- # the .dll file of the actual plugin. DON'T CHANGE ANY OF THAT.
- #
- # When you finish editing, save the file and close it. When the text
- # editor exits, the script will continue its job and will create all
- # the necessary Airwave bridge links in one fell swoop.
- #
- # The location where the plugin links will be created is hard wired.
- # They will be created in the following directory:
- # /usr/lib/vst/airwave/
- # Besides, you MUST have at least one *.so plugin link/bridge already
- # created by Airwave in that directory, or this script will not work.
- # If you don't have any Airwave *.so file in that directory, create at
- # least one with the Airwave GUI before running this script.
- # If you don't want /usr/lib/vst/airwave/ to be your target directory,
- # just edit that option in the script below. Come on, try it. It's not
- # rocket science.
- #
- # After running the script, open your DAW and have it refresh the list
- # of plugins (assuming it's already configured to find plugins in the
- # /usr/lib/vst directory). That's it. The DAW will detect the new
- # plugins in that directory and add them to its internal catalogue with
- # the names you chose to edit or leave untouched in the previous step.
- #
- # Note 1: if you're afraid of running the script, you can test it with
- # a dry run first. Just run it with any one or more arguments and see
- # what happens: the script will not do anything at all except print
- # out what it would have done if it had been run in normal mode.
- #
- # Example:
- # $ cd /some/directory/with/a/truckload/of/plugins
- # $ airblast dryrun
- #
- # Using the word 'dryrun' as argument in this example makes sense, but
- # the truth is that the script will run in dry run mode with any one
- # or more arguments of your choice. Any word at all will trigger dry
- # run mode. It's a safety mechanism against typos.
- #
- # Note 2: every time you run this script NOT in dry run mode, it makes
- # a backup copy of your airwave.conf file in the ~/.config/airwave/
- # directory. If something goes terribly wrong, use the backup file to
- # clean up the mess.
- #
- # This script is placed in the public domain.
- # No guarantees are included whatsoever. If it blows up in your face,
- # eats your files or teaches profanity to your parrot, no one will be
- # responsible.
- # If you find a bug, fix it for your own good. If you don't find any
- # bugs, rejoice. Ignorance is bliss.
- #
- # ==================================================================
- # USER OPTIONS. EDIT THESE AT WILL.
- set _editor "/usr/bin/vim"
- set _airwave_directory "/usr/lib/vst/airwave/"
- # SCRIPT BEGINS HERE. DON'T CHANGE ANYTHING BELOW THIS POINT
- # UNLESS YOU KNOW WHAT YOU'RE DOING.
- set _airwave_directory [file normalize $_airwave_directory]
- set _airwave_config [file normalize "~/.config/airwave"]
- set _found_dlls [file normalize "$_airwave_config/found_dlls.txt"]
- if {[file isdirectory $_airwave_directory] == 0} {
- puts "ERROR. The target directory '$_airwave_directory' doesn't even exist! Did you ever read the instructions???"
- puts "Please fix that problem and try again."
- puts ""
- exit
- }
- # --------------------------------
- proc rw {argRW argFile args} {
- set _fp [open $argFile $argRW]
- if {[string range $argRW 0 0] == "r"} {
- set _slurp [read $_fp]
- close $_fp
- return $_slurp
- }
- for {set i 0} {$i <= [llength $args]} {incr i} {
- puts -nonewline $_fp [lindex $args $i]
- }
- close $_fp
- }
- # --------------------------------
- rw w $_found_dlls [exec find [pwd] -iname "*.dll"]
- set _fp [open $_found_dlls r]
- while {-1 != [gets $_fp _line]} {
- regexp {([^/]+$)} $_line => _pluginfile
- regexp {([^/]+)\.[^/.]+$} $_line => _pluginname
- regsub {.*\.wine\/(.+)} $_line {\1} _fullpath
- append _prettylist "$_pluginname/$_fullpath\n"
- }
- close $_fp
- if {[info exists _prettylist] == 0} {
- puts "ERROR. No DLLs found. Perhaps you're running this in the wrong directory?"
- puts ""
- exit
- } else {rw w $_found_dlls $_prettylist}
- # --------------------------------
- # PAUSE TO REVIEW AND POSSIBLY EDIT THE LIST OF PLUGINS
- proc subreview {} {
- set _newplugins {}
- set _repeats {}
- set _conflicts {}
- eval "exec $::_editor $::_found_dlls <@stdin >@stdout"
- set _fp [open $::_found_dlls r]
- while {-1 != [gets $_fp _line]} {
- regexp {([^/]+)/.*} $_line => _pluginname
- lappend _newplugins $_pluginname
- }
- close $_fp
- foreach i $_newplugins {
- if {[llength [lsearch -all $_newplugins $i]] > 1} {
- lappend _repeats $i
- }
- }
- if {[llength $_repeats] > 0} {
- puts ""
- puts "You are trying to add more than one plugin with the exact same name, which is not possible. "
- puts "Maybe you're adding both the 32-bit and 64-bit versions of the same plugin? In that case, "
- puts "remove one or just rename it, e.g. plugin_name_64-bit."
- puts ""
- puts "Press Enter to continue, Ctrl-c to quit."
- gets stdin _line
- subreview
- }
- foreach i [glob $::_airwave_directory/*.so] {
- set i [file rootname [file tail $i]]
- lappend _alreadyexist $i
- }
- if {[llength $_alreadyexist] == 0} {
- puts "ERROR. The target directory doesn't have any previously created link."
- puts "Please refer to the instructions, specifically this part:"
- puts ""
- puts "\"The plugin links will be created in the following directory: $_airwave_directory"
- puts "Besides, you MUST have at least one *.so plugin link/bridge already created by Airwave in that directory, "
- puts "or the script will not work. And it must not be empty."
- puts "If you don't have any Airwave *.so file in that directory, create at least one with the Airwave GUI before "
- puts "running this script. If you don't like that choice of directory, just change that option in the script.\""
- puts ""
- exit
- }
- foreach i $_newplugins {
- if {[lsearch $_alreadyexist $i] >= 0} {
- puts "conflict: $i"
- lappend _conflicts $i
- }
- }
- if {[llength $_conflicts] > 0} {
- puts ""
- puts "Uh-oh! The following names you have chosen for plugins to be added are in conflict with already existing ones. "
- puts "You can't change existing ones, but you can change the ones you're adding now. The list will be opened in the "
- puts "text editor again so you can edit or delete them:"
- puts ""
- foreach k $_conflicts {
- puts $k
- }
- puts ""
- puts "Press Enter to continue, Ctrl-c to quit."
- gets stdin _line
- subreview
- # eval "exec $::_editor $::_found_dlls <@stdin >@stdout"
- }
- }
- subreview
- # --------------------------------
- # GOOD. MOVING ON...
- if {[llength $argc] == 0} {
- set _dryrun 0
- } else {set _dryrun 1}
- if {$argc == 0} {
- set timestamp [clock format [clock seconds] -format "%Y-%m-%d_%H:%M"]
- file copy -force "$_airwave_config/airwave.conf" "$_airwave_config/airwave.conf.backup.$timestamp"
- set _anyplugin [lindex [glob $_airwave_directory/*.so] 0]
- foreach i [split [rw r "$_found_dlls"] "\n"] {
- if {$i == ""} {continue}
- regexp {^([^/]+)/.*} $i -> _pluginname
- regexp {^([^/]+)/(.*)} $i -> -> _dllpath
- file copy "$_anyplugin" "$_airwave_directory/$_pluginname.so"
- eval "exec touch $_airwave_directory/$_pluginname.so"
- append _insert "\n {
- \"loader\" : \"default\",
- \"log_level\" : -1,
- \"path\" : \"$_airwave_directory/$_pluginname.so\",
- \"prefix\" : \"real\",
- \"target\" : \"$_dllpath\"
- },"
- set _oldconf [rw r "$_airwave_config/airwave.conf"]
- regsub {("links" : \[)} $_oldconf "\\1$_insert" _newconf
- }
- rw w "$_airwave_config/airwave.conf" $_newconf
- } else {
- puts "RUNNING IN DRY RUN MODE. The following changes will NOT be applied:"
- puts ""
- foreach i [split [rw r "$_found_dlls"] "\n"] {
- if {$i == ""} {continue}
- regexp {^([^/]+)/.*} $i -> _pluginname
- regexp {^([^/]+)/(.*)} $i -> -> _dllpath
- puts "CREATE BRIDGE: $_airwave_directory/$_pluginname.so"
- puts "POINTING TO: $_dllpath"
- puts ""
- }
- puts "END OF SIMULATION."
- puts ""
- }
- puts DONE!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement