Git Product home page Git Product logo

Comments (6)

mudcube avatar mudcube commented on September 18, 2024

Weird, I cannot reproduce. Is this happening on the MIDIPlayer demo for you?

from midi.js.

Miranet avatar Miranet commented on September 18, 2024

Just an idea, and maybe also a cure for the problem mentioned above:

The code "as is" did not work for me when I tried to play notes in real time, to get the right delay for noteOff commands I had to make the following fix where the ramp time is defined with ctx.currentTime:

root.noteOff = function (channel, note, delay) {
delay = delay || 0;
if (delay < ctx.currentTime) delay += ctx.currentTime;
var source = sources[channel + "" + note];
if (!source) return;
source.gain.linearRampToValueAtTime(1, delay);
source.gain.linearRampToValueAtTime(0, delay + 0.2);
source.noteOff(delay + 0.3);
return source;
};

The problem was that after the script has been initialized.at time point x, and the delay time for noteOff occurs in the past when depressing a button to stop playing a note with the the normal script. The above fix takes notice of the currentTime to stop the note from playing at the time I want it it to stop.

midi files still play back nicely here as expected, and playing in real time will now work just as expected.

Just an idea: the values of 0.2 and 0.3 could ofcourse be used as "release" parameter for ADSR like time settings.

Maybe we could also catch and flag the use of damper info (controller 60 or 40h I believe) in the midi file to disable source.noteOff to get very much better playback of piano and other mid's I suppose?

from midi.js.

0xfe avatar 0xfe commented on September 18, 2024

@Miranet, I think you've got it. Let me patch in your fix and try.

from midi.js.

0xfe avatar 0xfe commented on September 18, 2024

@mudcube This not for the MIDIPlayer demo. I discovered this when trying to use brass (or other long sustaining) instruments in my VexFlow integration. (I didn't need to bother with noteOff for pianos or clean guitars.)

If @Miranet's patch doesn't work, I'll try to provide a short script to reproduce the bug.

from midi.js.

0xfe avatar 0xfe commented on September 18, 2024

Excellent. Everything works as expected with @Miranet's patch. @mudcube perhaps you can patch this into head?

from midi.js.

mudcube avatar mudcube commented on September 18, 2024

@Miranet, thanks for the fix! It's been added into the latest master branch.

from midi.js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.