setcps(0.25);

// ==================================================
// 全曲时间轴
// A → B → C → D → E1 → E2 → E3 → F1 → F2 → F3 → G_B1 → G_B2 → G_C1 → G_C2 → G_A1 → G_A2 → H
// ==================================================
// Standalone scheduler: setcps(0.25).



// “蝴蝶”主题
const butterfly = note("a5 [g5 e5] [d5 e5] [~ [g5 ~]]")

// ==================================================
// E1 定义
// ==================================================

const E1 = stack(
  // 主线

  note("e4 ~ g4 a4")
    .sound("gm_flute")
    .velocity("0.038 0.000 0.044 0.050")
    .attack(0.55)
    .sustain(0.75)
    .release(1.8)
    .lpf(1750)
    .room(0.30)
    .pan(0.50),

  // 地面：极弱的 E
  note("e3")

    .sound("gm_cello")
    .velocity(0.010)
    .attack(1.5)
    .sustain(1)
    .release(3.2)
    .lpf(700)
    .room(0.48)
    .pan(0.50),

  // D 遗留
  note("e5")
    .sound("sine")
    .velocity(0.0028)
    .attack(1.4)
    .sustain(1)
    .release(3.8)
    .lpf(850)
    .room(0.22)
    .pan(0.50)

)


// ==================================================
// E2 记忆
// ==================================================

const E2 = stack(
  // 第一次
  note("a5 [g5 e5] ~ ~")
    .sound("piano")
    .velocity("0.047 0.038 0.030")
    .attack(0.018)
    .release(1.45)
    .lpf(2100)
    .room(0.48)
    .pan(0.52),

  // 第二次
  note("~ ~ a4 g4")
    .sound("gm_flute")
    .velocity("0 0 0.020 0.014")
    .attack(0.65)
    .release(2.0)
    .lpf(1600)
    .room(0.34)
    .pan(0.50),

  // --------------------------------------------------
  // 很轻地从 A4 回落到 G4
  // --------------------------------------------------

  note("a4 ~ ~ g4")
    .sound("gm_flute")
    .velocity("0.020 0.000 0.000 0.015")
    .attack(0.65)
    .sustain(0.65)
    .release(2.0)
    .lpf(1600)
    .room(0.34)
    .pan(0.50),

  // --------------------------------------------------
  // ④ 地面仍然是 E
  // 比 E1 更弱
  // --------------------------------------------------

  note("e3")
    .sound("gm_cello")
    .velocity(0.0075)
    .attack(1.7)
    .sustain(1)
    .release(3.5)
    .lpf(620)
    .room(0.54)
    .pan(0.50),

  // --------------------------------------------------
  // ⑤ 细线
  // --------------------------------------------------

  note("e5")
    .sound("sine")
    .velocity(0.0022)
    .attack(1.5)
    .sustain(1)
    .release(4.0)
    .lpf(780)
    .room(0.24)
    .pan(0.50)

)

// ============================================================
// E3 差一点碰到
// ============================================================

const E3 = stack(
  // 主题开始变得清楚，但停在 D5
  note("a5 [g5 e5] d5 ~")
    .sound("piano")
    .velocity("0.050 0.045 0.038 0")
    .attack(0.018)
    .release(1.70)
    .lpf(1950)
    .room(0.54)
    .pan(0.50),


  // 向上伸手

  note("e3 ~ e4 a4")
    .sound("gm_cello")
    .velocity("0.008 0 0.014 0.019")
    .attack(1.15)
    .release(3.2)
    .lpf(760)
    .room(0.56)
    .pan(0.47),

  // ④ 很细的“伸出去”的线
  note("~ ~ a4 e5")
    .sound("sine")
    .velocity("0.000 0.000 0.0032 0.0020")
    .attack(0.75)
    .sustain(1)
    .release(3.8)
    .lpf(1050)
    .room(0.30)
    .pan(0.57),

  // ⑤ 最后留下 A4
 note("~ ~ ~ a4")
  .sound("gm_flute")
  .velocity("0 0 0 0.011")
  .attack(0.72)
  .sustain(0.85)
  .release(3.40)
  .lpf(1450)
  .room(0.64)
  .delay(0.16)
  .delaytime(0.21)
  .pan(0.58)

)

// ==================================================
// F-F1
// ==================================================

const F1 = stack(
  butterfly
  .zoom(0.5, 1)
  .sound("piano")
  .velocity(0.050)
  .attack(0.065)
  .release(1.55)
  .lpf(1850)
  .room(0.46)
  .pan(0.50),

  // 极少量金色碎光
note("a6 ~ ~ e7")
  .sound("gm_xylophone")
  .velocity("0.0105 0 0 0.0080")
  .attack(0.003)
  .decay(0.075)
  .sustain(0)
  .release(0.16)
  .hpf(1800)
  .room(0.48)
  .delay(0.18)
  .delaytime(0.13)
  .pan("0.30 0.70")
)


// ==================================================
// F2
// ==================================================

