Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/aiomixer import aiomixer from git into usr.bin.



details:   https://anonhg.NetBSD.org/src/rev/e4c2ae4d68d2
branches:  trunk
changeset: 983167:e4c2ae4d68d2
user:      nia <nia%NetBSD.org@localhost>
date:      Fri May 07 16:29:24 2021 +0000

description:
import aiomixer from git into usr.bin.

aiomixer is a graphical (curses-based) mixer for NetBSD audio.

diffstat:

 usr.bin/aiomixer/Makefile   |   11 +
 usr.bin/aiomixer/aiomixer.1 |   90 ++++++
 usr.bin/aiomixer/app.h      |   82 ++++++
 usr.bin/aiomixer/draw.c     |  416 ++++++++++++++++++++++++++++++++
 usr.bin/aiomixer/draw.h     |   51 +++
 usr.bin/aiomixer/main.c     |  572 ++++++++++++++++++++++++++++++++++++++++++++
 usr.bin/aiomixer/parse.c    |  115 ++++++++
 usr.bin/aiomixer/parse.h    |   37 ++
 8 files changed, 1374 insertions(+), 0 deletions(-)

diffs (truncated from 1406 to 300 lines):

diff -r aa4a2dc188af -r e4c2ae4d68d2 usr.bin/aiomixer/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/aiomixer/Makefile Fri May 07 16:29:24 2021 +0000
@@ -0,0 +1,11 @@
+# $NetBSD: Makefile,v 1.1 2021/05/07 16:29:24 nia Exp $
+
+PROG=  aiomixer
+SRCS+= main.c draw.c parse.c
+
+LDADD+=        -lcurses
+DPADD+=        $(LIBCURSES)
+
+WARNS= 6
+
+.include <bsd.prog.mk>
diff -r aa4a2dc188af -r e4c2ae4d68d2 usr.bin/aiomixer/aiomixer.1
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/aiomixer/aiomixer.1       Fri May 07 16:29:24 2021 +0000
@@ -0,0 +1,90 @@
+.\"     $NetBSD: aiomixer.1,v 1.1 2021/05/07 16:29:24 nia Exp $
+.\"
+.\" Copyright (c) 2021 The NetBSD Foundation, Inc.
+.\" All rights reserved.
+.\"
+.\" This code is derived from software contributed to The NetBSD Foundation
+.\" by Nia Alarie.
+.\"
+.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+.\"
+.Dd April 4, 2019
+.Dt AIOMIXER 1
+.Os
+.Sh NAME
+.Nm aiomixer
+.Nd graphical mixer for
+.Nx
+audio
+.Sh SYNOPSIS
+.Nm aiomixer
+.Op Fl d Ar device
+.Op Fl u
+.Sh DESCRIPTION
+.Nm
+is a graphical frontend for
+.Xr mixer 4
+devices that runs in your terminal.
+.Pp
+.Nm
+is primarily controlled using the cursor keys, e.g. to select a
+control, or change a control's value.
+Movement similar to
+.Xr vi 1
+is also supported.
+The current class can be changed with the number keys.
+The Q or Escape key can be used to return to the previous pane or exit
+.Nm .
+.Pp
+By default, volume levels for individual channels cannot be changed
+separately.
+The U key can be pressed to toggle changing the volume of individual
+channels.
+.Pp
+The following options are available:
+.Bl -tag -width indent
+.It Fl d Ar device
+Used to specify an alternative mixer device.
+.It Fl u
+Used to unlock channels on start up.
+.El
+.Sh FILES
+.Bl -tag -width /dev/mixer[0-3] -compact
+.It Pa /dev/mixer
+.It Pa /dev/mixer[0-3]
+.El
+.Sh SEE ALSO
+.Xr mixerctl 1 ,
+.Xr mixer 4
+.Sh HISTORY
+The first version (only available in pkgsrc) didn't support
+.Dv AUDIO_MIXER_SET
+properly, among other bugs.
+.Sh AUTHORS
+.Nm
+was written by 
+.An Nia Alarie
+.Aq nia%NetBSD.org@localhost .
+.Sh BUGS
+.Nm aiomixer
+shows whatever mixer nodes the audio device's driver returns.
+Some drivers do not provide the most user-friendly control names.
diff -r aa4a2dc188af -r e4c2ae4d68d2 usr.bin/aiomixer/app.h
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/aiomixer/app.h    Fri May 07 16:29:24 2021 +0000
@@ -0,0 +1,82 @@
+/* $NetBSD: app.h,v 1.1 2021/05/07 16:29:24 nia Exp $ */
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nia Alarie.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
+ */
+#ifndef APP_H
+#define APP_H
+#include <sys/audioio.h>
+#include <stdbool.h>
+
+enum aiomixer_state {
+       STATE_DEVICE_SELECT,
+       STATE_CLASS_SELECT,
+       STATE_CONTROL_SELECT
+};
+
+struct aiomixer_control {
+       struct mixer_devinfo info;
+       /* currently selected index for sets, channel for sliders */
+       int setindex;
+       int widget_y;
+       int height;
+       WINDOW *widgetpad;
+};
+
+struct aiomixer_class {
+       char name[MAX_AUDIO_DEV_LEN];
+       struct aiomixer_control controls[128];
+       unsigned int numcontrols;
+       WINDOW *widgetpad;
+       int index;
+       int height;
+};
+
+struct aiomixer {
+       int fd;
+       enum aiomixer_state state;
+       struct audio_device mixerdev;
+       struct aiomixer_class classes[128];
+       unsigned int numclasses;
+       unsigned int curclass;
+       unsigned int curcontrol;
+       bool channels_unlocked;
+       int class_scroll_y;
+       int last_max_x;
+       bool widgets_resized;
+       WINDOW *header;
+       WINDOW *classbar;
+};
+
+#define COLOR_CONTROL_SELECTED 1
+#define COLOR_LEVELS           2
+#define COLOR_SET_SELECTED     3
+#define COLOR_ENUM_OFF         4
+#define COLOR_ENUM_ON          5
+#define COLOR_ENUM_MISC                6
+
+#endif
diff -r aa4a2dc188af -r e4c2ae4d68d2 usr.bin/aiomixer/draw.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.bin/aiomixer/draw.c   Fri May 07 16:29:24 2021 +0000
@@ -0,0 +1,416 @@
+/* $NetBSD: draw.c,v 1.1 2021/05/07 16:29:24 nia Exp $ */
+/*-
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Nia Alarie.
+ *
+ * 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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 <sys/audioio.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <curses.h>
+#include <err.h>
+#include <stdlib.h>
+#include "draw.h"
+
+static void bold_on(WINDOW *);
+static void bold_off(WINDOW *);
+static int get_enum_color(const char *);
+static void draw_enum(struct aiomixer_control *, int, bool);
+static void draw_set(struct aiomixer_control *, int);
+static void draw_levels(struct aiomixer_control *,
+    const struct mixer_level *, bool, bool);
+
+static void
+bold_on(WINDOW *w)
+{
+       /*
+        * Some (XXX: which?) legacy terminals do not support a Bold
+        * attribute.  In this case, we fall back to standout.
+        */
+       if (termattrs() & A_BOLD)
+               wattron(w, A_BOLD);
+       else
+               wattron(w, A_STANDOUT);
+}
+
+static void
+bold_off(WINDOW *w)
+{
+       chtype attrs = getattrs(w);
+
+       if (attrs & A_BOLD)
+               wattroff(w, A_BOLD);
+       if (attrs & A_STANDOUT)
+               wattroff(w, A_STANDOUT);
+}
+
+void
+draw_mixer_select(unsigned int num_mixers, unsigned int selected_mixer)
+{
+       struct audio_device dev;
+       char mixer_path[16];
+       unsigned int i;
+       int fd;
+
+       mvprintw(0, 0, "Select a mixer device:\n");
+
+       for (i = 0; i < num_mixers; ++i) {
+               (void)snprintf(mixer_path, sizeof(mixer_path),
+                   "/dev/mixer%d", i);
+               fd = open(mixer_path, O_RDWR);
+               if (fd == -1)
+                       break;
+               if (ioctl(fd, AUDIO_GETDEV, &dev) < 0) {
+                       close(fd);
+                       break;
+               }
+               close(fd);
+               if (selected_mixer == i) {
+                       bold_on(stdscr);
+                       addstr("[*] ");
+               } else {
+                       addstr("[ ] ");
+               }
+               printw("%s: %s %s %s\n", mixer_path,
+                   dev.name, dev.version, dev.config);
+               if (selected_mixer == i)
+                       bold_off(stdscr);



Home | Main Index | Thread Index | Old Index