# Path: mididings/extra/per_channel.py
# class PerChannel(object):
#     """
#     Utility class, usable with Process() and Call(), that delegates events
#     to different instances of the same class, using one instance per
#     channel/port combination.
#     New instances are created as needed, using the given factory function,
#     when the first event with a new channel/port arrives.
#     """
#     def __init__(self, factory):
#         self.channel_proc = {}
#         self.factory = factory
# 
#     def __call__(self, ev):
#         k = (ev.port, ev.channel)
#         if k not in self.channel_proc:
#             self.channel_proc[k] = self.factory()
#         return self.channel_proc[k](ev)


import mididings as _m
import mididings.event as _event
import mididings.engine as _engine
from mididings.extra.per_channel import PerChannel as _PerChannel
            n = None
            d = False

        dt = ((t - self.notes[self.current_note][1])
                if self.current_note in self.notes else 0.0)

        # change current note if...
        if (
            # note number changed and...
            n != self.current_note and (
                # we're always retriggering notes
                self.retrigger or
                # lowest/heighest voice are a bit of a special case
                self.voice in (0, -1) or
                # current note is no longer held
                self.current_note not in self.notes or
                # our previous note is very recent
                (ev.type == _m.NOTEON and dt < self.time) or
                # the new note is "better" than previous one
                self.diverted and not d
        )):
            # yield note-off for previous note (if any)
            if self.current_note:
                yield _event.NoteOffEvent(
                            ev.port, ev.channel, self.current_note, 0)
                self.current_note = None

            dt = (t - self.notes[n][1]) if n in self.notes else 0.0

            # yield note-on for new note (if any)

# Path: mididings/extra/per_channel.py
# class PerChannel(object):
#     """
#     Utility class, usable with Process() and Call(), that delegates events
#     to different instances of the same class, using one instance per
#     channel/port combination.
#     New instances are created as needed, using the given factory function,
#     when the first event with a new channel/port arrives.
#     """
#     def __init__(self, factory):
#         self.channel_proc = {}
#         self.factory = factory
# 
#     def __call__(self, ev):
#         k = (ev.port, ev.channel)
#         if k not in self.channel_proc:
#             self.channel_proc[k] = self.factory()
#         return self.channel_proc[k](ev)


# Path: mididings/extra/voices.py
import mididings as _m
import mididings.event as _event
import mididings.engine as _engine
from mididings.extra.per_channel import PerChannel as _PerChannel

            n = None
            d = False

        dt = ((t - self.notes[self.current_note][1])
                if self.current_note in self.notes else 0.0)

        # change current note if...
        if (
            # note number changed and...
            n != self.current_note and (
                # we're always retriggering notes
                self.retrigger or
                # lowest/heighest voice are a bit of a special case
                self.voice in (0, -1) or
                # current note is no longer held
                self.current_note not in self.notes or
                # our previous note is very recent
                (ev.type == _m.NOTEON and dt < self.time) or
                # the new note is "better" than previous one
                self.diverted and not d
        )):
            # yield note-off for previous note (if any)
            if self.current_note:
                yield _event.NoteOffEvent(
                            ev.port, ev.channel, self.current_note, 0)
                self.current_note = None

            dt = (t - self.notes[n][1]) if n in self.notes else 0.0

            # yield note-on for new note (if any)

            if n is not None and (