コード例 #1
0
def bassScrollTop(brightnessFactor):
    # always here
    global nStrips, lStrip
    client = fastopc.FastOPC('localhost:7890')
    # setup
    pixels = lib.Pixels(nStrips, lStrip, 0)
    theoStrip = np.zeros([lStrip, 3])
    stream = micStream.Stream(fps=30, nBuffers=4)
    powerSmooth = lib.ExpFilter(val=1.0, alpha_rise=0.01, alpha_decay=0.01)
    nColorWheel = 300
    colorWheel = lib.getColorWheel(nColorWheel)
    frameCount = 0
    powerMinFreqIndex = int(0 / stream.dFreq)
    powerMaxFreqIndex = int(120 / stream.dFreq)
    # loop
    while True:
        success = stream.readAndCalc()
        if success:
            frameNumEff = np.mod(frameCount, nColorWheel)
            power = np.sum(
                stream.freqSpectrum[powerMinFreqIndex:powerMaxFreqIndex])
            powerSmooth.update(power)
            displayPower = int(122 * np.power(power / powerSmooth.value, 1.5))
            theoStrip = np.roll(theoStrip, -1, axis=0)
            theoStrip[-2] = displayPower * colorWheel[frameNumEff]
            theoStrip[-1] = 1000 * colorWheel[frameNumEff]
            pixels.update(theoStrip, 0.7, 0.5)
            client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay())
            frameCount += 1
