当前位置: 首页>>代码示例>>Python>>正文


Python EEGsynth.limit方法代码示例

本文整理汇总了Python中EEGsynth.limit方法的典型用法代码示例。如果您正苦于以下问题:Python EEGsynth.limit方法的具体用法?Python EEGsynth.limit怎么用?Python EEGsynth.limit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EEGsynth的用法示例。


在下文中一共展示了EEGsynth.limit方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
 def run(self):
     pubsub = r.pubsub()
     pubsub.subscribe('OUTPUTMIDI_UNBLOCK')  # this message unblocks the redis listen command
     pubsub.subscribe(self.redischannel)  # this message contains the note
     while self.running:
         for item in pubsub.listen():
             if not self.running or not item['type'] == 'message':
                 break
             if item['channel']==self.redischannel:
                 if debug>1:
                     print(item['channel'], '=', item['data'])
                 # map the Redis values to MIDI values
                 val = item['data']
                 val = EEGsynth.rescale(val, slope=input_scale, offset=input_offset)
                 val = EEGsynth.limit(val, 0, 127)
                 val = int(val)
                 sendMidi(self.name, self.code, val)
开发者ID:nicofarr,项目名称:eegsynth,代码行数:19,代码来源:outputmidi.py

示例2: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
 def run(self):
     pubsub = r.pubsub()
     pubsub.subscribe('VOLCAKEYS_UNBLOCK')  # this message unblocks the redis listen command
     pubsub.subscribe(self.redischannel)    # this message contains the note
     while self.running:
         for item in pubsub.listen():
             if not self.running or not item['type'] == 'message':
                 break
             if item['channel']==self.redischannel:
                 # map the Redis values to MIDI values
                 val = EEGsynth.rescale(item['data'], slope=scale, offset=offset)
                 val = EEGsynth.limit(val, 0, 127)
                 val = int(val)
                 if debug>1:
                     print item['channel'], "=", val
                 msg = mido.Message('note_on', note=self.note, velocity=val, channel=midichannel)
                 lock.acquire()
                 outputport.send(msg)
                 lock.release()
开发者ID:neuroidss,项目名称:eegsynth,代码行数:21,代码来源:volcakeys.py

示例3: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
 def run(self):
     pubsub = r.pubsub()
     # this message unblocks the Redis listen command
     pubsub.subscribe('OUTPUTCVGATE_UNBLOCK')
     # this message triggers the event
     pubsub.subscribe(self.redischannel)
     while self.running:
         for item in pubsub.listen():
             if not self.running or not item['type'] == 'message':
                 break
             if item['channel'] == self.redischannel:
                 # switch to the value specified in the event, it can be 0 or 1
                 val = float(item['data']) > 0
                 SetGate(self.gate, val)
                 if self.duration != None:
                     # schedule a timer to switch it off after the specified duration
                     duration = patch.getfloat('duration', self.duration)
                     duration = EEGsynth.rescale(duration, slope=duration_scale, offset=duration_offset)
                     # some minimal time is needed for the delay
                     duration = EEGsynth.limit(duration, 0.05, float('Inf'))
                     t = threading.Timer(duration, SetGate, args=[self.gate, False])
                     t.start()
开发者ID:nicofarr,项目名称:eegsynth,代码行数:24,代码来源:outputcvgate.py

示例4: int

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
            midithread.setEnabled(False)
            previous_midi_play = False

        # do something whenever the value changes
        if midi_start and not previous_midi_start:
            if midiport != None:
                midiport.send(mido.Message('start'))
            previous_midi_start = True
        elif not midi_start and previous_midi_start:
            if midiport != None:
                midiport.send(mido.Message('stop'))
            previous_midi_start = False

        rate  = patch.getfloat('input', 'rate', default=0)
        rate  = EEGsynth.rescale(rate, slope=scale_rate, offset=offset_rate)
        rate  = EEGsynth.limit(rate, 30., 240.)

        shift = patch.getfloat('input', 'shift', default=0)
        shift = EEGsynth.rescale(shift, slope=scale_shift, offset=offset_shift)
        shift = int(shift)

        ppqn  = patch.getfloat('input', 'ppqn', default=0)
        ppqn  = EEGsynth.rescale(ppqn, slope=scale_ppqn, offset=offset_ppqn)
        ppqn  = find_nearest_value([1, 2, 3, 4, 6, 8, 12, 24], ppqn)

        if debug>0:
            # show the parameters whose value has changed
            show_change("redis_play",    redis_play)
            show_change("midi_play",     midi_play)
            show_change("midi_start",    midi_start)
            show_change("rate",          rate)
开发者ID:nicofarr,项目名称:eegsynth,代码行数:33,代码来源:generateclock.py

