mirror of
https://github.com/kuhyx/testsAndMisc-archive.git
synced 2026-07-04 13:43:02 +02:00
chore: hello world sonic pi track
This commit is contained in:
parent
6cc5d71482
commit
6e988cbe09
67
sonic_pi/chill_track.rb
Normal file
67
sonic_pi/chill_track.rb
Normal file
@ -0,0 +1,67 @@
|
||||
# Simple Chill Groove for Sonic Pi
|
||||
# Paste/run directly in Sonic Pi or use run.sh in this folder to auto-play.
|
||||
|
||||
use_bpm 96
|
||||
use_random_seed 1234
|
||||
|
||||
# Chord progression: Am – F – C – G
|
||||
prog = (ring chord(:a3, :minor), chord(:f3, :major), chord(:c4, :major), chord(:g3, :major))
|
||||
|
||||
# Master bar clock + shared progression
|
||||
live_loop :bar do
|
||||
cue :bar
|
||||
sleep 4
|
||||
end
|
||||
|
||||
live_loop :progression do
|
||||
sync :bar
|
||||
set :chord, prog.tick
|
||||
end
|
||||
|
||||
# DRUMS
|
||||
live_loop :kick do
|
||||
sample :bd_haus, amp: 2
|
||||
sleep 1
|
||||
end
|
||||
|
||||
live_loop :snare do
|
||||
sleep 1
|
||||
sample :sn_dolf, amp: 1.2
|
||||
sleep 1
|
||||
end
|
||||
|
||||
live_loop :hats do
|
||||
sample :drum_cymbal_closed, amp: 0.6, cutoff: 120
|
||||
sleep 0.5
|
||||
end
|
||||
|
||||
# MUSIC
|
||||
with_fx :reverb, room: 0.7, mix: 0.35 do
|
||||
live_loop :bass do
|
||||
sync :bar
|
||||
c = get(:chord)
|
||||
use_synth :tb303
|
||||
r = c.first - 12
|
||||
8.times do
|
||||
play r, release: 0.12, cutoff: rrand(90, 130), res: 0.9, wave: 0, amp: 0.9
|
||||
sleep 0.5
|
||||
end
|
||||
end
|
||||
|
||||
live_loop :pads do
|
||||
sync :bar
|
||||
c = get(:chord)
|
||||
use_synth :prophet
|
||||
play c, sustain: 3.5, release: 0.5, cutoff: 100, amp: 0.5
|
||||
end
|
||||
|
||||
live_loop :melody do
|
||||
sync :bar
|
||||
use_synth :pluck
|
||||
s = scale(:a4, :minor_pentatonic)
|
||||
8.times do
|
||||
play choose(s), amp: 0.5, release: 0.15, pan: rrand(-0.35, 0.35)
|
||||
sleep 0.5
|
||||
end
|
||||
end
|
||||
end
|
||||
132
sonic_pi/run.sh
Executable file
132
sonic_pi/run.sh
Executable file
@ -0,0 +1,132 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Headless Sonic Pi playback on Arch Linux only.
|
||||
# - Installs Sonic Pi from AUR (sonic-pi.git) if missing
|
||||
# - Starts the Sonic Pi server headlessly and evaluates the given .rb file
|
||||
# - Optional: --duration N to auto-stop after N seconds
|
||||
|
||||
PATH="$HOME/.local/bin:$PATH"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
TRACK_FILE="$SCRIPT_DIR/chill_track.rb"
|
||||
DURATION=""
|
||||
|
||||
require_cmd() {
|
||||
command -v "$1" >/dev/null 2>&1
|
||||
}
|
||||
|
||||
install_arch_from_aur_git() {
|
||||
# Build and install from AUR git repo directly (sonic-pi.git)
|
||||
local AUR_URL="https://aur.archlinux.org/sonic-pi.git"
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo "Do not run the AUR build as root. Re-run this script as a regular user." >&2
|
||||
return 1
|
||||
fi
|
||||
echo "Preparing to build Sonic Pi from AUR..."
|
||||
# Common build deps that often are needed
|
||||
sudo pacman -S --needed --noconfirm base-devel git cmake boost boost-libs qt6-base qt6-svg qt6-declarative qt6-tools ruby || true
|
||||
local TMPDIR
|
||||
TMPDIR=$(mktemp -d -t sonicpi-aur-XXXXXX)
|
||||
echo "Using temp dir: $TMPDIR"
|
||||
(
|
||||
set -e
|
||||
cd "$TMPDIR"
|
||||
repo_name=$(basename "$AUR_URL" .git)
|
||||
echo "Cloning $AUR_URL"
|
||||
git clone "$AUR_URL"
|
||||
cd "$repo_name"
|
||||
makepkg -si --noconfirm
|
||||
)
|
||||
}
|
||||
|
||||
install_sonic_pi() {
|
||||
echo "Installing Sonic Pi (if missing)..."
|
||||
if require_cmd pacman; then
|
||||
if require_cmd sonic-pi; then
|
||||
echo "Sonic Pi is already installed."
|
||||
return 0
|
||||
fi
|
||||
install_arch_from_aur_git
|
||||
if ! require_cmd sonic-pi; then
|
||||
echo "Sonic Pi installation failed via AUR." >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "This installer only supports Arch Linux (pacman)." >&2
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# No sonic-pi-tool or pip logic; headless playback uses the built-in REPL only.
|
||||
|
||||
find_repl() {
|
||||
REPL_BIN=""
|
||||
if [ -x "/opt/sonic-pi/bin/sonic-pi-repl.sh" ]; then
|
||||
REPL_BIN="/opt/sonic-pi/bin/sonic-pi-repl.sh"
|
||||
elif require_cmd sonic-pi-repl.sh; then
|
||||
REPL_BIN="$(command -v sonic-pi-repl.sh)"
|
||||
fi
|
||||
}
|
||||
|
||||
# Start Sonic Pi headlessly using the built-in REPL only
|
||||
headless_play() {
|
||||
find_repl
|
||||
if [ -n "$REPL_BIN" ]; then
|
||||
echo "Starting Sonic Pi REPL with track: $TRACK_FILE"
|
||||
if [ -n "$DURATION" ]; then
|
||||
"$REPL_BIN" "$TRACK_FILE" &
|
||||
REPL_PID=$!
|
||||
echo "REPL PID $REPL_PID; playing for $DURATION seconds..."
|
||||
sleep "$DURATION" || true
|
||||
echo "Stopping (TERM REPL to trigger graceful daemon exit)..."
|
||||
kill -TERM "$REPL_PID" || true
|
||||
wait "$REPL_PID" || true
|
||||
else
|
||||
exec "$REPL_BIN" "$TRACK_FILE"
|
||||
fi
|
||||
return 0
|
||||
fi
|
||||
|
||||
echo "REPL script not found. Ensure Sonic Pi is installed from AUR (sonic-pi.git)." >&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Usage: $(basename "$0") [--file path/to/track.rb] [--duration SECONDS]
|
||||
|
||||
Defaults:
|
||||
--file $TRACK_FILE
|
||||
--duration run until Ctrl+C
|
||||
(headless only)
|
||||
EOF
|
||||
}
|
||||
|
||||
parse_args() {
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
-f|--file)
|
||||
TRACK_FILE="$2"; shift 2 ;;
|
||||
-d|--duration)
|
||||
DURATION="$2"; shift 2 ;;
|
||||
-h|--help)
|
||||
usage; exit 0 ;;
|
||||
*)
|
||||
echo "Unknown argument: $1" >&2; usage; exit 1 ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
|
||||
main() {
|
||||
parse_args "$@"
|
||||
if [ ! -f "$TRACK_FILE" ]; then
|
||||
echo "Track file not found: $TRACK_FILE" >&2
|
||||
exit 1
|
||||
fi
|
||||
install_sonic_pi
|
||||
headless_play
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Loading…
Reference in New Issue
Block a user