mirror of
https://github.com/gryf/wmamixer.git
synced 2025-12-17 11:30:21 +01:00
Getting rid of warnings
This commit is contained in:
9
Makefile
9
Makefile
@@ -1,4 +1,7 @@
|
|||||||
all:
|
all:
|
||||||
gcc -Wall -Wextra -lXpm -lXext -lX11 -lasound wmamixer.c -o wmamixer
|
gcc -Wall -Wextra -lm -lXpm -lXext -lX11 -lasound wmamixer.c -o wmamixer
|
||||||
|
strip wmamixer
|
||||||
|
dev:
|
||||||
|
gcc -ggdb -Wall -Wextra -lm -lXpm -lXext -lX11 -lasound wmamixer.c -o wmamixer
|
||||||
|
clean:
|
||||||
|
rm wmamixer
|
||||||
|
|||||||
176
wmamixer.c
176
wmamixer.c
@@ -14,7 +14,6 @@
|
|||||||
struct Mixer *mix;
|
struct Mixer *mix;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
int i;
|
|
||||||
XGCValues gcv;
|
XGCValues gcv;
|
||||||
unsigned long gcm;
|
unsigned long gcm;
|
||||||
char back_color[] = "back_color";
|
char back_color[] = "back_color";
|
||||||
@@ -70,7 +69,7 @@ int main(int argc, char **argv) {
|
|||||||
XCopyArea(d_display, pm_main, pm_disp, gc_gc, 0, 0, 64, 64, 0, 0);
|
XCopyArea(d_display, pm_main, pm_disp, gc_gc, 0, 0, 64, 64, 0, 0);
|
||||||
XSetClipMask(d_display, gc_gc, None);
|
XSetClipMask(d_display, gc_gc, None);
|
||||||
|
|
||||||
mix = Mixer_create(card);
|
mix = Mixer_create();
|
||||||
|
|
||||||
readFile();
|
readFile();
|
||||||
|
|
||||||
@@ -85,24 +84,30 @@ int main(int argc, char **argv) {
|
|||||||
XMapWindow(d_display, w_main);
|
XMapWindow(d_display, w_main);
|
||||||
|
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while(!done ) {
|
while (!done) {
|
||||||
while(XPending(d_display) ) {
|
while(XPending(d_display) ) {
|
||||||
XNextEvent(d_display, &xev);
|
XNextEvent(d_display, &xev);
|
||||||
switch(xev.type ) {
|
switch(xev.type ) {
|
||||||
case Expose:
|
case Expose:
|
||||||
|
printf("DEBUG: Expose ev\n");
|
||||||
repaint();
|
repaint();
|
||||||
break;
|
break;
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
|
printf("DEBUG: ButtonPress ev\n");
|
||||||
pressEvent(&xev.xbutton);
|
pressEvent(&xev.xbutton);
|
||||||
break;
|
break;
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
|
printf("DEBUG: ButtonRelease ev\n");
|
||||||
releaseEvent();
|
releaseEvent();
|
||||||
break;
|
break;
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
|
printf("DEBUG: MotionNotify ev\n");
|
||||||
motionEvent(&xev.xmotion);
|
motionEvent(&xev.xmotion);
|
||||||
break;
|
break;
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
if (xev.xclient.data.l[0] == deleteWin) done=true;
|
printf("DEBUG: ClientMessage ev\n");
|
||||||
|
if (xev.xclient.data.l[0] == (int) deleteWin)
|
||||||
|
done=true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,7 +159,7 @@ int main(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Mixer struct support functions */
|
/* Mixer struct support functions */
|
||||||
struct Mixer *Mixer_create(char *devicename) {
|
struct Mixer *Mixer_create() {
|
||||||
struct Mixer *mixer = malloc(sizeof(struct Mixer));
|
struct Mixer *mixer = malloc(sizeof(struct Mixer));
|
||||||
int err;
|
int err;
|
||||||
const char *name;
|
const char *name;
|
||||||
@@ -205,14 +210,16 @@ struct Mixer *Mixer_create(char *devicename) {
|
|||||||
if (!capabilities.isvolume)
|
if (!capabilities.isvolume)
|
||||||
continue;
|
continue;
|
||||||
name = snd_mixer_selem_id_get_name(sid);
|
name = snd_mixer_selem_id_get_name(sid);
|
||||||
printf("DEBUG: capabilities cap: %d\n", capabilities.capture);
|
|
||||||
selems[mixer->devices_no] = malloc(sizeof(struct Selem));
|
selems[mixer->devices_no] = malloc(sizeof(struct Selem));
|
||||||
selems[mixer->devices_no]->elem = elem;
|
selems[mixer->devices_no]->elem = elem;
|
||||||
selems[mixer->devices_no]->capture = capabilities.capture;
|
selems[mixer->devices_no]->capture = capabilities.capture;
|
||||||
|
|
||||||
Mixer_set_limits(elem, selems[mixer->devices_no]);
|
Mixer_set_limits(elem, selems[mixer->devices_no]);
|
||||||
Mixer_set_selem_props(selems[mixer->devices_no], name);
|
Mixer_set_selem_props(selems[mixer->devices_no], name);
|
||||||
|
Mixer_set_channels(selems[mixer->devices_no]);
|
||||||
|
|
||||||
mixer->devices_no++;
|
mixer->devices_no++;
|
||||||
printf("DEBUG: Simple mixer control '%s',%i\n", snd_mixer_selem_id_get_name(sid), snd_mixer_selem_id_get_index(sid));
|
|
||||||
if (mixer->devices_no == 32) {
|
if (mixer->devices_no == 32) {
|
||||||
// stop here. This is ridiculous anyway
|
// stop here. This is ridiculous anyway
|
||||||
break;
|
break;
|
||||||
@@ -228,10 +235,7 @@ void Mixer_set_selem_props(struct Selem *selem, const char *name) {
|
|||||||
*cap = "Capture",
|
*cap = "Capture",
|
||||||
*boost = "Boost",
|
*boost = "Boost",
|
||||||
*line = "Line";
|
*line = "Line";
|
||||||
|
|
||||||
snd_mixer_selem_channel_id_t chn;
|
|
||||||
char variable[4];
|
char variable[4];
|
||||||
int idx;
|
|
||||||
|
|
||||||
// Get the name. Simple match.
|
// Get the name. Simple match.
|
||||||
if (strcmp("Master", name) == 0) {
|
if (strcmp("Master", name) == 0) {
|
||||||
@@ -298,16 +302,18 @@ void Mixer_set_selem_props(struct Selem *selem, const char *name) {
|
|||||||
namesCount.pcm++;
|
namesCount.pcm++;
|
||||||
selem->iconIndex = 6;
|
selem->iconIndex = 6;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mixer_set_channels(struct Selem *selem) {
|
||||||
|
int idx;
|
||||||
|
snd_mixer_selem_channel_id_t chn;
|
||||||
|
|
||||||
if (snd_mixer_selem_has_playback_volume(selem->elem)) {
|
if (snd_mixer_selem_has_playback_volume(selem->elem)) {
|
||||||
if (snd_mixer_selem_is_playback_mono(selem->elem)) {
|
if (snd_mixer_selem_is_playback_mono(selem->elem)) {
|
||||||
printf("DEBUG: playback mono\n");
|
|
||||||
selem->stereo = false;
|
selem->stereo = false;
|
||||||
selem->channels[0] = SND_MIXER_SCHN_MONO;
|
selem->channels[0] = SND_MIXER_SCHN_MONO;
|
||||||
selem->channels[1] = SND_MIXER_SCHN_MONO;
|
selem->channels[1] = SND_MIXER_SCHN_MONO;
|
||||||
} else {
|
} else {
|
||||||
printf("DEBUG: playback stereo\n");
|
|
||||||
idx = 0;
|
idx = 0;
|
||||||
for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++){
|
for (chn = 0; chn <= SND_MIXER_SCHN_LAST; chn++){
|
||||||
if (!snd_mixer_selem_has_playback_channel(selem->elem, chn))
|
if (!snd_mixer_selem_has_playback_channel(selem->elem, chn))
|
||||||
@@ -321,9 +327,7 @@ void Mixer_set_selem_props(struct Selem *selem, const char *name) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (snd_mixer_selem_has_capture_volume(selem->elem)) {
|
if (snd_mixer_selem_has_capture_volume(selem->elem)) {
|
||||||
printf("Capture channels: ");
|
|
||||||
if (snd_mixer_selem_is_capture_mono(selem->elem)) {
|
if (snd_mixer_selem_is_capture_mono(selem->elem)) {
|
||||||
printf("DEBUG: playback mono\n");
|
|
||||||
selem->stereo = false;
|
selem->stereo = false;
|
||||||
selem->channels[0] = SND_MIXER_SCHN_MONO;
|
selem->channels[0] = SND_MIXER_SCHN_MONO;
|
||||||
selem->channels[1] = SND_MIXER_SCHN_MONO;
|
selem->channels[1] = SND_MIXER_SCHN_MONO;
|
||||||
@@ -401,63 +405,52 @@ static int convert_prange(long val, long min, long max) {
|
|||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
int Mixer_get_volume(int current, int channelIndex) {
|
||||||
vol_ops = [
|
struct Selem *selem = selems[current];
|
||||||
{"has_volume": snd_mixer_selem_has_playback_volume,
|
|
||||||
"v": [
|
|
||||||
[snd_mixer_selem_get_playback_volume_range,
|
|
||||||
snd_mixer_selem_get_playback_volume,
|
|
||||||
set_playback_raw_volume],
|
|
||||||
[snd_mixer_selem_get_playback_dB_range,
|
|
||||||
snd_mixer_selem_get_playback_dB,
|
|
||||||
set_playback_dB],
|
|
||||||
[get_mapped_volume_range,
|
|
||||||
get_playback_mapped_volume,
|
|
||||||
set_playback_mapped_volume]]
|
|
||||||
},
|
|
||||||
// capt
|
|
||||||
{...}
|
|
||||||
]
|
|
||||||
*/
|
|
||||||
|
|
||||||
long get_volume(snd_mixer_elem_t *elem,
|
|
||||||
snd_mixer_selem_channel_id_t chn,
|
|
||||||
long min, long max, bool capt) {
|
|
||||||
long raw;
|
long raw;
|
||||||
int volume;
|
int volume;
|
||||||
|
|
||||||
if (!capt) {
|
if (!selem->capture) {
|
||||||
snd_mixer_selem_get_playback_volume(elem, chn, &raw);
|
snd_mixer_selem_get_playback_volume(selem->elem,
|
||||||
|
selem->channels[channelIndex], &raw);
|
||||||
} else {
|
} else {
|
||||||
snd_mixer_selem_get_capture_volume(elem, chn, &raw);
|
snd_mixer_selem_get_capture_volume(selem->elem,
|
||||||
|
selem->channels[channelIndex], &raw);
|
||||||
}
|
}
|
||||||
volume = convert_prange(raw, min, max);
|
|
||||||
|
volume = convert_prange(raw, selem->min, selem->max);
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mixer_set_volume(int current, int channelIndex, int value) {
|
||||||
|
struct Selem *selem = selems[current];
|
||||||
|
long raw;
|
||||||
|
|
||||||
|
raw = (long)convert_prange1(value, selem->min, selem->max);
|
||||||
|
|
||||||
|
if (!selem->capture) {
|
||||||
|
snd_mixer_selem_set_playback_volume(selem->elem,
|
||||||
|
selem->channels[channelIndex], raw);
|
||||||
|
} else {
|
||||||
|
snd_mixer_selem_set_capture_volume(selem->elem,
|
||||||
|
selem->channels[channelIndex], raw);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Mixer_set_left(int current, int value) {
|
void Mixer_set_left(int current, int value) {
|
||||||
|
Mixer_set_volume(current, 0, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mixer_set_right(int current, int value) {
|
void Mixer_set_right(int current, int value) {
|
||||||
}
|
Mixer_set_volume(current, 1, value);
|
||||||
|
|
||||||
void Mixer_write_volume(int current) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Mixer_read_left(int current) {
|
int Mixer_read_left(int current) {
|
||||||
struct Selem *selem = selems[current];
|
return Mixer_get_volume(current, 0);
|
||||||
return get_volume(selem->elem, selem->channels[0],
|
|
||||||
selem->min, selem->max, selem->capture);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int Mixer_read_right(int current) {
|
int Mixer_read_right(int current) {
|
||||||
struct Selem *selem = selems[current];
|
return Mixer_get_volume(current, 1);
|
||||||
return get_volume(selem->elem, selem->channels[1],
|
|
||||||
selem->min, selem->max, selem->capture);
|
|
||||||
}
|
|
||||||
|
|
||||||
int Mixer_read_volume(int current, bool read) {
|
|
||||||
return 50;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mixer_destroy(struct Mixer *mixer) {
|
void Mixer_destroy(struct Mixer *mixer) {
|
||||||
@@ -692,7 +685,6 @@ void readFile() {
|
|||||||
sscanf(buf, "setmono %i", &value);
|
sscanf(buf, "setmono %i", &value);
|
||||||
Mixer_set_left(current, value);
|
Mixer_set_left(current, value);
|
||||||
Mixer_set_right(current, value);
|
Mixer_set_right(current, value);
|
||||||
Mixer_write_volume(current);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -704,7 +696,6 @@ void readFile() {
|
|||||||
int value;
|
int value;
|
||||||
sscanf(buf, "setleft %i", &value);
|
sscanf(buf, "setleft %i", &value);
|
||||||
Mixer_set_left(current, value);
|
Mixer_set_left(current, value);
|
||||||
Mixer_write_volume(current);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -716,7 +707,6 @@ void readFile() {
|
|||||||
int value;
|
int value;
|
||||||
sscanf(buf, "setleft %i", &value);
|
sscanf(buf, "setleft %i", &value);
|
||||||
Mixer_set_right(current, value);
|
Mixer_set_right(current, value);
|
||||||
Mixer_write_volume(current);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -726,56 +716,50 @@ void readFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void checkVol(bool forced) {
|
void checkVol(bool forced) {
|
||||||
Mixer_read_volume(curchannel, true);
|
int nl = Mixer_read_left(curchannel);
|
||||||
int nl = Mixer_read_left(curchannel);
|
int nr = Mixer_read_right(curchannel);
|
||||||
int nr = Mixer_read_right(curchannel);
|
printf("DEBUG: checkVol: %d, %d\n", nl, nr);
|
||||||
if (forced ) {
|
if (forced) {
|
||||||
curleft=nl;
|
curleft = nl;
|
||||||
curright=nr;
|
curright = nr;
|
||||||
update();
|
update();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
} else {
|
||||||
else{
|
if (nl != curleft || nr != curright) {
|
||||||
if (nl!=curleft || nr!=curright ) {
|
if (nl != curleft) {
|
||||||
if (nl!=curleft ) {
|
curleft = nl;
|
||||||
curleft=nl;
|
if (selems[curchannel]->stereo)
|
||||||
if (selems[curchannel]->stereo)
|
drawLeft();
|
||||||
drawLeft();
|
else
|
||||||
else
|
drawMono();
|
||||||
drawMono();
|
}
|
||||||
}
|
if (nr != curright) {
|
||||||
if (nr!=curright ) {
|
curright = nr;
|
||||||
curright=nr;
|
if (selems[curchannel]->stereo)
|
||||||
if (selems[curchannel]->stereo)
|
drawRight();
|
||||||
drawRight();
|
else
|
||||||
else
|
drawMono();
|
||||||
drawMono();
|
}
|
||||||
}
|
if (!no_volume_display)
|
||||||
if (!no_volume_display)
|
drawVolLevel();
|
||||||
drawVolLevel();
|
repaint();
|
||||||
repaint();
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void pressEvent(XButtonEvent *xev) {
|
void pressEvent(XButtonEvent *xev) {
|
||||||
int inc, x, y, v;
|
int inc, x, y, v;
|
||||||
|
|
||||||
if (xev->button == Button4 || xev->button == Button5) {
|
if (xev->button == Button4 || xev->button == Button5) {
|
||||||
if (xev->button == Button4) {
|
if (xev->button == Button4)
|
||||||
printf("inc\n");
|
|
||||||
inc = 4;
|
inc = 4;
|
||||||
} else {
|
else
|
||||||
printf("dec\n");
|
|
||||||
inc = -4;
|
inc = -4;
|
||||||
}
|
|
||||||
|
|
||||||
Mixer_read_volume(curchannel, false);
|
Mixer_set_left(curchannel,
|
||||||
Mixer_set_left(curchannel,
|
|
||||||
CLAMP(Mixer_read_left(curchannel) + inc, 0, 100));
|
CLAMP(Mixer_read_left(curchannel) + inc, 0, 100));
|
||||||
Mixer_set_right(curchannel,
|
Mixer_set_right(curchannel,
|
||||||
CLAMP(Mixer_read_right(curchannel) + inc, 0, 100));
|
CLAMP(Mixer_read_right(curchannel) + inc, 0, 100));
|
||||||
Mixer_write_volume(curchannel);
|
|
||||||
checkVol(false);
|
checkVol(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -809,7 +793,6 @@ void pressEvent(XButtonEvent *xev) {
|
|||||||
Mixer_set_left(curchannel, v);
|
Mixer_set_left(curchannel, v);
|
||||||
if (x >= 45)
|
if (x >= 45)
|
||||||
Mixer_set_right(curchannel, v);
|
Mixer_set_right(curchannel, v);
|
||||||
Mixer_write_volume(curchannel);
|
|
||||||
checkVol(false);
|
checkVol(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -838,7 +821,6 @@ void motionEvent(XMotionEvent *xev)
|
|||||||
Mixer_set_left(curchannel, v);
|
Mixer_set_left(curchannel, v);
|
||||||
if (x>=45)
|
if (x>=45)
|
||||||
Mixer_set_right(curchannel, v);
|
Mixer_set_right(curchannel, v);
|
||||||
Mixer_write_volume(curchannel);
|
|
||||||
checkVol(false);
|
checkVol(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -868,6 +850,8 @@ void drawText(char *text) {
|
|||||||
char p2;
|
char p2;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
printf("DEBUG: Copy text as a label: %s\n", text);
|
||||||
|
|
||||||
for (i = 0; i < 4; i++, p++) {
|
for (i = 0; i < 4; i++, p++) {
|
||||||
p2 = toupper(*p);
|
p2 = toupper(*p);
|
||||||
if (p2 >= 'A' && p2 <= 'Z') {
|
if (p2 >= 'A' && p2 <= 'Z') {
|
||||||
|
|||||||
@@ -51,7 +51,6 @@
|
|||||||
#define convert_prange1(val, min, max) \
|
#define convert_prange1(val, min, max) \
|
||||||
ceil((val) * ((max) - (min)) * 0.01 + (min))
|
ceil((val) * ((max) - (min)) * 0.01 + (min))
|
||||||
|
|
||||||
|
|
||||||
// Pixmaps - standard
|
// Pixmaps - standard
|
||||||
Pixmap pm_main;
|
Pixmap pm_main;
|
||||||
Pixmap pm_tile;
|
Pixmap pm_tile;
|
||||||
@@ -184,18 +183,19 @@ void drawBtns(int btns);
|
|||||||
void drawBtn(int x, int y, int w, int h, bool down);
|
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_selem_props(struct Selem *selem, const char *name);
|
||||||
|
void Mixer_set_channels(struct Selem *selem);
|
||||||
slideCaptureMono Mixer_getcapabilities(snd_mixer_elem_t *elem);
|
slideCaptureMono Mixer_getcapabilities(snd_mixer_elem_t *elem);
|
||||||
|
|
||||||
struct Mixer *Mixer_create(char *devicename);
|
struct Mixer *Mixer_create();
|
||||||
void Mixer_set_left(int current, int value);
|
void Mixer_set_left(int current, int value);
|
||||||
void Mixer_set_right(int current, int value);
|
void Mixer_set_right(int current, int value);
|
||||||
void Mixer_write_volume(int current);
|
|
||||||
int Mixer_read_left(int current);
|
int Mixer_read_left(int current);
|
||||||
int Mixer_read_right(int current);
|
int Mixer_read_right(int current);
|
||||||
int Mixer_read_volume(int current, bool read);
|
|
||||||
|
|
||||||
void Mixer_set_limits(snd_mixer_elem_t *elem, struct Selem *selem);
|
void Mixer_set_limits(snd_mixer_elem_t *elem, struct Selem *selem);
|
||||||
|
|
||||||
void Mixer_destroy(struct Mixer *mix);
|
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 */
|
#endif /* WMAMIXER_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user