Esempio n. 1
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)
Esempio n. 2
0
 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)
Esempio n. 3
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)
Esempio n. 4
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)
def do_processing(input_signal):

    global max_amplitude_input
    global is_first_sample
    global max_amplitude_output

    # Listen to controller events

    note = pianohat.on_note(controller)
    oct_up = pianohat.on_octave_up(switch_up)
    oct_down = pianohat.on_octave_down(switch_down)
    oct_inst = pianohat.on_instrument(effect_on)

    # Convert to native array using the 'array' module for faster processing

    input_signal = array('f', input_signal)

    # Apply audio effects that have been selected by the user

    if effects[0]['effect_on'] is True:
        input_signal = amp_convolution(input_signal, hanning)
        f1.write('Amp Convolution : on')
        f1.write('\n')

    # Add little amounts to the effect amount to prevent 0 division

    if effects[1]['effect_on'] is True:
        amount = effects[1]['effect_amount']
        input_signal = mod_effect(input_signal, amount + 0.01)
        f1.write('Modulation : on')
        f1.write('\n')

    if effects[2]['effect_on'] is True:
        amount = effects[2]['effect_amount']
        input_signal = hard_clipping(input_signal, float(amount) / 100 + 0.005)
        f1.write('Distortion : on')
        f1.write('\n')

    if effects[3]['effect_on'] is True:
        amount = effects[3]['effect_amount']
        input_signal = chorus_effect(input_signal, 10, amount + 0.01)
        f1.write('Chorus : on')
        f1.write('\n')

    # Convert back to numpy array

    input_signal = np.array(input_signal)

    # Normalise output using a global maximum

    local_max = np.max(np.abs(input_signal))
    if local_max > max_amplitude_output:
        max_amplitude_output = local_max
    input_signal = np.float32(input_signal / float(local_max))

    return input_signal
Esempio n. 6
0
import pianohat
import time
from pygame import mixer


def handle_note(channel, pressed):
    if pressed:
        my_sounds[channel].play(loops=0)
        print("You pressed key {}".format(channel))
    else:
        print("You released key {}".format(channel))


mixer.init(22050, -16, 2, 512)
mixer.set_num_channels(13)
my_sound_files = [
    "/home/pi/moo.wav", "/home/pi/dog.wav", "/home/pi/dog.wav",
    "/home/pi/moo.wav", "/home/pi/dog.wav", "/home/pi/moo.wav",
    "/home/pi/dog.wav", "/home/pi/moo.wav", "/home/pi/dog.wav",
    "/home/pi/moo.wav", "/home/pi/dog.wav", "/home/pi/moo.wav",
    "/home/pi/dog.wav"
]
my_sounds = [mixer.Sound(sound_file) for sound_file in my_sound_files]
pianohat.on_note(handle_note)
while True:
    time.sleep(0.001)
Esempio n. 7
0
    if channel < len(samples) and pressed:
        print('Playing Sound: {}'.format(files[channel]))
        samples[channel].play(loops=0)
        next()


def handle_instrument(channel, pressed):
    pass


def handle_octave_up(channel, pressed):
    pass


def handle_octave_down(channel, pressed):
    pass


for x in range(16):
    pianohat.set_led(x, False)

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

pianohat.set_led(current_note(), True)

signal.pause()
Esempio n. 8
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()
    if not line:
        pass  # ignore blank input
    elif line.startswith("hi"):
        print("Hello from PianoHat!")
    else:
        print("echo: " + line)
    #
    line = sys.stdin.readline()
Esempio n. 9
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')

def play(note): # Play a note from the dictionary
	pygame.mixer.Sound(NOTES[note][1]).play(loops=0)
	time.sleep(1)

pianohat.on_note(handle_note) # Set keys to use our handler

while True:
  print('Here comes a C')
  time.sleep(1)
  play('0') # Play a C
  time.sleep(2)
  correct = False
  print('Now identify this note')
  time.sleep(2)
  note = random.choice(list(NOTES)) # Pick a random note
  play(note)
  print('press the key for the note you heard')
  count = 6 # Set countdown timer
  while count > 0 and correct == False:
    time.sleep(1)
Esempio n. 10
0
        print("Film 3")
        music("seaside.mp3")
        player("Blackpool_Issue_Title_Pathe_Pictorial_Goes_To_The_Seaside.mp4")
    elif ch == 5:
        print("Film 4")
        music("seaside.mp3")
        player("Blackpool_Promenade_1900.mp4")
    elif ch == 7:
        print("Film 5")
        music("seaside.mp3")
        player("Camera_Takes_Easter_Holiday_AKA_Blackpool_Beach.mp4")
    elif ch == 9:
        print("Film 6")
        music("seaside.mp3")
        player("Extra_!_Blackpool_Illuminations.mp4")
    elif ch == 11:
        print("Film 7")
        music("seaside.mp3")
        player("Holiday_News_Aka_Holiday_Scenes_-_Blackpool.mp4")
    elif ch == 12:
        print("Film 8")
        music("seaside.mp3")
        player("The_Pageant_Of_Progress.mp4")
    else:
        print("Press a key on the Wurlitzer")

pianohat.on_note(handle_touch)


signal.pause()
Esempio n. 11
0
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()
Esempio n. 12
0
        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()
Esempio n. 13
0
#!/usr/bin/env python

import signal

import pianohat

print("""
This simple example shows you how to make Piano HAT keypresses do something useful.

You should see details of each press appear below as you touch Piano HAT's keys

Press CTRL+C to exit.
""")

pianohat.auto_leds(True)


def handle_touch(ch, evt):
    print(ch, evt)


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

signal.pause()
Esempio n. 14
0
    """ 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()


def main_loop() -> None:
    """ Block to keep this program running. """
    while True: