Esempio n. 1
0
def updateMac(request):
    if request.method == 'POST':       
        mac_muse = request.POST['muse-mac']
        raspb_mac = request.POST['raspberry-mac']
        raspb = rasp_device.objects.get(mac_address=raspb_mac)
        if mac_muse == '':
            free_muse = raspb.connected_muse
            if free_muse != None:
                free_muse.used = False
                free_muse.save()
            raspb.connected_muse = None
            if raspb.ip != None:
                print("sending message to disconnect")
                c = liblo.Message('/change_mac', 'disconnected')
                outputAddress = liblo.Address(raspb.ip, 6001)
                liblo.send(outputAddress, c)
        else:
            free_muse = raspb.connected_muse
            if free_muse != None:
                free_muse.used = False
                free_muse.save()
            muse = muse_device.objects.get(mac_address=mac_muse)
            raspb.connected_muse = muse
            muse.used = True
            muse.save()
            if raspb.ip != None:
                print("sending message")
                c = liblo.Message('/change_mac', raspb.connected_muse.mac_address)
                outputAddress = liblo.Address(raspb.ip, 6001)
                liblo.send(outputAddress, c)
        raspb.save()
    return HttpResponseRedirect('/')
Esempio n. 2
0
 def testSendBundle(self):
     self.server.add_method('/foo', 'i', self.callback_dict)
     self.server.add_method('/bar', 's', self.callback_dict)
     self.server.send(1234, liblo.Bundle(
         liblo.Message('/foo', 123),
         liblo.Message('/bar', "blubb")
     ))
     self.assertTrue(self.server.recv(100))
     self.assertEqual(self.cb['/foo'].args[0], 123)
     self.assertEqual(self.cb['/bar'].args[0], "blubb")
Esempio n. 3
0
    def reset_display(self):
        osc_msg = liblo.Message('/set_output')
        osc_msg.add(('i', RESET_PIN_INDEX))
        osc_msg.add(('i', 0))

        liblo.send(self._sensei_address, osc_msg)
        time.sleep(0.05)
        osc_msg = liblo.Message('/set_output')
        osc_msg.add(('i', RESET_PIN_INDEX))
        osc_msg.add(('i', 1))      

        liblo.send(self._sensei_address, osc_msg)

        time.sleep(0.5)
Esempio n. 4
0
 def update(self):
     """
     update is called when value is updated
     might be used to send it to network or other protocols
     """
     for out in self.parent.get_device().outputs:
         try:
             split = out.port.split(':')
             ip_add = split[0]
             udp = split[1]
             try:
                 target = liblo.Address(ip_add, int(udp))
                 if __dbug__ >= 3:
                     print('connect to : ' + ip_add + ':' + str(udp))
             except liblo.AddressError as err:
                 if __dbug__ >= 3:
                     print('liblo.AddressError' + str(err))
             #msg = liblo.Message('/' + self.address)
             msg = liblo.Message(self.address)
             if isinstance(self.value, list):
                 # this is a list of values to send
                 for arg in self.value:
                     arg = check_type(arg)
                     msg.add(arg)
             else:
                 # this is a single value to send
                 msg.add(self.value)
             liblo.send(target, msg)
             if __dbug__ >= 3:
                 print('update ' + self.name + ' to value ' +
                       str(self.value))
             return True
         except NoOutputError:
             return False
Esempio n. 5
0
    def get_data(self, path, args):
        # Clear List for update
        print("Begin of sending Data..")
        msg = liblo.Message("/data/clear")
        liblo.send(self.puredata, msg)

        for i in range(0, len(self.data)):
            #            print(self.data[i])
            if self.data[i] != 'null':
                liblo.send(self.puredata, "/data/add", ('i', i),
                           ('s', self.data[i]))
#            sleep(0.01)

        msg = liblo.Message("/data/update")
        liblo.send(self.puredata, msg)

        print("Data sended")
Esempio n. 6
0
 def testSendMessage(self):
     self.server.add_method('/blah', 'is', self.callback)
     m = liblo.Message('/blah', 42, 'foo')
     self.server.send(1234, m)
     assert self.server.recv() == True
     assert self.cb.types == 'is'
     assert self.cb.args[0] == 42
     assert self.cb.args[1] == 'foo'
Esempio n. 7
0
 def testSendMessage(self):
     self.server.add_method('/blah', 'is', self.callback)
     m = liblo.Message('/blah', 42, 'foo')
     self.server.send(1234, m)
     self.assertTrue(self.server.recv())
     self.assertEqual(self.cb.types, 'is')
     self.assertEqual(self.cb.args[0], 42)
     self.assertEqual(self.cb.args[1], 'foo')
