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.

147 lines
3.8KB

  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=
  34. ONLY_COMPACTED=
  35. MOVE=1
  36. fatal ()
  37. {
  38. echo Error: "$1"
  39. echo 'Aborting!'
  40. cleanup
  41. exit 1
  42. }
  43. cleanup ()
  44. {
  45. rm -f "${TEMP}/all-sources" "${TEMP}/used-sources"
  46. }
  47. set_diff ()
  48. {
  49. diff --new-line-format '' --old-line-format '%L' --unchanged-line-format '' "$1" "$2"
  50. }
  51. remove_sources ()
  52. {
  53. local TOTAL=0
  54. local FILE
  55. local SIZE
  56. local PSIZE
  57. while read FILE
  58. do
  59. PSIZE=`stat -c '%s' "${FILE}.peak" 2>/dev/null`
  60. SIZE=`stat -c '%s' "${FILE}" 2>/dev/null`
  61. PSIZE=${PSIZE:-0}
  62. if ! [ -f "${FILE}" ]
  63. then
  64. echo "Would remove \"${FILE}\", if it existed."
  65. else
  66. if [ "$DRY_RUN" = 1 ]
  67. then
  68. echo "Would remove: ${FILE}"
  69. else
  70. if [ "$MOVE" = 1 ]
  71. then
  72. echo "Moving unused source \"${FILE}\"..."
  73. mv -f ./"${FILE}" ./"${FILE}".peak ../unused-sources
  74. else
  75. echo "Removing unused source \"${FILE}\"..."
  76. rm -f ./"${FILE}" ./"${FILE}".peak
  77. fi
  78. fi
  79. TOTAL=$(( $TOTAL + $SIZE + $PSIZE ))
  80. fi
  81. done
  82. echo "...Freeing a total of $(($TOTAL / ( 1024 * 1024 ) ))MB"
  83. }
  84. usage ()
  85. {
  86. fatal "Usage: $0 [-n] [-c] [-m|-d] path/to/project"
  87. }
  88. while getopts "dmnc" o
  89. do
  90. case "$o" in
  91. d) MOVE= ;;
  92. m) MOVE=1 ;;
  93. n) DRY_RUN=1 ;;
  94. c) ONLY_COMPACTED=1 ;;
  95. \?) usage ;;
  96. *) echo "$o" && usage ;;
  97. esac
  98. done
  99. shift $(( $OPTIND - 1 ))
  100. PROJECT="$1"
  101. [ $# -eq 1 ] || usage
  102. cd "$PROJECT" || fatal "No such project"
  103. [ -f history ] && [ -f info ] || fatal "Not a Non-DAW project?"
  104. [ -f .lock ] && fatal "Project appears to be in use"
  105. if [ "$ONLY_COMPACTED" = 1 ]
  106. then
  107. grep -v '\(^\{\|\}$\)\|create' history && fatal "Not a compacted project"
  108. fi
  109. echo "Scanning \"${PROJECT}\"..."
  110. sed -n 's/^\s*Audio_Region.* :source "\([^"]\+\)".*$/\1/p' history | sort | uniq > "${TEMP}/used-sources"
  111. cd sources || fatal "Can't change to source directory"
  112. [ "$MOVE" = 1 ] && mkdir ../unused-sources 2>/dev/null
  113. ls -1 | grep -v '\.peak$' | sort > "${TEMP}/all-sources"
  114. set_diff "${TEMP}/all-sources" "${TEMP}/used-sources" | remove_sources
  115. cleanup
  116. echo "Done."