尝试使用jquery设置鼠标按下时间以更改按钮触发器来控制音量滑块

时间:2016-04-19 15:20:53

标签: javascript jquery web-audio

所以我已经建立了一个基本的网络音频鼓机,但我想通过使用持续时间超过1.5秒的if mousedown功能控制每个打击垫的音量,然后控制滑块并且不要触发打击垫

        <div id="sectionSequencer">
                <table>
  <tr>
    <td><button class="pads" id="Kick">Kick<input type="range" min="0" max="1" step="0.01" value="1" class="padgain" /></button></td>

var indgain = [];

                          indgain["Kick"] = 0.25;

和函数的jquery

 $('#padgain').on("change mousemove", function() {
                                          indgain[selectedPad] = $(this).val();
                                          });
// Event handler for any button with "sample" class
                  $(".pads").button().mousedown(function(event){

                                              if (mousedown >= 1500) {
                                                    selectedPad = this.id;
                                                    var gainpad = audioCtx.createGain();
                                                    padgain.gain.value = indgain [this.id];
                                                    gainpad.connect(gainMaster);

                                                    }
                                                    else if (mousedown < 1500){
                                                    playSound;
                                                    }


                                            selectedPad = this.id;

                                            // Create an AudioBufferSourceNode
                                           var playSound = audioCtx.createBufferSource();
                                            var biquadFilter = audioCtx.createBiquadFilter();
                                            biquadFilter.type = "lowpass";
                                            biquadFilter.Q.value = 1;
                                            biquadFilter.frequency.value = padCutoffs[this.id];

                                            playSound.connect(biquadFilter);

                                            var myDelay = audioCtx.createDelay(0.25);
                                            myDelay.delayTime.value = paddelay[this.id];





                                            biquadFilter.connect(myDelay);


                                            var gainMaster = audioCtx.createGain();
                                            gainMaster.gain.value = 5;

                                            myDelay.connect(gainMaster);








                                            // Note: the Web Audio spec is moving from constants to strings. // filter.type = 'lowpass';


                                            // this.id has the key for the buffer in the array we wish to use
                                            // (retrieved from the button that was clicked)
                                            // Go ahead and assign this buffer to the AudioBufferSourceNode
                                            playSound.buffer = samples[this.id]

                                            // Connect the AudioBufferSourceNode to the context's output
                                            // playSound.connect(audioCtx.destination);


                                            // Queue the AudioBufferSourceNode up for playback immediately
                                            // playSound.start();
                                            //playSound.connect(audioCtx.destination);

                                            playSound.start();

                                            gainMaster.connect(audioCtx.destination);

1 个答案:

答案 0 :(得分:0)

你需要一个旋钮库吗?:

像这样???:http://anthonyterrien.com/knob/