nst midi = new Midi();
        const bpm = parseInt(document.getElementById('bpm').value);
        const secondsPerBeat = 60.0 / bpm;
        
        midi.header.setTempo(bpm);
        midi.header.timeSignature = [4, 4];
        midi.header.ppq = currentTimeManipulator.ppq;

        // Add tracks for each line
        currentLines.forEach(({type, line}, index) => {
            const track = midi.addTrack();
            
            // Set instrument and channel
            track.channel = index;
          