const F2 = stack(

  butterfly
    .sound("piano")
    .velocity("0.074 0.068 0.061 0.054")
    .attack(0.012)
    .release(1.65)
    .lpf(2200)
    .room(0.38)
    .pan(0.50),

  // 金粉主体：开始聚集
  note("~ [a6 e7] ~ [g6 e6]")
    .sound("gm_xylophone")
    .velocity("0.0115 0.0100 0.0090 0.0080")
    .attack(0.003)
    .decay(0.075)
    .sustain(0)
    .release(0.15)
    .hpf(1750)
    .room(0.42)
    .delay(0.20)
    .delaytime(0.12)
    .pan("0.68 0.34 0.61 0.42"),

  // 很轻的残光

  note("~ e7 ~ a6")
    .sound("sine")
    .velocity("0 0.0038 0 0.0032")
    .attack(0.018)
    .release(0.70)
    .hpf(2100)
    .lpf(5200)
    .room(0.68)
    .pan("0.36 0.70")

)

// ==================================================
// F3 — 失稳电子侵入
// ==================================================

const F3 = stack(

  // 同一个主题被时间拉长

  butterfly

    .slow(2)
    .sound("piano")
    .velocity("0.058 0.050 0.043 0.036")
    .attack(0.018)
    .release(1.55)
    .lpf(sine.slow(4).range(2100, 950))
    .room(0.50)
    .pan(0.48),

  // 金粉拖尾逐渐获得电子质感

 note("~ e6 [a6 e7] ~")
  .sound("sine")
  .velocity("0 0.0068 0.0052 0")
  .attack(0.055)
  .release(1.70)
  .lpf(2800)
  .room(0.62)
  .delay(0.18)
  .delaytime(0.16)
  .pan(0.61)

)


// G_final — 24 sec
// 时间轴 G_B1 → G_B2 → G_C1 → G_C2 → G_A1 → G_A2
// ============================================================
// G_B1
// ============================================================

const G_B1 = stack(
  // 碎片
  note("a5 [g5 e5] ~ ~")
    .sound("sine")
    .velocity("0.025 0.020 0 0.016")
    .attack(0.060)
    .release(1.55)
    .lpf(2850)
    .room(0.70)
    .delay(0.20)
    .delaytime(0.21)
    .pan("0.34 0.66 0.46 0.58")
    .orbit(2),

  // 自由漂浮

  note("[e6 ~] [~ a6] [g6 ~] [~ e7]")
    .sound("triangle")
    .velocity("0.011 0.014 0.010 0.013")
    .attack(0.004)
    .decay(0.08)
    .sustain(0)
    .release(0.60)
    .hpf(1750)
    .lpf(5000)
    .room(0.80)
    .delay(0.34)
    .delaytime(0.14)
    .pan(perlin.slow(3).range(0.18,0.82))
    .degradeBy(0.32)
    .orbit(2),

  // 第一次引力
  note("~ e2 ~ ~")
    .sound("sine")
    .velocity("0 0.060 0 0")
    .attack(0.035)
    .decay(0.46)
    .sustain(0)
    .release(0.70)
    .lpf(138)
    .room(0.13)
    .orbit(1)
    .duckorbit(2)
    .duckdepth(0.16)
    .duckattack(0.48)

)


// ============================================================
// G_B2
// ============================================================

const G_B2 = stack(

  note("~ [g5 e5] ~ g5")
    .sound("sine")
    .velocity("0.027 0.022 0 0.018")
    .attack(0.052)
    .release(1.45)
    .lpf(3000)
    .room(0.67)
    .delay(0.21)
    .delaytime(0.19)
    .pan("0.62 0.36 0.55 0.45")
    .orbit(2),

  // 稍微开始聚拢

  note("~ [e6 a6] [~ g6] [e7 ~]")
    .sound("triangle")
    .velocity("0 0.015 0.012 0.013")
    .attack(0.004)
    .decay(0.085)
    .sustain(0)
    .release(0.58)
    .hpf(1750)
    .lpf(5300)
    .room(0.77)
    .delay(0.32)
    .delaytime(0.13)
    .pan(perlin.slow(3).range(0.20,0.80))
    .degradeBy(0.24)
    .orbit(2),

  // 两个不完全对称的引力点

  note("~ e2 ~ [~ e2]")
    .sound("sine")
    .velocity("0 0.066 0 0.076")
    .attack(0.030)
    .decay(0.42)
    .sustain(0)
    .release(0.64)
    .lpf(148)
    .room(0.12)
    .orbit(1)
    .duckorbit(2)
    .duckdepth(0.21)
    .duckattack(0.44),

  // 开始察觉到回应，但还无法确认

  note("~ ~ ~ e6")

    .sound("triangle")
    .velocity("0 0 0 .0055")
    .attack(0.006)
    .decay(0.07)
    .sustain(0)
    .release(0.38)
    .hpf(1800)
    .lpf(3200)
    .room(0.72)
    .delay(0.22)
    .delaytime(0.19)
    .pan(0.67)
    .orbit(2)

)


// ============================================================
// G_C1
// ============================================================

