2
votes

In my band, all musicians have both hands busy at any time. However, we want to add whole synthesizer chords (1/4 .. whole note length), maybe triggered by a simple foot switch every time (because playing along a sequencer is currently too difficult for us).

Some time ago I wrote a (Windows) console application in C (MinGW) that converted incoming MIDI events to text, piped that text to an external program (AWK script), and re-converted that external program's text output back to MIDI events. Basically every sort of filtering or event generation was possible; I actually produced chords triggered by simple control messages; I kept note-ONs in memory to be able to -OFF them whenever a new chord was sent, etc. - the actual processing (execution) times were not a problem at all(!)

But I had to understand that not only latency, but also the notoriously unreliable (with respect to "when", "for how long") user application OS multitasking/switching made this concept practically worthless at least for "real-time" use. There were always clearly perceivable delays, of unpredictable duration. I read about user-mode driver programming and downloaded some resources, but somehow stopped working on that project without a real result.

Apart from that specific project, I even have some experience in writing small "virtual" machines that allow for expressing exactly the variables, conditionals and math, stored as a token tree and processed quite fast. Maybe there is also the option to embed Lua, V8, or anything like that. So calling another (external) program is not necessarily the issue here, since that can be avoided.

The problem that remains is that the processing as a whole is still done by a (user) application. So I figure there is no way around a (user mode) driver, in this scenario.

Alternatively, I was even considering (more "real-time") hardware - a Raspi or the like - but then the MIDI interface may be an additional challenge.

Is there any hardware or software solution (or project) available that may serve as a base for such a _Generic MIDI filter/processor_? Apart from predictable timing behaviour, it is desirable not to need a (C) compilation environment when building filters/rules, since that "creative" step will probably happen in our rehearsal room (laptop available), which is certainly not a "programming lab". Text-based "programs" are fine - for long-term I'll maybe build a GUI for wiring/generating rules anyway.

1
As long as no other stuff is running, multitasking should not introduce noticeable delays. I'd guess the problem are timer delays in your application, or the startup time of your AWK interpreter. - CL.
Interesting but very long, very broad and very off-topic doe SO question. On Windows or Linux uou should require no drivers, MIDI is a UART serial protocol..MIDI is a rather simple hardware interface, requiring an opto-isolator on the MIDI IN (which you may not need) and just resistors for MIDI OUT. The signals to the hardware interface can be driven directly from a UART at TTL (5v) logic levels and 31.25 baud . Many micros use 3.3v logic, which would not be strictly compliant, but will probably work - a question really for electronics.stackexchange.com. - Clifford
I am unclear whet the conversion from MIDI to text then back is for. It is possibly the cause of the latency, I'd be surprised if the you experienced such problems if the whole thing were done in C at the binary MIDI message level unless the PC were busy with other activities. - Clifford
midi is a fairly slow uart interface, should have tons of overhead. Note raspberry pi is not any more real-time than a windows pc or other, it is just another computer, granted easier to program bare metal, and remove some of those layers but can do that with a microcontroller as well, depends on what exactly you want to do with the data. converting to text, etc is a bit part of your bottleneck, you reason you cant have a nice user interface, but tune the processing for performance not ease of programming. - old_timer
I expect this question to get closed quickly, but you should look at Max or PureData, both of which exist for exactly this reason. - bgporter

1 Answers

0
votes

MIDI is handled pretty well in Windows. I'm not sure the source of the original problems you had. No doubt there is some latency though.

You can handle this in real time with a microcontroller. The good news is that you don't even have to build the hardware. Off-the-shelf controllers are available for this. For example: http://www.midisolutions.com/prodevp.htm