Skip to content

Commit 3dae694

Browse files
committed
Improve Beep Logic
1 parent 1747ee1 commit 3dae694

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

MonikaUI/beep_midi.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from ctypes import *
44
import signal
55
import sys
6+
import time
67

78
MonikaDLL = cdll.LoadLibrary(os.getcwd() + '\\MonikaDLL.dll')
89
MonikaDLL.get_my_driver_handle.restype = c_uint8
@@ -16,6 +17,7 @@ def signal_handler(sig, frame):
1617
print('You pressed Ctrl+C!')
1718
MonikaDLL.MonikaBeepStop()
1819
sys.exit(0)
20+
1921
signal.signal(signal.SIGINT, signal_handler)
2022

2123
# Function to convert MIDI note number to frequency (Hz)
@@ -28,11 +30,13 @@ def play_beep_for_midi(note, duration_ms):
2830
frequency = int(midi_note_to_freq(note)) # Convert MIDI note to frequency
2931
print(f'Playing note {note} at {frequency} Hz for {duration_ms} ms')
3032
MonikaDLL.MonikaBeepStart(frequency) # Start beep
33+
time.sleep(duration_ms / 1000) # Sleep for duration
34+
MonikaDLL.MonikaBeepStop() # Stop beep
3135

3236
# Read MIDI file
3337
def play_midi_beep(file_path):
3438
mid = mido.MidiFile(file_path)
35-
tempo = 500000 # Default tempo (microseconds per beat)
39+
tempo = 50000 # Default tempo (microseconds per beat)
3640

3741
for msg in mid.play():
3842
if msg.type == 'note_on' and msg.velocity > 0: # Play note

0 commit comments

Comments
 (0)