From: Giuliano Pochini Date: Wed, 19 Jan 2005 10:51:57 +0000 (+0000) Subject: echomixer update 3/4 X-Git-Tag: v1.0.9rc1~2 X-Git-Url: https://git.alsa-project.org/?a=commitdiff_plain;h=c57ea192bbf014e1320c2c7c0fc667713946b38e;p=alsa-tools.git echomixer update 3/4 - Code cleanup: remove some redundant variables. - Enhancement: The matrix mixer ignores mouse clicks that don't fall inside enabled mixer cells. Signed-off-by: Giuliano Pochini --- diff --git a/echomixer/echomixer.c b/echomixer/echomixer.c index b58e292..787c82d 100644 --- a/echomixer/echomixer.c +++ b/echomixer/echomixer.c @@ -114,9 +114,10 @@ struct geometry { // This structure contains the first and the last row of each section of the graphic mixer window struct { - int Monitor; // The first is always 0 - int VmixerFirst, VmixerLast; - int LineOut; // There is only one row + int VmixerFirst, VmixerLast; // Rows + int LineOut; // There is only one row + int Inputs; // Rows + int Outputs; // Columns } GMixerSection; struct mixel { @@ -255,12 +256,6 @@ char *strOutGain(char *s, int g) { -int ADATmode() { - return(!memcmp(dmodeName[dmodeVal], "ADAT", 4)); -} - - - // Write an enumerated ALSA control int SetEnum(int numid, int val) { int err; @@ -638,20 +633,12 @@ gint DrawMixer(gpointer unused) { static int InClip[ECHO_MAXAUDIOINPUTS]; static int OutClip[ECHO_MAXAUDIOOUTPUTS]; char str[8]; - int i, o, dB, inchannels, outchannels; + int i, o, dB; GdkColor Grid={0x787878, 0, 0, 0}; GdkColor Labels={0x9694C4, 0, 0, 0}; GdkColor Hilight={0x000078, 0, 0, 0}; GdkColor Hilight2={0x600000, 0, 0, 0}; - if (ADATmode()) { - inchannels=nIn; - outchannels=nLOut; - } else { - inchannels=fdIn+2; - outchannels=fdOut+2; - } - if (!Mixpixmap) return(TRUE); @@ -715,7 +702,7 @@ gint DrawMixer(gpointer unused) { gdk_draw_rectangle(Mixpixmap, gc, TRUE, 0, YCELLTOT*(GMixerSection.LineOut+1)-1, Mixwidth, 1); // Draw input levels and peaks - for (i=0; iy/YCELLTOT; GMixerColumn=(int)event->x/XCELLTOT-1; + if (GMixerColumn<0 || GMixerColumn>=GMixerSection.Outputs) + return TRUE; + /* grab_focus must follow set_active because the latter causes Vmixer_*_selector_clicked() to be called and, in turn, Vmixer_volume_changed() which changes mixerControl.input (or .output in non-reverse mode). grab_focus then causes Vmixer_volume_clicked() to be called and that event handler finally sets the correct value of mixerControl.input */ - if (GMixerRow<=GMixerSection.Monitor) { - if (GMixerColumn!=mixerControl.output && GMixerColumn>=0) { - if (GMixerColumn=GMixerSection.VmixerFirst && GMixerRow<=GMixerSection.VmixerLast) { - if (GMixerColumn!=vmixerControl.output && GMixerColumn>=0) { - if (GMixerColumny/YCELLTOT; GMixerColumn=(int)event->x/XCELLTOT-1; + if (GMixerColumn<0 || GMixerColumn>=GMixerSection.Outputs) + return TRUE; + // See the note above - if (GMixerRow<=GMixerSection.Monitor) { + if (GMixerRow=0) { - if (GMixerColumn=GMixerSection.VmixerFirst && GMixerRow<=GMixerSection.VmixerLast) { if (GMixerRow!=vmixerControl.vchannel) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vmixerControl.vchsel[GMixerRow-GMixerSection.VmixerFirst]), TRUE); - if (GMixerColumn!=vmixerControl.output && GMixerColumn>=0) { - if (GMixerColumnbutton==1) { @@ -999,6 +984,8 @@ static gint Gmixer_button_release(GtkWidget *widget, GdkEventButton *event) { +// Gets how many pixels the mouse pointer was moved of and updates +// the currently active mixer/vmixer/line_out control. static gint Gmixer_motion_notify(GtkWidget *widget, GdkEventMotion *event) { int x, y; GdkModifierType state; @@ -1012,42 +999,40 @@ static gint Gmixer_motion_notify(GtkWidget *widget, GdkEventMotion *event) { state=event->state; } - // Check if the button is still pressed because the release event can fall in another window, so we may miss it. - if (!(state & GDK_BUTTON1_MASK)) + // Check if the button is still pressed because the release event can + // fall in another window, so we may miss it. Ignore the event if there + // isn't a backing pixmap or the user clicked an invalid cell. We also + // have to check mouseButton because the button_press event may arrive + // after the respective motion_notify event. + if (!(state & GDK_BUTTON1_MASK) || !mouseButton || !Mixpixmap || GMixerColumn<0 || GMixerColumn>=GMixerSection.Outputs) { mouseButton=0; + return(TRUE); + } - if (GMixerRow<=GMixerSection.Monitor) { - if (mouseButton && Mixpixmap != NULL) { - val=INVERT(mixerControl.mixer[mixerControl.output][mixerControl.input].Gain); - val+=y-mouseY; - mouseY=y; - // Gtk already limits the range of "val" + if (GMixerRow=GMixerSection.VmixerFirst && GMixerRow<=GMixerSection.VmixerLast) { - if (mouseButton && Mixpixmap != NULL) { - val=INVERT(vmixerControl.mixer[vmixerControl.output][vmixerControl.vchannel].Gain); - val+=y-mouseY; - mouseY=y; - // Gtk already limits the range of "val" + val=INVERT(vmixerControl.mixer[vmixerControl.output][vmixerControl.vchannel].Gain); + val+=y-mouseY; + mouseY=y; #ifdef REVERSE - gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[vmixerControl.vchannel]), (gfloat)val); + gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[vmixerControl.vchannel]), (gfloat)val); #else - gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[vmixerControl.output]), (gfloat)val); + gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[vmixerControl.output]), (gfloat)val); #endif - } } else if (GMixerRow==GMixerSection.LineOut) { - if (mouseButton && Mixpixmap != NULL) { - val=INVERT(lineoutControl.Gain[GMixerColumn]); - val+=y-mouseY; - mouseY=y; - // Gtk already limits the range of "val" - gtk_adjustment_set_value(GTK_ADJUSTMENT(lineoutControl.adj[GMixerColumn]), (gfloat)val); - } + val=INVERT(lineoutControl.Gain[GMixerColumn]); + val+=y-mouseY; + mouseY=y; + gtk_adjustment_set_value(GTK_ADJUSTMENT(lineoutControl.adj[GMixerColumn]), (gfloat)val); } return(TRUE); @@ -1403,12 +1388,15 @@ void Digital_mode_activate(GtkWidget *widget, gpointer mode) { // When I change the digital mode, the clock source can change too gtk_option_menu_set_history(GTK_OPTION_MENU(clocksrcOpt), clocksrcVal=GetEnum(clocksrcId)); } - adat=ADATmode(); + adat=!memcmp(dmodeName[dmodeVal], "ADAT", 4); SetSensitivity(adat); - if (adat) - GMixerSection.Monitor=nIn-1; - else - GMixerSection.Monitor=fdIn+2-1; // S/PDIF has only 2 channels + if (adat) { + GMixerSection.Inputs=nIn; + GMixerSection.Outputs=nLOut; + } else { + GMixerSection.Inputs=fdIn+2; // S/PDIF has only 2 channels + GMixerSection.Outputs=fdOut+2; + } } @@ -1811,12 +1799,11 @@ int OpenControls(const char *card, const char *cardname) { #ifndef REAL vmixerId=1000; vmixerControl.vchannels=12; -vmixerControl.outputs=mixerControl.outputs=10; +vmixerControl.outputs=mixerControl.outputs=nLOut=10; metersStreams=3; metersNumber=16; metersTypes=2; nPOut=12; -nLOut=10; fdOut=2; nIn=10; fdIn=2; @@ -1928,7 +1915,8 @@ printf("components = %s\n", snd_ctl_card_info_get_components(hw_info));*/ Mixerw_geom.st=NOPOS; Vmixerw_geom.st=NOPOS; VUwindow=GMwindow=0; - GMixerSection.Monitor=fdIn+2-1; // The correct value is set by Digital_mode_activate() + GMixerSection.Inputs=fdIn+2; // The correct value is set by Digital_mode_activate() + GMixerSection.Outputs=fdOut+2; GMixerSection.VmixerFirst=nIn; GMixerSection.VmixerLast=nIn+vmixerControl.vchannels-1; GMixerSection.LineOut=GMixerSection.VmixerLast+1;