11# @author: https://github.com/Alperencode
22# @date: 01 Aug 2022
3- # @last update: 13 Oct 2022
3+ # @last update: 22 Oct 2022
44
55# Importing midi directory
66from midi import *
@@ -78,7 +78,7 @@ def __init__(self,note_name,octave=5,velocity=64,output=None, app=None):
7878
7979 self .__entry_box = Entry (self .app , width = 5 )
8080 self .__entry_box .place (x = 50 , y = 10 + (NoteButton .label_counter * 20 ))
81- self .__entry_box .bind ('<Return>' , lambda event : self .set_saved_pitch (self .__entry_box .get ()))
81+ self .__entry_box .bind ('<Return>' , lambda event : ( self .set_saved_pitch (self .__entry_box .get ()), self . update_local_pitch ()))
8282 else :
8383 NoteButton .label_counter += 1.5
8484
@@ -87,7 +87,7 @@ def __init__(self,note_name,octave=5,velocity=64,output=None, app=None):
8787
8888 self .__entry_box = Entry (self .app , width = 5 )
8989 self .__entry_box .place (x = 130 , y = 10 + (NoteButton .label_counter * 20 ))
90- self .__entry_box .bind ('<Return>' , lambda event : self .set_saved_pitch (self .__entry_box .get ()))
90+ self .__entry_box .bind ('<Return>' , lambda event : ( self .set_saved_pitch (self .__entry_box .get ()), self . update_local_pitch ()))
9191
9292 # Placing button in the GUI
9393 button .place (x = NoteButton .placement [NoteButton .counter ], y = 300 )
@@ -185,16 +185,22 @@ def send_note_on(self):
185185 Label (self .app , text = f"Sending { self .get_note_name ()} octave { self .get_octave ()} with \n { self .__pitch_value } pitch and { self .get_velocity ()} velocity" ,font = ("Arial" ,12 ,"bold" )).place (x = 200 , y = 40 )
186186
187187 # Sending midi signal
188- self .output .send ( mido .Message ('note_on' , note = note_to_number (self .get_note_name (), self .get_octave ()), velocity = self .get_velocity ()) )
189-
188+ try :
189+ self .output .send ( mido .Message ('note_on' , note = note_to_number (self .get_note_name (), self .get_octave ()), velocity = self .get_velocity ()) )
190+ except :
191+ print ("\a Invalid note" )
192+
190193 def send_pitch_wheel (self ):
191194 """Sending converted pitch value to the midi device"""
192195 sending_value = converter (self .get_pitch (), False )
193196 self .output .send ( mido .Message ('pitchwheel' , pitch = sending_value ) )
194197
195198 def send_note_off (self ):
196199 """Sending note_off message to the midi device"""
197- self .output .send ( mido .Message ('note_off' , note = note_to_number (self .get_note_name (), self .get_octave ()), velocity = self .get_velocity ()) )
200+ try :
201+ self .output .send ( mido .Message ('note_off' , note = note_to_number (self .get_note_name (), self .get_octave ()), velocity = self .get_velocity ()) )
202+ except :
203+ print ("\a Invalid note" )
198204 self .output .send ( NoteButton .control_change )
199205
200206 @staticmethod
0 commit comments