const G_C1 = stack(

  // A：蝴蝶线

  note("a5 ~ [d5 e5] ~")

    .sound("sine")
    .velocity("0.029 0.024 0.020 0")
    .attack(0.045)
    .release(1.30)
    .lpf(3150)
    .room(0.62)
    .delay(0.20)
    .delaytime(0.17)
    .pan("0.30 0.42 0.38 0.48")
    .orbit(2),

  // B：回应线
  // 比蝴蝶低一些、稳定一些

  note("~ e4 [~ b4] [g4 a4]")

    .sound("triangle")
    .velocity("0 0.013 0.011 0.015")
    .attack(0.085)
    .release(1.40)
    .lpf(1900)
    .room(0.56)
    .delay(0.16)
    .delaytime(0.22)
    .pan("0.68 0.60 0.72 0.55")
    .orbit(2),

  // 两条线碰到以后出现的微光

  note("~ [e6 ~] [~ g6] [a6 ~]")

  .sound("sine")
  .velocity("0 0.011 0.013 0.014")
  .attack(0.004)
  .decay(0.09)
  .sustain(0)
  .release(0.68)
  .hpf(1900)
  .lpf(5600)
  .room(0.80)
  .pan(perlin.slow(2).range(0.22, 0.78))
  .degradeBy(0.20)
  .orbit(2),

  // 心跳开始成形

  note("e2 ~ [~ e2] ~")
    .sound("sine")
    .velocity("0.080 0 0.070 0")
    .attack(0.026)
    .decay(0.38)
    .sustain(0)
    .release(0.60)
    .lpf(158)
    .room(0.11)
    .orbit(1)
    .duckorbit(2)
    .duckdepth(0.26)
    .duckattack(0.40)

)

// ============================================================
// G_C2 | 12–16s
// ============================================================

const G_C2 = stack(

  // 蝴蝶线

  note("~ [g5 e5] [d5 ~] ~")

    .sound("sine")
    .velocity("0.031 0.026 0.022 0.020")
    .attack(0.040)
    .release(1.18)
    .lpf(3300)
    .room(0.58)
    .delay(0.18)
    .delaytime(0.16)
    .pan("0.34 0.56 0.42 0.61")
    .orbit(2),

  // 回应线

  note("~ e4 [g4 b4] [a4 e5]")
    .sound("triangle")
    .velocity("0 0.016 0.015 0.018")
    .attack(0.065)
    .release(1.25)
    .lpf(2150)
    .room(0.51)
    .delay(0.15)
    .delaytime(0.20)
    .pan("0.66 0.54 0.70 0.48")
    .orbit(2),

  // 脉搏组织

  note("[~ e6] [a6 ~] [~ g6] [e7 a6]")

    .sound("sine")
    .velocity("0.008 0.014 0.012 0.016")
    .attack(0.003)
    .decay(0.085)
    .sustain(0)
    .release(0.62)
    .hpf(1900)
    .lpf(6000)
    .room(0.75)
    .pan(perlin.slow(2).range(0.20,0.80))
  .degradeBy(0.15)
    .orbit(2),

  // C2：离开 E

note("e2 ~ b1 [~ d2]")

  .sound("sine")
  .velocity("0.090 0 0.072 0.064")
    .attack(0.022)
    .decay(0.34)
    .sustain(0)
    .release(0.55)
    .lpf(172)
    .room(0.10)
    .orbit(1)
    .duckorbit(2)
    .duckdepth(0.31)
    .duckattack(0.36),

  // 从这里开始，重音不只是 bass

  note("~ b2 ~ d3")
  .sound("triangle")
  .velocity("0 0.013 0 0.016")
  .attack(0.008)
.decay(0.080)
.sustain(0)
.release(0.18)
.hpf(220)
.lpf(850)
.room(0.15)

)

// ============================================================
// G_A1 | 16–20s
// 共同脉搏。
// ============================================================

const G_A1 = stack(

  // 蝴蝶

  note("a5 [g5 e5] [d5 e5] ~")

    .sound("sine")
    .velocity("0.032 0.027 0.023 0.022")
    .attack(0.036)
    .release(1.05)
    .lpf(3450)
    .room(0.54)
    .delay(0.17)
    .delaytime(0.15)
    .pan("0.40 0.58 0.46 0.55")
    .orbit(2),

  // 回应线

  note("e4 [~ g4] [b4 e5] [~ a4]")

    .sound("triangle")
    .velocity("0.015 0.014 0.019 0.014")
    .attack(0.055)
    .release(1.10)
    .lpf(2300)
    .room(0.47)
    .pan("0.60 0.46 0.63 0.48")
    .orbit(2),

  // 高频不再独立演奏“小高音旋律”

  note("~ [e6 a6] ~ [g6 e7]")

    .sound("sine")
    .velocity("0 0.016 0 0.018")
    .attack(0.003)
    .decay(0.075)
    .sustain(0)
    .release(0.70)
    .hpf(2000)
    .lpf(6300)
    .room(0.72)
    .delay(0.26)
    .delaytime(0.12)
    .pan(perlin.slow(2).range(0.18,0.82))
  .degradeBy(0.10)
    .orbit(2),

  // 更明确

  note("e2 ~ e2 ~")

    .sound("sine")
    .velocity("0.103 0 0.088 0")
    .attack(0.018)
    .decay(0.30)
    .sustain(0)
    .release(0.50)
    .lpf(185)
    .room(0.09)
    .orbit(1)
    .duckorbit(2)
    .duckdepth(0.36)
    .duckattack(0.32),

)

