I brought this up a while back but didn't pursue it too far because I
foresaw the need for this, but hadn't actually arrived at the point
where I did need it.  So now I've arrived there, and I'm thinking
about it more seriously.

Basically, what I want is the ability to merge timestamped midi
streams.  Pm_Write insists that the timestamps be non-decreasing, and
merged streams would mean I could have two non-decreasing streams of
msgs.  Clearly this has to be done at the driver level, since this is
where the timing is handled, so I have to do some spelunking into
portmidi.  Here are some possibilities I came up with:

1- Make a non-portable extension to portmidi that provides a new
function, like "WriteThru".  Unfortunately I can't re-use any of the
portmidi implementation (I'm on a mac so it would be
pm_mac/pmmacosxcm.c) since everything is static, so I'd basically be
writing another non-portable MIDI interface, at which point why use
portmidi at all?

2- Do like the above, but modify portmidi itself.  I could either do
something like Pm_WriteThru, or an explicit merge like
Pm_OpenMergedOutput(PortMidiStream **new_stream, PortMidiStream
*merge_to_stream).  Since I only know how to implement this for Core
MIDI, it would have #error "not implemented" for the other platforms
until someone added them.  It's kinda complicated but it is explicit.

3- Modify portmidi to provide merged streams implicitly for 0
timestamp events: Pm_Write works normally with non-decreasing
timestamps, but 0 timestamps go out immediately.  This is both the
simplest to implement (and it's what I've already done) and I think is
the nicest interface, but is not good for portability as long as it's
only implemented for OS X because it's easy to implicitly rely on it
and then get weird output on another platform that doesn't have it
implemented.

So what's the consensus here?  I think #1 is not really realistic.
Unless I could send a patch just to unstatic certain things from
pmosxcm.c.  #2 is more complicated to implement and harder to use, but
at least is explicit.  I'd prefer #3, but I'm not sure if people think
it would be enough to put a note in the documentation that special
treatment for timestamp 0 is not universally implemented.  Of course
the best would be to implement it for the other platforms.  I'm pretty
sure alsa supports merging and it's probably not much harder to add
than it was for OS X, but I couldn't readily test it (well, I probably
could with some setup work).  I don't know about windows, maybe
there's someone out there who does?


To recap the motivation for such a feature in the first place, I have
a sequencer which (like all sequencers I imagine) writes timestamped
midi msgs.  It also (like many sequencers) supports recording while
playing and midi thru so you can hear what you're recording, which
means merging msgs that arrive in realtime and can't be scheduled with
prescheduled msgs.  So it seems to me like any sequencer that supports
record-during-play needs to be able to merge streams, which is why I
think this is a good candidate for inclusion into a portable midi
library (not sure how it's gotten along until now without it, though
my impression is that it's not very widely used, none of the open
source sequencers I've looked at use it), and also why I'm interested
in merging a timestamped stream with 0 "now" events rather than
generally merging two timestamped streams.

Anyway, I hope this all makes sense.  I could send out a patch right
now for OS X, and I could possibly do an alsa version if there were
anyone clamoring for it and maybe willing to test it, but definitely
can't do a windows version.  Or I could just keep a patched version of
portmidi and distribute that with my app when the time comes, clearly
not the best solution, but practical and works.
_______________________________________________
media_api mailing list
[email protected]
http://lists.create.ucsb.edu/mailman/listinfo/media_api

Reply via email to