Esempio n. 8
0
 def testSendLong(self):
     l = 1234567890123456
     self.server.add_method('/long', 'h', self.callback)
     m = liblo.Message('/long', l)
     self.server.send(1234, m)
     self.assertTrue(self.server.recv())
     self.assertEqual(self.cb.types, 'h')
     self.assertEqual(self.cb.args[0], l)
Esempio n. 9
0
 def setupOutputServer(self, context, envars):
     if load_liblo_success == True:
         #For sending
         self.address = liblo.Address(envars.udp_out, envars.port_out)
         msg = liblo.Message("/NodeOSC")
         msg.add("pyliblo server started up")
         self.st.send(self.address, msg)
         print("PyLiblo Server sended test message to " + envars.udp_out +
               " on port " + str(envars.port_out))
Esempio n. 10
0
 def answer(self, client_address, address, answer, port=33333):
     if answer == True:
         answer = 1
     if answer == False:
         answer = 0
     target = liblo.Address(client_address, port)
     msg = liblo.Message(address)
     msg.add(answer)
     liblo.send(target, msg)
Esempio n. 11
0
 def set_rot_enc_initial_val(self):
     """
     Needed so that the rotary encoder is properly initialized and it can be rutned counter-clockwise from a start
     https://forum.elk.audio/t/blackboard-turning-rotary-encoder-has-no-effect-if-i-dont-turn-it-right-first/565/9
     """
     osc_msg = liblo.Message('/set_output')
     osc_msg.add(('i', ROT_ENC_ID))
     osc_msg.add(('f', 0.5))
     liblo.send(self._sensei_address, osc_msg)
Esempio n. 12
0
 def set_led(self, idx, val):
     """ Immediately set one of the LEDs on the board.
         Inputs:
             idx : LED idx from 0 to 8
             val : 1 = LED on, 0 = LED off
     """
     osc_msg = liblo.Message('/set_output')
     osc_msg.add(('i', LED_BASE_IDX+idx))
     osc_msg.add(('f', val))
     liblo.send(self._sensei_address, osc_msg)
Esempio n. 13
0
 def open_callback(self, path, args):
     self.session_dir, self.display_name, self.client_id = args
     self.session_dir = os.path.split(self.session_dir)[0]
     self.begin_logging()
     self.log_write("session dir is {}".format(self.session_dir))
     self.log_write('attempting to commit... ', False)
     self.save()
     self.loaded.emit(self.session_dir)
     message = liblo.Message('/reply', "/nsm/client/open", 'done')
     liblo.send(self.NSM_URL, message)
Esempio n. 14
0
def make_message_manual(path, types, *args):
    if len(types) != len(args):
        sys.exit("length of type string doesn't match number of arguments")

    msg = liblo.Message(path)
    try:
        for a, t in zip(args, types):
            msg.add((t, a))
    except Exception, e:
        sys.exit(str(e))
Esempio n. 15
0
    def reply(self, default_path, sender, *args, **kwargs):
        if kwargs and 'merge' in kwargs.keys():
            kwargs['merge'] = True
        else:
            kwargs['merge'] = False

        try:
            if type(args[0]) == str and args[0][0] == '/':
                args = list(args)
                _msg = lo.Message(args.pop(0), *args)
            elif len(args) >= 2 and kwargs['merge']:
                args = list(args)
                path = args.pop(0)
                _msg = lo.Message(default_path + '/' + path, *args)
            else:
                _msg = lo.Message(default_path, *args)
        except (TypeError, KeyError, IndexError):
            _msg = lo.Message(default_path, *args)
        self.send(sender, _msg)
        return _msg
Esempio n. 16
0
def make_message_auto(path, *args):
    msg = liblo.Message(path)

    for a in args:
        try: v = int(a)
        except ValueError:
            try: v = float(a)
            except ValueError:
                v = a
        msg.add(v)

    return msg
Esempio n. 17
0
 def set_fader_led(self, idx, val):
     """ Immediately set one of the LEDs on the faders.
         Inputs:
             idx : fader idx from 0 to 3
             val : 1 = LED on, 0 = LED off
     """
     led_idx = LED_FADER_IDXS[idx]
     if led_idx is not None:
         osc_msg = liblo.Message('/set_output')
         osc_msg.add(('i', led_idx))
         osc_msg.add(('f', val))
         liblo.send(self._sensei_address, osc_msg)