// ============================================================
// G_A2 | 20–24s
// ============================================================

const G_A2 = stack(

  // 完整 butterfly

  note("a5 [g5 e5] [d5 e5] [g5 a5]")

    .sound("sine")
    .velocity("0.034 0.029 0.025 0.023")
    .attack(0.032)
    .release(0.95)
    .lpf(3650)
    .room(0.50)
    .delay(0.16)
    .delaytime(0.14)
    .pan("0.42 0.58 0.52 0.49")
    .orbit(2),

  // 两条线

  note("e4 [g4 a4] [b4 e5] [g5 a5]")

    .sound("triangle")
    .velocity("0.017 0.018 0.021 0.019")
    .attack(0.045)
    .release(1.10)
    .lpf(2700)
    .room(0.48)
    .pan("0.58 0.44 0.56 0.51")
    .orbit(2),

  // A2：回应线第一次进入蝴蝶音区

note("~ ~ ~ [g5 a5]")

  .sound("sine")
  .velocity("0 0 0 0.0085")
  .attack(0.060)
  .release(1.35)
  .lpf(3100)
  .room(0.58)
  .delay(0.15)
  .delaytime(0.14)
  .pan("0.49 0.52")
  .orbit(2),

  // 光粒子减少一点

  note("[~ e6] [a6 ~] [~ g6] [e7 a6]")

    .sound("sine")
    .velocity("0.010 0.018 0.014 0.020")
    .attack(0.003)
    .decay(0.070)
    .sustain(0)
    .release(0.64)
    .hpf(2050)
    .lpf(6600)
    .room(0.68)
    .delay(0.24)
    .delaytime(0.11)
    .pan(perlin.slow(2).range(0.20,0.80))
  .degradeBy(0.06)
    .orbit(2),

  // A2
note("e2 ~ e2 [~ b1]")
    .sound("sine")
    .velocity("0.116 0 0.098 0")
    .attack(0.014)
    .decay(0.27)
    .sustain(0)
    .release(0.46)
    .lpf(198)
    .room(0.08)
    .orbit(1)
    .duckorbit(2)
    .duckdepth(0.41)
    .duckattack(0.28),

  // 重音轮廓

  note("~ ~ e3 ~")

  .sound("triangle")
  .velocity("0 0 0.022 0")
  .attack(0.008)
.decay(0.080)
.sustain(0)
.release(0.18)
.hpf(220)
.lpf(850)
.room(0.15)

)

// ============================================================
// G_A3 | 24–28s
// 两条旋律逐渐汇聚到 E
// ============================================================

const G_A3 = stack(

  // 蝴蝶

  note("a5 [g5 e5] [d5 e5] e5")

    .sound("sine")
    .velocity("0.030 0.026 0.021 0.018")
    .attack(0.040)
    .release(1.80)
    .lpf(3350)
    .room(0.58)
    .delay(0.18)
    .delaytime(0.16)
    .pan("0.44 0.56 0.48 0.52")
    .orbit(2),

  // 回应线

  note("e4 [g4 a4] [b4 e5] [g5 e5]")

    .sound("triangle")
    .velocity("0.016 0.017 0.019 0.015")
    .attack(0.050)
    .release(1.70)
    .lpf(2550)
    .room(0.54)
    .pan("0.56 0.46 0.54 0.50")
    .orbit(2),

  // 最后一轮脉搏逐渐减弱

  note("e2 ~ ~ ~")
  .sound("sine")
  .velocity("0.088 0 0 0")
  .attack(0.020)
  .decay(0.38)
  .sustain(0)
  .release(1.20)
    .lpf(180)
    .room(0.12)
    .orbit(1)
    .duckorbit(2)
    .duckdepth(0.28)
    .duckattack(0.34),

  // 最后留下一个长 E6

  note("~ ~ e6 ~")

    .sound("sine")
    .velocity("0 0 0.014 0")
    .attack(0.35)
    .sustain(1)
    .release(4.00)
    .hpf(1500)
    .lpf(4200)
    .room(0.82)
    .delay(0.28)
    .delaytime(0.18)
    .pan(0.52)
    .orbit(2)

)


// ============================================================
// COMPLETE G
// 6 × 4 sec = 24 sec
// ============================================================

const G_final = cat(

  G_B1,

  G_B2,

  G_C1,

  G_C2,

  G_A1,

  G_A2,

  G_A3,

)

// ==================================================
// 正式时间轴
// A → B → C → D → E1 → E2 → E3 → F1 → F2 → F3 → G_B1 → G_B2 → G_C1 → G_C2 → G_A1 → G_A2 → H
// ==================================================

const standaloneAG = arrange(

  [17, cat(

  // ==================================================
  // A — 蝴蝶
  // 时间：0–4 秒（从周期 0 开始）
  // ==================================================

  stack(

    butterfly

      .sound("piano")
      .velocity("0.075 [0.12 0.17] [0.19 0.13] [~ [0.055 ~]]")
      .room(0.25),

    note("f5 [e5 ~] [b4 c5] [~ [e5 ~]]")

      .sound("piano")
      .velocity("0.022 [0.032 ~] [0.045 0.032] [~ [0.016 ~]]")
      .room(0.25)


  ).gain(0.48),



  // ==================================================
  // B — 金光
  // 时间：4–8 秒（从周期 0 开始）
  // ==================================================

  stack(

    note("g5 [a5 b5] [c6 b5] [a5 ~]")

      .sound("piano")
      .velocity("0.25 0.21 0.18 0.14")
      .room(0.25),

    note("e5 [f5 ~] [a5 g5] [e5 ~]")

      .sound("piano")
      .velocity(0.07)
      .room(0.25),


    // B 末尾：把最后一个 E4 留进 C

note("~ ~ e4 e4")

  .sound("gm_flute")
  .velocity("0 0 0.038 0.026")
  .attack(0.38)
  .sustain(0.75)
  .release(1.80)
  .lpf(1550)
  .room(0.58)
  .pan(0.54)

  ).gain(0.58),

  // ==================================================
  // C1-a | C 内 0–4 秒
  // ==================================================

stack(

    // 地面

    note("e3")

      .sound("gm_cello")
      .velocity(0.028)
      .attack(1.2)
      .release(3.2)
      .lpf(950)
      .room(0.50)
      .pan(0.5),

    // 主枝

    note("e4 ~ g4 ~")

  .sound("gm_oboe")
  .velocity(0.105)
  .attack(0.16)
  .release(0.90)
  .room(0.30)
  .pan(0.40),


    // 回应枝

    note("~ a4 ~ b4")

      .sound("gm_oboe")
      .velocity(0.065)
      .room(0.3)
      .pan(0.6),

    // 呼吸底层

    note("e4 e4 g4 g4")

      .sound("gm_flute")
      .velocity(0.032)
      .room(0.4)
      .pan(0.53),

    // 远处钢琴碎光

    note("e5 [g5 a5] b5 [e5 g5]")

      .sound("piano")
      .velocity(0.055)
      .room(0.42)
      .pan(0.55)

  ),

  // ==================================================
  // C1-b | C 内 4–8 秒
  // ==================================================

stack(

    // 地面

    note("g3")

      .sound("gm_cello")
      .velocity(0.025)
      .attack(1.3)
      .release(3.2)
      .lpf(900)
      .room(0.54)
      .pan(0.5),

    // 主枝

    note("g4 ~ a4 b4")

      .sound("gm_oboe")
      .velocity(0.100)
      .room(0.48)
      .pan(0.41),

    // 呼吸底层

    note("g4 g4 a4 a4")

      .sound("gm_flute")
      .velocity(0.030)
      .room(0.4)
      .pan(0.54),

    // 远处钢琴碎光

    note("g5 [a5 b5] d6 [b5 a5]")

      .sound("piano")
      .velocity(0.051)
      .room(0.46)
      .pan(0.59)

  ),

  // ==================================================
  // C2-a | C 内 8–12 秒
  // ==================================================

stack(

    // v3 旁枝开始：固定音池与候选，概率只删除本声部的事件。

    note("~ g5 ~ ~")

      .sound("gm_pizzicato_strings")
      .velocity(0.025)
      .room(0.52)
      .pan(perlin.slow(4).range(0.57, 0.71))
      .degradeBy(0.70),

    // v3 旁枝结束
    // 地面

    note("e3")

      .sound("gm_cello")
      .velocity(0.022)
      .attack(1.4)
      .release(3.0)
      .lpf(850)
      .room(0.58)
      .pan(0.5),

    // 主枝

    note("e4 ~ ~ g4")

      .sound("gm_pizzicato_strings")
      .velocity(0.120)
      .room(0.36)
      .pan(perlin.slow(3).range(0.355, 0.445)),

    // 回应枝

    note("~ a4 ~ ~")

      .sound("gm_oboe")
      .velocity(0.052)
      .room(0.48)
      .pan(0.6),
    // 远处钢琴碎光

    note("b5 ~ [a5 b5] g5")

      .sound("piano")
      .velocity(0.047)
      .room(0.48)
      .pan(0.64)

  ),



  // ==================================================
  // C2-b | C 内 12–16 秒
  // ==================================================

stack(

    // v3 旁枝开始

    note("~ g5 ~ a5")

      .sound("gm_pizzicato_strings")
      .velocity(0.028)
      .room(0.52)
      .pan(perlin.slow(4).range(0.57, 0.71))
      .degradeBy(0.60),

    // v3 旁枝结束
    // 地面

    note("b2")

      .sound("gm_cello")
      .velocity(0.016)
      .attack(1.5)
      .release(2.8)
      .lpf(780)
      .room(0.62)
      .pan(0.5),

    // 主枝

    note("e4 ~ [g4 a4] ~")

      .sound("gm_pizzicato_strings")
      .velocity(0.132)
      .room(0.36)
      .pan(perlin.slow(3).range(0.345, 0.435)),

    // 回应枝

    note("~ ~ b4 ~")

      .sound("gm_oboe")
      .velocity(0.048)
      .room(0.50)
      .pan(0.62),

    // 远处钢琴碎光

    note("d6 [e6 d6] b5 [g5 a5]")

      .sound("piano")
      .velocity(0.043)
      .room(0.50)
      .pan(0.66)

  ),



  // ==================================================
  // C2-c | C 内 16–20 秒
  // ==================================================

stack(

    // v3 旁枝开始

    note("~ a5 ~ b5")

      .sound("gm_pizzicato_strings")
      .velocity(0.032)
      .room(0.52)
      .pan(perlin.slow(4).range(0.57, 0.71))
      .degradeBy(0.45),

    // v3 旁枝结束
    // 地面退出

    note("e3")

      .sound("gm_cello")
      .velocity(0.010)
      .attack(1.6)
      .release(2.5)
      .lpf(700)
      .room(0.66)
      .pan(0.5),

    // 主枝

    note("g4 ~ [a4 b4] d5")

      .sound("gm_pizzicato_strings")
      .velocity(0.105)
      .lpf(3400)
      .room(0.36)
      .pan(perlin.slow(3).range(0.335, 0.425)),

    // 回应枝

    note("~ ~ d5 ~")

      .sound("gm_oboe")
      .velocity(0.042)
      .room(0.52)
      .pan(0.63),

    // 远处钢琴碎光

    note("b5 ~ d6 e6")

      .sound("piano")
      .velocity(0.038)
      .room(0.52)
      .pan(0.68)

  ),

  // ==================================================
  // C3-a | C 内 20–24 秒
  // ==================================================

stack(

    // v3 旁枝开始

    note("~ ~ d6 ~")
      .sound("gm_pizzicato_strings")
      .velocity(0.022)
      .room(0.52)
      .pan(perlin.slow(4).range(0.57, 0.71))
      .degradeBy(0.65),
    
// v3 旁枝结束
// 主枝

    note("g4 ~ [a4 b4] d5")

  .sound("gm_pizzicato_strings")
  .velocity("0.095 0.086 0.078 0.070")
  .lpf(3300)
  .room(0.52)
  .pan(perlin.slow(3).range(0.285, 0.415)),
   
 // 回应枝

    note("~ ~ f#5 ~")

      .sound("gm_oboe")
      .velocity(0.024)
      .room(0.64)
      .pan(0.66)

  ),



  // ==================================================
  // C3-b | C 内 24–28 秒
  // ==================================================

stack(

    // v3 旁枝开始

    note("~ ~ e6 ~")

      .sound("gm_pizzicato_strings")
      .velocity(0.018)
      .room(0.52)
      .pan(perlin.slow(4).range(0.57, 0.71))
      .degradeBy(0.75),

    // v3 旁枝结束
    // 主枝：音域上升、声场打开

note("a4 ~ [b4 d5] e5")

  .sound("gm_pizzicato_strings")
  .velocity("0.082 0.074 0.066 0.058")
  .lpf(3200)
  .room(0.58)
  .pan(perlin.slow(3).range(0.235, 0.365)),

    // 回应枝

    note("~ ~ f#5 ~")

      .sound("gm_oboe")
      .velocity(0.021)
      .room(0.68)
      .pan(0.69)

  ),


  // ==================================================
  // C3-c | C 内 28–32 秒
  // ==================================================

stack(

    // 主枝：只留下末梢

    note("~ d5 ~ e5")

  .sound("gm_pizzicato_strings")
  .velocity("0.052 0.043")
  .lpf(3000)
  .room(0.62)
  .pan(0.34),


    // 回应枝：低处残留

    note("b4 ~ ~ ~")

      .sound("gm_pizzicato_strings")
      .velocity(0.042)
      .room(0.60)
      .pan(0.66),

    // 张力残留

    note("~ f#5 ~ ~")

      .sound("gm_oboe")
      .velocity(0.018)
      .room(0.72)
      .pan(0.55),


    // ==================================================
    // C → D bridge
    // ==================================================

note("~ ~ [e5 ~] [~ d6]")

  .sound("gm_vibraphone")
  .velocity("0 0 0.010 0.022")
  .attack(0.20)
  .release(2.60)
  .lpf(2600)
  .room(0.76)
  .delay(0.20)
  .delaytime(0.16)
  .pan("0.52 0.44"),


note("~ ~ ~ a5")

  .sound("sine")
  .velocity("0 0 0 0.0045")
  .attack(0.45)
  .release(3.00)
  .lpf(1500)
  .room(0.52)
  .pan(0.48)

  ),



  // ==================================================
  // D v5：五朵核心保持0、0.8、1.6、2.4、3.2秒；细丝从D起点贯穿五朵。
  // ==================================================

stack(

stack(

  note("d6 ~ ~ ~")

  .sound("gm_xylophone")
  .velocity(0.088)
  .attack(0.008)
  .release(0.45)
  .room(0.46)
  .pan(0.44),

  note("a6 ~ ~ ~").late(0.07)

    .sound("gm_xylophone")
    .velocity(0.052)
    .release(0.40)
    .room(0.48)
    .pan(0.53),

  note("d7 ~ ~ ~").late(0.14)

    .sound("gm_xylophone")
    .velocity(0.030)
    .release(0.45)
    .room(0.52)
    .pan(0.36),


  note("a7 ~ ~ ~").late(0.19)

    .sound("gm_xylophone")
    .velocity(0.016)
    .release(0.50)
    .room(0.56)
    .pan(0.60)

),



// 第2朵 | D 内 0.80 秒

note("a6 ~ ~ ~").late(0.200)

  .sound("gm_xylophone")
  .velocity(0.078)
  .attack(0.008)
  .release(0.45)
  .room(0.44)
  .pan(0.60),


// 第2朵 | D 内 1.08 秒

note("e7 ~ ~ ~").late(0.270)

  .sound("gm_xylophone")
  .velocity(0.042)
  .attack(0.005)
  .release(0.40)
  .room(0.48)
  .pan(0.72),


// 第2朵 | D 内 1.36 秒

note("a7 ~ ~ ~").late(0.340)

  .sound("gm_xylophone")
  .velocity(0.023)
  .attack(0.005)
  .release(0.45)
  .room(0.52)
  .pan(0.48),

// 第2朵 | D 内 1.56 秒

note("e7 ~ ~ ~").late(0.390)

  .sound("gm_vibraphone")
  .velocity(0.018)
  .attack(0.025)
  .release(0.70)
  .room(0.56)
  .pan(0.76),

// 第3朵 | D 内 1.60 秒

note("e7 ~ ~ ~").late(0.400)

  .sound("gm_xylophone")
  .velocity(0.082)
  .attack(0.008)
  .release(0.48)
  .room(0.44)
  .pan(0.62),


// 第3朵 | D 内 1.88 秒

note("a7 ~ ~ ~").late(0.470)

  .sound("gm_xylophone")
  .velocity(0.045)
  .attack(0.005)
  .release(0.45)
  .room(0.50)
  .pan(0.80),


// 第3朵 | D 内 2.16 秒

note("g7 ~ ~ ~").late(0.540)

  .sound("gm_xylophone")
  .velocity(0.027)
  .attack(0.005)
  .release(0.48)
  .room(0.54)
  .pan(0.26),


// 第3朵 | D 内 2.36 秒

note("b6 ~ ~ ~").late(0.590)

  .sound("gm_vibraphone")
  .velocity(0.021)
  .attack(0.030)
  .release(0.85)
  .room(0.58)
  .pan(0.42),


// 第4朵 | D 内 2.40 秒

note("d7 ~ ~ ~").late(0.600)

  .sound("gm_xylophone")
  .velocity(0.070)
  .attack(0.012)
  .release(0.50)
  .room(0.48)
  .pan(0.34),


// 第4朵 | D 内 2.68 秒

note("a6 ~ ~ ~").late(0.670)

  .sound("gm_xylophone")
  .velocity(0.038)
  .attack(0.012)
  .release(0.48)
  .room(0.52)
  .pan(0.26),


// 第4朵 | D 内 2.96 秒

note("d6 ~ ~ ~").late(0.740)

  .sound("gm_vibraphone")
  .velocity(0.014)
  .attack(0.040)
  .release(1.10)
  .room(0.58)
  .pan(0.42),


// 第4朵 | D 内 3.16 秒

note("a6 ~ ~ ~").late(0.790)

  .sound("gm_vibraphone")
  .velocity(0.008)
  .attack(0.050)
  .release(1.20)
  .room(0.60)
  .pan(0.48),


// 第5朵 | D 内 3.20 秒

note("b6 ~ ~ ~").late(0.800)

  .sound("gm_vibraphone")
  .velocity(0.058)
  .attack(0.025)
  .release(1.30)
  .room(0.56)
  .pan(0.55),


// 第5朵 | D 内 3.48 秒

note("f#6 ~ ~ ~").late(0.870)

  .sound("gm_vibraphone")
  .velocity(0.030)
  .attack(0.045)
  .release(1.50)
  .room(0.60)
  .pan(0.51),

// 第5朵 | D 内 3.76 秒

note("e6 ~ ~ ~").late(0.940)

  .sound("gm_vibraphone")
  .velocity(0.009)
  .attack(0.060)
  .release(1.80)
  .room(0.60)
  .pan(0.48),


// 贯穿五朵的细丝：D起点只触发一次，完整周期4秒，随后释放4秒。
// 慢起音让它从第一朵下方浮现；不在第五朵重新触发。
// 第1朵附加碎光；D内0.12秒

note("a6 ~ ~ ~").late(0.030)

  .sound("gm_xylophone")
  .velocity(0.0120)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.32),


// 第1朵附加碎光；D内0.40秒

note("e7 ~ ~ ~").late(0.100)

  .sound("gm_xylophone")
  .velocity(0.0096)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.64),


// 第1朵附加碎光；D内0.64秒

note("d7 ~ ~ ~").late(0.160)

  .sound("gm_xylophone")
  .velocity(0.0072)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.42),

// 第2朵附加碎光；D内0.92秒

note("b6 ~ ~ ~").late(0.230)

  .sound("gm_xylophone")
  .velocity(0.0170)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.72),


// 第2朵附加碎光；D内1.20秒

note("d7 ~ ~ ~").late(0.300)

  .sound("gm_xylophone")
  .velocity(0.0136)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.38),

// 第2朵附加碎光；D内1.44秒

note("a7 ~ ~ ~").late(0.360)

  .sound("gm_xylophone")
  .velocity(0.0102)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.80),

// 第3朵附加碎光；D内1.72秒

note("g7 ~ ~ ~").late(0.430)

  .sound("gm_xylophone")
  .velocity(0.0220)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.22),


// 第3朵附加碎光；D内2.00秒

note("a7 ~ ~ ~").late(0.500)

  .sound("gm_xylophone")
  .velocity(0.0176)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.82),


// 第3朵附加碎光；D内2.24秒

note("e7 ~ ~ ~").late(0.560)

  .sound("gm_xylophone")
  .velocity(0.0132)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.40),


// 第4朵附加碎光；D内2.52秒

note("a6 ~ ~ ~").late(0.630)

  .sound("gm_xylophone")
  .velocity(0.0160)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.28),


// 第4朵附加碎光；D内2.80秒

note("b6 ~ ~ ~").late(0.700)

  .sound("gm_xylophone")
  .velocity(0.0128)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.65),


// 第4朵附加碎光；D内3.04秒

