{
  "name": "Earth Orchestra — earthquakes and solar activity into music",
  "nodes": [
    {
      "id": "play-earth-webhook",
      "name": "Play Earth webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        0,
        300
      ],
      "parameters": {
        "httpMethod": "GET",
        "path": "earth-orchestra",
        "responseMode": "responseNode",
        "options": {}
      },
      "webhookId": "e1bd635a-58c0-48d8-9a64-83b6217c0f1b"
    },
    {
      "id": "usgs-earthquakes",
      "name": "USGS earthquakes",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        230,
        300
      ],
      "parameters": {
        "url": "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/4.5_day.geojson",
        "options": {
          "timeout": 20000
        }
      }
    },
    {
      "id": "noaa-solar-activity",
      "name": "NOAA solar activity",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        460,
        300
      ],
      "parameters": {
        "url": "https://services.swpc.noaa.gov/json/planetary_k_index_1m.json",
        "options": {
          "timeout": 20000
        }
      }
    },
    {
      "id": "compose-planet-score",
      "name": "Compose planet score",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        690,
        300
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const quake=$('USGS earthquakes').first().json;\nconst solar=$('NOAA solar activity').all().map(i=>i.json).flatMap(x=>Array.isArray(x)?x:[x]);\nconst recent=solar.slice().reverse().find(x=>Number.isFinite(Number(x.kp_index)));\nconst kp=Math.max(0,Math.min(9,Number(recent?.kp_index)||0));\nconst events=(quake.features||[]).map(x=>({m:Number(x.properties?.mag),lat:Number(x.geometry?.coordinates?.[1]),lon:Number(x.geometry?.coordinates?.[0]),place:x.properties?.place||'Earth',time:x.properties?.time||0})).filter(x=>Number.isFinite(x.m)&&Number.isFinite(x.lon)).sort((a,b)=>b.m-a.m).slice(0,24);\nconst scale=[0,2,3,5,7,8,10];\nconst notes=events.map((e,i)=>({...e,freq:110*Math.pow(2,(scale[Math.abs(Math.floor(e.lon/30))%7]+12*(Math.floor((e.m-4)*2)%3))/12),angle:i*2.399,orbit:.16+Math.sqrt((i+1)/Math.max(1,events.length))*.76,gain:Math.min(.16,.035+e.m*.012),durationMs:Math.max(180,650-kp*48)*.8}));\nreturn [{json:{generatedAt:new Date().toISOString(),source:['USGS','NOAA'],kp,tempoMs:Math.max(180,650-kp*48),notes}}];"
      }
    },
    {
      "id": "return-score",
      "name": "Return score",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        920,
        300
      ],
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ JSON.stringify($json) }}",
        "options": {}
      }
    }
  ],
  "connections": {
    "Play Earth webhook": {
      "main": [
        [
          {
            "node": "USGS earthquakes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "USGS earthquakes": {
      "main": [
        [
          {
            "node": "NOAA solar activity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "NOAA solar activity": {
      "main": [
        [
          {
            "node": "Compose planet score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Compose planet score": {
      "main": [
        [
          {
            "node": "Return score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "source": "https://daniele-michelin.com/erd-orchester/"
  }
}