Esempio n. 18
0
    def save_callback(self, path, args):
        s_c = datetime.datetime.now().second
        self.server_saved = False
        message = liblo.Message('/reply', "/nsm/client/save",
                                'nsm-git is waiting to save')
        liblo.send(self.NSM_URL, message)
        self.log_write('save called. waiting...', False)
        while not self.server_saved:
            s_d = datetime.datetime.now().second
            if s_d - s_c > 3:
                message = liblo.Message("/nsm/client/message", 1,
                                        "nsm-git has waited long enough")
                liblo.send(self.NSM_URL, message)
                self.log_write('nsm-git has waited long enough. saving...')
                break
            self.recv(50)

        saved = self.save()
        msg = "nsm-git has committed" if saved else "nothing for nsm-git to commit"
        message = liblo.Message("/nsm/client/message", 1, msg)
        liblo.send(self.NSM_URL, message)
        self.saved.emit()
Esempio n. 19
0
    def nsmServerBroadcast(self, path, args, types, src_addr):
        if not args:
            return False

        #don't allow clients to broadcast NSM commands
        if args[0].startswith('/nsm/') or args[0].startswith('/ray'):
            return False

        for client in self.session.clients:
            if not client.addr:
                continue

            if not ray.areSameOscPort(client.addr.url, src_addr.url):
                self.send(client.addr, liblo.Message(*args))
Esempio n. 20
0
    def sendingOSC(self, context, event):
        if load_liblo_success == True:
            oscMessage = {}

            # gather all the ouput bound osc messages
            make_osc_messages(bpy.context.scene.NodeOSC_outputs, oscMessage)

            # and send them
            for key, args in oscMessage.items():
                msg = liblo.Message(key)
                if isinstance(args, (tuple, list)):
                    for argum in args:
                        msg.add(argum)
                    else:
                        msg.add(args)
                self.st.send(self.address, msg)
Esempio n. 21
0
def make_message_manual(path, types, *args):
    if len(types) != len(args):
        sys.exit("length of type string doesn't match number of arguments")

    msg = liblo.Message(path)
    try:
        for a, t in zip(args, types):
            if t == 'c' and len(
                    a) == 0:  #workaround for sending null character
                msg.add((t, "\0"))
            else:
                msg.add((t, a))
    except Exception as e:
        sys.exit(str(e))

    return msg
Esempio n. 22
0
  def call(self, cmd, context, **kwargs) :
    msg = liblo.Message(f"/nsm/server/{cmd}")
    for t, arg in self.args :

      if arg in kwargs :
        val = kwargs[arg]
      else :
        val = input(f"{arg} << ")

      if self.load :
        context.currentSession = val

      msg.add((t, val))

    context.nsm_server.server.send(context.address, msg)
    if self.quit :
      context.currentSession = ""
Esempio n. 23
0
    def sync(self, client):
        logger.debug('system="%s", action="sync", client="%r"', self.system,
                     client)

        liblo.send(
            client,
            liblo.Bundle(

                # Gross, this needs refactoring...
                liblo.Message(
                    "/light/cloud_z", self.controller.params.lightning_new /
                    self.lightningProbabilityScale),
                liblo.Message(
                    "/light2/brightness",
                    self.controller.params.brightness / self.brightnessScale),
                liblo.Message(
                    "/light2/contrast",
                    self.controller.params.contrast / self.contrastScale),
                liblo.Message("/light2/detail", self.controller.params.detail /
                              self.detailScale),
                liblo.Message("/light2/color_top",
                              self.controller.params.color_top),
                liblo.Message("/light2/color_bottom",
                              self.controller.params.color_bottom),
                liblo.Message(
                    "/light2/turbulence",
                    self.controller.params.turbulence / self.turbulenceScale),
                liblo.Message(
                    "/light2/speed",
                    self.controller.params.wind_speed / self.windSpeedScale),

                # XXX: This doesn't work- TouchOSC seems to spam these events
                #      at both XY pads for some reason. Bug in TouchOSC? Using
                #      liblo incorrectly?
                #
                # liblo.Message("/light2/heading",
                #     -math.cos(self.controller.params.wind_heading),
                #     math.sin(self.controller.params.wind_heading)),
                #
                # liblo.Message("/light2/rotation",
                #     math.sin(-self.controller.params.rotation),
                #     -math.cos(-self.controller.params.rotation))
            ))