note("d7 ~ ~ ~").late(0.760)

  .sound("gm_xylophone")
  .velocity(0.0096)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.46),


// 第5朵附加碎光；D内3.32秒

note("f#6 ~ ~ ~").late(0.830)

  .sound("gm_xylophone")
  .velocity(0.0090)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.59),

// 第5朵附加碎光；D内3.60秒

note("b6 ~ ~ ~").late(0.900)

  .sound("gm_xylophone")
  .velocity(0.0072)
  .attack(0.003)
  .decay(0.12)
  .sustain(0)
  .release(0.12)
  .room(0.32)
  .pan(0.40),


note("e6 ~ ~ ~").late(0.940)

  .sound("gm_vibraphone")
  .velocity(0.007)
  .attack(0.060)
  .release(2.60)
  .lpf(2700)
  .room(0.76)
  .delay(0.24)
  .delaytime(0.17)
  .pan(0.48),


// 更轻的E5细线

note("e5")

  .sound("sine")
  .velocity(0.004)
  .attack(1.200)
  .sustain(1)
  .release(4.00)
  .room(0.18)
  .pan(0.50)
  .lpf(900)

),

// ==================================================
// E → F
// ==================================================

E1,

E2,

E3,

F1,

F2,

F3

  )],

  // 0.4 秒真正停顿

  [0.10, silence],

  [7, G_final]

)



