def disconnect(self):
        # sign off
        for channel in range(0, 15):
            self.send_event(CCMidiEvent(channel=channel, param=120))
            self.send_event(CCMidiEvent(channel=channel, param=64))

        self.is_disconnecting.set()

        if self.jstation_wait_for_events_thread:
            # wait until waiting thread is terminated
            self.jstation_wait_for_events_thread.join()
            self.jstation_wait_for_events_thread = None

        if self.js_port_in:
            self.seq.disconnect_ports(
                (self.seq.client_id, self.port_out),
                (self.js_port_in.client, self.js_port_in.port))
        if self.js_port_out:
            self.seq.disconnect_ports(
                (self.js_port_out.client, self.js_port_out.port),
                (self.seq.client_id, self.port_in))
        self.js_port_in = None
        self.js_port_out = None
        self.is_connected = False
        self.is_disconnecting.clear()
Exemplo n.º 2
0
def test():
    print('\n==== MidiEventFactory test')

    CCMidiEvent.register_event_type_builder()
    CCMidiEvent.register()

    JStationSysexEvent.register_event_type_builder()
    WhoAmIResponse.register()

    sysex_data = [
        0xf0, 0, 0, 0x10, 0x7f, 0x54, 0x41, 0, 1, 0, 3, 0, 0, 0, 0, 0, 0, 0, 1,
        121, 0xf7
    ]
    print('input sysex data: %s' %
          ['x%02x' % (val & 0xff) for val in sysex_data])

    sysex_seq_event = alsaseq.SeqEvent(alsaseq.SEQ_EVENT_SYSEX)
    sysex_evt_data = dict()
    sysex_evt_data['ext'] = sysex_data
    sysex_seq_event.set_data(sysex_evt_data)

    factory = MidiEventFactory()
    sysex_event = factory.build_from_seq_event(sysex_seq_event)
    if sysex_event:
        print(sysex_event.is_valid())
        print(str(sysex_event))
    else:
        print('sysex not recognised')

    cc_seq_event = alsaseq.SeqEvent(alsaseq.SEQ_EVENT_CONTROLLER)
    cc_data = dict()
    cc_data['control.channel'] = 1
    cc_data['control.param'] = 34
    cc_data['control.value'] = 20
    cc_seq_event.set_data(cc_data)

    cc_event = factory.build_from_seq_event(cc_seq_event)
    if cc_event:
        print(cc_event.is_valid())
        print(str(cc_event))
    else:
        print('cc not recognised')
    def __init__(self, app_name, main_window):
        self.factory = MidiEventFactory()

        CCMidiEvent.register_event_type_builder()
        CCMidiEvent.register(self.one_parameter_cc_callback)

        PrgChangeEvent.register_event_type_builder()
        PrgChangeEvent.register(self.program_change_callback)

        JStationSysexEvent.register_event_type_builder()

        BankDumpRequest.register()
        EndBankDumpResponse.register(self.end_bank_dump_callback)

        NotifyStore.register(self.notify_store_callback)
        NotifyUtility.register(self.notify_utility_callback)

        OneProgramRequest.register()
        OneProgramResponse.register(self.one_program_callback)

        PRGIndicesRequest.register()
        PRGIndicesResponse.register(self.program_indices_callback)

        ReceiveProgramUpdate.register(self.program_update_response)
        ReloadProgram.register()
        RequestProgramUpdate.register()

        StartBankDumpResponse.register(self.default_event_callback)

        ToMessageResponse.register(self.response_to_message_callback)

        UtilitySettingsRequest.register()
        UtilitySettingsResponse.register(self.utility_settings_callback)

        WhoAmIRequest.register(self.who_am_i_callback_req)
        WhoAmIResponse.register(self.who_am_i_callback)

        self.is_connected = False
        self.is_disconnecting = Event()
        self.is_response_received_cndt = Condition()

        self.receive_channel = -1
        self.sysex_channel = -1

        self.js_port_in = None
        self.js_port_out = None

        self.jstation_wait_for_events_thread = None

        self.main_window = main_window
        self.is_disconnecting.clear()

        self.seq = alsaseq.Sequencer('hw', app_name, alsaseq.SEQ_OPEN_DUPLEX,
                                     alsaseq.SEQ_NONBLOCK, 1)
        if self.seq == None:
            print('Error while opening sequencer')
            exit(1)

        self.get_clients()

        self.port_out = self.seq.create_simple_port(
            'Output',
            alsaseq.SEQ_PORT_CAP_READ | alsaseq.SEQ_PORT_CAP_SUBS_READ)
        self.port_in = self.seq.create_simple_port(
            'Input', alsaseq.SEQ_PORT_TYPE_APPLICATION,
            alsaseq.SEQ_PORT_CAP_WRITE | alsaseq.SEQ_PORT_CAP_SUBS_WRITE)
 def send_command(self, command, value):
     success = False
     return self.send_event(
         CCMidiEvent(self.receive_channel, command, value))