コード例 #1
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)
コード例 #2
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)
コード例 #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)
コード例 #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)
コード例 #5
0
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
コード例 #6
0
ファイル: learn-to-play.py プロジェクト: RogueM/Piano-HAT
    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()
コード例 #7
0
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()
コード例 #8
0
        f = open(".pianohash", "w+")
        f.write(hashed)
        f.close()
        print "Password has been saved."
        # Launch procedure to encode text....
        encode_text()


def handle_octave_up(channel, pressed):
    global octave
    if pressed and octave < octaves:
        octave += 1
        print('Selected Octave: {}'.format(octave))


def handle_octave_down(channel, pressed):
    global octave
    if pressed and octave > 0:
        octave -= 1
        print('Selected Octave: {}'.format(octave))


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

load_samples(patches[patch_index])

signal.pause()
コード例 #9
0
ファイル: buttons.py プロジェクト: silasppeterson/Piano-HAT
#!/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()
コード例 #10
0
ファイル: buttons.py プロジェクト: rcursaru/pimoroni-piano
#!/usr/bin/env python
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.
""")
import pianohat
import signal

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()
コード例 #11
0
            pianohat.set_led(13, True)
            pianohat.set_led(14, False)
        if (ch == 14):
            bank = 1
            pianohat.set_led(13, False)
            pianohat.set_led(14, True)
        # toggle record on off, off also erases
        if (ch == 15):
            if (rec == True):
                rec = False
                recordings = [[-1], [-1], [-1], [-1], [-1], [-1], [-1], [-1]]
                pianohat.set_led(15, False)
            else:
                rec = True
                pianohat.set_led(15, True)


# create sound objects for all .wav files
sounds.append(settings.createSoundObjects(settings.files1))
sounds.append(settings.createSoundObjects(settings.files2))

# piano key handlers
pianohat.on_octave_up(changeSettings)
pianohat.on_octave_down(changeSettings)
pianohat.on_instrument(changeSettings)

pianohat.on_note(handleNote)

# start the led animation, also causes the app to keep listening for key presses
nextStep()
コード例 #12
0
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()


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