Пример #1
0
 def _run_scenes_impl(self, scenes, events):
     # set up a dummy engine
     setup._config_impl(backend='dummy')
     e = engine.Engine()
     e.setup(scenes, None, None, None)
     r = []
     # allow input to be a single event, as well as a sequence of events
     if not misc.issequence(events):
         events = [events]
     # process each event, append each list of output events to the
     # returned list of lists
     for ev in events:
         ret = e.process_event(ev)[:]
         for rev in ret:
             rev.__class__ = MidiEvent
         r.append(ret)
     return r
Пример #2
0
 def _run_scenes_impl(self, scenes, events):
     # set up a dummy engine
     setup._config_impl(backend='dummy')
     e = engine.Engine()
     e.setup(scenes, None, None, None)
     r = []
     # allow input to be a single event, as well as a sequence of events
     if not misc.issequence(events):
         events = [events]
     # process each event, append each list of output events to the
     # returned list of lists
     for ev in events:
         ret = e.process_event(ev)[:]
         for rev in ret:
             rev.__class__ = MidiEvent
         r.append(ret)
     return r
Пример #3
0
def process_file(infile, outfile, patch):
    """
    Process a MIDI file, using pysmf.
    """
    import smf

    # create dummy engine with no inputs or outputs
    _setup._config_impl(backend='dummy')
    engine = Engine()
    engine.setup({_util.offset(0): patch}, None, None, None)

    # open input file
    smf_in = smf.SMF(infile)

    # create SMF object with same ppqn and number of tracks as input file
    smf_out = smf.SMF()
    smf_out.ppqn = smf_in.ppqn
    for n in range(len(smf_in.tracks)):
        smf_out.add_track()

    for smf_ev in smf_in.events:
        if smf_ev.midi_buffer[0] == 0xff:
            # event is metadata. copy to output unmodified
            smf_out.add_event(smf.Event(smf_ev.midi_buffer),
                              smf_ev.track_number,
                              pulses=smf_ev.time_pulses)
        else:
            ev = _mididings.buffer_to_midi_event(smf_ev.midi_buffer,
                                                 smf_ev.track_number,
                                                 smf_ev.time_pulses)

            # use base class version of process_event() to bypass calling
            # ev._finalize(), which would fail since ev is of type
            # _mididings.MidiEvent.
            for out_ev in _mididings.Engine.process_event(engine, ev):
                buf, track, pulses = _mididings.midi_event_to_buffer(out_ev)
                smf_out.add_event(smf.Event(buf), track, pulses=pulses)

    smf_out.save(outfile)
Пример #4
0
def process_file(infile, outfile, patch):
    """
    Process a MIDI file, using pysmf.
    """
    import smf

    # create dummy engine with no inputs or outputs
    _setup._config_impl(backend='dummy')
    engine = Engine()
    engine.setup({_util.offset(0): patch}, None, None, None)

    # open input file
    smf_in = smf.SMF(infile)

    # create SMF object with same ppqn and number of tracks as input file
    smf_out = smf.SMF()
    smf_out.ppqn = smf_in.ppqn
    for n in range(len(smf_in.tracks)):
        smf_out.add_track()

    for smf_ev in smf_in.events:
        if smf_ev.midi_buffer[0] == 0xff:
            # event is metadata. copy to output unmodified
            smf_out.add_event(smf.Event(smf_ev.midi_buffer),
                              smf_ev.track_number, pulses=smf_ev.time_pulses)
        else:
            ev = _mididings.buffer_to_midi_event(smf_ev.midi_buffer,
                              smf_ev.track_number, smf_ev.time_pulses)

            # use base class version of process_event() to bypass calling
            # ev._finalize(), which would fail since ev is of type
            # _mididings.MidiEvent.
            for out_ev in _mididings.Engine.process_event(engine, ev):
                buf, track, pulses = _mididings.midi_event_to_buffer(out_ev)
                smf_out.add_event(smf.Event(buf), track, pulses=pulses)

    smf_out.save(outfile)