From nobody Tue Oct 04 14:50:19 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Mhgbv2k09z4f26T; Tue, 4 Oct 2022 14:50:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Mhgbv23qGz3pdd; Tue, 4 Oct 2022 14:50:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664895019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nUFaXWSGziXhQI6R1OLFyW3edsYxRCKjCdWPZcxHlQ8=; b=te6G1LKkR4YoJZI710svuqEblQXCpvMQc79CFo+jB6x9c7fj2PYAXjr3NMzuZtXMtAdH5N b8xk+EuwCRKw2KmjMmMVgVq3SfYXlvt6W/ODFTFAzysqGoZHP6V2Qo2v3WFo3R97Dd7meA IQNHNcZ+zQEPnhvR5JcadPPxdza5ai5MSnpuKuARw2TeYuqtwF2nG2KLE3RcliNI0m3l1V wjotrLaJNOrS7nGUNo7Smx6TtE+ODHTHy9cLEdScVvstj9Ka90QtfQTUigHryzgfd+YeHU SW6VzgqmqbFz02f1D5B+6f9ZS+YOTk6NyU03XQXo++nX2UtztGY86F9qEnzlSw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Mhgbv19Zjzbb1; Tue, 4 Oct 2022 14:50:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 294EoJlp029769; Tue, 4 Oct 2022 14:50:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 294EoJPX029763; Tue, 4 Oct 2022 14:50:19 GMT (envelope-from git) Date: Tue, 4 Oct 2022 14:50:19 GMT Message-Id: <202210041450.294EoJPX029763@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Hans Petter Selasky Subject: git: 15ae481e056b - stable/13 - snd_uaudio(4): Add some examples accessing USB MIDI devices. List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: hselasky X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 15ae481e056be4a67fa9aa5af7cbd04de2eece2b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664895019; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=nUFaXWSGziXhQI6R1OLFyW3edsYxRCKjCdWPZcxHlQ8=; b=l9OisO8VGHUs9YEd3hjV4DQ8x9iXBa+QN8TfS1045mXYKawv+KjO9YcbFa+neDFik0CEH5 B8HlD3MP95hwQmg6WDbC0Xn6r+3iA7ccg3qc5P6xyoDqNSXTnRm45SweWtPbVxGXdvdx8D pOJKsY+CF+0gO2A/MtP4kguyI3W4GD457W7/sNb2XZWxV85owurr9Sq52GkCF6qNZjY/R4 p8k/lak6GTrHtOQejvcpk9RwH7yPMP5hW9JXWxOUCnLX2d4TIn9iBSpBB5O6FWxYtlANSq I/mTkH+nKH8IvOE3Y+bYnQLdkTOSc2YiBY7KXpwTtdaTgXfV7ptU0yCQ7tzj6A== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664895019; a=rsa-sha256; cv=none; b=Ozcs8Ld3J6lLEjBWWhO27E8BJIGho35TzijxTYgstXgeWhj/QsURpZm8I4l0y1sD3bTCLj wBNlBKkHUyTLPVoEq7cLxTW9kf/KP/Ze8j6TJbG5YejE5ztEyYV7MRdVC/Rs2U642rFYYi 86E346YoR4Dx3SD5RBoclRL/dTfJqaNw2v/arTz3nKuVCqZQyHjfzsIMHmECJV2vbexuGz zI8sbwnK4I0ePxoycwq4Z91Tg89OoFRFcWAYmeIS8jwGLPVcqmmU42V7yIHirTg8C1VhT5 dZH8oefDR/ESPj92OInL09GTb7OqtRvJz9D7spBPnFND6XF25giQDMPGIc6nXA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by hselasky: URL: https://cgit.FreeBSD.org/src/commit/?id=15ae481e056be4a67fa9aa5af7cbd04de2eece2b commit 15ae481e056be4a67fa9aa5af7cbd04de2eece2b Author: Goran Mekic AuthorDate: 2022-09-27 17:28:27 +0000 Commit: Hans Petter Selasky CommitDate: 2022-10-04 14:40:50 +0000 snd_uaudio(4): Add some examples accessing USB MIDI devices. Differential Revision: https://reviews.freebsd.org/D36195 Sponsored by: NVIDIA Networking (cherry picked from commit f092c21bf630543dc899a444fa7885d0bbbaedfd) --- share/examples/Makefile | 2 ++ share/examples/sound/midi.c | 76 ++++++++++++++++++++++++++++++++++++++++++ share/examples/sound/ossmidi.h | 63 ++++++++++++++++++++++++++++++++++ 3 files changed, 141 insertions(+) diff --git a/share/examples/Makefile b/share/examples/Makefile index 1d916f344b77..7179f1bff1a4 100644 --- a/share/examples/Makefile +++ b/share/examples/Makefile @@ -320,6 +320,8 @@ SE_DIRS+= sound SE_SOUND= \ basic.c \ ossinit.h \ + ossmidi.h \ + midi.c \ README SE_DIRS+= sunrpc diff --git a/share/examples/sound/midi.c b/share/examples/sound/midi.c new file mode 100644 index 000000000000..fbe4d9480530 --- /dev/null +++ b/share/examples/sound/midi.c @@ -0,0 +1,76 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * 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 "ossmidi.h" + +int +main() +{ + midi_event_t event; + midi_config_t midi_config; + int l = -1; + unsigned char raw; + + midi_config.device = "/dev/umidi1.0"; + oss_midi_init(&midi_config); + + while ((l = read(midi_config.fd, &raw, sizeof(raw))) != -1) { + if (!(raw & 0x80)) { + continue; + } + event.type = raw & CMD_MASK; + event.channel = raw & CHANNEL_MASK; + switch (event.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); + } + break; + } + switch (event.type) { + case NOTE_ON: + case NOTE_OFF: + printf("Channel %d, note %d, velocity %d\n", event.channel, event.note, event.velocity); + break; + case CONTROLER_ON: + printf("Channel %d, controller %d, value %d\n", event.channel, event.controller, event.value); + break; + default: + printf("Unknown event type %d\n", event.type); + } + } + return 0; +} diff --git a/share/examples/sound/ossmidi.h b/share/examples/sound/ossmidi.h new file mode 100644 index 000000000000..507508061de4 --- /dev/null +++ b/share/examples/sound/ossmidi.h @@ -0,0 +1,63 @@ +/* + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * 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); + } +}