1

I'm trying to create an infinite loop to poll for midi input. The loop I have here is technically infinite but I think what's happening is it's getting stuck on the WScript.StdIn.ReadLine() method. It seems that it waits each time for the user to enter something before it continues. I think this because when I enter a character, any midi input in that instance will get routed and the WScript.Echo message will go off.

How can I get it to not wait but check in that instance if there's a character or not? so that the loop doesn't get stopped waiting for input. Is there another ReadLine() method that would work for what I'm looking for?

Here's the code:

while (true) {
    str = WScript.StdIn.ReadLine();
    if (str == 'q')
        break;
    // WScript.StdOut.Write("the while loop continues..."
    WScript.Echo("the while loop continues...")

    msgStr = mox.GetMidiInput()

    if (msgStr !== "") {
    msgArray = msgStr.split(",")
    tStamp = msgArray[0]
    port = msgArray[1]
    stat = msgArray[2]
    data1 = msgArray[3]
    data2 = msgArray[4]

    mox.OutputMidiMsg( 3, stat, data1, data2);
    } else {
        continue;
    }
}

EDIT:

Right now I just got rid of the ReadLine() because I read on MSDN that it waits for an enter keypress before it returns and I don't think there are any arguments to change that... so I have an infinite loop like I want but I have to resort to ctrl+c to exit it. Anybody have any ideas for a construct that would allow me to quit via the keyboard somehow?

EDIT 2:

I found out that midiox actually provides a method to be polled to exit the script and it works great.

Jpaji Rajnish
  • 1,491
  • 4
  • 17
  • 35

0 Answers0