Esempio n. 24
0
    def on_midi(self, message):
        if message.type == "clock":
            return

        log.debug("MIDI received: {}".format(message))

        if message.type == "sysex":
            addr = '/sysex'
            arg = ('s', message_to_oscsysexpayload(message))
        else:
            addr = '/midi'
            arg = ('m', message_to_oscmidipayload(message))

        osc = liblo.Message(addr, arg)
        log.debug("Sending OSC {}, {} to: {}:{} UDP: {} URL: {}".format(
            addr, arg, self.target.get_hostname(), self.target.get_port(),
            self.target.get_protocol() == liblo.UDP, self.target.get_url()))
        liblo.send(self.target, osc)
Esempio n. 25
0
    def handshake(self):
        application_name = "nsm-git"
        capabilities = ":message:optional-gui:"
        executable_name = os.path.realpath(__file__)
        self.executable_dir = os.path.dirname(executable_name)
        executable_name = "nsm-git"  # this leads to mostly correct behaviour, I don't know how to find the actual 'correct' value though
        pid = os.getpid()
        api_version_major = 1
        api_version_minor = 2

        message = liblo.Message("/nsm/server/announce", application_name,
                                capabilities, executable_name,
                                api_version_major, api_version_minor, pid)
        liblo.send(self.NSM_URL, message)

        while not self.session_dir:
            self.recv()
            if self.exit:
                sys.exit()
Esempio n. 26
0
def update(src, id, pos, time):
    msg = liblo.Message("/foo%d" % (id - 1 % 4))
    msg.add(-pos[0])
    msg.add(pos[1])
    msg.add(pos[2])
    global batido

    if pos[2] > 1000:
        msg.add(1)
        batido = True
    else:
        msg.add(0)

    for i in range(3):
        if pos[i] < menor[i]: menor[i] = pos[i]
        if pos[i] > maior[i]: maior[i] = pos[i]

    liblo.send(target, msg)

    print 'Update ', id, pos
Esempio n. 27
0
analogdata = np.zeros(3)
digitaldata = np.zeros(1)
timestamps = np.zeros(3)

while True:

    # this is specific to GrovePi Zero.  Additional pins may be used.
    # See https://www.dexterindustries.com/GrovePi/engineering/port-description/
    # for unlocking more I/O

    analogdata[0] = grovepi.analogRead(0)
    analogdata[1] = grovepi.analogRead(1)
    analogdata[2] = grovepi.analogRead(2)
    timestamps[0] = time.time(
    )  # let's take a timestamp, in case we want to use it someday
    analogMessage = lo.Message('/grove/analog', analogdata[0], analogdata[1],
                               analogdata[2])
    lo.send(outputAddress, analogMessage)

    digitaldata[0] = grovepi.digitalRead(3)
    timestamps[1] = time.time()
    digitalMessage = lo.Message('/grove/digital', digitaldata[0])
    lo.send(outputAddress, digitalMessage)

    if options.printDebug:
        print("analog: A0 %.3f, A1 %.3f, A2 %.3f" %
              (analogdata[0], analogdata[1], analogdata[2]))
        print("digital: D3 %d" % (digitaldata[0]))

    if options.withPulse:
        pulseMessage = lo.Message('/grove/pulsesensor', analogdata[0])
        lo.send(outputAddress, pulseMessage)
Esempio n. 28
0
def send_osc2(addr, osc_target, args):
    msg = liblo.Message(addr)
    for arg in args:
        msg.add(arg)
    liblo.send(osc_target, msg)
Esempio n. 29
0
import liblo, sys

# send all messages to port 1234 on the local machine
try:
    target = liblo.Address("192.168.1.138", 3001)

except liblo.AddressError as err:
    print(err)
    sys.exit()

# send message "/foo/message1" with int, float and string arguments
liblo.send(target, "/foo/message1", 123, 456.789, "test")

# send double, int64 and char
liblo.send(target, "/foo/message2", ('d', 3.1415), ('h', 2**42), ('c', 'x'))

# we can also build a message object first...
msg = liblo.Message("/foo/blah")
# ... append arguments later...
msg.add(123, "foo")
# ... and then send it
liblo.send(target, msg)

# send a list of bytes as a blob
blob = [4, 8, 15, 16, 23, 42]
liblo.send(target, "/foo/blob", blob)

# wrap a message in a bundle, to be dispatched after 2 seconds
bundle = liblo.Bundle(liblo.time() + 2.0, liblo.Message("/blubb", 123))
liblo.send(target, bundle)
Esempio n. 30
0
 def send(self, target, path, *data):
     m = liblo.Message(path)
     m.add(*data)
     self.server.send(target, m)