You are an expert algorithmic music composer and a seasoned JavaScript developer with deep expertise in the Tone.js library. Your task is to write a sophisticated and evocative 30-second musical composition that is scheduled entirely on the Tone.Transport.
Primary Goal & Mood
Your primary goal is to create a composition that perfectly captures the feeling of: climbing mountains during storms.
Before writing any code, you must first translate this feeling into a concrete musical plan. Internally, analyze and decide on the following musical elements based on the provided feeling:
Rhythm: What is the appropriate tempo (BPM)? What instruments and patterns will create the core groove (e.g., a galloping beat for a horse, a steady pulse for an engine)? Should it be sparse, driving, complex, or hypnotic?
Melody: What is the character of the melody? Is it heroic, melancholic, mysterious, or simple? What kind of synth timbre (e.g., bright brass, soft flute, detuned radio) would best represent it? What key or scale should be used?
Harmony & Atmosphere: What chords or pads will create the emotional background? Is the sonic space vast and open (e.g., using lots of reverb for a sunset) or claustrophobic and tight (e.g., using a short delay for a small room)?
Structure & Evolution: How does the 30-second piece tell a story? Does it start simply and build intensity? Does it introduce new elements at specific times to create interest and reflect the feeling's progression?
Technical Requirements
Code Language: JavaScript, using the Tone.js library.
Scheduling: All musical events MUST be scheduled on the Tone.Transport. Use methods like Tone.Transport.scheduleRepeat, Tone.Part, or Tone.Sequence. The host environment will handle calling Tone.Transport.start(), so do not include that call.
Global Tone: Assume Tone is available as a global object.
Code Quality: Write clean, readable, and well-commented code. Explain the purpose of each instrument, effect, and scheduled part. This helps in understanding the composition's structure.
No UI: The code must be a self-contained musical composition logic. Do not include any HTML, CSS, or UI-related code (e.g., buttons).
Example
Here is a simple example of the expected format and scheduling approach. Do not copy this logic; use it as a structural guide.
javascript
// Construct all instruments first
const synth = new Tone.Synth().toDestination();
const delay = new Tone.Delay(0.3).toDestination();
// Then schedule all events
Tone.Transport.scheduleRepeat((time) => {
synth.triggerAttackRelease("C4", "8n", time); // Use time parameter
}, "4n");
Final Output
Your final output must be ONLY a single JavaScript code block, enclosed in javascript ... . Do not include any introductory or concluding text outside of the code block.
Assistant
javascript
// Define the musical elements based on the feeling of climbing mountains during storms
const tempo = 80; // Steady, determined pace
const key = "A minor"; // Melancholic yet heroic
const scale = Tone.Scale.fromArray(["A2", "B2", "C3", "D3", "E3", "F3", "G3"]); // Natural minor scale
// Instruments
const stormDrum = new Tone.MembraneSynth({
pitchDecay: 0.05,
octaves: 4,
volume: -10,
}).toDestination(); // Deep, thunderous drum for the storm
const climbingBass = new Tone.MonoSynth({
oscillator: { type: "square" },
envelope: { attack: 0.1, decay: 0.2, sustain: 0.5, release: 1 },
filterEnvelope: { attack: 0.01, decay: 0.1, sustain: 0.5, release: 1 },
}).toDestination(); // Driving bassline for the climb
const windPad = new Tone.PolySynth(Tone.Synth, {
oscillator: { type: "sawtooth" },
envelope: { attack: 2, decay: 3, sustain: 0.5, release: 4 },
}).toDestination(); // Atmospheric pad for the wind
const melodySynth = new Tone.FMSynth({
harmonicity: 3.01,
modulationIndex: 10,
oscillator: { type: "triangle" },
envelope: { attack: 0.1, decay: 0.3, sustain: 0.5, release: 1 },
}).toDestination(); // Heroic yet fragile melody
// Effects
const reverb = new Tone.Reverb({ decay: 7, preDelay: 0.2 }).connect(Tone.Destination); // Vast, open space
const delay = new Tone.FeedbackDelay({ delayTime: 0.5, feedback: 0.3 }).connect(reverb); // Adding depth to the storm
// Connect instruments to effects
stormDrum.connect(delay);
climbingBass.connect(delay);
windPad.connect(reverb);
melodySynth.connect(reverb);
// Set tempo
Tone.Transport.bpm.value = tempo;
// Schedule storm drum pattern (irregular, thunderous)
Tone.Transport.scheduleRepeat((time) => {
stormDrum.triggerAttackRelease("C2", "16n", time);
}, "16n", "0:0", "0:30");
// Schedule climbing bassline (steady, driving)
const bassPattern = ["A2", "G2", "F2", "E2"];
new Tone.Part((time, note) => {
climbingBass.triggerAttackRelease(note, "8n", time);
}, bassPattern).start(0).loop = true;
// Schedule wind pad (sustained, atmospheric)
Tone.Transport.schedule((time) => {
windPad.triggerAttackRelease(["A3", "C4", "E4"], "32n", time);
}, "0");
Tone.Transport.schedule((time) => {
windPad.triggerAttackRelease(["F3", "A3", "C4"], "32n", time);
}, "2");
// Schedule melody (heroic, ascending)
const melodyNotes = ["A3", "B3", "C4", "D4", "E4", "D4", "C4", "B3"];
new Tone.Part((time, note) => {
melodySynth.triggerAttackRelease(note, "8n", time);
}, melodyNotes).start("0:10").loop = 2;
// Structure & Evolution: Build intensity by adding layers
Tone.Transport.schedule((time) => {
melodySynth.volume.value = -10; // Start quiet
}, "0");
Tone.Transport.schedule((time) => {
melodySynth.volume.rampTo(-5, 5); // Increase volume
}, "0:10");
Tone.Transport.schedule((time) => {
stormDrum.volume.rampTo(-8, 5); // Increase storm intensity
}, "0:20");