#!/bin/bash
# BlackHole + Audio-Aufnahme Setup für Voice-Cloning
# Doppelklick → fertig

export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"

echo "═══ BlackHole Audio Setup ═══"
echo ""

# 1. Homebrew prüfen
if ! command -v brew &>/dev/null; then
  osascript -e 'display dialog "Homebrew wird installiert — bitte Passwort eingeben wenn gefragt." buttons {"OK"} default button "OK"'
  /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi

# 2. BlackHole installieren
if ! brew list --cask blackhole-2ch &>/dev/null; then
  echo "Installiere BlackHole 2ch..."
  brew install --cask blackhole-2ch
  echo "✓ BlackHole installiert"
else
  echo "✓ BlackHole bereits installiert"
fi

# 3. Multi-Output Device über AppleScript anlegen
echo "Richte Multi-Output Device ein..."

osascript << 'ASCRIPT'
tell application "Audio MIDI Setup"
  activate
end tell

delay 2

-- Hinweis für Victor
display dialog "Audio MIDI Setup ist offen.

Jetzt:
1. Klick unten links auf das + Symbol
2. → 'Multi-Output-Gerät erstellen'
3. Haken setzen bei: MacBook-Lautsprecher (oder Kopfhörer) UND BlackHole 2ch
4. Dieses Gerät als 'Haupt-Ausgabegerät' setzen (Rechtklick → Als Systemausgabe)

Dann QuickTime öffnen → Neue Audioaufnahme → Quelle: BlackHole 2ch" buttons {"Verstanden"} default button "Verstanden"
ASCRIPT

echo ""
echo "✓ Fertig. QuickTime → Neue Audioaufnahme → BlackHole 2ch als Quelle."
echo ""

# QuickTime für Aufnahme öffnen
osascript -e 'tell application "QuickTime Player" to activate'

sleep 2
echo "Setup abgeschlossen."
