diff --git a/share/examples/Makefile b/share/examples/Makefile index 1fbc74f51083..04117719aa95 100644 --- a/share/examples/Makefile +++ b/share/examples/Makefile @@ -1,411 +1,410 @@ # # Doing a make install builds /usr/share/examples .include PACKAGE=examples FILESDIR= ${SHAREDIR}/examples LDIRS= BSD_daemon \ FreeBSD_version \ IPv6 \ bootforth \ csh \ drivers \ etc \ find_interface \ flua \ indent \ ipfw \ jails \ kld \ libvgl \ mdoc \ netgraph \ perfmon \ ppi \ ppp \ printing \ ses \ scsi_target \ sound \ sunrpc \ ypldap SE_DIRS+= BSD_daemon SE_BSD_DAEMON= \ FreeBSD.pfa \ README \ beastie.eps \ beastie.fig \ eps.patch \ poster.sh .if ${MACHINE_CPUARCH} == "amd64" .if ${MK_BHYVE} != "no" LDIRS+= bhyve SE_DIRS+= bhyve SE_BHYVE= vmrun.sh PACKAGE_bhyve/vmrun.sh= bhyve .endif .endif SE_DIRS+= FreeBSD_version SE_FREEBSD_VERSION= \ FreeBSD_version.c \ Makefile \ README SE_DIRS+= IPv6 SE_IPV6= USAGE SE_DIRS+= bootforth SE_BOOTFORTH= \ README \ boot.4th \ frames.4th \ loader.rc \ menu.4th \ menuconf.4th \ screen.4th SE_DIRS+= csh SE_CSH= dot.cshrc SE_DIRS+= drivers SE_DRIVERS= \ README \ make_device_driver.sh \ make_pseudo_driver.sh SE_DIRS+= etc SE_ETC= \ README.examples \ bsd-style-copyright \ make.conf SE_DIRS+= find_interface SE_FIND_INTERFACE= \ Makefile \ README \ find_interface.c SE_DIRS+= flua SE_FLUA= libjail.lua SE_DIRS+= indent SE_INDENT= indent.pro .if ${MK_IPFILTER} != "no" SUBDIR+= ipfilter .endif SE_DIRS+= ipfw SE_IPFW= change_rules.sh SE_DIRS+= jails SE_JAILS= \ README \ VIMAGE \ jail.xxx.conf \ jib \ jng \ rc.conf.jails \ rcjail.xxx.conf SE_DIRS+= kld SE_KLD= Makefile SE_DIRS+= kld/cdev SE_KLD_CDEV= \ Makefile \ README \ SE_DIRS+= kld/cdev/module SE_KLD_CDEV_MODULE= \ Makefile \ cdev.c \ cdev.h \ cdevmod.c SE_DIRS+= kld/cdev/test SE_KLD_CDEV_TEST= \ Makefile \ testcdev.c SE_DIRS+= kld/dyn_sysctl SE_KLD_DYN_SYSCTL= \ Makefile \ README \ dyn_sysctl.c SE_DIRS+= kld/firmware SE_KLD_FIRMWARE= \ Makefile \ README SE_DIRS+= kld/firmware/fwconsumer SE_KLD_FIRMWARE_FWCONSUMER= \ Makefile \ fw_consumer.c SE_DIRS+= kld/firmware/fwimage SE_KLD_FIRMWARE_FWIMAGE= \ Makefile \ firmware.img.uu SE_DIRS+= kld/khelp SE_KLD_KHELP= \ Makefile \ README \ h_example.c SE_DIRS+= kld/syscall SE_KLD_SYSCALL= Makefile SE_DIRS+= kld/syscall/module SE_KLD_SYSCALL_MODULE= \ Makefile \ syscall.c SE_DIRS+= kld/syscall/test SE_KLD_SYSCALL_TEST= \ Makefile \ call.c SE_DIRS+= libvgl SE_LIBVGL= \ Makefile \ demo.c SE_DIRS+= mdoc SE_MDOC= \ POSIX-copyright \ deshallify.sh \ example.1 \ example.3 \ example.4 \ example.9 SE_DIRS+= netgraph SE_NETGRAPH= \ ether.bridge \ frame_relay \ ngctl \ raw \ udp.tunnel \ virtual.chain \ virtual.lan \ SE_DIRS+= perfmon SE_PERFMON= \ Makefile \ README \ perfmon.c \ .if ${MK_PF} != "no" SE_DIRS+= pf .if ${MK_STAGING} == "no" SE_PF= \ ackpri \ faq-example1 \ faq-example2 \ faq-example3 \ pf.conf \ queue1 \ queue2 \ queue3 \ queue4 \ spamd .endif .endif SE_DIRS+= ppi SE_PPI= \ Makefile \ ppilcd.c SE_DIRS+= ppp SE_PPP= \ chap-auth \ login-auth \ ppp.conf.sample \ ppp.conf.span-isp \ ppp.conf.span-isp.working \ ppp.linkdown.sample \ ppp.linkdown.span-isp \ ppp.linkdown.span-isp.working \ ppp.linkup.sample \ ppp.linkup.span-isp \ ppp.linkup.span-isp.working \ ppp.secret.sample \ ppp.secret.span-isp \ ppp.secret.span-isp.working SE_DIRS+= printing SE_PRINTING= \ diablo-if-net \ hpdf \ hpif \ hpof \ hprf \ hpvf \ if-simple \ if-simpleX \ ifhp \ make-ps-header \ netprint \ psdf \ psdfX \ psif \ pstf \ pstfX SE_DIRS+= ses SE_SES= \ Makefile \ Makefile.inc SE_DIRS+= ses/getencstat SE_SES_GETENCSTAT= \ Makefile \ getencstat.0 SE_DIRS+= ses/sesd SE_SES_SESD= \ Makefile \ sesd.0 SE_DIRS+= ses/setencstat SE_SES_SETENCSTAT= \ Makefile \ setencstat.0 SE_DIRS+= ses/setobjstat SE_SES_SETOBJSTAT= \ Makefile \ setobjstat.0 SE_DIRS+= ses/srcs SE_SES_SRCS= \ chpmon.c \ eltsub.c \ eltsub.h \ getencstat.c \ getnobj.c \ getobjmap.c \ getobjstat.c \ inienc.c \ sesd.c \ setencstat.c \ setobjstat.c SE_DIRS+= scsi_target SE_SCSI_TARGET= \ Makefile \ scsi_target.c \ scsi_target.h \ scsi_target.8 \ scsi_cmds.c SE_DIRS+= sound SE_SOUND= \ sndstat_nv.c SE_DIRS+= sound/oss SE_SOUND_OSS= \ README \ basic.c \ midi.c \ - ossinit.h \ - ossmidi.h + ossinit.h SE_DIRS+= sunrpc SE_SUNRPC= Makefile SE_DIRS+= sunrpc/dir SE_SUNRPC_DIR= \ Makefile \ dir.x \ dir_proc.c \ rls.c SE_DIRS+= sunrpc/msg SE_SUNRPC_MSG= \ Makefile \ msg.x \ msg_proc.c \ printmsg.c \ rprintmsg.c SE_DIRS+= sunrpc/sort SE_SUNRPC_SORT= \ Makefile \ rsort.c \ sort.x \ sort_proc.c .if ${MK_EFI} != "no" LDIRS+= uefisign SE_DIRS+= uefisign SE_UEFISIGN= uefikeys .endif SE_DIRS+= ypldap SE_YPLDAP= ypldap.conf .if ${MK_HAST} != "no" LDIRS+= hast SE_DIRS+= hast SE_HAST= ucarp.sh \ ucarp_down.sh \ ucarp_up.sh \ vip-down.sh \ vip-up.sh .endif .if ${MK_USB} != "no" LDIRS+= libusb20 SE_DIRS+= libusb20 SE_LIBUSB20= \ Makefile \ README \ util.c \ util.h \ bulk.c \ control.c .endif # Setup the FILES_GROUPS for all DIRS variables above. # The variables are prefixed by 'SE_' to prevent variable collision in # other parts of the system .for d in ${SE_DIRS} .for f in ${SE_${d:tu:C/\//_/g}} SER_${d:tu:C/\//_/g}+= ${d}/${f} .endfor FILESGROUPS+= SER_${d:tu:C/\//_/g} SER_${d:tu:C/\//_/g}DIR+= ${SHAREDIR}/examples/${d} .endfor BINDIR= ${SHAREDIR}/examples beforeinstall: copies META_TARGETS+= copies copies: .for i in ${LDIRS} if [ -L ${DESTDIR}${BINDIR}/$i ]; then \ rm -f ${DESTDIR}${BINDIR}/$i; \ fi .endfor SUBDIR+= smbfs HAS_TESTS= SUBDIR.${MK_TESTS}+= tests SUBDIR_PARALLEL= .include diff --git a/share/examples/sound/oss/midi.c b/share/examples/sound/oss/midi.c index 7149bcb31c82..5b001ba537e5 100644 --- a/share/examples/sound/oss/midi.c +++ b/share/examples/sound/oss/midi.c @@ -1,76 +1,89 @@ /* * SPDX-License-Identifier: BSD-2-Clause * * Copyright (c) 2022 Goran Mekić + * Copyright (c) 2024 The FreeBSD Foundation + * + * Portions of this software were developed by Christos Margiolis + * under sponsorship from the FreeBSD Foundation. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ +#include +#include +#include +#include #include -#include "ossmidi.h" +#define CMD_MASK 0xF0 +#define CHANNEL_MASK 0x0F +#define NOTE_ON 0x90 +#define NOTE_OFF 0x80 +#define CTL_CHANGE 0xB0 int -main() +main(int argc, char *argv[]) { - midi_event_t event; - midi_config_t midi_config; - int l = -1; - unsigned char raw; + int fd; + unsigned char raw, type, channel, b1, b2; - midi_config.device = "/dev/umidi1.0"; - oss_midi_init(&midi_config); + if ((fd = open("/dev/umidi0.0", O_RDWR)) < 0) + err(1, "Error opening MIDI device"); - while ((l = read(midi_config.fd, &raw, sizeof(raw))) != -1) { - if (!(raw & 0x80)) { + for (;;) { + if (read(fd, &raw, sizeof(raw)) < sizeof(raw)) + err(1, "Error reading command byte"); + if (!(raw & 0x80)) continue; - } - event.type = raw & CMD_MASK; - event.channel = raw & CHANNEL_MASK; - switch (event.type) { + + type = raw & CMD_MASK; + channel = raw & CHANNEL_MASK; + + if (read(fd, &b1, sizeof(b1)) < sizeof(b1)) + err(1, "Error reading byte 1"); + if (read(fd, &b2, sizeof(b2)) < sizeof(b2)) + err(1, "Error reading byte 2"); + + switch (type) { case NOTE_ON: - case NOTE_OFF: - case CONTROLER_ON: - if ((l = read(midi_config.fd, &(event.note), sizeof(event.note))) == -1) { - perror("Error reading MIDI note"); - exit(1); - } - if ((l = read(midi_config.fd, &(event.velocity), sizeof(event.velocity))) == -1) { - perror("Error reading MIDI velocity"); - exit(1); - } + printf("Channel %d, note on %d, velocity %d\n", + channel, b1, b2); break; - } - switch (event.type) { - case NOTE_ON: case NOTE_OFF: - printf("Channel %d, note %d, velocity %d\n", event.channel, event.note, event.velocity); + printf("Channel %d, note off %d, velocity %d\n", + channel, b1, b2); break; - case CONTROLER_ON: - printf("Channel %d, controller %d, value %d\n", event.channel, event.controller, event.value); + case CTL_CHANGE: + printf("Channel %d, controller change %d, value %d\n", + channel, b1, b2); break; default: - printf("Unknown event type %d\n", event.type); + printf("Unknown event type %d\n", type); + break; } } - return 0; + + close(fd); + + return (0); } diff --git a/share/examples/sound/oss/ossmidi.h b/share/examples/sound/oss/ossmidi.h deleted file mode 100644 index 60bf5e41173e..000000000000 --- a/share/examples/sound/oss/ossmidi.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * SPDX-License-Identifier: BSD-2-Clause - * - * Copyright (c) 2022 Goran Mekić - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include -#include -#include - -#define CMD_MASK 0xF0 -#define NOTE_ON 0x90 -#define NOTE_OFF 0x80 -#define CHANNEL_MASK 0xF -#define CONTROLER_ON 0xB0 - -typedef struct midi_event { - unsigned char type; - unsigned char channel; - union { - unsigned char note; - unsigned controller; - }; - union { - unsigned char velocity; - unsigned char value; - }; -} midi_event_t; - -typedef struct midi_config { - char *device; - int fd; -} midi_config_t; - -void -oss_midi_init(midi_config_t *config) -{ - if ((config->fd = open(config->device, O_RDWR)) == -1) { - perror("Error opening MIDI device"); - exit(1); - } -}