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


Python EEGsynth.rescale方法代码示例

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


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

示例1: forward_handler

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
def forward_handler(addr, tags, data, source):
    global prefix
    global scake
    global offset

    if debug > 1:
        print("---")
        print("source %s" % OSC.getUrlStr(source))
        print("addr   %s" % addr)
        print("tags   %s" % tags)
        print("data   %s" % data)

    if addr[0] != '/':
        # ensure it starts with a slash
        addr = '/' + addr

    if tags == 'f' or tags == 'i':
        # it is a single value
        key = prefix + addr.replace('/', '.')
        val = EEGsynth.rescale(data[0], slope=scale, offset=offset)
        patch.setvalue(key, val)

    else:
        for i in range(len(data)):
            # it is a list, send it as multiple scalar control values
            # append the index to the key, this starts with 0
            key = prefix + addr.replace('/', '.') + '.%i' % i
            val = EEGsynth.rescale(data[i], slope=scale, offset=offset)
            patch.setvalue(key, val)
开发者ID:nicofarr,项目名称:eegsynth,代码行数:31,代码来源:inputosc.py

示例2: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
 def run(self):
     pubsub = r.pubsub()
     # this message unblocks the Redis listen command
     pubsub.subscribe('OUTPUTGPIO_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 PWM value specified in the event
                 val = item['data']
                 val = EEGsynth.rescale(val, slope=input_scale, offset=input_offset)
                 val = int(val)
                 SetGPIO(self.gpio, val)
                 if self.duration != None:
                     # schedule a timer to switch it off after the specified duration
                     duration = patch.getfloat('duration', self.gpio)
                     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, SetGPIO, args=[self.gpio, 0])
                     t.start()
开发者ID:nicofarr,项目名称:eegsynth,代码行数:26,代码来源:outputgpio.py

示例3: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [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

示例4: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [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

示例5: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
 def run(self):
     pubsub = r.pubsub()
     pubsub.subscribe('RECORDTRIGGER_UNBLOCK')  # this message unblocks the Redis listen command
     pubsub.subscribe(self.redischannel)        # this message triggers the event
     while self.running:
         for item in pubsub.listen():
             timestamp = datetime.datetime.now().isoformat()
             if not self.running or not item['type'] == 'message':
                 break
             if item['channel']==self.redischannel:
                 # the trigger value should also be saved
                 val = item['data']
                 val = EEGsynth.rescale(val, slope=input_scale, offset=input_offset)
                 if not f.closed:
                     lock.acquire()
                     f.write("%s\t%g\t%s\n" % (self.redischannel, val, timestamp))
                     lock.release()
                     if debug>0:
                         print("%s\t%g\t%s" % (self.redischannel, val, timestamp))
开发者ID:neuroidss,项目名称:eegsynth,代码行数:21,代码来源:recordtrigger.py

示例6: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
    def run(self):
        pubsub = r.pubsub()
        pubsub.subscribe('SEQUENCER_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:
                    now = time.time()
                    if self.prevtime != None:
                        self.steptime = now - self.prevtime
                    self.prevtime = now
                    if len(self.sequence) > 0:
                        # the sequence can consist of a list of values or a list of Redis channels
                        val = self.sequence[self.step % len(self.sequence)]

                        try:
                            # convert the string from the ini to floating point
                            val = float(val)
                        except:
                            # get the value from Redis
                            val = r.get(val)
                            if val == None:
                                val = 0.
                            else:
                                # convert the string from Redis to floating point
                                val = float(val)

                        # apply the scaling, offset and transpose the note
                        val = EEGsynth.rescale(val, slope=scale_note, offset=offset_note)
                        val += self.transpose
                        # send it as sequencer.note with the note as value
                        patch.setvalue(self.key, val, duration=self.duration*self.steptime)
                        if val>=1.:
                            # send it also as sequencer.noteXXX with value 1.0
                            key = '%s%03d' % (self.key, val)
                            patch.setvalue(key, 1., duration=self.duration*self.steptime)
                        if debug>0:
                            print "step %2d :" % (self.step + 1), self.key, "=", val
                        # increment to the next step
                        self.step = (self.step + 1) % len(self.sequence)
开发者ID:neuroidss,项目名称:eegsynth,代码行数:44,代码来源:sequencer.py

示例7: len

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
    thresh = np.logical_and(thresh[1:], np.logical_not(thresh[0:-1]))
    sample = np.where(thresh)[0]+1

    if len(sample)<1:
        # no beat was detected
        continue

    # determine the last beat in the window
    last = sample[-1]
    last = (last + begsample) / hdr_input.fSample

    if np.isnan(prev):
        # the first beat has not been detected yet
        prev = last
        continue

    if last-prev>debounce:
        # require a minimum time between beats
        bpm  = 60./(last-prev)
        prev = last

        if not np.isnan(bpm):
            # this is to schedule a timer that switches the gate off
            duration        = patch.getfloat('general', 'duration', default=0.1)
            duration_scale  = patch.getfloat('scale', 'duration', default=1)
            duration_offset = patch.getfloat('offset', 'duration', default=0)
            duration        = EEGsynth.rescale(duration, slope=duration_scale, offset=duration_offset)

            patch.setvalue(key_rate, bpm, debug=debug)
            patch.setvalue(key_beat, bpm, debug=debug, duration=duration)
开发者ID:neuroidss,项目名称:eegsynth,代码行数:32,代码来源:heartrate.py

示例8: update

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
def update():
    global specmax_curr, specmin_curr, specmax_hist, specmin_hist, fft_prev, fft_hist, redfreq, redwidth, bluefreq, bluewidth, counter, history

    # get last data
    last_index = ft_input.getHeader().nSamples
    begsample  = (last_index - window)
    endsample  = (last_index - 1)
    data = ft_input.getData([begsample, endsample])

    if debug>0:
        print("reading from sample %d to %d" % (begsample, endsample))

    # demean and detrend data before filtering to reduce edge artefacts and center timecourse
    data = detrend(data, axis=0)

    # taper data
    taper = np.hanning(len(data))
    data = data * taper[:, np.newaxis]

    # shift data to next sample
    history = np.roll(history, 1, axis=2)

    for ichan in range(numchannel):
        channr = int(chanarray[ichan])

        # estimate FFT at current moment, apply some temporal smoothing
        fft_temp = abs(fft(data[:, channr]))
        fft_curr[ichan] = fft_temp * lrate + fft_prev[ichan] * (1 - lrate)
        fft_prev[ichan] = fft_curr[ichan]

        # update FFT history with current estimate
        history[ichan, :, numhistory - 1] = fft_temp
        fft_hist = np.nanmean(history, axis=2)

        # user-selected frequency band
        arguments_freqrange = patch.getfloat('arguments', 'freqrange', multiple=True)
        freqrange = np.greater(freqaxis, arguments_freqrange[0]) & np.less_equal(freqaxis, arguments_freqrange[1])

        # update panels
        spect_curr[ichan].setData(freqaxis[freqrange], fft_curr[ichan][freqrange])
        spect_hist[ichan].setData(freqaxis[freqrange], fft_hist[ichan][freqrange])

        # adapt the vertical scale to the running mean of min/max
        specmax_curr[ichan] = float(specmax_curr[ichan]) * (1 - lrate) + lrate * max(fft_curr[ichan][freqrange])
        specmin_curr[ichan] = float(specmin_curr[ichan]) * (1 - lrate) + lrate * min(fft_curr[ichan][freqrange])
        specmax_hist[ichan] = float(specmax_hist[ichan]) * (1 - lrate) + lrate * max(fft_hist[ichan][freqrange])
        specmin_hist[ichan] = float(specmin_hist[ichan]) * (1 - lrate) + lrate * min(fft_hist[ichan][freqrange])

        freqplot_curr[ichan].setXRange(arguments_freqrange[0], arguments_freqrange[1])
        freqplot_hist[ichan].setXRange(arguments_freqrange[0], arguments_freqrange[1])
        freqplot_curr[ichan].setYRange(specmin_curr[ichan], specmax_curr[ichan])
        freqplot_hist[ichan].setYRange(specmin_hist[ichan], specmax_hist[ichan])

        # update plotted lines
        redfreq   = patch.getfloat('input', 'redfreq', default=10. / arguments_freqrange[1])
        redfreq   = EEGsynth.rescale(redfreq, slope=scale_red, offset=offset_red) * arguments_freqrange[1]
        redwidth  = patch.getfloat('input', 'redwidth', default=1. / arguments_freqrange[1])
        redwidth  = EEGsynth.rescale(redwidth, slope=scale_red, offset=offset_red) * arguments_freqrange[1]
        bluefreq  = patch.getfloat('input', 'bluefreq', default=20. / arguments_freqrange[1])
        bluefreq  = EEGsynth.rescale(bluefreq, slope=scale_blue, offset=offset_blue) * arguments_freqrange[1]
        bluewidth = patch.getfloat('input', 'bluewidth', default=4. / arguments_freqrange[1])
        bluewidth = EEGsynth.rescale(bluewidth, slope=scale_blue, offset=offset_blue) * arguments_freqrange[1]

        if showred:
            redleft_curr[ichan].setData(x=[redfreq - redwidth, redfreq - redwidth], y=[specmin_curr[ichan], specmax_curr[ichan]])
            redright_curr[ichan].setData(x=[redfreq + redwidth, redfreq + redwidth], y=[specmin_curr[ichan], specmax_curr[ichan]])
        if showblue:
            blueleft_curr[ichan].setData(x=[bluefreq - bluewidth, bluefreq - bluewidth], y=[specmin_curr[ichan], specmax_curr[ichan]])
            blueright_curr[ichan].setData(x=[bluefreq + bluewidth, bluefreq + bluewidth], y=[specmin_curr[ichan], specmax_curr[ichan]])
        if showred:
            redleft_hist[ichan].setData(x=[redfreq - redwidth, redfreq - redwidth], y=[specmin_hist[ichan], specmax_hist[ichan]])
            redright_hist[ichan].setData(x=[redfreq + redwidth, redfreq + redwidth], y=[specmin_hist[ichan], specmax_hist[ichan]])
        if showblue:
            blueleft_hist[ichan].setData(x=[bluefreq - bluewidth, bluefreq - bluewidth], y=[specmin_hist[ichan], specmax_hist[ichan]])
            blueright_hist[ichan].setData(x=[bluefreq + bluewidth, bluefreq + bluewidth], y=[specmin_hist[ichan], specmax_hist[ichan]])

    # update labels at plotted lines
    if showred:
        text_redleft.setText('%0.1f' % (redfreq - redwidth))
        text_redleft.setPos(redfreq - redwidth, specmax_curr[0])
        text_redright.setText('%0.1f' % (redfreq + redwidth))
        text_redright.setPos(redfreq + redwidth, specmax_curr[0])
    else:
        text_redleft.setText("")
        text_redright.setText("")
    if showblue:
        text_blueleft.setText('%0.1f' % (bluefreq - bluewidth))
        text_blueleft.setPos(bluefreq - bluewidth, specmax_curr[0])
        text_blueright.setText('%0.1f' % (bluefreq + bluewidth))
        text_blueright.setPos(bluefreq + bluewidth, specmax_curr[0])
    else:
        text_blueleft.setText("")
        text_blueright.setText("")

    if showred:
        text_redleft_hist.setText('%0.1f' % (redfreq - redwidth))
        text_redleft_hist.setPos(redfreq - redwidth, specmax_hist[0])
        text_redright_hist.setText('%0.1f' % (redfreq + redwidth))
        text_redright_hist.setPos(redfreq + redwidth, specmax_hist[0])
    else:
#.........这里部分代码省略.........
开发者ID:nicofarr,项目名称:eegsynth,代码行数:103,代码来源:plotspectral.py

示例9: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
    def run(self):
        while self.running:
            ################################################################################
            # these are to map the Redis values to MIDI values
            ################################################################################
            scale_vco_pitch = patch.getfloat('scale', 'vco_pitch')
            offset_vco_pitch = patch.getfloat('offset', 'vco_pitch')

            ################################################################################
            # VCO
            ################################################################################
            vco_pitch = patch.getfloat('control', 'vco_pitch', default=60)
            vco_sin = patch.getfloat('control', 'vco_sin', default=0.75)
            vco_tri = patch.getfloat('control', 'vco_tri', default=0.00)
            vco_saw = patch.getfloat('control', 'vco_saw', default=0.25)
            vco_sqr = patch.getfloat('control', 'vco_sqr', default=0.00)

            # map the Redis values to MIDI values
            vco_pitch = EEGsynth.rescale(vco_pitch, scale_vco_pitch, offset_vco_pitch)

            vco_total = vco_sin + vco_tri + vco_saw + vco_sqr
            if vco_total > 0:
                # these are all scaled relatively to each other
                vco_sin = vco_sin / vco_total
                vco_tri = vco_tri / vco_total
                vco_saw = vco_saw / vco_total
                vco_sqr = vco_sqr / vco_total

            ################################################################################
            # LFO
            ################################################################################
            lfo_frequency = patch.getfloat('control', 'lfo_frequency', default=2)
            lfo_depth = patch.getfloat('control', 'lfo_depth', default=0.5)

            ################################################################################
            # ADSR
            ################################################################################
            adsr_attack = patch.getfloat('control', 'adsr_attack', default=0.25)
            adsr_decay = patch.getfloat('control', 'adsr_decay', default=0.25)
            adsr_sustain = patch.getfloat('control', 'adsr_sustain', default=0.5)
            adsr_release = patch.getfloat('control', 'adsr_release', default=0.25)

            # convert from value between 0 and 1 into time in samples
            adsr_attack *= float(rate)
            adsr_decay *= float(rate)
            adsr_sustain *= float(rate)
            adsr_release *= float(rate)

            ################################################################################
            # VCA
            ################################################################################
            vca_envelope = patch.getfloat('control', 'vca_envelope', default=0.5)

            ################################################################################
            # store the control values in the local object
            ################################################################################
            lock.acquire()
            self.vco_pitch = vco_pitch
            self.vco_sin = vco_sin
            self.vco_tri = vco_tri
            self.vco_saw = vco_saw
            self.vco_sqr = vco_sqr
            self.lfo_depth = lfo_depth
            self.lfo_frequency = lfo_frequency
            self.adsr_attack = adsr_attack
            self.adsr_decay = adsr_decay
            self.adsr_sustain = adsr_sustain
            self.adsr_release = adsr_release
            self.vca_envelope = vca_envelope
            lock.release()
            if debug > 2:
                print('----------------------------------')
                print('vco_pitch      =', vco_pitch)
                print('vco_sin        =', vco_sin)
                print('vco_tri        =', vco_tri)
                print('vco_saw        =', vco_saw)
                print('vco_sqr        =', vco_sqr)
                print('lfo_depth      =', lfo_depth)
                print('lfo_frequency  =', lfo_frequency)
                print('adsr_attack    =', adsr_attack)
                print('adsr_decay     =', adsr_decay)
                print('adsr_sustain   =', adsr_sustain)
                print('adsr_release   =', adsr_release)
                print('vca_envelope   =', vca_envelope)
开发者ID:nicofarr,项目名称:eegsynth,代码行数:86,代码来源:synthesizer.py

示例10: int

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

            if port_val is None:
                # the value is not present in Redis, skip it
                if debug > 2:
                    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!'
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:endorphines.py

示例11: not

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
    return not(val % 2)

def clip01(val):
    return min(max(val,0),1)

dwelltime = 0.
edge = 0
previous = 'no'

while True:
    # measure the time that it takes
    start = time.time()

    # these can change on the fly
    switch_time = patch.getfloat('switch', 'time', default=1.0)
    switch_time = EEGsynth.rescale(switch_time, slope=scale_time, offset=offset_time)
    switch_precision = patch.getfloat('switch', 'precision', default=0.1)
    switch_precision = EEGsynth.rescale(switch_precision, slope=scale_precision, offset=offset_precision)
    show_change('time', switch_time)
    show_change('precision', switch_precision)

    # get the input value and scale between 0 and 1
    input = patch.getfloat('input', 'channel', default=np.NaN)
    input = EEGsynth.rescale(input, slope=scale_input, offset=offset_input)

    if switch_precision > 0:
        # the input value is scaled relative to the vertices
        # so that the switching happens exactly at the vertices and is not visible
        input = input * (1 + 2 * switch_precision) - switch_precision
        lower_treshold = 0
        upper_treshold = 1
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:geomixer.py

示例12:

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
        time.sleep(0.1);
        continue

    # measure the time that it takes
    start = time.time();

    if debug>1:
        print "Generating block", block, 'from', begsample, 'to', endsample

    frequency = patch.getfloat('signal', 'frequency', default=10)
    amplitude = patch.getfloat('signal', 'amplitude', default=0.8)
    offset    = patch.getfloat('signal', 'offset', default=0)           # the DC component of the output signal
    noise     = patch.getfloat('signal', 'noise', default=0.1)
    dutycycle = patch.getfloat('signal', 'dutycycle', default=0.5)      # for the square wave
    # map the Redis values to signal parameters
    frequency = EEGsynth.rescale(frequency, slope=scale_frequency, offset=offset_frequency)
    amplitude = EEGsynth.rescale(amplitude, slope=scale_amplitude, offset=offset_amplitude)
    offset    = EEGsynth.rescale(offset, slope=scale_offset, offset=offset_offset)
    noise     = EEGsynth.rescale(noise, slope=scale_noise, offset=offset_noise)
    dutycycle = EEGsynth.rescale(dutycycle, slope=scale_dutycycle, offset=offset_dutycycle)

    if frequency!=prev_frequency or debug>2:
        print "frequency =", frequency
        prev_frequency = frequency
    if amplitude!=prev_amplitude or debug>2:
        print "amplitude =", amplitude
        prev_amplitude = amplitude
    if offset!=prev_offset or debug>2:
        print "offset    =", offset
        prev_offset = offset
    if noise!=prev_noise or debug>2:
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:generatesignal.py

示例13: run

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [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

示例14: range

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
        for chanindx in range(1, 512):
            chanstr = "channel%03d" % chanindx
            # 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:
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:outputdmx512.py

示例15: show_change

# 需要导入模块: import EEGsynth [as 别名]
# 或者: from EEGsynth import rescale [as 别名]
    show_change('offset_active',    offset_active)
    show_change('offset_transpose', offset_transpose)
    show_change('offset_note',      offset_note)
    show_change('offset_duration',  offset_duration)

try:
    while True:
        # measure the time to correct for the slip
        now = time.time()

        if debug > 1:
            print 'loop'

        # the active sequence is specified as an integer between 0 and 127
        active = patch.getfloat('sequence', 'active', default=0)
        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)
开发者ID:neuroidss,项目名称:eegsynth,代码行数:33,代码来源:sequencer.py


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