示例5: NotImplementedError

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
            f.setnchannels(nchans)
            f.setnframes(0)
            f.setsampwidth(4)  # 1, 2 or 4
            f.setframerate(1. / delay)
        else:
            raise NotImplementedError('unsupported file format')

    if recording:
        D = []
        for chan in channels:
            xval = r.get(chan)
            try:
                xval = float(xval)
            except ValueError:
                xval = 0.
            xval = EEGsynth.limit(xval, physical_min, physical_max)
            D.append([xval])
        sample += 1

        if (sample % synchronize) == 0:
            patch.setvalue("recordcontrol.synchronize", sample)

        if debug > 1:
            print "Writing", D
        elif debug > 0:
            print "Writing sample", sample, "as", np.shape(D)

        if fileformat == 'edf':
            f.writeBlock(D)
        elif fileformat == 'wav':
            D = np.asarray(D)
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:recordcontrol.py

示例6: int

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
            # this returns None when the channel is not present
            chanval = patch.getfloat('input', chanstr)

            if chanval==None:
                # the value is not present in Redis, skip it
                if debug>2:
                    print chanstr, 'not available'
                continue

            # the scale and offset options are channel specific
            scale  = patch.getfloat('scale', chanstr, default=255)
            offset = patch.getfloat('offset', chanstr, default=0)
            # apply the scale and offset
            chanval = EEGsynth.rescale(chanval, slope=scale, offset=offset)
            # ensure that it is within limits
            chanval = EEGsynth.limit(chanval, lo=0, hi=255)
            chanval = int(chanval)

            if dmxdata[chanindx]!=chr(chanval):
                if debug>0:
                    print "DMX channel%03d" % chanindx, '=', chanval
                # update the DMX value for this channel
                dmxdata = senddmx(dmxdata,chanindx,chanval)
            elif (time.time()-prevtime)>1:
                # send a maintenance packet now and then
                dmxdata = senddmx(dmxdata,chanindx,chanval)
                prevtime = time.time()

except KeyboardInterrupt:
    if debug>0:
        print "closing..."
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:outputdmx512.py

示例7: int

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
        active = EEGsynth.rescale(active, slope=scale_active, offset=offset_active)
        active = int(active)

        # get the corresponding sequence as a single string
        try:
            sequence = patch.getstring('sequence', "sequence%03d" % active, multiple=True)
        except:
            sequence = []

        transpose = patch.getfloat('sequence', 'transpose', default=0.)
        transpose = EEGsynth.rescale(transpose, slope=scale_transpose, offset=offset_transpose)

        # the duration is relative to the time between clock ticks
        duration = patch.getfloat('sequence', 'duration', default=0.)
        duration = EEGsynth.rescale(duration, slope=scale_duration, offset=offset_duration)
        duration = EEGsynth.limit(duration, 0.1, 0.9)

        if debug > 0:
            # show the parameters whose value has changed
            show_change("active",    active)
            show_change("sequence",  sequence)
            show_change("transpose", transpose)
            show_change("duration",  duration)

        sequencethread.setSequence(sequence)
        sequencethread.setTranspose(transpose)
        sequencethread.setDuration(duration)

        elapsed = time.time() - now
        naptime = patch.getfloat('general', 'delay') - elapsed
        if naptime > 0:
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:sequencer.py

示例8: zip

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
try:
    while True:
        time.sleep(patch.getfloat('general', 'delay'))

        for name, cmd in zip(control_name, control_code):
            # loop over the control values
            val = patch.getfloat('control', name)
            if val==None:
                continue # it should be skipped when not present
            if val==previous_val[name]:
                continue # it should be skipped when identical to the previous value
            previous_val[name] = val
            # map the Redis values to MIDI values
            val = EEGsynth.rescale(val, slope=scale, offset=offset)
            val = EEGsynth.limit(val, 0, 127)
            val = int(val)
            msg = mido.Message('control_change', control=cmd, value=val, channel=midichannel)
            if debug>1:
                print cmd, val, name
            lock.acquire()
            outputport.send(msg)
            lock.release()

except KeyboardInterrupt:
    print "Closing threads"
    for thread in trigger:
        thread.stop()
    r.publish('VOLCAKEYS_UNBLOCK', 1)
    for thread in trigger:
        thread.join()
开发者ID:neuroidss,项目名称:eegsynth,代码行数:32,代码来源:volcakeys.py

示例9: int

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
                    print name, 'not available'
                continue

            # the scale and offset options are channel specific
            scale  = patch.getfloat('scale', name, default=1)
            offset = patch.getfloat('offset', name, default=0)

            # map the Redis values to MIDI pitch values
            val = EEGsynth.rescale(val, slope=scale, offset=offset)

            # portamento range is hardcoded 0-127, so no need for user-config
            port_val = EEGsynth.rescale(port_val, slope=127, offset=0)

            # ensure that values are within limits
            if patch.getstring('general', 'mode') == 'note':
                val = EEGsynth.limit(val, lo=0, hi=127)
                val = int(val)
                port_val = EEGsynth.limit(port_val, lo=0, hi=127)
                port_val = int(port_val)
            elif patch.getstring('general', 'mode') == 'pitchbend':
                val = EEGsynth.limit(val, lo=-8192, hi=8191)
                val = int(val)
            else:
                print 'No output mode (note or pitchbend) specified!'
                break

            if val != previous_val[name] or not val: # it should be skipped when identical to the previous value

                previous_val[name] = val

                if debug > 0:
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:endorphines.py