// H — AFTER LANDING：保留原始定义，在 A–G 结束后持续播放。

  const butterflyCore = note("a5 [g5 ~] [~ e5] [~ g5] [g5 ~]")

    .sound("piano").velocity(0.030).attack(0.055).release(2.80)
    .lpf(sine.range(1550, 1950).slow(12))
    .room(sine.range(0.64, 0.72).slow(16))
    .pan(sine.range(0.47, 0.53).slow(20)).slow(2.5);

  const memory = note("~ [~ e5] [d5 ~] ~ ~")
    .sound("piano").velocity(0.016).attack(0.070).release(2.50)
    .lpf(sine.range(1350, 1750).slow(15)).room(0.76)
    .pan(sine.range(0.48, 0.55).slow(17))
    .sometimes(x => x.degradeBy(0.42)).slow(2.5);

  const ghost = note("~ ~ ~ e5 ~ ~ ~")

    .sound("sine").velocity(0.0025).attack(0.35).release(3.80)
    .hpf(700).lpf(2200).room(0.88).pan(0.40)
    .degradeBy(0.68).slow(3.0);

  const star = note("~ ~ g6 ~ ~ ~ ~")

    .sound("sine").velocity(0.0022).attack(0.080).release(2.20)
    .hpf(1500).lpf(sine.range(3200, 4300).slow(19))
    .room(sine.range(0.76, 0.86).slow(21))
    .pan(sine.range(0.66, 0.74).slow(23)).slow(3.1);

  const echo = note("~ ~ ~ ~ ~ ~ g6 ~ ~")

    .sound("sine").velocity(0.0012).attack(0.40).release(4.20)
    .hpf(1800).lpf(3600).room(0.92).pan(0.82)
    .degradeBy(0.72).slow(4.3);

  const standaloneH = stack(butterflyCore, memory, ghost, star, echo);



// Standalone 播放结构：A–G 只播放一次，H 从自身时间 0 开始持续运行。
// 原始 A–G 时长：17 + 0.10 + 7 = 24.1 cycles = 96.4 秒。
const standaloneAGCycles = 17 + 0.10 + 7;

stack(
  standaloneAG.filterWhen(t => t >= 0 && t < standaloneAGCycles),
  standaloneH.filterWhen(t => t >= 0).late(standaloneAGCycles)
)
