# 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
from mididings.extra.per_channel import PerChannel as _PerChannel
            self.held_notes.add(ev.note)
            return ev
        elif ev.type == _m.NOTEOFF:
            self.held_notes.discard(ev.note)

            # send note off only if the note is not currently being sustained
            if ev.note not in self.sustained_notes:
                return ev
            else:
                return None
        else:
            # everything else: return as is
            return ev


def PedalToNoteoff(ctrl=64, sostenuto=False):
    """
    Convert sustain pedal control changes to note-off events,
    by delaying note-offs until the pedal is released.

    :param ctrl:
        The pedal's controller number.

    :param sostenuto:
        If true act like a sostenuto pedal, instead of a regular sustain
        pedal.
    """
    if sostenuto:
        proc = _m.Process(_PerChannel(lambda: _SostenutoToNoteoff(ctrl)))
    else:

# 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/pedal_noteoff.py
import mididings as _m
import mididings.event as _event
from mididings.extra.per_channel import PerChannel as _PerChannel

            self.held_notes.add(ev.note)
            return ev
        elif ev.type == _m.NOTEOFF:
            self.held_notes.discard(ev.note)

            # send note off only if the note is not currently being sustained
            if ev.note not in self.sustained_notes:
                return ev
            else:
                return None
        else:
            # everything else: return as is
            return ev


def PedalToNoteoff(ctrl=64, sostenuto=False):
    """
    Convert sustain pedal control changes to note-off events,
    by delaying note-offs until the pedal is released.

    :param ctrl:
        The pedal's controller number.

    :param sostenuto:
        If true act like a sostenuto pedal, instead of a regular sustain
        pedal.
    """
    if sostenuto:
        proc = _m.Process(_PerChannel(lambda: _SostenutoToNoteoff(ctrl)))
    else:

        proc = _m.Process(_PerChannel(lambda: _SustainToNoteoff(ctrl)))