Assists music production by grouping standalone programs into sessions. Community version of "Non Session Manager".
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
3.2KB

  1. #!/bin/sh
  2. # Copyright (C) 2008 Jonathan Moore Liles #
  3. # #
  4. # This program is free software; you can redistribute it and/or modify it #
  5. # under the terms of the GNU General Public License as published by the #
  6. # Free Software Foundation; either version 2 of the License, or (at your #
  7. # option) any later version. #
  8. # #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT #
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
  12. # more details. #
  13. # #
  14. # You should have received a copy of the GNU General Public License along #
  15. # with This program; see the file COPYING. If not,write to the Free Software #
  16. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
  17. ## remove-unused-sources
  18. #
  19. # April 2008, Jonathan Moore Liles
  20. #
  21. # Simple script to scan a compacted Non-DAW project and remove all
  22. # unused sources from disk.
  23. #
  24. # USAGE:
  25. #
  26. # $ remove-unused-sources ~/audio/'The Best Song Ever'
  27. #
  28. # NOTES:
  29. #
  30. # This script will not ask for comfirmation! It will ruthlessly
  31. # delete all unused sources! You have been warned.
  32. #
  33. DRY_RUN=no
  34. ONLY_COMPACTED=no
  35. fatal ()
  36. {
  37. echo Error: "$1"
  38. echo 'Aborting!'
  39. cleanup
  40. exit 1
  41. }
  42. cleanup ()
  43. {
  44. rm -f "${TEMP}/all-sources" "${TEMP}/used-sources"
  45. }
  46. set_diff ()
  47. {
  48. diff --new-line-format '' --old-line-format '%L' --unchanged-line-format '' "$1" "$2"
  49. }
  50. remove_sources ()
  51. {
  52. local TOTAL=0
  53. local FILE
  54. local SIZE
  55. while read FILE
  56. do
  57. SIZE=`stat -c '%s' "${FILE}" 2>/dev/null`
  58. if [ $? -ne 0 ]
  59. then
  60. echo "Would remove \"${FILE}\", if it existed."
  61. else
  62. if [ $DRY_RUN = yes ]
  63. then
  64. echo "Would remove: ${FILE}"
  65. else
  66. echo "Removing unused source \"${FILE}\"..."
  67. rm -f ./"${FILE}" ./"${FILE}-"*.peak
  68. fi
  69. TOTAL=$(( $TOTAL + $SIZE ))
  70. fi
  71. done
  72. echo "...Freeing a total of $(($TOTAL / ( 1024 * 1024 ) ))MB"
  73. }
  74. [ $# -gt 0 ] || fatal "Usage: $0 [--dry-run] path/to/project"
  75. if [ "$1" = --dry-run ]
  76. then
  77. DRY_RUN=yes
  78. shift 1
  79. fi
  80. PROJECT="$1"
  81. cd "$PROJECT" || fatal "No such project"
  82. [ -f history ] && [ -f info ] || fatal "Not a Non-DAW project?"
  83. [ -f .lock ] && fatal "Project appears to be in use"
  84. if [ $ONLY_COMPACTED = yes ]
  85. then
  86. grep -v '\(^\{\|\}$\)\|create' history && fatal "Not a compacted project"
  87. fi
  88. echo "Scanning \"${PROJECT}\"..."
  89. sed -n 's/^\s\+Audio_Region.* :source "\([^"]\+\)".*$/\1/p' history | sort | uniq > "${TEMP}/used-sources"
  90. cd sources || fatal "Can't change to source directory"
  91. ls -1 | grep -v '\.peak$' | sort > "${TEMP}/all-sources"
  92. set_diff "${TEMP}/all-sources" "${TEMP}/used-sources" | remove_sources
  93. cleanup
  94. echo "Done."