@@ -27,11 +27,15 @@ class MidiService extends ServiceBundle<MidiInputServiceConfig, MidiInputService
27
27
devices . push ( device ) ;
28
28
}
29
29
} ) ;
30
+
30
31
if ( devices . length === 0 ) {
31
- return error ( "No device matched the configured pattern! " ) ;
32
+ return error ( "No device matched the configured pattern. " ) ;
32
33
}
33
- if ( devices . length > 1 ) {
34
- return error ( "The configured pattern is ambiguous!" ) ;
34
+
35
+ // If we have a device with the exact same name we prioritize it and use that device.
36
+ // If we have no exact match an ambiguous pattern is not allowed.
37
+ if ( devices . length > 1 && ! devices . includes ( config . device ) ) {
38
+ return error ( "The configured pattern is ambiguous." ) ;
35
39
}
36
40
}
37
41
@@ -48,11 +52,18 @@ class MidiService extends ServiceBundle<MidiInputServiceConfig, MidiInputService
48
52
logger . info ( `Checking device name "${ config . device } ".` ) ;
49
53
50
54
let deviceName : string | null = null ;
51
- easymidi . getInputs ( ) . forEach ( ( device ) => {
52
- if ( device . includes ( config . device ) && deviceName === null ) {
53
- deviceName = device ;
54
- }
55
- } ) ;
55
+ const allDevices = easymidi . getInputs ( ) ;
56
+ if ( allDevices . includes ( config . device ) ) {
57
+ // If we have a device with the correct name we use that device.
58
+ deviceName = config . device ;
59
+ } else {
60
+ // Otherwise we find a device which contains the pattern.
61
+ easymidi . getOutputs ( ) . forEach ( ( device ) => {
62
+ if ( device . includes ( config . device ) && deviceName === null ) {
63
+ deviceName = device ;
64
+ }
65
+ } ) ;
66
+ }
56
67
57
68
logger . info ( `Connecting to MIDI input device ${ deviceName } .` ) ;
58
69
if ( deviceName !== null ) {
0 commit comments