#!/bin/bash
# Run a single effect by number (0-42)
# Usage: ./run-effect.sh <effect-number>
#
# Note: For effects with simple numeric params, you can also use native params:
#   python3 plan.py recipe-parametric.sexp -p strength=5 -p amount=30 | python3 execute.py - -d . -o output.mp4

EFFECT_NUM=${1:-0}

# Effect definitions array
EFFECTS=(
  "(effect invert)"
  "(effect grayscale)"
  "(effect sepia)"
  "(effect brightness :amount 30)"
  "(effect contrast :amount 1.5)"
  "(effect saturation :amount 2.0)"
  "(effect hue_shift :degrees 90)"
  "(effect color_cycle :speed 2)"
  "(effect threshold :level 128)"
  "(effect posterize :levels 6)"
  "(effect blur :radius 10)"
  "(effect sharpen :amount 2)"
  "(effect bloom :intensity 0.6 :radius 20)"
  "(effect color-adjust :brightness 20 :contrast 1.2)"
  "(effect swirl :strength 3)"
  "(effect fisheye :strength 0.5)"
  "(effect wave :amplitude 30 :wavelength 60)"
  "(effect ripple :amplitude 20 :frequency 6)"
  "(effect kaleidoscope :segments 6 :rotation_speed 30)"
  "(effect zoom :factor 1.2)"
  "(effect rotate :angle 15)"
  "(effect mirror :direction \"horizontal\")"
  "(effect pixelate :block_size 16)"
  "(effect ascii_art :char_size 8 :color_mode \"color\")"
  "(effect ascii_zones :char_size 10)"
  "(effect edge_detect :low 50 :high 150)"
  "(effect emboss :strength 1.5)"
  "(effect outline :thickness 2)"
  "(effect neon_glow :glow_radius 20 :glow_intensity 2)"
  "(effect crt :line_spacing 3 :vignette_amount 0.3)"
  "(effect scanlines :spacing 3 :intensity 0.4)"
  "(effect film_grain :intensity 0.25)"
  "(effect vignette :strength 0.6)"
  "(effect noise :amount 40)"
  "(effect rgb_split :offset_x 20)"
  "(effect echo :num_echoes 4 :decay 0.5)"
  "(effect trails :persistence 0.7)"
  "(effect strobe :frequency 4)"
  "(effect flip :direction \"horizontal\")"
  "(effect tile_grid :rows 2 :cols 2)"
  "(effect pixelsort :threshold_low 30 :threshold_high 220)"
  "(effect datamosh :corruption 0.5 :block_size 24)"
)

if [ "$EFFECT_NUM" -lt 0 ] || [ "$EFFECT_NUM" -ge ${#EFFECTS[@]} ]; then
  echo "Effect number must be 0-$((${#EFFECTS[@]}-1))"
  exit 1
fi

EFFECT="${EFFECTS[$EFFECT_NUM]}"
echo "Running effect $EFFECT_NUM: $EFFECT"

# Create temp recipe with selected effect
cat > /tmp/recipe-temp.sexp << EOF
(recipe "effect-test"
  :version "1.0"
  :encoding (:codec "libx264" :crf 20 :preset "medium" :audio-codec "aac" :fps 30)

  (effect ascii_art :path "sexp_effects/effects/ascii_art.sexp")
  (effect ascii_zones :path "sexp_effects/effects/ascii_zones.sexp")
  (effect bloom :path "sexp_effects/effects/bloom.sexp")
  (effect blur :path "sexp_effects/effects/blur.sexp")
  (effect brightness :path "sexp_effects/effects/brightness.sexp")
  (effect color-adjust :path "sexp_effects/effects/color-adjust.sexp")
  (effect color_cycle :path "sexp_effects/effects/color_cycle.sexp")
  (effect contrast :path "sexp_effects/effects/contrast.sexp")
  (effect crt :path "sexp_effects/effects/crt.sexp")
  (effect datamosh :path "sexp_effects/effects/datamosh.sexp")
  (effect echo :path "sexp_effects/effects/echo.sexp")
  (effect edge_detect :path "sexp_effects/effects/edge_detect.sexp")
  (effect emboss :path "sexp_effects/effects/emboss.sexp")
  (effect film_grain :path "sexp_effects/effects/film_grain.sexp")
  (effect fisheye :path "sexp_effects/effects/fisheye.sexp")
  (effect flip :path "sexp_effects/effects/flip.sexp")
  (effect grayscale :path "sexp_effects/effects/grayscale.sexp")
  (effect hue_shift :path "sexp_effects/effects/hue_shift.sexp")
  (effect invert :path "sexp_effects/effects/invert.sexp")
  (effect kaleidoscope :path "sexp_effects/effects/kaleidoscope.sexp")
  (effect mirror :path "sexp_effects/effects/mirror.sexp")
  (effect neon_glow :path "sexp_effects/effects/neon_glow.sexp")
  (effect noise :path "sexp_effects/effects/noise.sexp")
  (effect outline :path "sexp_effects/effects/outline.sexp")
  (effect pixelate :path "sexp_effects/effects/pixelate.sexp")
  (effect pixelsort :path "sexp_effects/effects/pixelsort.sexp")
  (effect posterize :path "sexp_effects/effects/posterize.sexp")
  (effect rgb_split :path "sexp_effects/effects/rgb_split.sexp")
  (effect ripple :path "sexp_effects/effects/ripple.sexp")
  (effect rotate :path "sexp_effects/effects/rotate.sexp")
  (effect saturation :path "sexp_effects/effects/saturation.sexp")
  (effect scanlines :path "sexp_effects/effects/scanlines.sexp")
  (effect sepia :path "sexp_effects/effects/sepia.sexp")
  (effect sharpen :path "sexp_effects/effects/sharpen.sexp")
  (effect strobe :path "sexp_effects/effects/strobe.sexp")
  (effect swirl :path "sexp_effects/effects/swirl.sexp")
  (effect threshold :path "sexp_effects/effects/threshold.sexp")
  (effect tile_grid :path "sexp_effects/effects/tile_grid.sexp")
  (effect trails :path "sexp_effects/effects/trails.sexp")
  (effect vignette :path "sexp_effects/effects/vignette.sexp")
  (effect wave :path "sexp_effects/effects/wave.sexp")
  (effect zoom :path "sexp_effects/effects/zoom.sexp")

  (def video (source :path "monday.webm"))
  (def audio (source :path "dizzy.mp3"))
  (def clip (-> video (segment :start 0 :duration 10)))
  (def audio-clip (-> audio (segment :start 0 :duration 10)))
  (def result (-> clip $EFFECT))
  (mux result audio-clip))
EOF

python3 plan.py /tmp/recipe-temp.sexp | python3 execute.py - -d . -o "effect-${EFFECT_NUM}.mp4"
echo "Output: effect-${EFFECT_NUM}.mp4"
