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.

106 lines
2.9KB

  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 FILE
  53. while read FILE
  54. do
  55. if [ $DRY_RUN = yes ]
  56. then
  57. echo "Would remove: ${FILE}"
  58. else
  59. echo "Removing unused source \"${FILE}\"..."
  60. rm -f ./"${FILE}" ./"${FILE}-"*.peak
  61. fi
  62. done
  63. }
  64. [ $# -gt 0 ] || fatal "Usage: $0 [--dry-run] path/to/project"
  65. if [ "$1" = --dry-run ]
  66. then
  67. DRY_RUN=yes
  68. shift 1
  69. fi
  70. PROJECT="$1"
  71. cd "$PROJECT" || fatal "No such project"
  72. [ -f history ] && [ -f info ] || fatal "Not a Non-DAW project?"
  73. [ -f .lock ] && fatal "Project appears to be in use"
  74. if [ $ONLY_COMPACTED = yes ]
  75. then
  76. grep -v '\(^\{\|\}$\)\|create' history && fatal "Not a compacted project"
  77. fi
  78. echo "Scanning \"${PROJECT}\"..."
  79. sed -n 's/^\s\+Audio_Region.* :source "\([^"]\+\)".*$/\1/p' history | sort | uniq > "${TEMP}/used-sources"
  80. cd sources || fatal "Can't change to source directory"
  81. ls -1 | grep -v '\.peak$' | sort > "${TEMP}/all-sources"
  82. set_diff "${TEMP}/all-sources" "${TEMP}/used-sources" | remove_sources
  83. cleanup
  84. echo "Done."