3535from lisp .core .plugin import PluginNotLoadedError
3636from lisp .plugins .controller .common import LayoutAction , tr_layout_action
3737from lisp .plugins .controller .protocol import Protocol
38- from lisp .plugins .midi .midi_utils import (
39- MIDI_MSGS_NAME ,
40- midi_data_from_msg ,
41- midi_msg_from_data ,
42- midi_from_dict ,
43- midi_from_str ,
44- MIDI_MSGS_SPEC ,
45- MIDI_ATTRS_SPEC ,
46- PortDirection ,
47- )
48- from lisp .plugins .midi .widgets import MIDIPatchCombo , MIDIMessageEditDialog
4938from lisp .ui .qdelegates import (
5039 CueActionDelegate ,
5140 EnumComboBoxDelegate ,
5544from lisp .ui .settings .pages import CuePageMixin , SettingsPage
5645from lisp .ui .ui_utils import translate
5746
47+ try :
48+ from lisp .plugins .midi .midi_utils import (
49+ MIDI_MSGS_NAME ,
50+ midi_data_from_msg ,
51+ midi_msg_from_data ,
52+ midi_from_dict ,
53+ midi_from_str ,
54+ MIDI_MSGS_SPEC ,
55+ MIDI_ATTRS_SPEC ,
56+ PortDirection ,
57+ )
58+ from lisp .plugins .midi .widgets import MIDIPatchCombo , MIDIMessageEditDialog
59+ except ImportError :
60+ midi_from_str = lambda * _ : None
61+
5862
5963logger = logging .getLogger (__name__ )
6064
@@ -76,6 +80,16 @@ def __init__(self, actionDelegate, **kwargs):
7680
7781 self .midiModel = MidiModel ()
7882
83+ try :
84+ self .__midi = get_plugin ("Midi" )
85+ except PluginNotLoadedError :
86+ self .setEnabled (False )
87+ self .midiNotInstalledMessage = QLabel ()
88+ self .midiNotInstalledMessage .setAlignment (Qt .AlignCenter )
89+ self .midiGroup .layout ().addWidget (self .midiNotInstalledMessage )
90+ self .retranslateUi ()
91+ return
92+
7993 self .midiView = MidiView (actionDelegate , parent = self .midiGroup )
8094 self .midiView .setModel (self .midiModel )
8195 self .midiGroup .layout ().addWidget (self .midiView , 0 , 0 , 1 , 2 )
@@ -117,12 +131,13 @@ def __init__(self, actionDelegate, **kwargs):
117131 self .retranslateUi ()
118132
119133 self ._defaultAction = None
120- try :
121- self .__midi = get_plugin ("Midi" )
122- except PluginNotLoadedError :
123- self .setEnabled (False )
124134
125135 def retranslateUi (self ):
136+ if hasattr (self , "midiNotInstalledMessage" ):
137+ self .midiNotInstalledMessage .setText (
138+ translate ("ControllerSettings" , "MIDI plugin not installed" ))
139+ return
140+
126141 self .addButton .setText (translate ("ControllerSettings" , "Add" ))
127142 self .removeButton .setText (translate ("ControllerSettings" , "Remove" ))
128143
@@ -262,9 +277,16 @@ def __init__(self):
262277 translate ("ControllerMidiSettings" , "Action" ),
263278 ]
264279 )
265- self .__midi = get_plugin ("Midi" )
280+ try :
281+ self .__midi = get_plugin ("Midi" )
282+ if not self .__midi .is_loaded ():
283+ self .__midi = None
284+ except PluginNotLoadedError :
285+ self .__midi = None
266286
267287 def appendMessage (self , patch_id , message , action ):
288+ if not self .__midi :
289+ return
268290 data = midi_data_from_msg (message )
269291 data .extend ((None ,) * (3 - len (data )))
270292 self .appendRow (patch_id , message .type , * data , action )
@@ -354,8 +376,13 @@ class Midi(Protocol):
354376
355377 def __init__ (self ):
356378 super ().__init__ ()
357- # Install callback for new MIDI messages
358- get_plugin ("Midi" ).received .connect (self .__new_message )
379+ try :
380+ # Install callback for new MIDI messages
381+ midi = get_plugin ("Midi" )
382+ if midi .is_loaded ():
383+ midi .received .connect (self .__new_message )
384+ except PluginNotLoadedError :
385+ pass
359386
360387 def __new_message (self , patch_id , message ):
361388 if hasattr (message , "velocity" ):
0 commit comments