def init(): global tap, scaleX, scaleY, pos, minExtent tap = CalTap() maxExtent = tap.getRawMax() minExtent = tap.getRawMin() scaleX = (maxExtent[0] - minExtent[0]) / 127 scaleY = (maxExtent[1] - minExtent[1]) / 127 pos = [0, 0, 0, False]
def init(): global colours, tap, pixels, posScan, stepTime, markTime global colBuffer, sounds # put your own colours here colours = [(255, 0, 0), (255, 72, 0), (255, 145, 0), (255, 218, 0), (218, 255, 0), (145, 255, 0), (72, 255, 0), (0, 255, 0), (255, 255, 255)] tap = CalTap() pixel_pin = board.D18 num_pixels = 128 # RGB or GRB. Some NeoPixels have red and green reversed ORDER = neopixel.GRB BRIGHTNESS = 0.1 # 0.6 is maximum brightness for 3A external supply pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=BRIGHTNESS, auto_write=False, pixel_order=ORDER) pixels.fill((0, 0, 0)) posScan = 0 stepTime = 0.3 markTime = time.time() colBuffer = [(0, 0, 0)] * 8 mixer.pre_init(44100, -16, 12, 512) mixer.init() # change these to other sample names soundNames = ["0", "1", "2", "3", "4", "5", "6", "7"] # change Marimba to another directory containing your samples sounds = [ mixer.Sound("Marimba/" + soundNames[i] + ".wav") for i in range(0, len(soundNames)) ] mixer.set_num_channels(16)
#!/usr/bin/env python3 # Free draw by Mike Cook August 2020 # prints out stream of points when touching the screen # using external CalTap class from caltap import CalTap tap = CalTap() print("touch anywhere") while 1: pos = tap.getRaw() if pos[3] > 0: print("x", pos[0], " y", pos[1], " z", pos[2])
#!/usr/bin/env python3 # Tap_A_Sketch by Mike Cook August 2020 # using external CalTap class import time import board import neopixel from caltap import CalTap tap = CalTap() pixel_pin = board.D18 num_pixels = 128 # RGB or GRB. Some NeoPixels have red and green reversed ORDER = neopixel.GRB BRIGHTNESS = 0.1 # 0.6 is maximum brightness for 3A external supply pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=BRIGHTNESS, auto_write=False, pixel_order=ORDER) print("Tap to change an LED") # put your own colours here colours = [(255, 0, 0), (255, 72, 0), (255, 145, 0), (255, 218, 0), (218, 255, 0), (145, 255, 0), (72, 255, 0), (0, 255, 0), (255, 255, 255)] pixels.fill((0, 0, 0)) for i in range(8): pixels[i] = colours[i % len(colours)] pixels[i + 120] = colours[i % len(colours)] pixels.show()
def init(): global colours, tap, pixels, posScan, stepTime, markTime global colBuffer, instNames, instNums, screen, textHeight global motor, markerRect, shutDown, incRect, midiout global decRect, icon, decRect, muteRect, voiceRect, sampleRect global font, rsRect, tempo, lastNote, lastChan, chan, note global velocity, mute, shutDown, update, lineCol, backCol, hiCol global running, stepTime, step, samples, newScan # put your own colours here if you like colours = [(255, 0, 0), (255, 170, 0), (169, 255, 0), (0, 255, 0), (0, 255, 171), (0, 168, 255), (1, 0, 255), (172, 0, 255)] tap = CalTap() midiout = rtmidi.MidiOut() pixel_pin = board.D18 num_pixels = 128 # RGB or GRB. Some NeoPixels have red and green reversed ORDER = neopixel.GRB BRIGHTNESS = 0.1 # 0.6 is maximum brightness for 3A external supply pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=BRIGHTNESS, auto_write=False, pixel_order=ORDER) pixels.fill((0, 0, 0)) pixels.show() posScan = 0 stepTime = 0.3 markTime = time.time() colBuffer = [(0, 0, 0)] * 8 pygame.init() pygame.event.set_allowed(None) pygame.event.set_allowed([ pygame.KEYDOWN, pygame.QUIT, pygame.MOUSEBUTTONDOWN, pygame.MOUSEBUTTONUP ]) pygame.display.set_caption("Tap-A-LED - MIDI Sequencer") os.environ['SDL_VIDEO_WINDOW_POS'] = 'center' sWide = 430 sHigh = 480 padCo = (sWide // 2 - 100, 48) # top of screen screen = pygame.display.set_mode([sWide, sHigh], 0, 32) instNames = [ "Piano", "Harpsichord", "Glockenspiel", "Marimba", "Bells", "Organ", "Guitar", "Bass", "Timpani", "Percusion", "Alto Sax", "Clarinet", "Rain", "Goblins", "Banjo", "Tinkle Bell" ] instNums = [0, 6, 9, 12, 14, 19, 27, 32, 47, 52, 65, 71, 96, 101, 105, 112] textHeight = 18 font = pygame.font.Font(None, textHeight) icon = [ pygame.image.load("icons/" + str(i) + ".png").convert_alpha() for i in range(0, 2) ] incRect = [pygame.Rect((0, 0), (15, 15))] * 26 decRect = [pygame.Rect((0, 0), (15, 15))] * 26 for j in range(0, 3): for i in range(0, 8): incRect[i + j * 8] = pygame.Rect((76 + j * 80, 76 + i * 40), (15, 15)) decRect[i + j * 8] = pygame.Rect((76 + j * 80, 96 + i * 40), (15, 15)) incRect[24] = pygame.Rect((76, 418), (15, 15)) decRect[24] = pygame.Rect((76, 438), (15, 15)) incRect[25] = pygame.Rect((116, 418), (15, 15)) decRect[25] = pygame.Rect((116, 438), (15, 15)) rsRect = pygame.Rect((296, 407), (38, 22)) muteRect = [pygame.Rect((0, 0), (15, 15))] * 8 voiceRect = [pygame.Rect((0, 0), (15, 15))] * 8 for i in range(0, 8): muteRect[i] = pygame.Rect((370, 80 + i * 40), (28, 20)) voiceRect[i] = pygame.Rect((268, 85 + i * 40), (100, 20)) sampleRect = [pygame.Rect((0, 0), (15, 15))] * 16 for i in range(0, 16): sampleRect[i] = pygame.Rect((16 + i * 25, 20), (16, 16)) markerRect = [pygame.Rect((0, 0), (15, 15))] * 16 for i in range(0, 16): markerRect[i] = pygame.Rect((19 + i * 25, 23), (10, 10)) lastNote = [0] * 16 lastChan = [-1] * 16 chan = [1] * 8 velocity = [64] * 8 mute = [False] * 8 shutDown = False update = False lineCol = (128, 128, 0) backCol = (160, 160, 160) hiCol = (0, 255, 255) # highlight colour scale = [72, 71, 69, 67, 65, 64, 62, 60] # key of C major note = [scale[i] for i in range(0, 8)] running = False # MIDI sequencer tempo = 60 # BPM to start setTime() # determine time interval between samples step = 0 samples = 16 newScan = False initMIDI()