change piano sample
This commit is contained in:
parent
5e7a923c3a
commit
3c96a3f3ad
18
piano.py
18
piano.py
|
@ -1,26 +1,26 @@
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
from telemetrix_rpi_pico import telemetrix_rpi_pico
|
||||||
from siwatlib.debounce import debounce
|
from siwatlib.debounce import debounce
|
||||||
from siwatlib.sound import beep
|
from siwatlib.sound import piano_key
|
||||||
|
|
||||||
import winsound
|
import winsound
|
||||||
|
|
||||||
index_shift = 2
|
index_shift = 2
|
||||||
freqs = [261.6256,293.6648,329.6276,349.2282,391.9954,440.0000,493.8833,523.2511]
|
|
||||||
|
|
||||||
debouncers = []
|
debouncers = []
|
||||||
|
|
||||||
def handle_button_press(data):
|
def handle_button_press(data):
|
||||||
freq = freqs[data[1]-index_shift]
|
try:
|
||||||
print(freq)
|
print(str(data[1])+' Pressed')
|
||||||
recieved_state = not data[2]
|
recieved_state = not data[2]
|
||||||
if debouncers[data[1]-index_shift].set_state(state=recieved_state):
|
if debouncers[data[1]-index_shift].set_state(state=recieved_state):
|
||||||
beep(frequency=freq,duration=0.25)
|
piano_key((data[1]-1)*2-1)
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port='COM10')
|
mcu = telemetrix_rpi_pico.TelemetrixRpiPico(com_port='COM10')
|
||||||
|
|
||||||
for i in range(2,10):
|
for i in range(2,10):
|
||||||
debouncers.append(debounce(state=False,debounce_time=0.15))
|
debouncers.append(debounce(state=False,debounce_time=0.2))
|
||||||
mcu.set_pin_mode_digital_input(i,callback=handle_button_press)
|
mcu.set_pin_mode_digital_input(i,callback=handle_button_press)
|
||||||
while True:
|
while True:
|
||||||
sleep(100)
|
sleep(100)
|
|
@ -1 +1,2 @@
|
||||||
telemetrix-rpi-pico
|
telemetrix-rpi-pico
|
||||||
|
playsound==1.2.2
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,6 +1,8 @@
|
||||||
from pysine import pysine
|
from pysine import pysine
|
||||||
import winsound
|
import winsound
|
||||||
import threading
|
import threading
|
||||||
|
from playsound import playsound
|
||||||
|
import os
|
||||||
|
|
||||||
MODE = 'pysine'
|
MODE = 'pysine'
|
||||||
|
|
||||||
|
@ -23,5 +25,17 @@ def beep(frequency: float, duration: float):
|
||||||
kwargs={'frequency': frequency, 'duration': duration}
|
kwargs={'frequency': frequency, 'duration': duration}
|
||||||
)
|
)
|
||||||
__beeper__.start()
|
__beeper__.start()
|
||||||
|
|
||||||
|
#TODO Tune the piano
|
||||||
|
|
||||||
|
def __piano_key_thread__(note: str):
|
||||||
|
note = format(note,'02')
|
||||||
|
soundfile = os.path.dirname(__file__)+'\\piano_sample\\key'+note+'.mp3'
|
||||||
|
print(soundfile)
|
||||||
|
playsound(soundfile)
|
||||||
|
|
||||||
|
def piano_key(note: str):
|
||||||
|
threading.Thread(target=__piano_key_thread__,
|
||||||
|
kwargs={'note': note}
|
||||||
|
).start()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue