コード例 #1
0
ファイル: pipianoui.py プロジェクト: dougn/PiPianoUi
 def select(self):
     """Initialize the pygame mixer for mp3 playback.
     """
     if pianohat:
         pianohat.auto_leds(True)
     pygame.mixer.pre_init(4411 * (self.initial_octave + 1), -16, 2, 2048)
     pygame.mixer.init()
コード例 #2
0
ファイル: pipianoui.py プロジェクト: dougn/PiPianoUi
 def deselect(self):
     if pianohat:
         for i in xrange(16):
             pianohat.set_led(i, False)
         pianohat.auto_leds(True)
     self.enabled = FlipFlopState()
     pygame.mixer.stop()
     pygame.mixer.quit()
コード例 #3
0
ファイル: pipianoui.py プロジェクト: dougn/PiPianoUi
 def select(self):
     """Initialize the pygame mixer, and load the samples from files.
     """
     if pianohat:
         pianohat.auto_leds(True)
     pygame.mixer.pre_init(44100, -16, 1, 512)
     pygame.mixer.init()
     pygame.mixer.set_num_channels(32)
     self.samples = [pygame.mixer.Sound(sample) for sample in self.files]
コード例 #4
0
ファイル: pipianoui.py プロジェクト: dougn/PiPianoUi
 def register(self):
     """Register the callback methods with pianohat
     """
     if not pianohat:
         return
     startup_lights(pygame.display.update)
     pianohat.on_note(self.handle_note)
     pianohat.on_octave_up(self.handle_octave_up)
     pianohat.on_octave_down(self.handle_octave_down)
     pianohat.on_instrument(self.handle_instrument)
     pianohat.auto_leds(True)
コード例 #5
0
ファイル: pipianoui.py プロジェクト: dougn/PiPianoUi
 def select(self):
     if pianohat:
         pianohat.auto_leds(False)
         for i in xrange(16):
             pianohat.set_led(i, False)
     self.enabled = FlipFlopState()
     pygame.mixer.pre_init(self.SAMPLERATE, -self.BITRATE, 1, 1024)
     pygame.mixer.init(channels=1)
     #pygame.mixer.set_num_channels(32)
     self.toggle('sine')  # by default enable sine.
     return "C2=sine,v=square,^saw"
コード例 #6
0
    def __init__(self, container, sound_index):
        super(Piano, self).__init__(sound_index)

        self.container = container

        pianohat.on_note(self.handle_note)
        pianohat.on_octave_up(self.handle_octave_up)
        pianohat.on_octave_down(self.handle_octave_down)
        pianohat.on_instrument(self.handle_instrument)

        pianohat.auto_leds(True)
コード例 #7
0
 def setActive (self, state):
     if debug:
         print(self.name, "setActive", state)
     #
     # use default implementation to start up SPI
     #
     adapter.adapters.Adapter.setActive(self, state);
     self.bool_auto_leds =   self.isTrue( self.parameters['auto_leds']  )
     
     pianohat.auto_leds( self.bool_auto_leds )
     pianohat.on_note(self.handle_touch)
     pianohat.on_octave_up(self.handle_touch)
     pianohat.on_octave_down(self.handle_touch)
     pianohat.on_instrument(self.handle_touch)
コード例 #8
0
 def setActive (self, state):
     if debug:
         print(self.name, "setActive", state)
     #
     # use default implementation to start up SPI
     #
     adapter.adapters.Adapter.setActive(self, state);
     self.bool_auto_leds =   self.isTrue( self.parameters['auto_leds']  )
     
     pianohat.auto_leds( self.bool_auto_leds )
     pianohat.on_note(self.handle_touch)
     pianohat.on_octave_up(self.handle_touch)
     pianohat.on_octave_down(self.handle_touch)
     pianohat.on_instrument(self.handle_touch)
コード例 #9
0
def handle_note(channel, pressed): # handler for key presses
    global note
    global correct
    if channel < 13 and pressed: # Only for note keys
        if str(channel) == note: # Did the player get it right?
          print('correct, it was a ' + str(NOTES[note][0]) )
          pianohat.auto_leds(False)
          for x in range(16): # Flash all the lights to celebrate
            pianohat.set_led(x, True)
          time.sleep(0.05)
          for x in range(16): # Them turn them off
            pianohat.set_led(x,False)
          pianohat.auto_leds(True)
          correct = True
        else:
        	print('wrong, try again')
