Skip to content

Instantly share code, notes, and snippets.

@jsleeio
Last active June 8, 2019 21:05
Show Gist options
  • Save jsleeio/98ba05eb654ddb5cb250ac280337ab64 to your computer and use it in GitHub Desktop.
Save jsleeio/98ba05eb654ddb5cb250ac280337ab64 to your computer and use it in GitHub Desktop.
Prepare random sets of Make Noise Morphagene reels for copying to SD card
#!/bin/bash
### given a folder full of Morphagene-suitable audio files, select 32
### at random and make a directory full of hardlinks(!!) to them, ready
### for copying to an SD card. Also generates an index file so you can
### trace back to the original filenames.
# macOS and GNU both seem to have sort -R for randomizing. You may need to
# adjust if using some other implementation
REELS_HOME="$HOME/Documents/Audio/reels"
if [ "$1" != "" ] ; then
REELS_HOME="$1"
fi
_die() {
echo "select-random-reels.sh: FATAL: $*" >&2
exit 1
}
cd "$REELS_HOME" || _die "can't access reels: $REELS_HOME"
# the final 'sort' is intended to ensure any related reels in the selection
# are adjacent
selected="$(
find . -type f -name '*.wav' -maxdepth 1 ! -name 'mg[1-9a-w].wav' \
| sort -R \
| head -32 \
| xargs -n1 basename \
| sort -n \
)"
digest="$(echo "$selected" | openssl sha)"
# from Morphagene user manual; colours repeat in this order, except white
# which is prepended to keep the modulus indexing uncomplicated
declare -a reelcolours
reelcolours[0]=white
reelcolours[1]=blue
reelcolours[2]=eucalypt
reelcolours[3]=green
reelcolours[4]=yellow
reelcolours[5]=orange
reelcolours[6]=red
reelcolours[7]=violet
reelcolours[8]=white
# Morphagene reel filenames are mg1.wav thru mg9.wav and mga.wav thru mgw.wav
# pregenerate the names
declare -a reelnames
n=1
for id in {1..9} {a..w} ; do
reelnames[$n]="mg${id}.wav"
n=$((n+1))
done
n=1
mkdir "$digest" || _die "can't make reelset directory: $digest"
cd "$digest" || _die "can't access reelset directory: $digest"
{ echo "# random reelset: $digest"; echo; } >> INDEX.md
{
echo 'COLOUR NAME ORIGINAL-NAME'
for reel in $selected ; do
mgn="${reelnames[$n]}"
colourindex=$(((n+8) % 8))
echo "${reelcolours[$colourindex]}" "$mgn" "$reel"
ln "../$reel" "$mgn"
n=$((n+1))
done
} | column -t >> INDEX.md
echo "your new reel selection: $digest"
@jsleeio
Copy link
Author

jsleeio commented Sep 15, 2018

comment here if you have a better name than eucalypt for the first green in the reel colour sequence :-/

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment