Exemplo n.º 1
0
    def __call__(self, event, data=None):
        mididata, deltatime = event
        self._wallclock += deltatime
        mm = midi.MidiMessage(mididata)

        msg = 'niet'

        if mm.maintype() == 'NOTEON':

            txt = self.xls.getCell(
                -1, mm.octave(),
                max(1, 16 * (self.bank) + 1) + mm.note_abs() + 1)
            if txt:
                msg = {'topic': '/add', 'payload': txt}

        elif mm.maintype() == 'NOTEOFF':
            txt = self.xls.getCell(
                -1, mm.octave(),
                max(1, 16 * (self.bank) + 1) + mm.note_abs() + 1)
            if txt:
                msg = {'topic': '/rm', 'payload': txt}

        elif mm.maintype() == 'CC':

            # CC 14 = ARPPEGIO SPEED
            if mm.values[0] == 12:
                msg = {'topic': '/speed', 'payload': str(mm.values[1] * 10)}

            # CC 0 = Bank
            elif mm.values[0] == 0:
                self.bank = mm.values[1]
                print('bank', mm.values[1])

            # CC 120 / 123 == ALL OFF
            if mm.values[0] == 120 or mm.values[0] == 123:
                msg = {'topic': '/clear', 'payload': ""}

        else:
            return

        if msg != 'niet':
            print('webapp', msg)
            sio.emit('mqtt', msg)
Exemplo n.º 2
0
    def __call__(self, event, data=None):
        msg, deltatime = event
        self._wallclock += deltatime
        mm = midi.MidiMessage(msg)

        if mm.maintype() == 'NOTEON' or mm.maintype() == 'CC' or mm.maintype(
        ) == 'NOTEOFF':

            # NOTEON = dmx channel // CC moins 20 = dmx channel

            # CC shift -20
            note = mm.values[0]
            if mm.maintype() == 'CC':
                note -= 20

            # Set new value
            if note >= 0:
                if note < FIXTURE_SIZE:
                    if mm.maintype() == 'NOTEOFF':
                        # if  self.payload[mm._channel][note] != 0:
                        #     self.payload[mm._channel][note] = 0
                        #     self.dirty[mm._channel] = DIRTY_PUSH
                        pass
                    else:
                        if self.payload[mm._channel][note] != mm.values[1] * 2:
                            self.payload[mm._channel][note] = mm.values[1] * 2
                            self.dirty[mm._channel] = DIRTY_PUSH

                # CLEAR channel
                elif note == 127:
                    self.payload[mm._channel] = bytearray(FIXTURE_SIZE)
                    self.dirty[mm._channel] = DIRTY_PUSH

            # CC 119 / 120 / 123 == ALL OFF
            if mm.maintype() == 'CC' and (mm.values[0] == 120 or mm.values[0]
                                          == 119 or mm.values[0] == 123):
                self.clear()
                self.dirty[mm._channel] = True
Exemplo n.º 3
0
    def __call__(self, event, data=None):
        msg, deltatime = event
        self._wallclock += deltatime
        mm = midi.MidiMessage(msg)

        # FILTERS
        if mm.maintype() not in ['NOTEON', 'NOTEOFF', 'CC']:
            print('discarded')
            return
        if mm.maintype() == 'CC':
            if mm.values[0] not in [1, 2, 7, 119, 120]:
                print('discarded')
                return

        ## QOS
        # VOLUME CC 7
        if mm.maintype() == 'CC' and mm.values[0] == 7:
            qos = 0
        # OTHERS
        else:
            qos = 1

        # PAYLOAD
        payload = '-'.join([str(v).zfill(3) for v in mm.message[:3]])

        if mm.channel() == 16:
            self.mqttc.publish('k32/all/midi',
                               payload=payload,
                               qos=qos,
                               retain=False)
            print('k32/all/midi', payload, mm.maintype())
        else:
            self.mqttc.publish('k32/c' + str(mm.channel()) + '/midi',
                               payload=payload,
                               qos=qos,
                               retain=False)
            print('k32/c' + str(mm.channel()) + '/midi', payload,
                  mm.maintype())
Exemplo n.º 4
0
    def __call__(self, event, data=None):
        msg, deltatime = event
        self._wallclock += deltatime
        mm = midi.MidiMessage(msg)

        # print(mm.maintype(), 'chan '+str(mm.channel()), mm.values)

        if mm.maintype() in ['NOTEON', 'NOTEOFF']:

            # NOTEON 127
            if mm.maintype() == 'NOTEON' and mm.note() == 127:
                self.mqttc.publish('k32/c' + str(mm.channel()) +
                                   '/titre/clear',
                                   payload="",
                                   qos=1,
                                   retain=False)
                print('NOTE 127: k32/c' + str(mm.channel()) + '/titre/clear')

            # NOTES TXT from XLS
            else:
                txt = self.xls.getCell(self.bank[mm.channel()],
                                       mm.channel() + 1,
                                       mm.note() + 2)
                if txt:
                    txt = txt.replace("\n", ";")
                    txt = txt.replace("\r", "")

                    sub = txt.split(";")
                    if len(sub) > 1:
                        sub1 = ("_").join(sub[1:])
                        txt = sub[0] + ";" + sub1

                    if txt.endswith(';'):
                        txt += "_"

                    txt += '§' + getMode(txt) + '§' + str(mm.values[1])

                    if mm.maintype() == 'NOTEON':
                        if mm.values[1] > 1:
                            self.mqttc.publish('k32/c' + str(mm.channel()) +
                                               '/titre/text',
                                               payload=txt,
                                               qos=0,
                                               retain=False)  #add
                            print('k32/c' + str(mm.channel()) + '/titre/text',
                                  txt)
                        else:
                            self.mqttc.publish('k32/c' + str(mm.channel()) +
                                               '/titre/clear',
                                               payload='',
                                               qos=0,
                                               retain=False)  #add
                            print('k32/c' + str(mm.channel()) + '/titre/clear')

                    #elif mm.maintype() == 'NOTEOFF':
                    #    self.mqttc.publish('k32/c'+str(mm.channel())+'/titre/clear', payload=txt, qos=0, retain=False) #rm
                    #    print('k32/c'+str(mm.channel())+'/titre/clear', txt)

        elif mm.maintype() == 'CC':

            # CC 14 = ARPPEGIO SPEED
            if mm.values[0] == 12:
                self.mqttc.publish('k32/c' + str(mm.channel()) +
                                   '/titre/speed',
                                   payload=str(128 - mm.values[1]),
                                   qos=1,
                                   retain=False)
                print('k32/c' + str(mm.channel()) + '/titre/speed',
                      str(128 - mm.values[1]))

            # CC 0 = Bank
            elif mm.values[0] == 0:
                self.bank[mm.channel()] = mm.values[1]
                self.mqttc.publish('k32/all/titre/clear',
                                   payload="",
                                   qos=1,
                                   retain=False)
                print('bank', mm.values[1])

            # CC 120 / 123 == ALL OFF
            if mm.values[0] == 120 or mm.values[0] == 123:
                self.mqttc.publish('k32/c' + str(mm.channel()) +
                                   '/titre/clear',
                                   payload="",
                                   qos=1,
                                   retain=False)
                print('CC 120/127: k32/c' + str(mm.channel()) + '/titre/clear')