コード例 #10
0
ファイル: pipianoui.py プロジェクト: dougn/PiPianoUi
def startup_lights(callback=None):
    """Cycle the leds on the PianoHAT in a pretty way to show things started up.
    """
    if not pianohat:
        return
    pianohat.auto_leds(False)
    led = FlipFlopState()
    for i in xrange(16):
        if i < 13:
            pianohat.set_led(i, True)
        if i - 3 >= 0:
            pianohat.set_led(i - 3, False)
        j = 13 + (i % 3)
        pianohat.set_led(j, led.toggle(j))
        time.sleep(_STARTUP_DELAY)
        if callback and callable(callback):
            callback()
    for i in xrange(16):
        pianohat.set_led(1, False)
    pianohat.auto_leds(True)
コード例 #11
0
def main():

    # Initialise Variables

    global max_amplitude_output
    global max_amplitude_input

    global current_window
    global previous_window

    global is_first_sample

    pianohat.auto_leds(True)
    current_window = []
    previous_window = []

    # Initialise PyAudio stream and pass 'callback' as callback function

    stream = p.open(
        format=pyaudio.paFloat32,
        channels=CHANNELS,
        rate=RATE,
        output=True,
        input=True,
        output_device_index=0,
        frames_per_buffer=CHUNK,
        stream_callback=callback,
    )

    # Keep the audio card from overloading by restarting the stream continously

    while True:
        stream.start_stream()
        time.sleep(20)
        stream.stop_stream()

    stream.close()
    p.terminate()
コード例 #12
0
ファイル: learn-to-play.py プロジェクト: RogueM/Piano-HAT
    '39174__jobro__piano-ff-027.wav',
    '39175__jobro__piano-ff-028.wav',
    '39176__jobro__piano-ff-029.wav',
    '39177__jobro__piano-ff-030.wav',
    '39178__jobro__piano-ff-031.wav',
    '39179__jobro__piano-ff-032.wav',
    '39180__jobro__piano-ff-033.wav',
    '39181__jobro__piano-ff-034.wav',
    '39182__jobro__piano-ff-035.wav',
    '39183__jobro__piano-ff-036.wav',
    '39184__jobro__piano-ff-037.wav'
]

samples = [pygame.mixer.Sound(os.path.join(SOUNDS, sample)) for sample in files]

pianohat.auto_leds(False)


def handle_note(channel, pressed):
    if not channel == current_note():
        return

    if channel < len(samples) and pressed:
        print('Playing Sound: {}'.format(files[channel]))
        samples[channel].play(loops=0)
        next()


def handle_instrument(channel, pressed):
    pass
コード例 #13
0
#
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
####

import pianohat, sys

key_names = [
    "C_lo", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B", "C_hi",
    "Octave_down", "Octave_up", "Instrument"
]

pianohat.auto_leds(True)


def handler(key, evt):
    if not evt:  # key release
        print("PianoHat key: " + str(key) + "; name: " + key_names[key])


pianohat.on_note(handler)
pianohat.on_octave_up(handler)
pianohat.on_octave_down(handler)
pianohat.on_instrument(handler)

line = sys.stdin.readline()
while line:
    line = line.strip()
コード例 #14
0
ファイル: 8bit-synth.py プロジェクト: rbarraud/Piano-HAT
print("Initializing subsystem...")
pygame.mixer.pre_init(SAMPLERATE, -BITRATE, 4, 256)
pygame.mixer.init()
pygame.mixer.set_num_channels(32)

print("Generating samples...")
for f in [
        261.626, 277.183, 293.665, 311.127, 329.628, 349.228, 369.994, 391.995,
        415.305, 440.000, 466.164, 493.883, 523.251
]:
    notes['sine'] += [
        generate_sample(f, volume=volume['sine'], wavetype=wave_sine)
    ]
    notes['saw'] += [
        generate_sample(f, volume=volume['saw'], wavetype=wave_saw)
    ]
    notes['square'] += [
        generate_sample(f, volume=volume['square'], wavetype=wave_square)
    ]

pianohat.auto_leds(False)
pianohat.on_note(play_sample)
pianohat.on_instrument(handle_instrument)
pianohat.on_octave_up(handle_instrument)
pianohat.on_octave_down(handle_instrument)
update_leds()

print("Now, make beautiful music...")

signal.pause()
コード例 #15
0
ファイル: pathe.py プロジェクト: lesp/BpoolMuseum
#!/usr/bin/env python

import pianohat,time,signal,pygame,os

pianohat.auto_leds(True)
pygame.mixer.init()

def music(audio):
    pygame.mixer.music.load(audio)
    pygame.mixer.music.play(1)
    time.sleep(5)

def player(video):
    os.system("omxplayer -o local "+str(video))

def handle_touch(ch, evt):
    #print(ch, evt)
    if ch == 0:
        print("Film 1")
        music("seaside.mp3")
        player("Blackpool_Illuminations.mp4")
    elif ch == 2:
        print("Film 2")
        music("seaside.mp3")
        player("Blackpool_Illuminations_Ride.mp4")
    elif ch == 4:
        print("Film 3")
        music("seaside.mp3")
        player("Blackpool_Issue_Title_Pathe_Pictorial_Goes_To_The_Seaside.mp4")
    elif ch == 5:
        print("Film 4")
コード例 #16
0
import pianohat # import libraries we need
import pygame
import time, random

pygame.mixer.pre_init(44100, -16, 1, 512) #Configure pygame sound
pygame.mixer.init() #Initialise pygame mixer
pygame.mixer.set_num_channels(16)
pianohat.auto_leds(True) # LEDs light whne keys pressed
# A dictionary mapping sounds and notes onto keys
NOTES = {'0':['C','./sounds/piano/39172__jobro__piano-ff-025.wav'], # C
  '1': ['C Sharp', './sounds/piano/39173__jobro__piano-ff-026.wav'], # C sharp
  '2':['D','./sounds/piano/39174__jobro__piano-ff-027.wav'], # D
  '3':['D Sharp','./sounds/piano/39175__jobro__piano-ff-028.wav'], # D sharp
  '4':['E','./sounds/piano/39176__jobro__piano-ff-029.wav'], # E
  '5':['F','./sounds/piano/39177__jobro__piano-ff-030.wav'], # F
  '6':['F Sharp','./sounds/piano/39178__jobro__piano-ff-031.wav'], # F sharp
  '7':['G','./sounds/piano/39179__jobro__piano-ff-032.wav'], # G
  '8':['G Sharp','./sounds/piano/39180__jobro__piano-ff-033.wav'], # G sharp
  '9':['A','./sounds/piano/39181__jobro__piano-ff-034.wav'], # A
  '10':['A Sharp','./sounds/piano/39182__jobro__piano-ff-035.wav'], # A sharp
  '11':['B','./sounds/piano/39183__jobro__piano-ff-036.wav'], # B
  '12':['C','./sounds/piano/39184__jobro__piano-ff-037.wav'] # C
}

def handle_note(channel, pressed): # handler for key presses
    global note
    global correct
    if channel < 13 and pressed: # Only for note keys
        if str(channel) == note: # Did the player get it right?
          print('correct, it was a ' + str(NOTES[note][0]) )
          pianohat.auto_leds(False)
コード例 #17
0
            pianohat.set_led(i, onOrOff)


def leds_off() -> None:
    """ Turn off all LEDs on the Piano Hat """
    for i in range(15):
        pianohat.set_led(i, False)


pygame.init()
pygame.mixer.init()
pygame.mixer.music.set_volume(volume)

leds_off()

pianohat.auto_leds(enable=False)
pianohat.on_octave_down(volume_down)
pianohat.on_octave_up(volume_up)
pianohat.on_instrument(pause_music)
pianohat.on_note(play_song)


def shutdown() -> None:
    """ Things we need to do to gracefully shut this program down. """
    leds_off()
    sys.exit(0)


def handle_sigterm(signal, frame) -> None:
    shutdown()