示例10: int

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
for thread in trigger:
    thread.start()


try:
    while True:
        time.sleep(patch.getfloat('general', 'delay'))

        for gpio, channel in config.items('control'):
            val = patch.getfloat('control', gpio)
            if val == None:
                continue  # it should be skipped when not present
            if val == previous_val[gpio]:
                continue  # it should be skipped when identical to the previous value
            previous_val[gpio] = val
            val = EEGsynth.rescale(val, slope=input_scale, offset=input_offset)
            val = EEGsynth.limit(val, 0, 100)
            val = int(val)
            lock.acquire()
            wiringpi.softPwmWrite(pin[gpio], val)
            lock.release()

except KeyboardInterrupt:
    print("Closing threads")
    for thread in trigger:
        thread.stop()
    r.publish('OUTPUTGPIO_UNBLOCK', 1)
    for thread in trigger:
        thread.join()
    sys.exit()
开发者ID:nicofarr,项目名称:eegsynth,代码行数:32,代码来源:outputgpio.py

示例11: print

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
            # this returns None when the channel is not present
            chanval = patch.getfloat('input', chanstr)

            if chanval == None:
                # the value is not present in Redis, skip it
                if debug > 2:
                    print(chanstr, 'not available')
                continue

            # the scale and offset options are channel specific
            scale = patch.getfloat('scale', chanstr, default=4095)
            offset = patch.getfloat('offset', chanstr, default=0)
            # apply the scale and offset
            chanval = EEGsynth.rescale(chanval, slope=scale, offset=offset)
            # ensure that it is within limits
            chanval = EEGsynth.limit(chanval, lo=0, hi=4095)
            chanval = int(chanval)

            if debug > 0:
                show_change(chanstr, chanval)

            lock.acquire()
            s.write('*c%dv%04d#' % (chanindx, chanval))
            lock.release()

        for chanindx in range(1, 5):
            chanstr = "gate%d" % chanindx
            chanval = patch.getfloat('input', chanstr)

            if chanval == None:
                # the value is not present in Redis, skip it
开发者ID:nicofarr,项目名称:eegsynth,代码行数:33,代码来源:outputcvgate.py

示例12: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import limit [as 别名]
    def run(self):
        pubsub = r.pubsub()
        pubsub.subscribe('KEYBOARD_UNBLOCK')  # this message unblocks the Redis listen command
        pubsub.subscribe(self.onset)      # this message triggers the note
        while self.running:
            for item in pubsub.listen():
                if not self.running or not item['type'] == 'message':
                    break
                if item['channel']==self.onset:
                    # the trigger may contain a value that should be mapped to MIDI
                    val = item['data']
                    val = EEGsynth.rescale(val, slope=input_scale, offset=input_offset)
                    val = EEGsynth.limit(val, 0, 127)
                    val = int(val)

                    if self.velocity == None:
                        # use the value of the onset trigger
                        velocity = val
                    elif type(self.velocity) == str:
                        velocity = float(r.get(self.velocity))
                        velocity = EEGsynth.rescale(velocity, slope=scale_velocity, offset=offset_velocity)
                        velocity = EEGsynth.limit(velocity, 0, 127)
                        velocity = int(velocity)
                    else:
                        velocity = self.velocity

                    if type(self.pitch) == str:
                        pitch = float(r.get(self.pitch))
                        pitch = EEGsynth.rescale(pitch, slope=scale_pitch, offset=offset_pitch)
                        pitch = EEGsynth.limit(pitch, 0, 127)
                        pitch = int(pitch)
                    else:
                        pitch = self.pitch

                    if type(self.duration) == str:
                        duration = float(r.get(self.duration))
                        duration = EEGsynth.rescale(duration, slope=scale_duration, offset=offset_duration)
                        duration = EEGsynth.limit(duration, 0.05, float('Inf')) # some minimal time is needed for the delay
                    else:
                        duration = self.duration

                    if debug>1:
                        print '----------------------------------------------'
                        print "onset   ", self.onset,       "=", val
                        print "velocity", self.velocity,    "=", velocity
                        print "pitch   ", self.pitch,       "=", pitch
                        print "duration", self.duration,    "=", duration

                    if midichannel is None:
                        msg = mido.Message('note_on', note=pitch, velocity=velocity)
                    else:
                        msg = mido.Message('note_on', note=pitch, velocity=velocity, channel=midichannel)
                    SendMessage(msg)

                    if duration != None:
                        # schedule a delayed MIDI message to be sent to switch the note off
                        if midichannel is None:
                            msg = mido.Message('note_on', note=pitch, velocity=0)
                        else:
                            msg = mido.Message('note_on', note=pitch, velocity=0, channel=midichannel)
                        t = threading.Timer(duration, SendMessage, args=[msg])
                        t.start()
开发者ID:neuroidss,项目名称:eegsynth,代码行数:64,代码来源:keyboard.py


注:本文中的EEGsynth.limit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。