コード例 #2
0
def kickDrum(brightnessFactor):
    # always here
    global nStrips, lStrip
    client = fastopc.FastOPC('localhost:7890')
    # setup
    pixels = lib.Pixels(nStrips, lStrip, 0)
    theoStrip = np.zeros([lStrip // 2, 3])
    stream = micStream.Stream(fps=60, nBuffers=4)
    powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.1, alpha_decay=0.1)
    nColorWheel = 300
    colorWheel = lib.getColorWheel(nColorWheel)
    frameCount = 0
    # loop
    while True:
        success = stream.readAndCalc()
        if success:
            frameNumEff = np.mod(frameCount, nColorWheel)
            #power = np.sum(stream.freqSpectrum[20//7:250//7])
            power = np.sum(stream.freqSpectrum[:20])
            powerSmooth.update(power)
            if power > 1.e4:
                displayPower = int(122 *
                                   np.power(power / powerSmooth.value, 1.5))
                theoStrip[:] = displayPower * colorWheel[frameNumEff]
                #theoStrip[0] = 1000*colorWheel[frameNumEff]
                pixels.update(theoStrip, 1.0, 0.4)
                client.putPixels(
                    0, brightnessFactor * pixels.getArrayForDisplay())
                frameCount += 1
            else:
                theoStrip[:] = np.zeros_like(theoStrip[:])
                #theoStrip[0] = 1000*colorWheel[frameNumEff]
                pixels.update(theoStrip, 1.0, 0.4)
                client.putPixels(
                    0, brightnessFactor * pixels.getArrayForDisplay())
コード例 #3
0
def bassWiden(brightnessFactor):
    # always here
    global nStrips, lStrip
    client = fastopc.FastOPC('localhost:7890')
    # setup
    pixels = lib.Pixels(nStrips, lStrip, 20)
    theoStrip = np.zeros([lStrip // 2, 3])
    stream = micStream.Stream(fps=30, nBuffers=4)
    powerMinFreqIndex1 = int(0 / stream.dFreq)
    powerMaxFreqIndex1 = int(200 / stream.dFreq)
    powerSmooth = lib.ExpFilter(val=1.0, alpha_rise=0.01, alpha_decay=0.01)
    nColorWheel = 600
    colorWheel = lib.getColorWheel(nColorWheel)
    frameCount = 0
    # loop
    while True:
        success = stream.readAndCalc()
        if success:
            frameNumEff = np.mod(frameCount, nColorWheel)
            power = np.sum(
                stream.freqSpectrum[powerMinFreqIndex1:powerMaxFreqIndex1])
            powerSmooth.update(power)
            displayPower = max(int(122 * power / powerSmooth.value), 50)
            width = int(2 + 0.5 * np.sqrt(float(displayPower)))
            theoStrip[width:] = displayPower * colorWheel[np.mod(
                frameNumEff + 200, nColorWheel)]
            theoStrip[0:width] = 255 * colorWheel[np.mod(
                frameNumEff, nColorWheel)]
            #pixels.update(theoStrip, 0.7, 0.2)
            pixels.update(theoStrip, 1.0, 1.0)
            client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay())
            frameCount += 1
コード例 #4
0
def scroll(brightnessFactor):
    global lNeck, lBody, lStrap
    client    = fastopc.FastOPC('localhost:7890')
    pixels    = lib.BassPixels(lNeck, lBody, lStrap, 0)
    theoNeck  = np.zeros([lNeck,  3])
    theoBody  = np.zeros([lBody,  3])
    theoStrap = np.zeros([lStrap, 3])
    stream    = micStream.Stream(fps=30, nBuffers=4)

    powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.05, alpha_decay=0.05)
    nColorWheel = 600
    colorWheel = lib.getColorWheel(nColorWheel)
    frameCount = 0

    while True:
        success = stream.readAndCalc()
        if success:
            frameNumEff = np.mod(frameCount, nColorWheel)
            power = np.sum(stream.freqSpectrum[20//7:250//7])
            powerSmooth.update(power)
            displayPower = int(122*np.power(power/powerSmooth.value, 1.5))
            theoNeck     = np.roll(theoNeck, 1, axis=0)
            theoNeck[0]  = displayPower * colorWheel[frameNumEff]
            theoBody     = displayPower * colorWheel[np.mod(frameNumEff+200, nColorWheel)]
            pixels.updateBody(theoBody, 0.5, 0.5)
            pixels.updateNeck(theoNeck, 0.5, 0.5)
            client.putPixels(0, brightnessFactor*pixels.getArrayForDisplay())
            frameCount+=1
コード例 #5
0
def basic(brightnessFactor):
    print('brightness factor is ' + str(brightnessFactor))
    global lNeck, lBody, lStrap
    client    = fastopc.FastOPC('localhost:7890')
    pixels    = lib.BassPixels(lNeck, lBody, lStrap, 0)
    theoNeck  = np.zeros([lNeck,  3])
    theoBody  = np.zeros([lBody,  3])
    theoStrap = np.zeros([lStrap, 3])
    stream    = micStream.Stream(fps=30, nBuffers=4)

    powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.05, alpha_decay=0.05)
    nColorWheel = 600
    colorWheel = lib.getColorWheel(nColorWheel)
    frameCount = 0

    while True:
        success = stream.readAndCalc()
        if success:
            frameNumEff = np.mod(frameCount, nColorWheel)
            power = np.sum(stream.freqSpectrum[20//7:250//7])
            powerSmooth.update(power)
            displayPower = int(122*power/powerSmooth.value)
            width = int(5 + np.sqrt(float(displayPower)))
            theoBody          = displayPower * colorWheel[np.mod(frameNumEff+200, nColorWheel)]
            theoNeck[0:width] = 255          * colorWheel[np.mod(frameNumEff,     nColorWheel)]
            pixels.updateBody(theoBody, 0.7, 0.1)
            pixels.updateNeck(theoNeck, 0.7, 0.1)
            client.putPixels(0, brightnessFactor*pixels.getArrayForDisplay())
            frameCount+=1
コード例 #6
0
def drums_midi(brightnessFactor):
    # always here
    global nStrips, lStrip
    client = fastopc.FastOPC('localhost:7890')
    # setup
    pixels = lib.Pixels(nStrips, lStrip, 0)
    theoAll = np.zeros([lStrip * nStrips, 3])
    inputNames = mido.get_input_names()
    inport = mido.open_input(inputNames[1])
    board = lib.Board()
    speedCut = 100
    frameNum = 0
    nColorWheel = nStrips
    colorWheel = lib.getColorWheel(nColorWheel)
    stripColors = np.zeros([nStrips, 3])
    n = 0
    while n < nStrips:
        stripColors[n] = colorWheel[n] * 255
        n += 1
    midiNotes = []
    while len(midiNotes) < nStrips:
        for msg in inport.iter_pending():
            if msg.type == 'note_on':
                midiNotes.append(msg.note)
                print(midiNotes)
        justTurnedOn = np.zeros(nStrips)
    # loop
    while True:
        for msg in inport.iter_pending():
            board.update(msg)
        #overallFactor = float(board.knobs[51]+1)/(128.0)
        #if np.mod(frameNum, speedCut) == 0:
        for n in range(nStrips):
            theoAll[n * lStrip, :] = 0
        theoAll = np.roll(theoAll, -1, axis=0)
        for n in range(nStrips):
            if board.notes[midiNotes[n]] == 1:
                theoAll[(n * lStrip) + lStrip - 1] = stripColors[n]
        pixels.update(theoAll, 1.0, 0.4)
        client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay())
        time.sleep(2.e-2)
        frameNum += 1
コード例 #7
0
def rain1(brightnessFactor):
    # always here
    global nStrips, lStrip
    client = fastopc.FastOPC('localhost:7890')
    # setup
    nColorWheel = 100
    colorWheel = lib.getColorWheel(nColorWheel)
    pixels = lib.Pixels(nStrips, lStrip, 0)
    theoAll = np.zeros([lStrip * nStrips, 3])
    frameCount = 0
    # loop
    while True:
        for i in range(nStrips):
            theoAll[i * lStrip, :] = 0
        frameNumEff = np.mod(frameCount, nColorWheel)
        theoAll = 0.99 * np.roll(theoAll, -1, axis=0)
        if np.random.rand() < 0.75:
            stripNum = np.random.randint(0, high=nStrips)
            theoAll[(stripNum * lStrip) + lStrip -
                    1] = 255 * colorWheel[frameNumEff]
        pixels.update(theoAll, 1.0, 0.4)
        client.putPixels(0, brightnessFactor * pixels.getArrayForDisplay())
        time.sleep(0.05)
        frameCount += 1
コード例 #8
0
else: brightnessFactor = float(sys.argv[1])

nStrips = 16
lStrip = 64

client = fastopc.FastOPC('localhost:7890')

pixels = lib.Pixels(nStrips, lStrip, 0)
theo = np.zeros([nStrips * lStrip, 3])

stream = micStream.Stream(fps=30, nBuffers=4)

powerSmooth = lib.ExpFilter(val=0.05, alpha_rise=0.05, alpha_decay=0.05)
nColorWheel = 300
nOnOneStrip = 30
colorWheel = lib.getColorWheel(nColorWheel)
frameCount = 0

while True:
    success = stream.readAndCalc()
    if success:
        frameNumEff = np.mod(frameCount, nColorWheel)
        stripNum = np.mod(np.floor(frameCount / nOnOneStrip), nStrips // 2)
        power = np.sum(stream.freqSpectrum[20 // 7:250 // 7])
        powerSmooth.update(power)
        displayPower = int(122 * np.power(power / powerSmooth.value, 1.5))

        theo = np.roll(theo, 1, axis=0)

        for i in range(nStrips):
            theo[i * lStrip + 63] = [0, 0, 0]