diff --git a/.gemini/skills/strudel_fix_and_explain.md b/.gemini/skills/strudel_fix_and_explain.md new file mode 100644 index 0000000..7c7ab01 --- /dev/null +++ b/.gemini/skills/strudel_fix_and_explain.md @@ -0,0 +1,26 @@ +# Skill: Strudel Fixer & Explainer + +## Persona +You are an expert Strudel debugger and musicologist. Your goal is to ensure code runs perfectly while providing deep insight into the musical genre and structure. + +## Task +Analyze the input Strudel code and perform the following: +1. **Syntax Correction**: + - Fix obvious errors (e.g., replace `~` with `-`). + - Ensure `setcps()` is present at the start. + - Ensure tracks use the `$: ` notation. +2. **Genre & Intent Inference**: Based on the patterns, samples, and effects, identify the musical genre (e.g., Minimal Techno, Lo-fi Hip Hop, Glitch). +3. **Explanation**: Provide a brief summary of what the code does and add inline comments to the fixed code. +4. **Suggested Filename**: A descriptive name based on the inferred genre. + +## Constraints +- Do NOT fundamentally change the musical idea (unlike the Refactor skill). +- Focus on making the existing code "correct" and "documented". +- Refer to the provided documentation for valid function names. + +## Output Format +The first line of your response MUST be in the format: `FILENAME: .md`. +Followed by: +- **Genre**: [Inferred Genre] +- **Description**: [Brief explanation in Japanese] +- **Fixed Code**: [The corrected code block with Japanese comments] \ No newline at end of file diff --git a/.gemini/skills/strudel_refactor.md b/.gemini/skills/strudel_refactor.md new file mode 100644 index 0000000..72bd44c --- /dev/null +++ b/.gemini/skills/strudel_refactor.md @@ -0,0 +1,22 @@ +# Skill: Strudel Refactorer + +## Persona +You are a world-class Strudel composer and live-coding expert. You have deep knowledge of algorithmic music composition. + +## Context +Refer to the provided documentation on: +- **Samples**: Default banks, custom loading, and sampler effects (begin, chop, slice). +- **Synths**: Basic waveforms, FM synthesis, and Wavetables. +- **Effects**: Filters (lpf, hpf), Envelopes (adsr, lpenv, penv), and Global FX (delay, room). +- **Probability**: Randomness functions (choose, degrade, sometimes). + +## Task +Analyze the input Strudel code and provide a refactored version in Markdown format: +1. **Analysis**: Explain the musical structure and technical implementation. +2. **Commented Code**: Provide the original code with detailed inline comments for each function. +3. **Refactored Version**: An improved, more idiomatic, or musically interesting version using advanced Strudel features. +4. **Suggested Filename**: A short, descriptive filename in kebab-case (e.g., `ambient-techno-poly.md`). + +## Output Format +The first line of your response MUST be in the format: `FILENAME: .md`. +Followed by the rest of the analysis in Markdown. \ No newline at end of file diff --git a/.gemini/strudel_fix_and_explain.md b/.gemini/strudel_fix_and_explain.md new file mode 100644 index 0000000..7c7ab01 --- /dev/null +++ b/.gemini/strudel_fix_and_explain.md @@ -0,0 +1,26 @@ +# Skill: Strudel Fixer & Explainer + +## Persona +You are an expert Strudel debugger and musicologist. Your goal is to ensure code runs perfectly while providing deep insight into the musical genre and structure. + +## Task +Analyze the input Strudel code and perform the following: +1. **Syntax Correction**: + - Fix obvious errors (e.g., replace `~` with `-`). + - Ensure `setcps()` is present at the start. + - Ensure tracks use the `$: ` notation. +2. **Genre & Intent Inference**: Based on the patterns, samples, and effects, identify the musical genre (e.g., Minimal Techno, Lo-fi Hip Hop, Glitch). +3. **Explanation**: Provide a brief summary of what the code does and add inline comments to the fixed code. +4. **Suggested Filename**: A descriptive name based on the inferred genre. + +## Constraints +- Do NOT fundamentally change the musical idea (unlike the Refactor skill). +- Focus on making the existing code "correct" and "documented". +- Refer to the provided documentation for valid function names. + +## Output Format +The first line of your response MUST be in the format: `FILENAME: .md`. +Followed by: +- **Genre**: [Inferred Genre] +- **Description**: [Brief explanation in Japanese] +- **Fixed Code**: [The corrected code block with Japanese comments] \ No newline at end of file diff --git a/organize_strudel.sh b/organize_strudel.sh deleted file mode 100644 index e69de29..0000000 diff --git a/script/fix_and_explain_strudel.sh b/script/fix_and_explain_strudel.sh new file mode 100644 index 0000000..fdbc502 --- /dev/null +++ b/script/fix_and_explain_strudel.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# スクリプトの場所 (scripts/) からプロジェクトルート (notebook/) を動的に取得 +BASE_DIR=$(cd "$(dirname "$0")/.." && pwd) +OUTPUT_DIR="$BASE_DIR/explained" +SKILL_FILE="$BASE_DIR/.gemini/skills/strudel_fix_and_explain.md" + +# 出力先フォルダの作成 +mkdir -p "$OUTPUT_DIR" + +# 引数がある場合はそれを使用し、ない場合は strudel/ フォルダの全mdファイルを対象にする +if [ $# -gt 0 ]; then + files=("$@") +else + files=("$BASE_DIR/strudel"/*.md) +fi + +echo "Strudel Fix & Explain Skill started..." + +for file in "${files[@]}"; do + # 除外設定 + [[ "$file" == *"Strudel Making Sound.md"* ]] && continue + [[ "$file" == *"Strudel Study.md"* ]] && continue + [[ "$file" == *"/refactoring/"* ]] && continue + [[ "$file" == *"/explained/"* ]] && continue + [[ "$file" == *"/script/"* ]] && continue + [ -f "$file" ] || continue + + filename=$(basename "$file") + echo "Analyzing and fixing $filename..." + + # 一時ファイルに出力 + tmp_file="$OUTPUT_DIR/tmp_$filename" + cat "$file" | gemini-cli --system "$(cat "$SKILL_FILE")" > "$tmp_file" + + if [ $? -eq 0 ]; then + # 1行目から提案されたファイル名を抽出 + suggested_name=$(head -n 1 "$tmp_file" | grep "FILENAME:" | sed 's/FILENAME: //g' | tr -d '\r') + + if [ -n "$suggested_name" ]; then + # 1行目を除去して保存 + tail -n +2 "$tmp_file" > "$OUTPUT_DIR/$suggested_name" + rm "$tmp_file" + echo "Done: $OUTPUT_DIR/$suggested_name" + else + mv "$tmp_file" "$OUTPUT_DIR/$filename" + echo "Done: $filename (No rename)" + fi + else + rm -f "$tmp_file" + echo "Error processing $filename" + fi +done \ No newline at end of file diff --git a/script/organize_strudel.sh b/script/organize_strudel.sh new file mode 100644 index 0000000..288096b --- /dev/null +++ b/script/organize_strudel.sh @@ -0,0 +1,39 @@ +#!/bin/bash + +# スクリプトの場所 (scripts/) からプロジェクトルートを動的に取得 +ROOT_DIR=$(cd "$(dirname "$0")/.." && pwd) +BASE_DIR="$ROOT_DIR/organized_strudel" +SOURCE_DIR="$ROOT_DIR/strudel" + +mkdir -p "$BASE_DIR" + +echo "Starting Strudel code categorization..." + +for file in "$SOURCE_DIR"/*.md; do + # ドキュメントファイル自体は除外 + [[ "$file" == *"Strudel Making Sound.md"* ]] && continue + [[ "$file" == *"Strudel Study.md"* ]] && continue + [[ "$file" == *"/script/"* ]] && continue + [ -e "$file" ] || continue + + filename=$(basename "$file") + echo "Analyzing $filename..." + + # gemini-cli を使用してカテゴリを判定 + category=$(cat "$file" | gemini-cli "Analyze this Strudel code. + Based on functions like s(), note(), fm(), degrade(), or effects like lpf(), + classify this into exactly one of these categories: + 'Sampling', 'Synthesis', 'Generative', 'Ambient_FX'. + Return only the category name as a single word.") + + # カテゴリが取得できなかった場合のデフォルト + if [ -z "$category" ]; then + category="Unclassified" + fi + + target_path="$BASE_DIR/$category" + mkdir -p "$target_path" + + cp "$file" "$target_path/" + echo "-> Moved to $category/" +done \ No newline at end of file diff --git a/script/refactor_strudel.sh b/script/refactor_strudel.sh new file mode 100644 index 0000000..f5c39cd --- /dev/null +++ b/script/refactor_strudel.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +# スクリプトの場所 (scripts/) からプロジェクトルート (notebook/) を動的に取得 +BASE_DIR=$(cd "$(dirname "$0")/.." && pwd) +REFACTOR_DIR="$BASE_DIR/refactoring" +SKILL_FILE="$BASE_DIR/.gemini/skills/strudel_refactor.md" + +# 出力先フォルダの作成 +mkdir -p "$REFACTOR_DIR" + +# 引数がある場合はそれを使用し、ない場合は strudel/ フォルダの全mdファイルを対象にする +if [ $# -gt 0 ]; then + files=("$@") +else + files=("$BASE_DIR/strudel"/*.md) +fi + +echo "Strudel Code Analysis & Refactoring Skill started..." + +for file in "${files[@]}"; do + # 除外設定 + [[ "$file" == *"Strudel Making Sound.md"* ]] && continue + [[ "$file" == *"Strudel Study.md"* ]] && continue + [[ "$file" == *"/refactoring/"* ]] && continue + [[ "$file" == *"/scripts/"* ]] && continue + [ -f "$file" ] || continue + + filename=$(basename "$file") + echo "Processing $filename..." + + # スキルファイルをシステムプロンプトとして使用 + tmp_file="$REFACTOR_DIR/tmp_$filename" + cat "$file" | gemini-cli --system "$(cat "$SKILL_FILE")" > "$tmp_file" + + if [ $? -eq 0 ]; then + # 1行目から提案されたファイル名を抽出 + suggested_name=$(head -n 1 "$tmp_file" | grep "FILENAME:" | sed 's/FILENAME: //g' | tr -d '\r') + + if [ -n "$suggested_name" ]; then + # 1行目(FILENAME行)を除去してリネーム保存 + tail -n +2 "$tmp_file" > "$REFACTOR_DIR/$suggested_name" + rm "$tmp_file" + echo "Successfully refactored and renamed to: $suggested_name" + else + mv "$tmp_file" "$REFACTOR_DIR/$filename" + echo "Successfully refactored: $filename (Rename tag not found)" + fi + else + rm -f "$tmp_file" + echo "Error processing $filename" + fi +done \ No newline at end of file