저는 MIDI 키보드 "Impulse"와 raspi3를 가지고 있습니다. 키보드를 raspi에 연결하여 아무것도 건드리지 않고 소리를 내고 싶습니다.
그래서 오디오 드라이버로 fluidsynth
with를 사용합니다 . jack
Fluidsynth는 systemd 서비스에 의해 시작됩니다. 괜찮아요.
그래서 저는 포트를 "jack_connect"하고 키보드의 미디 포트를 신디사이저 Fluidsynth에 다음과 같이 "연결"하는 스크립트를 만들었습니다.
impulseport=$(aconnect -i|grep -i "IMPULSE" | cut -d ' ' -f 2)0
synthport=$(aconnect -o |grep -i "FLUID" | cut -d ' ' -f 2)0
# some verifications of existence and exit if one port is missing
aconnect ${impulseport} ${synthport}
문제는 내가 원하는 대로 되지 않는다는 것이다. 내 udev 규칙은 "snd-usb-audio" 인터페이스 드라이버를 로드하기 전에 이 스크립트를 트리거하는 것입니다. 따라서 변수는 $impulseport
비어 있습니다(실제로는 =0, 마지막에 연결됨).
내 udev 규칙은 다음과 같습니다.
ACTION=="add", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="1235", ATTRS{idProduct}=="001a", RUN+="/bin/su -c /home/pi/piano_connect - pi"
ACTION=="remove", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="1235", ATTRS{idProduct}=="001a", RUN+="/usr/bin/aconnect -x"
시스템 로그에서:
1 systemd[410]: Started Sound Service.
2 fluidsynth[423]: fluidsynth: Jack sample rate mismatch, adjusting. (synth.sample-rate=44100, jackd=48000)
3 kernel: [162.772916] usb 1-1.2: new full-speed USB device number 4 using dwc_otg
4 kernel: [162.905473] usb 1-1.2: New USB device found, idVendor=1235, idProduct=001a, bcdDevice= 0.00
5 kernel: [162.905491] usb 1-1.2: New USB device strings: Mfr=1, Product=2, SerialNumber=0
6 kernel: [162.905500] usb 1-1.2: Product: Impulse
7 kernel: [162.905509] usb 1-1.2: Manufacturer: Focusrite A.E. Ltd
8 mtp-probe: checking bus 1, device 4: "/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2"
9 mtp-probe: bus: 1, device: 4 was not an MTP device
10 systemd[1]: Started Session c2 of user pi.
11 pi: [Piano] Jackd : connecting system to fluidsynth ports
12 pi: [Piano] Error: Port Impulse unknown, exiting
13 systemd-udevd[473]: Process '/bin/su -c /home/pi/piano_connect - pi' failed with exit code 1.
14 systemd[1]: session-c2.scope: Succeeded.15
15 kernel: [165.876060] usbcore: registered new interface driver snd-usb-audio
16 mtp-probe: checking bus 1, device 4: "/sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2"
17 mtp-probe: bus: 1, device: 4 was not an MTP device
문제는 12번째 줄에 있습니다. $impulseport
비어있습니다! 따라서 스크립트가 종료됩니다(라인 13). 15번 줄에서 드라이버가 나중에 로드되는 것을 볼 수 있습니다. 그래서 내 스크립트에서는 디렉터리가 a /sys/bus/usb/drivers/snd-usb-audio
로 존재하는지 확인하는 while 루프와 같은 지저분한 작업을 수행 sleep
하지만 이로 인해 시스템이 중단되고 모듈이 로드되지 않습니다. 당신은 알고 있나요? 탈출구는 없나요?
참고: USB MIDI 키보드를 뽑았다가 다시 연결하면 제대로 작동하지만 부팅 후 첫 번째 플러그에서 작동하고 싶습니다...또는 키보드가 이미 연결되어 있는 부팅 후에도 정상적으로 작동합니다: D
답변1
글쎄요, 몇 가지 조사 끝에 탈출구를 찾았습니다. 1. udevadm monitor
사용하기 전에 플러그를 뽑았다가 꽂으십시오. 출력은 다음과 같습니다.
KERNEL[126.555200] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
KERNEL[126.555888] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
KERNEL[126.556508] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.1 (usb)
KERNEL[126.557829] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.2 (usb)
KERNEL[126.558188] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.3 (usb)
KERNEL[126.558548] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
KERNEL[129.399848] add /module/snd_seq_dummy (module)
UDEV [129.406959] add /module/snd_seq_dummy (module)
UDEV [129.493966] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
UDEV [129.501782] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.2 (usb)
UDEV [129.505609] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.3 (usb)
KERNEL[129.508606] add /module/snd_rawmidi (module)
UDEV [129.510396] add /module/snd_rawmidi (module)
KERNEL[129.513459] add /module/snd_usbmidi_lib (module)
UDEV [129.515605] add /module/snd_usbmidi_lib (module)
KERNEL[129.516631] add /module/snd_hwdep (module)
UDEV [129.518617] add /module/snd_hwdep (module)
KERNEL[129.535977] add /module/snd_usb_audio (module)
UDEV [129.537881] add /module/snd_usb_audio (module)
KERNEL[129.538452] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.1 (usb)
KERNEL[129.538547] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1 (sound)
KERNEL[129.539135] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/midiC1D0 (sound)
KERNEL[129.539260] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/seq-midi-1-0 (snd_seq)
KERNEL[129.539985] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/controlC1 (sound)
KERNEL[129.541172] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV [129.541345] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.1 (usb)
KERNEL[129.541428] add /bus/usb/drivers/snd-usb-audio (drivers)
UDEV [129.542776] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV [129.542917] add /bus/usb/drivers/snd-usb-audio (drivers)
KERNEL[129.549489] add /module/snd_seq_midi_event (module)
UDEV [129.551648] add /module/snd_seq_midi_event (module)
KERNEL[129.552118] add /module/snd_seq_midi (module)
KERNEL[129.552213] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/seq-midi-1-0 (snd_seq)
KERNEL[129.552288] add /bus/snd_seq/drivers/snd_seq_midi (drivers)
UDEV [129.554430] add /module/snd_seq_midi (module)
UDEV [129.554572] add /bus/snd_seq/drivers/snd_seq_midi (drivers)
UDEV [129.561871] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2 (usb)
UDEV [129.564936] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.1 (usb)
UDEV [129.566125] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1 (sound)
UDEV [129.568261] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/seq-midi-1-0 (snd_seq)
UDEV [129.570243] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/midiC1D0 (sound)
KERNEL[129.573057] change /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1 (sound)
UDEV [129.607147] add /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/controlC1 (sound)
UDEV [129.609881] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0 (usb)
UDEV [129.611644] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/seq-midi-1-0 (snd_seq)
UDEV [129.618931] change /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1 (sound)
마지막 줄을 확인한 후 UDEV [129.611644] bind /devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/seq-midi-1-0 (snd_seq)
USB MIDI 키보드를 연결하고 다음을 수행했습니다.
devadm info -a /sys/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2\:1.0/sound/card1/seq-midi-1-0/> /tmp/udev`
출력에서 첫 번째 줄은 다음과 같습니다.
looking at device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1/seq-midi-1-0':
KERNEL=="seq-midi-1-0"
SUBSYSTEM=="snd_seq"
DRIVER=="snd_seq_midi"
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0/sound/card1':
KERNELS=="card1"
SUBSYSTEMS=="sound"
DRIVERS==""
ATTRS{number}=="1"
ATTRS{id}=="Impulse"
looking at parent device '/devices/platform/soc/3f980000.usb/usb1/1-1/1-1.2/1-1.2:1.0':
KERNELS=="1-1.2:1.0"
SUBSYSTEMS=="usb"
DRIVERS=="snd-usb-audio"
ATTRS{bInterfaceProtocol}=="00"
ATTRS{bInterfaceSubClass}=="01"
ATTRS{interface}=="Novation Impulse"
ATTRS{bInterfaceNumber}=="00"
ATTRS{supports_autosuspend}=="1"
ATTRS{bAlternateSetting}==" 0"
ATTRS{authorized}=="1"
ATTRS{bNumEndpoints}=="00"
ATTRS{bInterfaceClass}=="01"
흥미로운 정보는 SUBSYSTEM
과 입니다 DRIVERS
. 그래서 udev 규칙을 다음과 같이 변경했습니다.
ACTION=="bind", SUBSYSTEM=="snd_seq", DRIVERS=="snd-usb-audio", RUN+="/bin/su -c /home/pi/piano_connect - pi"
ACTION=="remove", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}=="1235", ATTRS{idProduct}=="001a", RUN+="/usr/bin/aconnect -x"
여기서는 첫 번째 명령( )이 udevadm monitor
제품 ID가 아닌 와 일치하기 때문에 ACTION을 "bind"로 변경했습니다. 그것은 매력처럼 작동합니다! 도움이 되길 바랍니다. :)SUBSYSTEM
DRIVERS