Chris@320: #!/bin/bash
Chris@320: 
Chris@320: audio=/data/music
Chris@320: preferred=$audio/free
Chris@320: list=audiofiles.txt
Chris@320: used=audiofiles-used.txt
Chris@320: 
Chris@320: df=vamp:vamp-aubio:aubioonset:detectionfunction
Chris@320: #df=vamp:qm-vamp-plugins:qm-tempotracker:detection_fn
Chris@320: onsets=vamp:vamp-aubio:aubioonset:onsets
Chris@320: #onsets=vamp:qm-vamp-plugins:qm-tempotracker:beats
Chris@320: beats=vamp:vamp-aubio:aubiotempo:beats
Chris@320: #beats=$onsets
Chris@320: #onsets=$beats
Chris@320: chromagram=vamp:qm-vamp-plugins:qm-chromagram:chromagram
Chris@320: notes=vamp:vamp-aubio:aubionotes:notes
Chris@320: 
Chris@320: pid=`cat /tmp/demoscript.pid 2>/dev/null`
Chris@320: if [ -n "$pid" ]; then
Chris@320:     kill "$pid"
Chris@320: fi
Chris@320: echo $$ > /tmp/demoscript.pid
Chris@320: trap "rm /tmp/demoscript.pid" 0
Chris@320: 
Chris@320: sv-command quit
Chris@320: sleep 1
Chris@320: killall -9 sonic-visualiser
Chris@320: sleep 1
Chris@320: 
Chris@320: pick_file()
Chris@320: {
Chris@320:     file=""
Chris@320:     count=`wc -l "$list" 2>/dev/null | awk '{ print $1 }'`
Chris@320:     if [ ! -f "$list" ] || [ "$count" -eq "0" ] ; then
Chris@320: 	find "$audio" -name \*.ogg -print >> "$list"
Chris@320: 	find "$audio" -name \*.mp3 -print >> "$list"
Chris@320: 	find "$audio" -name \*.wav -print >> "$list"
Chris@320: 	find "$preferred" -name \*.ogg -print >> "$list"
Chris@320: 	find "$preferred" -name \*.mp3 -print >> "$list"
Chris@320: 	find "$preferred" -name \*.wav -print >> "$list"
Chris@320: 	count=`wc -l "$list" 2>/dev/null | awk '{ print $1 }'`
Chris@320:     fi
Chris@320:     while [ -z "$file" ]; do
Chris@320: 	index=$((RANDOM % $count))
Chris@320: 	file=`tail +"$index" "$list" | head -1`
Chris@320: 	[ -f "$file" ] || continue
Chris@320:     done
Chris@320:     fgrep -v "$file" "$list" > "$list"_ && mv "$list"_ "$list"
Chris@320:     echo "$file"
Chris@320: }
Chris@320: 
Chris@320: load_a_file()
Chris@320: {
Chris@320:     file=`pick_file`
Chris@320:     if ! sv-command open "$file"; then
Chris@320: 	pid="`pidof sonic-visualiser`"
Chris@320: 	if [ -z "$pid" ]; then
Chris@320: 	    ( setsid sonic-visualiser -geometry 1000x500+10+100 & )
Chris@320: 	    sleep 2
Chris@320:             sudo renice +19 `pidof sonic-visualiser`
Chris@320:             sudo renice +18 `pidof Xorg`
Chris@320:             sv-command resize 1000 500
Chris@320: 	    load_a_file
Chris@320: 	else
Chris@320: 	    echo "ERROR: Unable to contact sonic-visualiser pid $pid" 1>&2
Chris@320: 	    exit 1
Chris@320: 	fi
Chris@320:     fi
Chris@320: }
Chris@320: 
Chris@320: show_stuff()
Chris@320: {
Chris@320:     sv-command set overlays 2
Chris@320: #    sv-command set zoomwheels 1
Chris@320:     sv-command set propertyboxes 1
Chris@320: }
Chris@320: 
Chris@320: hide_stuff()
Chris@320: {
Chris@320:     sv-command set overlays 0
Chris@320: #    sv-command set zoomwheels 0
Chris@320:     sv-command set propertyboxes 0
Chris@320: }
Chris@320: 
Chris@320: reset()
Chris@320: {
Chris@320:     for pane in 1 2 3 4 5; do
Chris@320: 	for layer in 1 2 3 4 5 6 7 8 9 10; do
Chris@320: 	    sv-command delete layer
Chris@320: 	done
Chris@320: 	sv-command delete pane
Chris@320:     done
Chris@320:     sv-command zoom default
Chris@320:     sv-command add waveform
Chris@320:     show_stuff
Chris@320: }
Chris@320: 
Chris@320: scroll_and_zoom()
Chris@320: {
Chris@320:     sv-command set overlays 0
Chris@320:     sv-command set zoomwheels 0
Chris@320:     sv-command set propertyboxes 0
Chris@320: #    sv-command setcurrent 1 1
Chris@320: #    sv-command delete layer
Chris@320: #    sv-command setcurrent 1 1
Chris@320:     sv-command set layer Colour Red
Chris@320:     sleep 1
Chris@320:     sv-command set pane Global-Zoom off
Chris@320:     sv-command set pane Global-Scroll off
Chris@320:     sv-command set pane Follow-Playback Scroll
Chris@320:     for zoom in 950 900 850 800 750 700 650 600 550 512 450 400 350 300 256 192 160 128 96 64 48 32 24 16; do
Chris@320: 	sv-command zoom $zoom
Chris@320: 	sleep 0.1
Chris@320:     done
Chris@320: }
Chris@320: 
Chris@320: play()
Chris@320: {
Chris@320:     sv-command play "$@"
Chris@320: }
Chris@320: 
Chris@320: fade_in()
Chris@320: {
Chris@320:     sv-command set gain 0
Chris@320:     sleep 0.5
Chris@320:     play "$@"
Chris@320:     for gain in 0.001 0.01 0.05 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1; do
Chris@320: 	sv-command set gain $gain
Chris@320: 	sleep 0.1
Chris@320:     done
Chris@320: }
Chris@320: 
Chris@320: fade_out()
Chris@320: {
Chris@320:     for gain in 0.9 0.8 0.7 0.6 0.5 0.4 0.3 0.2 0.1 0.05 0.01 0.001; do
Chris@320: 	sv-command set gain $gain
Chris@320: 	sleep 0.1
Chris@320:     done
Chris@320:     stop
Chris@320:     sv-command set gain 1
Chris@320: }
Chris@320: 
Chris@320: slow()
Chris@320: {
Chris@320: #    for speed in -1 -10 -20 -30 -40 -50 -60 -70 -80 -100 -140 -200 -250 -300 -400 -500 -700 -800 -900 -1000; do
Chris@320: #	sv-command set speedup "$speed"
Chris@320: #	sleep 1
Chris@320: #    done
Chris@320:     for speed in -20 -100 -1000; do
Chris@320:         sv-command set speedup "$speed"
Chris@320:         sleep 10
Chris@320:     done
Chris@320: }
Chris@320: 
Chris@320: stop()
Chris@320: {
Chris@320:     sv-command stop "$@"
Chris@320:     sv-command set speedup 0
Chris@320: }
Chris@320: 
Chris@320: quit()
Chris@320: {
Chris@320:     sv-command quit
Chris@320: }
Chris@320: 
Chris@320: add_melodic_range_spectrogram()
Chris@320: {
Chris@320:     sv-command set propertyboxes 1
Chris@320:     sv-command add spectrogram
Chris@320:     sv-command set layer Window-Size 8192
Chris@320: #    sv-command set layer Window-Size 4096
Chris@320:     sv-command set layer Window-Overlap 4
Chris@320: #    sv-command set layer Window-Overlap 3
Chris@320:     sv-command set layer Frequency-Scale Log
Chris@320:     sv-command set layer Colour-Scale Meter
Chris@320: }
Chris@320: 
Chris@320: zoom_in_spectrogram() 
Chris@320: {
Chris@320:     sv-command zoomvertical 43 8000
Chris@320:     for x in 1 2 3 4 5 6; do
Chris@320: 	max=$((8000 - 1000*$x))
Chris@320: 	sv-command zoomvertical 43 "$max"
Chris@320: 	sleep 0.5
Chris@320:     done
Chris@320:     for x in 1 2 3 4 5; do
Chris@320: 	max=$((2000 - 100 * $x))
Chris@320: 	sv-command zoomvertical 43 "$max"
Chris@320: 	sleep 0.5
Chris@320:     done
Chris@320: }
Chris@320: 
Chris@320: zoom_in_spectrogram_further() 
Chris@320: {
Chris@320:     for x in 1 2 3 4 5; do
Chris@320: 	sv-command zoomvertical in
Chris@320:     done
Chris@320: }
Chris@320: 
Chris@320: playback_bits()
Chris@320: {
Chris@320:     sv-command setcurrent 1
Chris@320:     sv-command set pane Global-Zoom off
Chris@320:     sv-command set pane Global-Scroll off
Chris@320:     sv-command set pane Follow-Playback Scroll
Chris@320:     sv-command jump 10
Chris@320:     sv-command setcurrent 1 1
Chris@320:     sv-command delete layer
Chris@320:     sv-command setcurrent 1 1
Chris@320: #    sv-command setcurrent 1 2
Chris@320:     sv-command set layer Colour Blue
Chris@320:     sleep 5
Chris@320:     hide_stuff
Chris@320:     sv-command set overlays 0
Chris@320:     sv-command set zoomwheels 0
Chris@320:     sv-command set propertyboxes 0
Chris@320:     fade_in
Chris@320:     sleep 10
Chris@320: #    sv-command set layer Colour Blue
Chris@320: #    sleep 1
Chris@320: #    sv-command set layer Colour Orange
Chris@320: #    sleep 1
Chris@320: #    sv-command set layer Colour Red
Chris@320: #    sleep 1
Chris@320: #    sv-command set layer Colour Green
Chris@320: #    sleep 1
Chris@320: #    sleep 1
Chris@320:     
Chris@320:     
Chris@320: #    scroll_and_zoom
Chris@320: 
Chris@320: #    sv-command set overlays 0
Chris@320: #    sv-command set zoomwheels 0
Chris@320: #    sv-command set propertyboxes 0
Chris@320: #    sv-command setcurrent 1 1
Chris@320: #    sv-command delete layer
Chris@320: #    sv-command setcurrent 1 1
Chris@320: #    sv-command set layer Colour Red
Chris@320: #    sleep 1
Chris@320: #    sv-command set pane Global-Zoom off
Chris@320: #    sv-command set pane Global-Scroll off
Chris@320: #    sv-command set pane Follow-Playback Scroll
Chris@320:     sv-command set zoomwheels 1
Chris@320:     sleep 1
Chris@320:     for zoom in 950 900 850 800 750 700 650 600 550 512 450 400 350 300 256 192 160 128 96 64 48 32 24 16; do
Chris@320: 	sv-command zoom $zoom
Chris@320: 	sleep 0.1
Chris@320:     done
Chris@320:     
Chris@320:     sleep 1
Chris@320:     sv-command set zoomwheels 0
Chris@320:     sv-command zoom 16
Chris@320: 
Chris@320:     sleep 10
Chris@320:     #slow
Chris@320:     #sv-command set layer Normalize-Visible-Area on
Chris@320: #    for zoom in 15 14 13 12 11 10 9 8 7 6 5 4 ; do
Chris@320: #	sv-command zoom $zoom
Chris@320: #	sleep 0.1
Chris@320:  #   done
Chris@320:     sleep 1
Chris@320:     sv-command set zoomwheels 0
Chris@320:     slow
Chris@320:     sleep 7
Chris@320:     fade_out
Chris@320:     sv-command setcurrent 1
Chris@320:     sv-command set pane Follow-Playback Page
Chris@320:     sv-command set pane Global-Zoom on
Chris@320:     sv-command set pane Global-Scroll on
Chris@320:     done_playback_bits=1
Chris@320: }
Chris@320: 
Chris@320: spectrogram_bits()
Chris@320: {
Chris@320:     sv-command set pane Global-Zoom on
Chris@320:     sv-command zoom 1024
Chris@320:     add_melodic_range_spectrogram
Chris@320:     sv-command zoom 1024
Chris@320:     sleep 5
Chris@320:     sv-command jump 10
Chris@320:     sleep 20
Chris@320:     zoom_in_spectrogram
Chris@320:     sleep 20
Chris@320: 
Chris@320:     sv-command select 7.5 11
Chris@320:     fade_in selection
Chris@320:     sleep 10
Chris@320:     sv-command set speedup -200
Chris@320:     sleep 10
Chris@320:     sv-command setcurrent 1
Chris@320:     sv-command delete pane
Chris@320:     sv-command zoom in
Chris@320:     sv-command setcurrent 1 2
Chris@320:     sv-command set layer Normalize-Columns off
Chris@320:     sv-command set layer Normalize-Visible-Area on
Chris@320:     sleep 20
Chris@320:     sv-command set speedup 0
Chris@320:     sleep 10
Chris@320:     sv-command select none
Chris@320: #    fade_out
Chris@320: 
Chris@320: #    if [ -n "$done_playback_bits" ]; then
Chris@320: #	sv-command setcurrent 1
Chris@320: #	sv-command zoom out
Chris@320: #	sv-command zoom outvamp:qm-vamp-plugins:qm-chromagram:chromagram
Chris@320: #	sv-command zoom out
Chris@320: #	sv-command zoom out
Chris@320: #	sv-command zoom out
Chris@320: #	sv-command setcurrent 2
Chris@320: #    fi
Chris@320:     
Chris@320: #    hide_stuff
Chris@320: #    fade_in
Chris@320:     sleep 10
Chris@320: #    sv-command set layer Bin-Display Frequencies
Chris@320: #    sv-command set layer Normalize-Columns on
Chris@320: #    sleep 20
Chris@320:     sv-command set layer Bin-Display "All Bins"
Chris@320:     sv-command set layer Normalize-Columns on
Chris@320:     sv-command set layer Normalize-Visible-Area off
Chris@320:     sv-command set layer Colour-Scale 0
Chris@320:     sv-command set layer Colour "Red on Blue"
Chris@320:     sv-command zoomvertical 23 800
Chris@320:     sleep 20
Chris@320:     sv-command transform $onsets
Chris@320:     sv-command set layer Colour Orange
Chris@320:     sleep 20
Chris@320:     fade_out
Chris@320:     sleep 1
Chris@320: #    sv-command jump 10
Chris@320: #    sv-command setcurrent 1 2
Chris@320: #    sv-command set layer Colour "Black on White"
Chris@320: #    sv-command transform $notes
Chris@320: #    sv-command set layer Colour Orange
Chris@320:     sleep 10
Chris@320: #    sv-command setcurrent 1 3
Chris@320: #    sv-command delete layer
Chris@320:     sv-command setcurrent 1 3
Chris@320:     sv-command delete layer
Chris@320:     sv-command setcurrent 1 2
Chris@320:     sv-command set layer Colour Default
Chris@320:     done_spectrogram_bits=1
Chris@320: 
Chris@320: #    zoom_in_spectrogram_further
Chris@320: }
Chris@320: 
Chris@320: onset_bits()
Chris@320: {
Chris@320:     show_stuff
Chris@320:     sv-command set zoomwheels 0
Chris@320:     sv-command setcurrent 1
Chris@320:     sv-command set pane Global-Zoom on
Chris@320:     sv-command set pane Global-Scroll on
Chris@320:     sleep 0.5
Chris@320:     sv-command set layer Colour Blue
Chris@320:     sleep 0.5
Chris@320:     sv-command set layer Colour Orange
Chris@320:     sleep 0.5
Chris@320:     sv-command set layer Colour Red
Chris@320:     sleep 0.5
Chris@320:     sv-command set layer Colour Green
Chris@320:     sleep 1
Chris@320: #    sleep 1
Chris@320: #    if [ -n "$done_spectrogram_bits" ]; then
Chris@320: #	sv-command setcurrent 2
Chris@320: #	sv-command delete pane
Chris@320: #    fi
Chris@320: #    sv-command zoom default
Chris@320: #    sv-command zoom in
Chris@320: #    sv-command zoom in
Chris@320: #    sv-command zoom in
Chris@320:     sv-command zoom 192
Chris@320:     sv-command zoom in
Chris@320:     sv-command add timeruler
Chris@320:     sv-command jump 0
Chris@320:     sv-command transform $df
Chris@320:     sv-command set layer Colour Black
Chris@320:     sleep 5
Chris@320:     sv-command set layer Plot-Type Curve
Chris@320:     sleep 5
Chris@320:     sv-command jump 30
Chris@320:     sv-command setcurrent 1
Chris@320:     sv-command set pane Follow-Playback Page
Chris@320:     sv-command transform $df
Chris@320:     sv-command set layer Colour Red
Chris@320:     sleep 5
Chris@320:     sv-command jump 30
Chris@320:     sleep 5
Chris@320:     if [ "$RANDOM" -lt 16384 ]; then
Chris@320:         sv-command set layer Vertical-Scale "Log Scale"
Chris@320:     fi
Chris@320:     sv-command set layer Plot-Type Segmentation
Chris@320:     sleep 5 
Chris@320: #    hide_stuff
Chris@320:     sleep 10
Chris@320:     sv-command set overlays 0
Chris@320:     sv-command set propertyboxes 0
Chris@320: #    sv-command setcurrent 1 1
Chris@320: #    sv-command set layer Colour Black
Chris@320: #    sv-command setcurrent 1 2
Chris@320:     sleep 2
Chris@320:     fade_in
Chris@320:     sleep 2
Chris@320:     sv-command transform $onsets
Chris@320:     sv-command set layer Colour Black
Chris@320:     sv-command setcurrent 2
Chris@320:     sv-command transform $onsets
Chris@320:     sv-command set layer Colour Blue
Chris@320:     sleep 20
Chris@320: #    sv-command setcurrent 2
Chris@320: #    sv-command transform vamp:qm-vamp-plugins:qm-tempotracker:beats
Chris@320: #    sv-command transform $beats
Chris@320:     sleep 20
Chris@320: #    fade_out
Chris@320: #    show_stuff
Chris@320: }
Chris@320: 
Chris@320: selection_bits()
Chris@320: {
Chris@320: #    reset
Chris@320:     sv-command set overlays 1
Chris@320:     sv-command set zoomwheels 0
Chris@320:     sv-command resize 1000 500
Chris@320:     sv-command zoom default
Chris@320:     sv-command setcurrent 2
Chris@320:     sv-command delete pane
Chris@320: #    if [ -n "$done_playback_bits" ]; then
Chris@320: 	sv-command setcurrent 1 2
Chris@320: #    else
Chris@320: #	sv-command setcurrent 1 3
Chris@320: #    fi
Chris@320:     sv-command delete layer
Chris@320: #    if [ -n "$done_playback_bits" ]; then
Chris@320: 	sv-command setcurrent 1 2
Chris@320: #    else
Chris@320: #	sv-command setcurrent 1 3
Chris@320: #    fi
Chris@320:     sv-command delete layer
Chris@320:     sv-command setcurrent 1 2
Chris@320:     sv-command set layer Colour Orange
Chris@320: #    sv-command transform vamp:qm-vamp-plugins:qm-tempotracker:beats
Chris@320:     sv-command transform $beats
Chris@320: #    sv-command setcurrent 1 2
Chris@320:     sv-command set layer Colour Black
Chris@320:     sleep 20
Chris@320:     sv-command loop on
Chris@320:     base=$((RANDOM % 100))
Chris@320:     sv-command select $base $base.3
Chris@320: #    fade_in selection
Chris@320:     play selection
Chris@320:     sleep 8
Chris@320:     base=$((base + 4))
Chris@320:     sv-command addselect $base $base.1
Chris@320:     #sleep 12
Chris@320:     base=$((base + 2))
Chris@320:     sv-command addselect $base $base.1
Chris@320:     #sleep 6
Chris@320:     base=$((base + 2))
Chris@320:     sv-command addselect $base $base.3
Chris@320:     #sleep 6
Chris@320:     base=$((base + 3))
Chris@320:     sv-command addselect $base $base.3
Chris@320:     #sleep 6
Chris@320:     base=$((base + 2))
Chris@320:     sv-command addselect $base $base.3
Chris@320:     sleep 4
Chris@320:     sv-command delete layer
Chris@320:     sleep 16
Chris@320:     sv-command set speedup -50
Chris@320:     sleep 14
Chris@320:     sv-command set speedup 50
Chris@320:     sleep 8
Chris@320:     sv-command set speedup 100
Chris@320:     sleep 5
Chris@320:     sv-command set speedup 200
Chris@320:     fade_out
Chris@320: #    sleep 10
Chris@320:     sv-command select none
Chris@320:     sv-command set overlays 2
Chris@320:     sv-command set propertyboxes 1
Chris@320: #    sv-command setcurrent 1 3
Chris@320: #    sv-command delete layer
Chris@320:     sv-command setcurrent 1 2
Chris@320:     sv-command set layer Colour Black
Chris@320: }
Chris@320: 
Chris@320: chromagram_bits()
Chris@320: {
Chris@320: #    add_melodic_range_spectrogram
Chris@320: #    sleep 10
Chris@320:     sv-command add timeruler
Chris@320:     sleep 5
Chris@320:     sv-command jump 10
Chris@320:     sv-command zoom out
Chris@320:     sleep 5
Chris@320:     sv-command transform $chromagram
Chris@320:     sleep 40
Chris@320:     sv-command zoom out
Chris@320:     fade_in
Chris@320:     sleep 20
Chris@320:     fade_out
Chris@320: }
Chris@320: 
Chris@320: while /bin/true; do
Chris@320: 
Chris@320: sleep 2
Chris@320: load_a_file
Chris@320: sv-command loop on
Chris@320: 
Chris@320: sv-command resize 1000 500
Chris@320: show_stuff
Chris@320: sleep 5
Chris@320: sleep 20
Chris@320: playback_bits
Chris@320: 
Chris@320: #sleep 10
Chris@320: sv-command resize 1000 700
Chris@320: sv-command zoom default
Chris@320: show_stuff
Chris@320: onset_bits
Chris@320: 
Chris@320: selection_bits
Chris@320: 
Chris@320: #sv-command resize 1000 700
Chris@320: 
Chris@320: #sleep 10
Chris@320: sv-command resize 1000 700
Chris@320: #show_stuff
Chris@320: spectrogram_bits
Chris@320: 
Chris@320: #sleep 10
Chris@320: #sv-command jump 0
Chris@320: #show_stuff
Chris@320: #chromagram_bits
Chris@320: 
Chris@320: sleep 20
Chris@320: 
Chris@320: #reset
Chris@320: killall -9 sonic-visualiser
Chris@320: 
Chris@320: done