From 4f3c64607e3035e66bfe873705b6e22a8af9af57 Mon Sep 17 00:00:00 2001 From: Roman Dobosz Date: Thu, 29 Jan 2015 21:53:41 +0100 Subject: [PATCH] Cleanup the code, added some info to readme, realigned the master volume icon --- Makefile | 4 +-- README | 51 +++++++++++++++++++++++++++-- XPM/icons.xcf | Bin 5129 -> 4904 bytes XPM/icons.xpm | 22 ++++++------- XPM/{wmsmixer.xpm => wmamixer.xpm} | 2 +- wmamixer.c | 42 +++++++++--------------- wmamixer.h | 51 ++++++++++++++--------------- 7 files changed, 102 insertions(+), 70 deletions(-) rename XPM/{wmsmixer.xpm => wmamixer.xpm} (99%) diff --git a/Makefile b/Makefile index 86119e4..042df18 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,5 @@ all: - gcc -Wall -Wextra -lm -lXpm -lXext -lX11 -lasound wmamixer.c -o wmamixer + gcc wmamixer.c -Wall -Wextra -lm -lXpm -lXext -lX11 -lasound -o wmamixer strip wmamixer -dev: - gcc -ggdb -Wall -Wextra -lm -lXpm -lXext -lX11 -lasound wmamixer.c -o wmamixer clean: rm wmamixer diff --git a/README b/README index 73a4ae6..b0d7a41 100644 --- a/README +++ b/README @@ -1,4 +1,51 @@ wmamixer --------- +======== -wmamixer is an alsa mixer for windowmaker based on wmsmixer. +Wmamixer is a fork of wmsmixer and is an ALSA mixer dockapp for Window Maker. + +The code for the ALSA part was taken and adapted from amixer and alsamixer +programs from alsa-utils package. + +Bugs +---- + +If spotted any bug, please report it using bug tracker on bitbucket. + +Changes +------- + +Changes with comparison with wmsmixer: + +- ALSA instead of OSS. This is real thing, using alsa-lib, not just emulation + of OSS. +- Placement of configuration file changed to "$XDG_CONFIG_HOME/wmamixer.conf", + which usually translate to "$HOME/.config/wmamixer.conf" + +Limitations +----------- + +1. Currently, wmamixer does not support switches and enum type of controls. +Only volume is supported. Enum and switch based ALSA controls are simply +ignored. + +2. There are controls with really small limit range, for example here is +control Beep (pc speaker in other words) which is represented by amixer like +this: + + Simple mixer control 'Beep',0 + Capabilities: pvolume pvolume-joined pswitch pswitch-joined + Playback channels: Mono + Limits: Playback 0 - 3 + Mono: Playback 1 [33%] [-12.00dB] [on] + +Under "Limits" section, there is a Playback capability with range 0 - 3. Using +scrollwheel on such low ranges is somehow awkward. For that controls it's +better to use clicking instead of scrolling. + + +Links +----- +wmsmixer homepage: +http://web.archive.org/web/20081024034859/http://www.hibernaculum.net/wmsmixer/index.php +ALSA homepage: +http://www.alsa-project.org diff --git a/XPM/icons.xcf b/XPM/icons.xcf index 92e33962fdb90b1f680ee257f1dee5274c3c96ff..1f68099fb39be7eebcc5344448c7e09f8c107658 100644 GIT binary patch delta 578 zcmXZWziJgh6vy#1GdnxGx%Vcy{(&(>a$+IkpY*9L1R18V7azdJU~8w1h#;tpRh~ew zQ7lBXnese?MN;Pt;{Bt)Gh|?v-S3=XKW}e+zWL#He~*YRnU8lKm^a^^-#7j@zN!2$ zzYbsM8`c?i#O{dfC!)*S*t>dwb#Z3D5``y3lVhT-jq=4Fn7wjpcg#+)?napNDiZs0 z*X_UD;&miLJzH8cd3^*5Y@?xdm2tN6|?F}byEKH&6Vn`4&}UWt~!3d7B;8<0g(fk_5c6? delta 849 zcmY+CziSjh6vyA}-p=0U?s9i-iX}hDi-n06YMaW!W*D#%EUXj>5)>_rSe_6RQUuhg z{0|fYA~r&*5iF*(*2cm@QP3t3@Al&NjT^y%@9ulw_h#pP*m-ekXYI)uwf6MAN$c-@>2 zE3U-UVs>I>m?)VGkNlPIT|m6Kc_YN|)8rv)0Yi7}^FLI}RKI zCwv%~5yJT$PzVeX8&uG4yA?@nNRjNdB8d%I07;lK0zC2n605@03W-IIsiQZMuYtsd zLcB*Hv24Wzi4C3D2oft}fW(F#tQr#xu^-c+6C{l%Czc_et3!dIQDw`EZZiXy+sz`F z@dD=Adja#z2nEce;04Th<+U5=2xfeWWL>Xl{37EscTHDUKw*6DF|h}knaEa97+;9@ z5EO=un4mDe6B|Kck6_)0x{zBadw&3gh~Ah0 diff --git a/XPM/icons.xpm b/XPM/icons.xpm index 6734cca..434e143 100644 --- a/XPM/icons.xpm +++ b/XPM/icons.xpm @@ -15,17 +15,17 @@ static char *icons_xpm[] = { "....................................+...............................................#..........................#++..............................................#++#.............................##@@..##................#@++++@#.........", "....................................+........................++...................#+++#.......................#++#+......................#++++++#...............+.#+............................#+@##@@@................#+@#..#@+#........", ".................................+.++....+..+.+.............++#+..................+++++.......................++#+#+....................#++++++++++++#+............+...........................#+......................#+#......#+#.......", -"...................#+............+.++....+..+.+............+#+.+.......+.........#+++++#......................+#+#++...................#+++++++....+.+.+.........#+#...........................#+......................+#........#+.......", -".................#+++.......+.+.++.++...++..+.++..........+#+.###......#+.........+++++........................+#++.+..................+#++++++++++++#+..........+#.............................#+....................#+..........+#......", -"...............#+++++.......+.+.+++++.+.++.++.++.........+##+#.#+..+....+.........#+++#..........#+.............++##.+.................+.#++++++#................#.............#+................#+...................@+..........+@......", -".............#+++++++.......+++.+++++++.+++++++++........###++#.+..#+.#.#+..........#..........#+++...............+##.+................+.........................+#..........#+++..........#++++++++++++++#..........@++#........#++@.....", -"...........#+++++++++.......+++++++++++++++++++++........###+#+.#.+.+.+..+...................#+++++................+##.+...............#+..................................#+++++..........+##..#..#..#.@#+.........@++++........++++@....", -".........#+++++++++++.......@@@@@@@@@@@@@@@@@@@@@........#.#+#+.+.#.+.#..+.................#+++++++.................+##.+...............#+...............................#+++++++.........#+#@.#@.#@.#@.#.+#........+@+++........+++@+....", -".......#+++++++++++++.......+++++++++++++++++++++.........#.++..+..#+....+...............#+++++++++..................+##.+...............+.............................#+++++++++.........+#..#..#..#..#.##+........+#+++........+++#+....", -".....#+++++++++++++++.......+.+++++++++++++++++++........+.#+...+..+....+..............#+++++++++++...................+##+...............+...........................#+++++++++++........#+@.#@.#@.#@.#@.@#+#.......+#+++........+++#+....", -"....+++++++++++++++++.......+.++++.++++.++++++++..........+#+..##......#+............#+++++++++++++....................+++...............+.........................#+++++++++++++........+#.#..#..#..#..#..#+.......+@+++........+++@+....", -"..............................++.+.++++..+.+++.+...........+.+.+.......+...........#+++++++++++++++.......................+.............++.......................#+++++++++++++++........++++++++++++++++++++.......@++++........++++@....", -"...............................+.+.++.+..+.++..+............++#+..................+++++++++++++++++................#+++...+#...........++.......................+++++++++++++++++........++++++++++++++++++++........@++#........#++@.....", +".................................+.++....+..+.+............+#+.+.......+.........#+++++#......................+#+#++...................#+++++++....+.+.+.........#+#...........................#+......................+#........#+.......", +"............................+.+.++.++...++..+.++..........+#+.###......#+.........+++++........................+#++.+..................+#++++++++++++#+..........+#.............................#+....................#+..........+#......", +"...................#+.......+.+.+++++.+.++.++.++.........+##+#.#+..+....+.........#+++#..........#+.............++##.+.................+.#++++++#................#.............#+................#+...................@+..........+@......", +".................#+++.......+++.+++++++.+++++++++........###++#.+..#+.#.#+..........#..........#+++...............+##.+................+.........................+#..........#+++..........#++++++++++++++#..........@++#........#++@.....", +"...............#+++++.......+++++++++++++++++++++........###+#+.#.+.+.+..+...................#+++++................+##.+...............#+..................................#+++++..........+##..#..#..#.@#+.........@++++........++++@....", +".............#+++++++.......@@@@@@@@@@@@@@@@@@@@@........#.#+#+.+.#.+.#..+.................#+++++++.................+##.+...............#+...............................#+++++++.........#+#@.#@.#@.#@.#.+#........+@+++........+++@+....", +"...........#+++++++++.......+++++++++++++++++++++.........#.++..+..#+....+...............#+++++++++..................+##.+...............+.............................#+++++++++.........+#..#..#..#..#.##+........+#+++........+++#+....", +".........#+++++++++++.......+.+++++++++++++++++++........+.#+...+..+....+..............#+++++++++++...................+##+...............+...........................#+++++++++++........#+@.#@.#@.#@.#@.@#+#.......+#+++........+++#+....", +".......#+++++++++++++.......+.++++.++++.++++++++..........+#+..##......#+............#+++++++++++++....................+++...............+.........................#+++++++++++++........+#.#..#..#..#..#..#+.......+@+++........+++@+....", +".....#+++++++++++++++.........++.+.++++..+.+++.+...........+.+.+.......+...........#+++++++++++++++.......................+.............++.......................#+++++++++++++++........++++++++++++++++++++.......@++++........++++@....", +"....+++++++++++++++++..........+.+.++.+..+.++..+............++#+..................+++++++++++++++++................#+++...+#...........++.......................+++++++++++++++++........++++++++++++++++++++........@++#........#++@.....", "...............................+.+..+.+....+.................++....................................................+...+++#...........++..................................................................................................", ".................................+..+.................................................................................................+...................................................................................................", "..........................................................................................................................................................................................................................................", diff --git a/XPM/wmsmixer.xpm b/XPM/wmamixer.xpm similarity index 99% rename from XPM/wmsmixer.xpm rename to XPM/wmamixer.xpm index ce9bc20..fa8d4b0 100644 --- a/XPM/wmsmixer.xpm +++ b/XPM/wmamixer.xpm @@ -1,5 +1,5 @@ /* XPM */ -static char * wmsmixer_xpm[] = { +static char * wmamixer_xpm[] = { "64 64 7 1", " c None", ". c #000000", diff --git a/wmamixer.c b/wmamixer.c index fe0fe12..5a04424 100644 --- a/wmamixer.c +++ b/wmamixer.c @@ -16,17 +16,8 @@ struct Mixer *mix; int main(int argc, char **argv) { XGCValues gcv; unsigned long gcm; - char back_color[] = "back_color"; - char led_color_high[] = "led_color_high"; - char led_color_med[] = "led_color_med"; - char led_color_low[] = "led_color_low"; + XpmAttributes xpmattr; - XpmColorSymbol xpmcsym[4] = { - {back_color, NULL, color[0]}, - {led_color_high, NULL, color[1]}, - {led_color_med, NULL, color[2]}, - {led_color_low, NULL, color[3]} - }; scanArgs(argc, argv); initXWin(argc, argv); @@ -40,12 +31,19 @@ int main(int argc, char **argv) { color[2] = mixColor(ledcolor, 60, backcolor, 40); color[3] = mixColor(ledcolor, 25, backcolor, 75); + XpmColorSymbol xpmcsym[4] = { + {"back_color", NULL, color[0]}, + {"led_color_high", NULL, color[1]}, + {"led_color_med", NULL, color[2]}, + {"led_color_low", NULL, color[3]} + }; + xpmattr.numsymbols = 4; xpmattr.colorsymbols = xpmcsym; xpmattr.exactColors = false; xpmattr.closeness = 40000; xpmattr.valuemask = XpmColorSymbols | XpmExactColors | XpmCloseness; - XpmCreatePixmapFromData(d_display, w_root, wmsmixer_xpm, &pm_main, + XpmCreatePixmapFromData(d_display, w_root, wmamixer_xpm, &pm_main, &pm_mask, &xpmattr); XpmCreatePixmapFromData(d_display, w_root, tile_xpm, &pm_tile, NULL, &xpmattr); @@ -89,23 +87,18 @@ int main(int argc, char **argv) { XNextEvent(d_display, &xev); switch(xev.type ) { case Expose: - printf("DEBUG: Expose ev\n"); repaint(); break; case ButtonPress: - printf("DEBUG: ButtonPress ev\n"); pressEvent(&xev.xbutton); break; case ButtonRelease: - printf("DEBUG: ButtonRelease ev\n"); releaseEvent(); break; case MotionNotify: - printf("DEBUG: MotionNotify ev\n"); motionEvent(&xev.xmotion); break; case ClientMessage: - printf("DEBUG: ClientMessage ev\n"); if (xev.xclient.data.l[0] == (int) deleteWin) done=true; break; @@ -136,11 +129,10 @@ int main(int argc, char **argv) { drawVolLevel(); repaint(); } - // printf("%c", text_counter); } XFlush(d_display); - + snd_mixer_handle_events(mix->handle); usleep(50000); } } @@ -205,7 +197,7 @@ struct Mixer *Mixer_create() { if (!snd_mixer_selem_is_active(elem)) continue; - capabilities = Mixer_getcapabilities(elem); + capabilities = Mixer_get_capabilities(elem); if (!capabilities.isvolume) continue; @@ -235,11 +227,12 @@ void Mixer_set_selem_props(struct Selem *selem, const char *name) { *cap = "Capture", *boost = "Boost", *line = "Line"; - char variable[4]; + char variable[5]; // Get the name. Simple match. if (strcmp("Master", name) == 0) { selem->name = "mstr"; + selem->iconIndex = 0; } else if (strstr(pcm, name)) { selem->iconIndex = 1; if (strcmp(pcm, name) == 0) { @@ -297,9 +290,9 @@ void Mixer_set_selem_props(struct Selem *selem, const char *name) { selem->iconIndex = 3; } else { /* defaults */ + printf("defaults\n"); sprintf(variable, "vol%d", namesCount.vol); - selem->name = variable; - namesCount.pcm++; + namesCount.vol++; selem->iconIndex = 6; } } @@ -345,7 +338,7 @@ void Mixer_set_channels(struct Selem *selem) { } } -slideCaptureMono Mixer_getcapabilities(snd_mixer_elem_t *elem) { +slideCaptureMono Mixer_get_capabilities(snd_mixer_elem_t *elem) { slideCaptureMono retval; retval.mono = false; retval.capture = false; @@ -718,7 +711,6 @@ void readFile() { void checkVol(bool forced) { int nl = Mixer_read_left(curchannel); int nr = Mixer_read_right(curchannel); - printf("DEBUG: checkVol: %d, %d\n", nl, nr); if (forced) { curleft = nl; curright = nr; @@ -850,8 +842,6 @@ void drawText(char *text) { char p2; int i; - printf("DEBUG: Copy text as a label: %s\n", text); - for (i = 0; i < 4; i++, p++) { p2 = toupper(*p); if (p2 >= 'A' && p2 <= 'Z') { diff --git a/wmamixer.h b/wmamixer.h index 40049e5..f098c4b 100644 --- a/wmamixer.h +++ b/wmamixer.h @@ -63,7 +63,7 @@ Pixmap pm_digits; Pixmap pm_chars; // Xpm images - standard -#include "XPM/wmsmixer.xpm" +#include "XPM/wmamixer.xpm" #include "XPM/tile.xpm" // Xpm images - custom @@ -159,43 +159,40 @@ static int smixer_level = 0; static struct snd_mixer_selem_regopt smixer_options; // Procedures and functions - standard -void initXWin(int argc, char **argv); -void freeXWin(); void createWin(Window *win, int x, int y); +void freeXWin(); +void initXWin(int argc, char **argv); unsigned long mixColor(char *color1, int prop1, char *color2, int prop2); // Procedures and functions - custom -void scanArgs(int argc, char **argv); -void readFile(); -void usage(); void checkVol(bool forced); -void pressEvent(XButtonEvent *xev); -void releaseEvent(); -void motionEvent(XMotionEvent *xev); -void repaint(); -void update(); -void drawLeft(); -void drawRight(); -void drawMono(); -void drawVolLevel(); -void drawText(char *text); -void drawBtns(int btns); void drawBtn(int x, int y, int w, int h, bool down); - -void Mixer_set_selem_props(struct Selem *selem, const char *name); -void Mixer_set_channels(struct Selem *selem); -slideCaptureMono Mixer_getcapabilities(snd_mixer_elem_t *elem); +void drawBtns(int btns); +void drawLeft(); +void drawMono(); +void drawRight(); +void drawText(char *text); +void drawVolLevel(); +void motionEvent(XMotionEvent *xev); +void pressEvent(XButtonEvent *xev); +void readFile(); +void releaseEvent(); +void repaint(); +void scanArgs(int argc, char **argv); +void update(); +void usage(); struct Mixer *Mixer_create(); -void Mixer_set_left(int current, int value); -void Mixer_set_right(int current, int value); +void Mixer_destroy(struct Mixer *mix); +slideCaptureMono Mixer_get_capabilities(snd_mixer_elem_t *elem); +int Mixer_get_volume(int current, int channelIndex); int Mixer_read_left(int current); int Mixer_read_right(int current); - +void Mixer_set_selem_props(struct Selem *selem, const char *name); +void Mixer_set_channels(struct Selem *selem); +void Mixer_set_left(int current, int value); +void Mixer_set_right(int current, int value); void Mixer_set_limits(snd_mixer_elem_t *elem, struct Selem *selem); - -void Mixer_destroy(struct Mixer *mix); -int Mixer_get_volume(int current, int channelIndex); void Mixer_set_volume(int current, int channelIndex, int value); #endif /* WMAMIXER_H */