MIDI-OX User Forum (http://www.midiox.com/cgi-bin/yabb/YaBB.pl)
MIDI-OX >> Questions and Discussion >> That nasty sustain pedal
(Message started by: rumborak on Nov 3rd, 2002, 2:07am)

Title: That nasty sustain pedal
Post by rumborak on Nov 3rd, 2002, 2:07am
Hi all,

I have a MIDI problem and I was hoping someone might have a solution to this:

I'm using my soundcard's MIDI function mostly for playing piano (hooking it up with my MIDI keyboard).

However, everytime I press the sustain pedal, I run into the obvious problem: Polyphony.
After a few seconds, there aren't any free oscillators anymore and even though I'm still hitting keys, there's no nothing happening anymore.

The stupid thing (I find) however is that hitting the same note twice in a row does *not* result in the first oscillator starting from the beginning of the sample again, but rather a second oscillator being used.
Result: Polyphony issues and nasty phasing effects.

Now, I understand this is all done *inside* the soundcard (ie the handling of the sustain pedal), so there's no way to directly change it, however, shouldn't it be possible to

<algorithm>
catch the sustain pedal MIDI event and *not* transmit it to the card but store the information locally (in the program), then

*not* transmit the "Note off" event to the soundcard when the pedal is pushed, and

transmit the "Note on" events to the soundcard but put a "Note off" event immediately in front of it.
</algorithm>

If I'm not mistaken, that should result in exactly the same effect as the original soundcard handling, with the difference that there never will be more than one oscillator playing the same note and unless you really hit more than 32 keys at once, you won't run out of polyphony.

Is there any way to do this in MidiOx ?
If not, I think this would be a great feature (and I think quite easy to implement also)

Title: Re: That nasty sustain pedal
Post by rumborak on Nov 3rd, 2002, 3:11pm
Ah ! I found the answer myself.
Here it goes (for those interested):
Awesome ! No longer polyphony problems when playing piano !
(As long as I don't play more than 32 keys at once  ;D)

----------------- JScript ---------------------------
var Pedal_pressed = 0;
var del_noff = new Array(256); // This array stores if we need to send a delayed note off event when the pedal is released

function Mox_OnMidiInput( timestamp, port, status, d1, d2 ) {
if ((status == 176)&&(d1 == 64)) { // Pedal event
  if (d2 > 64) {
    Pedal_pressed = 1;
  }else{
    Pedal_pressed = 0;
    for (var count = 0;count < 255;count++) {
      if (del_noff[count] == 1) {
        Mox.OutputMidiMsg( -1,144,count,0);  
      del_noff[count] = 0;
      }
    }
  }
}else if (status == 144) { //Note event
  if (d2 == 0) { // Note off
    if (Pedal_pressed == 0) {
      Mox.OutputMidiMsg( -1,status,d1,d2);
    }else{
      del_noff[d1] = 1;
    }
  }else{ // Note on
      Mox.OutputMidiMsg( -1,status,d1,0);
      Mox.OutputMidiMsg( -1,status,d1,d2);
      del_noff[d1] = 0;
  }
}
}

var Mox = WScript.CreateObject("MIDIOX.MOXScript.1","Mox_On");
var dev = Mox.GetFirstOpenMidiInDev();
dev = Mox.GetFirstOpenMidiOutDev();

Mox.ShutdownAtEnd = 1;
Mox.FireMidiInput = 1;
Mox.DivertMidiInput = 1;

while( !Mox.ShouldExitScript ) {
 Mox.sleep(10);
}

WScript.Quit();
-----------------------------------------------------


Title: Re: That nasty sustain pedal
Post by rumborak on Nov 3rd, 2002, 3:16pm
Oh, for those not familiar with the scripting functionality in Midi-OX:
Copy the stuff between the "------.." lines into Notepad and save as "Sustainer.js". Double-click on the file and there you go !



MIDI-OX User Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.