Blame echomixer/echomixer.c

Packit 427e91
/*
Packit 427e91
 *  ALSA mixer console for Echoaudio soundcards.
Packit 427e91
 *  Copyright (C) 2003 Giuliano Pochini <pochini@shiny.it>
Packit 427e91
 *
Packit 427e91
 *  This program is free software; you can redistribute it and/or modify
Packit 427e91
 *  it under the terms of the GNU General Public License as published by
Packit 427e91
 *  the Free Software Foundation; version 2 of the License.
Packit 427e91
 *
Packit 427e91
 *  This program is distributed in the hope that it will be useful,
Packit 427e91
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 427e91
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 427e91
 *  GNU General Public License for more details.
Packit 427e91
 *
Packit 427e91
 *  You should have received a copy of the GNU General Public License
Packit 427e91
 *  along with this program; if not, write to the Free Software
Packit 427e91
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 427e91
 */
Packit 427e91
Packit 427e91
#define EM_VERSION "%s Echomixer v" VERSION
Packit 427e91
Packit 427e91
Packit 427e91
/*******
Packit 427e91
  Remove the "//" if you want to compile Echomixer in reverse mode.
Packit 427e91
*******/
Packit 427e91
Packit 427e91
//#define REVERSE
Packit 427e91
Packit 427e91
Packit 427e91
/*******
Packit 427e91
 Constants marked with *M* can be modified to customize the interface.
Packit 427e91
*******/
Packit 427e91
Packit 427e91
Packit 427e91
#define BORDER		6			// *M* Inner border of GTK containers
Packit 427e91
#define SPACING		8			// *M* Spacing of control sections
Packit 427e91
Packit 427e91
// Graphic mixer constants
Packit 427e91
#define GM_BARWIDTH	5			// *M* Width of meters bars
Packit 427e91
#define XCELLBORDER	2			// *M* Space between the grid lines and the content of the cell
Packit 427e91
#define YCELLBORDER	2			// *M*
Packit 427e91
#define XCELLDIM	20			// *M* Width of the cell
Packit 427e91
#define YCELLDIM	32			// Height of the cell
Packit 427e91
#define XCELLTOT (1+XCELLBORDER*2+XCELLDIM)	// line + left border + cell + right border
Packit 427e91
#define YCELLTOT (1+YCELLBORDER*2+YCELLDIM)
Packit 427e91
#define XVOLUME (1+XCELLBORDER+3)		// Position of the volume slider
Packit 427e91
#define XMETER (1+XCELLBORDER-GM_BARWIDTH/2+13)	// Position of the VU bar
Packit 427e91
Packit 427e91
// VU-meter constants
Packit 427e91
#define VU_XGRAF	30			// Left margin of the graphic
Packit 427e91
#define VU_YGRAF	20			// Top margin
Packit 427e91
#define VU_BARWIDTH	6			// *M* Width of VU-meters bars
Packit 427e91
#define VU_BARSEP	2			// *M* Space between bars
Packit 427e91
Packit 427e91
#define SHORTSTEP	1			// *M* 1dB (when the users moves a slider with cursor keys)
Packit 427e91
#define LONGSTEP	6			// *M* 6dB (with Page up/down or clicking the background)
Packit 427e91
#define DIGITAL_MODES	16			// Max number of digital modes
Packit 427e91
#define ECHO_CLOCKS	8			// Max number of clock sources
Packit 427e91
Packit 427e91
#define INPUT 0
Packit 427e91
#define OUTPUT 1
Packit 427e91
#define ECHO_MAXAUDIO_IOS	32		// The maximum number of inputs + outputs
Packit 427e91
#define ECHO_MAXAUDIOINPUTS	32		// Max audio input channels
Packit 427e91
#define ECHO_MAXAUDIOOUTPUTS	32		// Max audio output channels
Packit 427e91
#define ECHOGAIN_MUTED		(-128)		// Minimum possible gain
Packit 427e91
#define ECHOGAIN_MINOUT		(-128)		// Min output gain (unit is 1dB)
Packit 427e91
#define ECHOGAIN_MAXOUT		6		// Max output gain (unit is 1dB)
Packit 427e91
#define ECHOGAIN_MININP		(-50)		// Min input gain (unit is 0.5dB)
Packit 427e91
#define ECHOGAIN_MAXINP		50		// Max input gain (unit is 0.5dB)
Packit 427e91
Packit 427e91
// GTK+ adjustment widgets have the mininum value at top and maximum at bottom,
Packit 427e91
// position, but we need the opposite. This function puts the scale upside-down.
Packit 427e91
#define INVERT(x)	(ECHOGAIN_MINOUT+ECHOGAIN_MAXOUT-(x))
Packit 427e91
#define IN_INVERT(x)	(ECHOGAIN_MININP+ECHOGAIN_MAXINP-(x))
Packit 427e91
Packit 427e91
// REAL is for debugging only.
Packit 427e91
#define REAL
Packit 427e91
Packit 427e91
//#define CTLID_DEBUG(x) printf x
Packit 427e91
#define CTLID_DEBUG(x)
Packit 427e91
Packit 427e91
#define UI_DEBUG(x)
Packit 427e91
//#define UI_DEBUG(x) printf x
Packit 427e91
Packit 427e91
Packit 427e91
#include <stdio.h>
Packit 427e91
#include <stdlib.h>
Packit 427e91
#include <ctype.h>
Packit 427e91
#include <gtk gtk.h="">
Packit 427e91
#include <gdk gdk.h="">
Packit 427e91
#include <alsa asoundlib.h="">
Packit 427e91
Packit 427e91
Packit 427e91
char card[64], cardId[16];
Packit 427e91
char dmodeName[DIGITAL_MODES][64], clocksrcName[DIGITAL_MODES][64], spdifmodeName[DIGITAL_MODES][64];
Packit 427e91
int nLOut, nIn, fdIn, fdOut, nPOut, ClockMask;
Packit 427e91
int ndmodes, nclocksrc, nspdifmodes;
Packit 427e91
int GMixerRow, GMixerColumn, Gang, AutoClock;
Packit 427e91
int lineinId, pcmoutId, lineoutId, mixerId, vmixerId, p4InId, p4OutId, dmodeId;
Packit 427e91
int clocksrcId, spdifmodeId, vuswitchId, vumetersId, channelsId, phantomId, automuteId;
Packit 427e91
int metersStreams, metersNumber, metersTypes;
Packit 427e91
int outvolCount;
Packit 427e91
int mouseY, mouseButton;
Packit 427e91
int dmodeVal, clocksrcVal, spdifmodeVal;
Packit 427e91
int VUwidth, VUheight, Mixwidth, Mixheight;
Packit 427e91
Packit 427e91
#define DONT_DRAW (ECHOGAIN_MUTED-1)
Packit 427e91
#define DONT_CHANGE (1<<31)
Packit 427e91
#define NOPOS 999999
Packit 427e91
struct geometry {
Packit 427e91
  int st;		// window status: 0 = hidden ; 1 = visible ; NOPOS = no stored setting
Packit 427e91
  GtkWidget *toggler;	// The toggle button that controls this window
Packit 427e91
  int x, y;
Packit 427e91
  int w, h;
Packit 427e91
} Mainw_geom, Miscw_geom, PVw_geom, LVw_geom, Mixerw_geom, Vmixerw_geom, VUw_geom, GMw_geom;
Packit 427e91
Packit 427e91
// This structure contains the first and the last row of each section of the graphic mixer window
Packit 427e91
struct {
Packit 427e91
  int VmixerFirst, VmixerLast;	// Rows
Packit 427e91
  int LineOut;			// There is only one row
Packit 427e91
  int Inputs;			// Rows
Packit 427e91
  int Outputs;			// Columns
Packit 427e91
} GMixerSection;
Packit 427e91
Packit 427e91
struct mixel {
Packit 427e91
  int id;
Packit 427e91
  int Gain;
Packit 427e91
};
Packit 427e91
Packit 427e91
snd_ctl_t *ctlhandle;
Packit 427e91
Packit 427e91
Packit 427e91
struct mixerControl_s {
Packit 427e91
  int input, inputs;
Packit 427e91
  int output, outputs;
Packit 427e91
  int id;
Packit 427e91
  GtkWidget *window;
Packit 427e91
  GtkWidget *volume[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  GtkWidget *label[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  GtkObject *adj[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  GtkWidget *outsel[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  GtkWidget *inpsel[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  GtkWidget *vchsel[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  struct mixel mixer[ECHO_MAXAUDIOOUTPUTS][ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
} mixerControl, vmixerControl;
Packit 427e91
Packit 427e91
struct VolumeControl_s {
Packit 427e91
  int input, output;				// Currently selected channels
Packit 427e91
  int inputs, outputs;
Packit 427e91
  int id;
Packit 427e91
  GtkWidget *window;
Packit 427e91
  GtkWidget *volume[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  GtkWidget *label[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  GtkObject *adj[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int Gain[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
} lineinControl, lineoutControl, pcmoutControl;
Packit 427e91
Packit 427e91
struct NominalLevelControl_s {
Packit 427e91
  int id;
Packit 427e91
  int Channels;
Packit 427e91
  char Level[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  GtkWidget *Button[ECHO_MAXAUDIOINPUTS];
Packit 427e91
} NominalIn, NominalOut;
Packit 427e91
Packit 427e91
struct SwitchControl_s {
Packit 427e91
  int id;
Packit 427e91
  int value;
Packit 427e91
  GtkWidget *Button;
Packit 427e91
} PhantomPower, Automute;
Packit 427e91
Packit 427e91
GtkWidget *clocksrc_menuitem[ECHO_CLOCKS];
Packit 427e91
GtkWidget *dmodeOpt, *clocksrcOpt, *spdifmodeOpt, *phantomChkbutton, *autoclockChkbutton;
Packit 427e91
GtkWidget *window, *Mainwindow, *Miscwindow, *LVwindow, *VUwindow, *GMwindow;
Packit 427e91
GtkWidget *VUdarea, *Mixdarea;
Packit 427e91
gint VUtimer, Mixtimer, clocksrctimer;
Packit 427e91
Packit 427e91
GdkGC *gc=0;
Packit 427e91
static GdkPixmap *VUpixmap = NULL;
Packit 427e91
static GdkPixmap *Mixpixmap = NULL;
Packit 427e91
GdkFont *fnt;
Packit 427e91
Packit 427e91
void Clock_source_activate(GtkWidget *widget, gpointer clk);
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
int CountBits(int n) {
Packit 427e91
  int c;
Packit 427e91
Packit 427e91
  c=0;
Packit 427e91
  while (n) {
Packit 427e91
    c++;
Packit 427e91
    n&=(n-1);
Packit 427e91
  }
Packit 427e91
  return(c);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void ClampOutputVolume(int *v) {
Packit 427e91
Packit 427e91
  if (*v>ECHOGAIN_MAXOUT)
Packit 427e91
    *v=ECHOGAIN_MAXOUT;
Packit 427e91
  else if (*v
Packit 427e91
    *v=ECHOGAIN_MINOUT;
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void ClampInputVolume(int *v) {
Packit 427e91
Packit 427e91
  if (*v>ECHOGAIN_MAXINP)
Packit 427e91
    *v=ECHOGAIN_MAXINP;
Packit 427e91
  else if (*v
Packit 427e91
    *v=ECHOGAIN_MININP;
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// -128 dB means muted, that is -infinite dB
Packit 427e91
int Add_dB (int a, int b) {
Packit 427e91
Packit 427e91
  if (a==ECHOGAIN_MINOUT || b==ECHOGAIN_MINOUT)
Packit 427e91
    return(ECHOGAIN_MINOUT);
Packit 427e91
  a+=b;
Packit 427e91
  if (a
Packit 427e91
    return(ECHOGAIN_MINOUT);
Packit 427e91
  return(a);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
char *strOutGain(char *s, int g) {
Packit 427e91
Packit 427e91
  if (g==ECHOGAIN_MINOUT)
Packit 427e91
    strcpy(s, "mute");
Packit 427e91
  else
Packit 427e91
    sprintf(s, "%+d", g);
Packit 427e91
  return(s);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Write an enumerated ALSA control
Packit 427e91
int SetEnum(int numid, int val) {
Packit 427e91
  int err;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, numid==clocksrcId ? SND_CTL_ELEM_IFACE_PCM : SND_CTL_ELEM_IFACE_CARD);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, numid);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  snd_ctl_elem_value_set_enumerated(control, 0, val);
Packit 427e91
  if ((err=snd_ctl_elem_write(ctlhandle, control)) < 0)
Packit 427e91
    printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
  return(err);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Read an enumerated ALSA control
Packit 427e91
int GetEnum(int numid) {
Packit 427e91
  int err, val;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, numid==clocksrcId ? SND_CTL_ELEM_IFACE_PCM : SND_CTL_ELEM_IFACE_CARD);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, numid);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  if ((err=snd_ctl_elem_read(ctlhandle, control)) < 0)
Packit 427e91
    printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
  val=snd_ctl_elem_value_get_enumerated(control, 0);
Packit 427e91
  return(val);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Turn VU-meters on/off
Packit 427e91
void SetVUmeters(int onoff) {
Packit 427e91
  static signed char oncount=0;
Packit 427e91
  int err;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  if (onoff)
Packit 427e91
    oncount++;
Packit 427e91
  else
Packit 427e91
    if (--oncount<0)
Packit 427e91
      oncount=0;
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_CARD);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, vuswitchId);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  snd_ctl_elem_value_set_integer(control, 0, !!oncount);
Packit 427e91
  if ((err=snd_ctl_elem_write(ctlhandle, control)) < 0) {
Packit 427e91
    printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void GetVUmeters(int *InLevel, int *InPeak, int *OutLevel, int *OutPeak, int *VirLevel, int *VirPeak) {
Packit 427e91
  int err, i, m;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, vumetersId);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  if ((err = snd_ctl_elem_read(ctlhandle, control)) < 0) {
Packit 427e91
    printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
    return;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  m=0;
Packit 427e91
  for (i=0; i
Packit 427e91
    OutLevel[i]=snd_ctl_elem_value_get_integer(control, m++);
Packit 427e91
    OutPeak[i]=snd_ctl_elem_value_get_integer(control, m++);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  m=1*metersNumber*metersTypes;
Packit 427e91
  for (i=0; i
Packit 427e91
    InLevel[i]=snd_ctl_elem_value_get_integer(control, m++);
Packit 427e91
    InPeak[i]=snd_ctl_elem_value_get_integer(control, m++);
Packit 427e91
  }
Packit 427e91
  
Packit 427e91
  if (metersStreams==3) {	// Has PCM levels (Mia only) ?
Packit 427e91
    m=2*metersNumber*metersTypes;
Packit 427e91
#ifdef REAL
Packit 427e91
    for (i=0; i
Packit 427e91
      VirLevel[i]=snd_ctl_elem_value_get_integer(control, m++);
Packit 427e91
      VirPeak[i]=snd_ctl_elem_value_get_integer(control, m++);
Packit 427e91
    }
Packit 427e91
#else
Packit 427e91
    for (i=0; i
Packit 427e91
      VirLevel[i]=i*5-100;
Packit 427e91
      VirPeak[i]=i*5-90;
Packit 427e91
    }
Packit 427e91
#endif
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
Packit 427e91
// Enable/disable widgets that control ADAT digital channels
Packit 427e91
void SetSensitivity(int enable) {
Packit 427e91
  int i;
Packit 427e91
Packit 427e91
  for (i=fdOut+2; i
Packit 427e91
    if (!enable && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mixerControl.outsel[i])))
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mixerControl.outsel[0]), TRUE);
Packit 427e91
    if (mixerId)
Packit 427e91
      gtk_widget_set_sensitive(mixerControl.outsel[i], enable);
Packit 427e91
    if (vmixerId) {
Packit 427e91
      if (!enable && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vmixerControl.outsel[i])))
Packit 427e91
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vmixerControl.outsel[0]), TRUE);
Packit 427e91
      gtk_widget_set_sensitive(vmixerControl.outsel[i], enable);
Packit 427e91
    }
Packit 427e91
    if (pcmoutId) {
Packit 427e91
      gtk_widget_set_sensitive(pcmoutControl.label[i], enable);
Packit 427e91
      gtk_widget_set_sensitive(pcmoutControl.volume[i], enable);
Packit 427e91
    }
Packit 427e91
    // Line-out control is always present
Packit 427e91
    gtk_widget_set_sensitive(lineoutControl.label[i], enable);
Packit 427e91
    gtk_widget_set_sensitive(lineoutControl.volume[i], enable);
Packit 427e91
  }
Packit 427e91
  for (i=fdIn+2; i
Packit 427e91
    gtk_widget_set_sensitive(mixerControl.label[i], enable);
Packit 427e91
    gtk_widget_set_sensitive(mixerControl.volume[i], enable);
Packit 427e91
  }
Packit 427e91
  if (!enable && mixerControl.input>=fdIn+2)
Packit 427e91
    mixerControl.input=0;
Packit 427e91
}
Packit 427e91
Packit 427e91
#else // REVERSE
Packit 427e91
Packit 427e91
// Enable/disable widgets that control ADAT digital channels
Packit 427e91
void SetSensitivity(int enable) {
Packit 427e91
  int i;
Packit 427e91
Packit 427e91
  for (i=fdIn+2; i
Packit 427e91
    if (!enable && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(mixerControl.inpsel[i])))
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mixerControl.inpsel[0]), TRUE);
Packit 427e91
    gtk_widget_set_sensitive(mixerControl.inpsel[i], enable);
Packit 427e91
  }
Packit 427e91
  for (i=fdOut+2; i
Packit 427e91
    if (mixerId) {
Packit 427e91
      gtk_widget_set_sensitive(mixerControl.label[i], enable);
Packit 427e91
      gtk_widget_set_sensitive(mixerControl.volume[i], enable);
Packit 427e91
    }
Packit 427e91
    if (vmixerId) {
Packit 427e91
      gtk_widget_set_sensitive(vmixerControl.label[i], enable);
Packit 427e91
      gtk_widget_set_sensitive(vmixerControl.volume[i], enable);
Packit 427e91
    }
Packit 427e91
    if (pcmoutId) {
Packit 427e91
      gtk_widget_set_sensitive(pcmoutControl.label[i], enable);
Packit 427e91
      gtk_widget_set_sensitive(pcmoutControl.volume[i], enable);
Packit 427e91
    }
Packit 427e91
    // Line-out control is always present
Packit 427e91
    gtk_widget_set_sensitive(lineoutControl.label[i], enable);
Packit 427e91
    gtk_widget_set_sensitive(lineoutControl.volume[i], enable);
Packit 427e91
  }
Packit 427e91
  if (!enable && mixerControl.output>=fdOut+2)
Packit 427e91
    mixerControl.output=0;
Packit 427e91
  if (vmixerId && !enable && vmixerControl.output>=fdOut+2)
Packit 427e91
    vmixerControl.output=0;
Packit 427e91
}
Packit 427e91
Packit 427e91
#endif // REVERSE
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Read current control settings.
Packit 427e91
int ReadControl(int *vol, int channels, int numid, int iface) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err, ch;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, iface);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, numid);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  if ((err=snd_ctl_elem_read(ctlhandle, control))<0) {
Packit 427e91
    printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
    return(err);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  for (ch=0; ch
Packit 427e91
    vol[ch]=snd_ctl_elem_value_get_integer(control, ch);
Packit 427e91
  return(0);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void ReadNominalLevels(struct NominalLevelControl_s *NominalLevel) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err, i;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, NominalLevel->id);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  if ((err=snd_ctl_elem_read(ctlhandle, control))<0)
Packit 427e91
    printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
  for (i=0; i<nominallevel->Channels; i++)
Packit 427e91
    NominalLevel->Level[i]=snd_ctl_elem_value_get_integer(control, i);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
int SetMixerGain(struct mixel *mxl, int Gain) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, mxl->id);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  snd_ctl_elem_value_set_integer(control, 0, Gain);
Packit 427e91
  if ((err = snd_ctl_elem_write(ctlhandle, control)) < 0) {
Packit 427e91
    printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
    return(err);
Packit 427e91
  }
Packit 427e91
  return(0);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Read current (v)mixer settings.
Packit 427e91
void ReadMixer(struct mixerControl_s *mixer) {
Packit 427e91
  int err, in, out;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
#ifndef REAL
Packit 427e91
    return;
Packit 427e91
#endif
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
Packit 427e91
  for (out=0; out<mixer->outputs; out++) {
Packit 427e91
    for (in=0; in<mixer->inputs; in++) {
Packit 427e91
      snd_ctl_elem_id_set_numid(id, mixer->mixer[out][in].id);
Packit 427e91
      snd_ctl_elem_value_set_id(control, id);
Packit 427e91
      if ((err=snd_ctl_elem_read(ctlhandle, control))<0)
Packit 427e91
        printf("InitMixer - Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
      mixer->mixer[out][in].Gain=snd_ctl_elem_value_get_integer(control, 0);
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void GetChannels(void) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_HWDEP);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, channelsId);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  if ((err = snd_ctl_elem_read(ctlhandle, control)) < 0) {
Packit 427e91
    printf("GetChannels() read error: %s\n", snd_strerror(err));
Packit 427e91
    exit(1);
Packit 427e91
  }
Packit 427e91
  if (!nIn) {	// Only read the first time (mainly for debugging, see #define REAL)
Packit 427e91
    nIn=snd_ctl_elem_value_get_integer(control, 0);	// Number of input channels
Packit 427e91
    fdIn=snd_ctl_elem_value_get_integer(control, 1);	// First digital in (= number of analog input channels)
Packit 427e91
    nLOut=snd_ctl_elem_value_get_integer(control, 2);	// Number of output channels
Packit 427e91
    fdOut=snd_ctl_elem_value_get_integer(control, 3);	// First digital out
Packit 427e91
    nPOut=snd_ctl_elem_value_get_integer(control, 4);	// Number of virtual output channels (==nLOut on non-vmixer cards)
Packit 427e91
Packit 427e91
    mixerControl.outputs = nLOut;
Packit 427e91
    mixerControl.inputs = nIn;
Packit 427e91
Packit 427e91
    if (vmixerId) {
Packit 427e91
      vmixerControl.outputs = nLOut;
Packit 427e91
      vmixerControl.inputs = nPOut;
Packit 427e91
Packit 427e91
      /* For outputs and inputs. */
Packit 427e91
      metersStreams = 2;
Packit 427e91
    } else {
Packit 427e91
      /* For outputs, inputs and system outputs. */
Packit 427e91
      metersStreams = 3;
Packit 427e91
    }
Packit 427e91
Packit 427e91
    /* For the number of channels. */
Packit 427e91
    metersNumber = 16;
Packit 427e91
    /* For each of levels and peaks. */
Packit 427e91
    metersTypes = 2;
Packit 427e91
  }
Packit 427e91
  ClockMask=snd_ctl_elem_value_get_integer(control, 5);	// Bitmask of available input clocks
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Read what input clocks are valid and (de)activate the pop-down menu items accordingly
Packit 427e91
gint CheckInputs(gpointer unused) {
Packit 427e91
  int clk, valid, source;
Packit 427e91
Packit 427e91
  GetChannels();
Packit 427e91
  source=-1;
Packit 427e91
Packit 427e91
  // Switch to internal if the source is not available
Packit 427e91
  if (AutoClock>=0 && !(ClockMask & (1<
Packit 427e91
    source=0;
Packit 427e91
Packit 427e91
  for (clk=0; clk
Packit 427e91
    valid=!!(ClockMask & (1<
Packit 427e91
    gtk_widget_set_sensitive(clocksrc_menuitem[clk], valid);
Packit 427e91
    if (clk==AutoClock && valid)
Packit 427e91
      source=AutoClock;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (source>=0 && source!=clocksrcVal) {
Packit 427e91
    // Set the clock source, but do not change the value of AutoClock
Packit 427e91
    Clock_source_activate(clocksrc_menuitem[source], (gpointer)(long)(source|DONT_CHANGE));
Packit 427e91
    gtk_option_menu_set_history(GTK_OPTION_MENU(clocksrcOpt), clocksrcVal);
Packit 427e91
  }
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void DrawBar(int x, int y, int level, int peak, int gain) {
Packit 427e91
  GdkColor Bars={0x00FF00, 0, 0, 0};
Packit 427e91
  GdkColor Bars1={0x000000, 0, 0, 0};
Packit 427e91
  GdkColor Peak={0x1BABFF, 0, 0, 0};
Packit 427e91
  GdkColor Level={0xC0B000, 0, 0, 0};
Packit 427e91
  int db;
Packit 427e91
Packit 427e91
  x=XMETER+XCELLTOT*x;
Packit 427e91
  y=YCELLTOT*y+YCELLBORDER;
Packit 427e91
Packit 427e91
  if (level>ECHOGAIN_MUTED) {
Packit 427e91
    // Draw the "integer" part of the bar
Packit 427e91
    db=level>>2;
Packit 427e91
    gdk_gc_set_foreground(gc, &Bars);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, x, y-db, GM_BARWIDTH, YCELLDIM+db);
Packit 427e91
Packit 427e91
    // Draw the antialiased part
Packit 427e91
    Bars1.pixel=(level&3) << (6 + 8);	// 4 levels (256/4==64==2^6) of green (2^8)
Packit 427e91
    if (Bars1.pixel) {
Packit 427e91
      gdk_gc_set_foreground(gc, &Bars1);
Packit 427e91
      gdk_draw_rectangle(Mixpixmap, gc, TRUE, x, y-db-1, GM_BARWIDTH, 1);
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Draw the peak
Packit 427e91
  if (peak>ECHOGAIN_MUTED) {
Packit 427e91
    db=peak>>2;
Packit 427e91
    gdk_gc_set_foreground(gc, &Peak);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, x, y-db, GM_BARWIDTH, 1);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Draw the mixer gain
Packit 427e91
  if (gain>=ECHOGAIN_MUTED) {
Packit 427e91
    db=gain>>2;
Packit 427e91
    gdk_gc_set_foreground(gc, &Level);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, x-XMETER+XVOLUME, y, 1, YCELLDIM);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, x-XMETER+XVOLUME-2, y-db, 5, 1);
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Draw the matrix mixer
Packit 427e91
gint DrawMixer(gpointer unused) {
Packit 427e91
  GdkRectangle update_rect;
Packit 427e91
  int InLevel[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  int InPeak[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  int OutLevel[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int OutPeak[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int VirLevel[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int VirPeak[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  static int InClip[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  static int OutClip[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  char str[8];
Packit 427e91
  int i, o, dB;
Packit 427e91
  GdkColor Grid={0x787878, 0, 0, 0};
Packit 427e91
  GdkColor Labels={0x9694C4, 0, 0, 0};
Packit 427e91
  GdkColor Hilight={0x000078, 0, 0, 0};
Packit 427e91
  GdkColor Hilight2={0x600000, 0, 0, 0};
Packit 427e91
Packit 427e91
  if (!Mixpixmap)
Packit 427e91
    return(TRUE);
Packit 427e91
Packit 427e91
  update_rect.x = 0;
Packit 427e91
  update_rect.y = 0;
Packit 427e91
  update_rect.width = Mixwidth;
Packit 427e91
  update_rect.height = Mixheight;
Packit 427e91
  GetVUmeters(InLevel, InPeak, OutLevel, OutPeak, VirLevel, VirPeak);
Packit 427e91
Packit 427e91
  if (!gc) {
Packit 427e91
    gc=gdk_gc_new(gtk_widget_get_parent_window(Mixdarea));
Packit 427e91
    for (i=0; i
Packit 427e91
      InClip[i]=0;
Packit 427e91
    for (i=0; i
Packit 427e91
      OutClip[i]=0;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  gdk_draw_rectangle(Mixpixmap, Mixdarea->style->black_gc, TRUE, 0, 0, Mixwidth, Mixheight);
Packit 427e91
Packit 427e91
  // Highlight
Packit 427e91
  gdk_gc_set_foreground(gc, &Hilight);
Packit 427e91
  gdk_draw_rectangle(Mixpixmap, gc, TRUE, 0, YCELLTOT*mixerControl.input, XCELLTOT*(mixerControl.output+1), YCELLTOT);
Packit 427e91
  gdk_draw_rectangle(Mixpixmap, gc, TRUE, XCELLTOT*(mixerControl.output+1), YCELLTOT*mixerControl.input, XCELLTOT, Mixheight);
Packit 427e91
  if (vmixerId) {
Packit 427e91
    gdk_gc_set_foreground(gc, &Hilight2);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, 0, YCELLTOT*(GMixerSection.VmixerFirst+vmixerControl.input), XCELLTOT*(vmixerControl.output+1), YCELLTOT);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, XCELLTOT*(vmixerControl.output+1), YCELLTOT*(GMixerSection.VmixerFirst+vmixerControl.input), XCELLTOT, Mixheight);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Draw the grid
Packit 427e91
Packit 427e91
  gdk_gc_set_font(gc, fnt);
Packit 427e91
  // Horizontal lines and input channel labels
Packit 427e91
  for (i=0; i
Packit 427e91
    gdk_gc_set_foreground(gc, &Grid);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, 0, YCELLTOT*(i+1)-1, Mixwidth, 1);
Packit 427e91
    if (i
Packit 427e91
      sprintf(str, "A%d", i);		// Analog
Packit 427e91
    else if (i
Packit 427e91
      sprintf(str, "D%d", i-fdIn);	// Digital
Packit 427e91
    else
Packit 427e91
      sprintf(str, "V%d", i-nIn);	// Virtual
Packit 427e91
    gdk_gc_set_foreground(gc, &Labels);
Packit 427e91
    gdk_draw_string(Mixpixmap, fnt, gc, 1, YCELLTOT*i+(YCELLTOT/2)+4, str);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Vertical lines and output channel labels
Packit 427e91
  for (o=0; o
Packit 427e91
    gdk_gc_set_foreground(gc, &Grid);
Packit 427e91
    gdk_draw_rectangle(Mixpixmap, gc, TRUE, XCELLTOT*(o+1), 0, 1, Mixheight);
Packit 427e91
    if (o
Packit 427e91
      sprintf(str, "A%d", o);
Packit 427e91
    else
Packit 427e91
      sprintf(str, "D%d", o-fdOut);
Packit 427e91
    gdk_gc_set_foreground(gc, &Labels);
Packit 427e91
    gdk_draw_string(Mixpixmap, fnt, gc, XCELLTOT*(o+1)+(XCELLTOT/2)-6, YCELLTOT*GMixerSection.LineOut+YCELLTOT+8, str);
Packit 427e91
  }
Packit 427e91
  gdk_draw_string(Mixpixmap, fnt, gc, 1, 8, "In");
Packit 427e91
  gdk_draw_string(Mixpixmap, fnt, gc, 1, YCELLTOT*GMixerSection.LineOut+YCELLTOT+8, "Out");
Packit 427e91
  gdk_gc_set_foreground(gc, &Grid);
Packit 427e91
  gdk_draw_rectangle(Mixpixmap, gc, TRUE, 0, YCELLTOT*(GMixerSection.LineOut+1)-1, Mixwidth, 1);
Packit 427e91
Packit 427e91
  // Draw input levels and peaks
Packit 427e91
  for (i=0; i
Packit 427e91
    DrawBar(0, i, InLevel[i], InPeak[i], DONT_DRAW);
Packit 427e91
Packit 427e91
  // Draw vchannels levels and peaks (Vmixer cards only)
Packit 427e91
  if (vmixerId) {
Packit 427e91
    for (i=0; i
Packit 427e91
      DrawBar(0, i+GMixerSection.VmixerFirst, VirLevel[i], VirPeak[i], DONT_DRAW);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Draw output levels, peaks and volumes
Packit 427e91
  for (o=0; o
Packit 427e91
    DrawBar(o+1, GMixerSection.LineOut, OutLevel[o], OutPeak[o], lineoutControl.Gain[o]);
Packit 427e91
Packit 427e91
  // Draw monitor mixer elements
Packit 427e91
  for (o=0; o
Packit 427e91
    for (i=0; i
Packit 427e91
      dB=Add_dB(mixerControl.mixer[o][i].Gain, InLevel[i]);
Packit 427e91
      DrawBar(o+1, i, dB, DONT_DRAW, mixerControl.mixer[o][i].Gain);
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Draw vmixer elements (Vmixer cards only)
Packit 427e91
  if (vmixerId) {
Packit 427e91
    for (o=0; o
Packit 427e91
      for (i=0; i
Packit 427e91
        dB=Add_dB(vmixerControl.mixer[o][i].Gain, VirLevel[i]);
Packit 427e91
        DrawBar(o+1, i+GMixerSection.VmixerFirst, dB, DONT_DRAW, vmixerControl.mixer[o][i].Gain);
Packit 427e91
      }
Packit 427e91
  }
Packit 427e91
Packit 427e91
  gtk_widget_draw(Mixdarea, &update_rect);
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Draw the VU-meter
Packit 427e91
gint DrawVUmeters(gpointer unused) {
Packit 427e91
  GdkRectangle update_rect;
Packit 427e91
  int InLevel[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  int InPeak[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  int OutLevel[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int OutPeak[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int VirLevel[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int VirPeak[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  static int InClip[ECHO_MAXAUDIOINPUTS];
Packit 427e91
  static int OutClip[ECHO_MAXAUDIOOUTPUTS];
Packit 427e91
  int i, x, dB;
Packit 427e91
  char str[16];
Packit 427e91
  GdkColor Selected={0xC86060, 0, 0, 0};
Packit 427e91
  GdkColor Grid={0x9694C4, 0, 0, 0};
Packit 427e91
  GdkColor Grid2={0x646383, 0, 0, 0};
Packit 427e91
  GdkColor dBValues={0x00B000, 0, 0, 0};
Packit 427e91
  GdkColor AnBars={0x00E0B8, 0, 0, 0};
Packit 427e91
  GdkColor DiBars={0x98E000, 0, 0, 0};
Packit 427e91
  GdkColor ClipPeak={0, 0, 0, 0};
Packit 427e91
  GdkColor Peak={0x00FF00, 0, 0, 0};
Packit 427e91
Packit 427e91
  if (!VUpixmap)
Packit 427e91
    return(TRUE);
Packit 427e91
Packit 427e91
  update_rect.x = 0;
Packit 427e91
  update_rect.y = 0;
Packit 427e91
  update_rect.width = VUwidth;
Packit 427e91
  update_rect.height = VUheight;
Packit 427e91
  GetVUmeters(InLevel, InPeak, OutLevel, OutPeak, VirLevel, VirPeak);
Packit 427e91
Packit 427e91
  if (!gc) {
Packit 427e91
    gc=gdk_gc_new(gtk_widget_get_parent_window(VUdarea));
Packit 427e91
    for (i=0; i
Packit 427e91
      InClip[i]=0;
Packit 427e91
    for (i=0; i
Packit 427e91
      OutClip[i]=0;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Clear the image
Packit 427e91
  gdk_draw_rectangle(VUpixmap, VUdarea->style->black_gc, TRUE, 0, 0, VUwidth, VUheight);
Packit 427e91
Packit 427e91
  // Draw the dB scale and the grid
Packit 427e91
  gdk_gc_set_font(gc, fnt);
Packit 427e91
  gdk_gc_set_foreground(gc, &Peak);
Packit 427e91
  gdk_draw_string(VUpixmap, fnt, gc, 2, VU_YGRAF-12+4, "  dB");
Packit 427e91
  for (i=0; i<=120; i+=12) {
Packit 427e91
    sprintf(str, "%4d", -i);
Packit 427e91
    gdk_gc_set_foreground(gc, &dBValues);
Packit 427e91
    gdk_draw_string(VUpixmap, fnt, gc, 2, VU_YGRAF+i+4, str);
Packit 427e91
    gdk_gc_set_foreground(gc, &Grid);
Packit 427e91
    gdk_draw_rectangle(VUpixmap, gc, TRUE, VU_XGRAF, VU_YGRAF+i, VUwidth-VU_XGRAF, 1);
Packit 427e91
  }
Packit 427e91
  gdk_gc_set_foreground(gc, &Grid2);
Packit 427e91
  gdk_draw_rectangle(VUpixmap, gc, TRUE, VU_XGRAF, VU_YGRAF+128, VUwidth-VU_XGRAF, 1);
Packit 427e91
Packit 427e91
  x=VU_XGRAF+VU_BARSEP;
Packit 427e91
Packit 427e91
  // Draw inputs
Packit 427e91
  for (i=0; i
Packit 427e91
    if (i
Packit 427e91
      gdk_gc_set_foreground(gc, &AnBars);
Packit 427e91
    else
Packit 427e91
      gdk_gc_set_foreground(gc, &DiBars);
Packit 427e91
    dB=InLevel[i];
Packit 427e91
    gdk_draw_rectangle(VUpixmap, gc, TRUE, x, VU_YGRAF-dB, VU_BARWIDTH, 129+VU_YGRAF-(VU_YGRAF-dB));
Packit 427e91
Packit 427e91
    dB=InPeak[i];
Packit 427e91
    if (dB==0)
Packit 427e91
      InClip[i]=64;
Packit 427e91
    if (InClip[i]) {
Packit 427e91
      InClip[i]--;
Packit 427e91
      ClipPeak.pixel=(InClip[i]<<18)+((255-(InClip[i]*3))<<8);
Packit 427e91
      gdk_gc_set_foreground(gc, &ClipPeak);
Packit 427e91
    } else {
Packit 427e91
      gdk_gc_set_foreground(gc, &Peak);
Packit 427e91
    }
Packit 427e91
    gdk_draw_rectangle(VUpixmap, gc, TRUE, x, VU_YGRAF-dB, VU_BARWIDTH, 1);
Packit 427e91
    if (mixerControl.input==i) {
Packit 427e91
      gdk_gc_set_foreground(gc, &Selected);
Packit 427e91
      gdk_draw_rectangle(VUpixmap, gc, TRUE, x+1, VU_YGRAF+128+3, VU_BARWIDTH-2, 1);
Packit 427e91
      gdk_draw_rectangle(VUpixmap, gc, TRUE, x, VU_YGRAF+128+4, VU_BARWIDTH, 1);
Packit 427e91
    }
Packit 427e91
    x+=VU_BARWIDTH+VU_BARSEP;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Draw outputs
Packit 427e91
  x+=VU_BARWIDTH+VU_BARSEP;
Packit 427e91
  for (i=0; i
Packit 427e91
    if (i
Packit 427e91
      gdk_gc_set_foreground(gc, &AnBars);
Packit 427e91
    else
Packit 427e91
      gdk_gc_set_foreground(gc, &DiBars);
Packit 427e91
    dB=OutLevel[i];
Packit 427e91
    gdk_draw_rectangle(VUpixmap, gc, TRUE, x, VU_YGRAF-dB, VU_BARWIDTH, 129+VU_YGRAF-(VU_YGRAF-dB));
Packit 427e91
Packit 427e91
    dB=OutPeak[i];
Packit 427e91
    if (dB==0)
Packit 427e91
      OutClip[i]=64;
Packit 427e91
    if (OutClip[i]) {
Packit 427e91
      OutClip[i]--;
Packit 427e91
      ClipPeak.pixel=(OutClip[i]<<18)+((255-(OutClip[i]*3))<<8);
Packit 427e91
      gdk_gc_set_foreground(gc, &ClipPeak);
Packit 427e91
    } else {
Packit 427e91
      gdk_gc_set_foreground(gc, &Peak);
Packit 427e91
    }
Packit 427e91
    gdk_draw_rectangle(VUpixmap, gc, TRUE, x, VU_YGRAF-dB, VU_BARWIDTH, 1);
Packit 427e91
    if (mixerControl.output==i) {
Packit 427e91
      gdk_gc_set_foreground(gc, &Selected);
Packit 427e91
      gdk_draw_rectangle(VUpixmap, gc, TRUE, x+1, VU_YGRAF+128+3, VU_BARWIDTH-2, 1);
Packit 427e91
      gdk_draw_rectangle(VUpixmap, gc, TRUE, x, VU_YGRAF+128+4, VU_BARWIDTH, 1);
Packit 427e91
    }
Packit 427e91
    x+=VU_BARWIDTH+VU_BARSEP;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  gtk_widget_draw(VUdarea, &update_rect);
Packit 427e91
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
///////////////////// GUI events
Packit 427e91
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
Packit 427e91
void Mixer_Output_selector_clicked(GtkWidget *widget, gpointer och) {
Packit 427e91
  int ich, val;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  if (mixerControl.output==(int)och)
Packit 427e91
    return;
Packit 427e91
Packit 427e91
  mixerControl.output=(int)och;
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  for (ich=0; ich
Packit 427e91
    val=INVERT(mixerControl.mixer[mixerControl.output][ich].Gain);
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(mixerControl.adj[ich]), (gfloat)val);
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
#else // REVERSE
Packit 427e91
Packit 427e91
void Mixer_Input_selector_clicked(GtkWidget *widget, gpointer ich) {
Packit 427e91
  int och, val;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  if (mixerControl.input==(int)(long)ich)
Packit 427e91
    return;
Packit 427e91
Packit 427e91
  mixerControl.input=(int)(long)ich;
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  for (och=0; och
Packit 427e91
    val=INVERT(mixerControl.mixer[och][mixerControl.input].Gain);
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(mixerControl.adj[och]), (gfloat)val);
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
#endif // REVERSE
Packit 427e91
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
Packit 427e91
static gint Gmixer_button_press(GtkWidget *widget, GdkEventButton *event) {
Packit 427e91
Packit 427e91
  GMixerRow=(int)event->y/YCELLTOT;
Packit 427e91
  GMixerColumn=(int)event->x/XCELLTOT-1;
Packit 427e91
Packit 427e91
  if (GMixerColumn<0 || GMixerColumn>=GMixerSection.Outputs)
Packit 427e91
    return TRUE;
Packit 427e91
Packit 427e91
  /* grab_focus must follow set_active because the latter causes
Packit 427e91
     Vmixer_*_selector_clicked() to be called and, in turn,
Packit 427e91
     Vmixer_volume_changed() which changes mixerControl.input
Packit 427e91
     (or .output in non-reverse mode). grab_focus then causes
Packit 427e91
     Vmixer_volume_clicked() to be called and that event handler
Packit 427e91
     finally sets the correct value of mixerControl.input */
Packit 427e91
  if (GMixerRow
Packit 427e91
    if (GMixerColumn!=mixerControl.output)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mixerControl.outsel[GMixerColumn]), TRUE);
Packit 427e91
    if (GMixerRow!=mixerControl.input)
Packit 427e91
      gtk_widget_grab_focus(GTK_WIDGET(mixerControl.volume[GMixerRow]));
Packit 427e91
  } else if (GMixerRow>=GMixerSection.VmixerFirst && GMixerRow<=GMixerSection.VmixerLast) {
Packit 427e91
    if (GMixerColumn!=vmixerControl.output)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vmixerControl.outsel[GMixerColumn]), TRUE);
Packit 427e91
    if (GMixerRow!=vmixerControl.input)
Packit 427e91
      gtk_widget_grab_focus(GTK_WIDGET(vmixerControl.volume[GMixerRow-GMixerSection.VmixerFirst]));
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (event->button==1) {
Packit 427e91
    mouseY=event->y;
Packit 427e91
    mouseButton=1;
Packit 427e91
  }
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
#else //REVERSE
Packit 427e91
Packit 427e91
static gint Gmixer_button_press(GtkWidget *widget, GdkEventButton *event) {
Packit 427e91
Packit 427e91
  GMixerRow=(int)event->y/YCELLTOT;
Packit 427e91
  GMixerColumn=(int)event->x/XCELLTOT-1;
Packit 427e91
Packit 427e91
  if (GMixerColumn<0 || GMixerColumn>=GMixerSection.Outputs)
Packit 427e91
    return TRUE;
Packit 427e91
Packit 427e91
  // See the note above
Packit 427e91
  if (GMixerRow
Packit 427e91
    if (GMixerRow!=mixerControl.input)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(mixerControl.inpsel[GMixerRow]), TRUE);
Packit 427e91
    if (GMixerColumn!=mixerControl.output)
Packit 427e91
      gtk_widget_grab_focus(GTK_WIDGET(mixerControl.volume[GMixerColumn]));
Packit 427e91
  } else if (GMixerRow>=GMixerSection.VmixerFirst && GMixerRow<=GMixerSection.VmixerLast) {
Packit 427e91
    if (GMixerRow!=vmixerControl.input+GMixerSection.VmixerFirst)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(vmixerControl.vchsel[GMixerRow-GMixerSection.VmixerFirst]), TRUE);
Packit 427e91
    if (GMixerColumn!=vmixerControl.output)
Packit 427e91
      gtk_widget_grab_focus(GTK_WIDGET(vmixerControl.volume[GMixerColumn]));
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (event->button==1) {
Packit 427e91
    mouseY=event->y;
Packit 427e91
    mouseButton=1;
Packit 427e91
  }
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
#endif //REVERSE
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
static gint Gmixer_button_release(GtkWidget *widget, GdkEventButton *event) {
Packit 427e91
Packit 427e91
  if (event->state & GDK_BUTTON1_MASK)
Packit 427e91
    mouseButton=0;
Packit 427e91
  return TRUE;
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Gets how many pixels the mouse pointer was moved of and updates
Packit 427e91
// the currently active mixer/vmixer/line_out control.
Packit 427e91
static gint Gmixer_motion_notify(GtkWidget *widget, GdkEventMotion *event) {
Packit 427e91
  int x, y;
Packit 427e91
  GdkModifierType state;
Packit 427e91
  float val;
Packit 427e91
Packit 427e91
  if (event->is_hint)
Packit 427e91
    gdk_window_get_pointer(event->window, &x, &y, &state);
Packit 427e91
  else {
Packit 427e91
    x=event->x;
Packit 427e91
    y=event->y;
Packit 427e91
    state=event->state;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Check if the button is still pressed because the release event can
Packit 427e91
  // fall in another window, so we may miss it. Ignore the event if there
Packit 427e91
  // isn't a backing pixmap or the user clicked an invalid cell. We also
Packit 427e91
  // have to check mouseButton because the button_press event may arrive
Packit 427e91
  // after the respective motion_notify event.
Packit 427e91
  if (!(state & GDK_BUTTON1_MASK) || !mouseButton || !Mixpixmap || GMixerColumn<0 || GMixerColumn>=GMixerSection.Outputs) {
Packit 427e91
    mouseButton=0;
Packit 427e91
    return(TRUE);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (GMixerRow
Packit 427e91
    val=INVERT(mixerControl.mixer[mixerControl.output][mixerControl.input].Gain);
Packit 427e91
    val+=y-mouseY;
Packit 427e91
    mouseY=y;
Packit 427e91
    // Gtk already limits the range of "val"
Packit 427e91
#ifdef REVERSE
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(mixerControl.adj[mixerControl.input]), (gfloat)val);
Packit 427e91
#else
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(mixerControl.adj[mixerControl.output]), (gfloat)val);
Packit 427e91
#endif
Packit 427e91
  } else if (GMixerRow>=GMixerSection.VmixerFirst && GMixerRow<=GMixerSection.VmixerLast) {
Packit 427e91
    val=INVERT(vmixerControl.mixer[vmixerControl.output][vmixerControl.input].Gain);
Packit 427e91
    val+=y-mouseY;
Packit 427e91
    mouseY=y;
Packit 427e91
#ifdef REVERSE
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[vmixerControl.input]), (gfloat)val);
Packit 427e91
#else
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[vmixerControl.output]), (gfloat)val);
Packit 427e91
#endif
Packit 427e91
  } else if (GMixerRow==GMixerSection.LineOut) {
Packit 427e91
    val=INVERT(lineoutControl.Gain[GMixerColumn]);
Packit 427e91
    val+=y-mouseY;
Packit 427e91
    mouseY=y;
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(lineoutControl.adj[GMixerColumn]), (gfloat)val);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Monitor_volume_changed(GtkWidget *widget, gpointer cnl) {
Packit 427e91
  int val, rval, ch;
Packit 427e91
  int i, o;
Packit 427e91
  char str[16];
Packit 427e91
Packit 427e91
  UI_DEBUG(("Monitor_volume_changed()  %d %d\n",mixerControl.input,mixerControl.output));
Packit 427e91
  val=rval=INVERT((int)GTK_ADJUSTMENT(widget)->value);
Packit 427e91
Packit 427e91
  ch=(int)(long)cnl;
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
  i=ch;
Packit 427e91
  o=mixerControl.output;
Packit 427e91
#else
Packit 427e91
  i=mixerControl.input;
Packit 427e91
  o=ch;
Packit 427e91
#endif
Packit 427e91
Packit 427e91
  // Emulate the line-out volume if this card can't do it in hw.
Packit 427e91
  if (!lineoutId) {
Packit 427e91
    rval=Add_dB(val, lineoutControl.Gain[o]);
Packit 427e91
    ClampOutputVolume(&rval);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  SetMixerGain(&mixerControl.mixer[o][i], rval);	//@ we should restore the old adj position on error
Packit 427e91
  mixerControl.mixer[o][i].Gain=val;
Packit 427e91
Packit 427e91
  if (Gang) {
Packit 427e91
    SetMixerGain(&mixerControl.mixer[o^1][i^1], rval);
Packit 427e91
    mixerControl.mixer[o^1][i^1].Gain=val;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  gtk_label_set_text(GTK_LABEL(mixerControl.label[ch]), strOutGain(str, val));
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Monitor_volume_clicked(GtkWidget *widget, gpointer ch) {
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
  mixerControl.input=(int)(long)ch;
Packit 427e91
#else
Packit 427e91
  mixerControl.output=(int)(long)ch;
Packit 427e91
#endif
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Gang_button_toggled(GtkWidget *widget, gpointer unused) {
Packit 427e91
Packit 427e91
  Gang=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void PCM_volume_changed(GtkWidget *widget, gpointer ch) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  char str[16];
Packit 427e91
  int err, channel, val, rval;
Packit 427e91
  struct VolumeControl_s *vol;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
Packit 427e91
  if ((int)(long)ch
Packit 427e91
    // Input
Packit 427e91
    channel=(int)(long)ch;
Packit 427e91
    vol=&lineinControl;
Packit 427e91
    rval=val=IN_INVERT((int)GTK_ADJUSTMENT(widget)->value);
Packit 427e91
    sprintf(str, "%+4.1f", 0.5*val);
Packit 427e91
  } else {
Packit 427e91
    // Output
Packit 427e91
    channel=(int)(long)ch-ECHO_MAXAUDIOINPUTS;
Packit 427e91
    vol=&pcmoutControl;
Packit 427e91
    val=rval=INVERT((int)GTK_ADJUSTMENT(widget)->value);
Packit 427e91
    pcmoutControl.Gain[channel]=val;
Packit 427e91
    // Emulate the line-out volume if this card can't do it in hw.
Packit 427e91
    if (!lineoutId) {
Packit 427e91
      rval=Add_dB(val, lineoutControl.Gain[channel]);
Packit 427e91
      ClampOutputVolume(&rval);
Packit 427e91
    }
Packit 427e91
    strOutGain(str, val);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  gtk_label_set_text(GTK_LABEL(vol->label[channel]), str);
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_set_numid(id, vol->id);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
Packit 427e91
  if ((err=snd_ctl_elem_read(ctlhandle, control))<0) {
Packit 427e91
    printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
    return;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  snd_ctl_elem_value_set_integer(control, channel, rval);
Packit 427e91
  if ((err=snd_ctl_elem_write(ctlhandle, control))<0) {
Packit 427e91
    printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
  } else {
Packit 427e91
    vol->Gain[channel]=val;
Packit 427e91
  }
Packit 427e91
  if (Gang)
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(vol->adj[channel^1]), (gfloat)GTK_ADJUSTMENT(widget)->value);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Changes the PCM volume according to the current Line-out volume for non-vmixer cards
Packit 427e91
void UpdatePCMVolume(int outchannel) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err, val;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, pcmoutId);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
Packit 427e91
  if ((err=snd_ctl_elem_read(ctlhandle, control))<0)
Packit 427e91
    printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
Packit 427e91
  val=Add_dB(pcmoutControl.Gain[outchannel], lineoutControl.Gain[outchannel]);
Packit 427e91
  ClampOutputVolume(&val);
Packit 427e91
Packit 427e91
  snd_ctl_elem_value_set_integer(control, outchannel, val);
Packit 427e91
  if ((err=snd_ctl_elem_write(ctlhandle, control))<0)
Packit 427e91
    printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Changes the monitor mixer volume according to the current Line-out volume for non-vmixer cards.
Packit 427e91
void UpdateMixerVolume(int outchannel) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err, val, ch;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
Packit 427e91
  for (ch=0; ch
Packit 427e91
    val=Add_dB(mixerControl.mixer[outchannel][ch].Gain, lineoutControl.Gain[outchannel]);
Packit 427e91
    ClampOutputVolume(&val);
Packit 427e91
    snd_ctl_elem_id_set_numid(id, mixerControl.mixer[outchannel][ch].id);
Packit 427e91
    snd_ctl_elem_value_set_id(control, id);
Packit 427e91
    snd_ctl_elem_value_set_integer(control, 0, val);
Packit 427e91
    if ((err = snd_ctl_elem_write(ctlhandle, control)) < 0)
Packit 427e91
      printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Changes the vmixer volume according to the current Line-out volume for vmixer cards.
Packit 427e91
void UpdateVMixerVolume(int outchannel) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err, val, ch;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
Packit 427e91
  for (ch=0; ch
Packit 427e91
    val=Add_dB(vmixerControl.mixer[outchannel][ch].Gain, lineoutControl.Gain[outchannel]);
Packit 427e91
    ClampOutputVolume(&val);
Packit 427e91
    snd_ctl_elem_id_set_numid(id, vmixerControl.mixer[outchannel][ch].id);
Packit 427e91
    snd_ctl_elem_value_set_id(control, id);
Packit 427e91
    snd_ctl_elem_value_set_integer(control, 0, val);
Packit 427e91
    if ((err = snd_ctl_elem_write(ctlhandle, control)) < 0)
Packit 427e91
      printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void LineOut_volume_changed(GtkWidget *widget, gpointer ch) {
Packit 427e91
  char str[16];
Packit 427e91
  int err, channel, val;
Packit 427e91
Packit 427e91
  channel=(int)(long)ch;
Packit 427e91
Packit 427e91
  val=INVERT((int)GTK_ADJUSTMENT(widget)->value);
Packit 427e91
  lineoutControl.Gain[channel]=val;
Packit 427e91
Packit 427e91
  gtk_label_set_text(GTK_LABEL(lineoutControl.label[channel]), strOutGain(str, val));
Packit 427e91
Packit 427e91
  if (lineoutId) {	// If this card has the line-out control, use it
Packit 427e91
    snd_ctl_elem_id_t *id;
Packit 427e91
    snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
    snd_ctl_elem_id_alloca(&id);
Packit 427e91
    snd_ctl_elem_value_alloca(&control);
Packit 427e91
    snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
    snd_ctl_elem_id_set_numid(id, lineoutId);
Packit 427e91
    snd_ctl_elem_value_set_id(control, id);
Packit 427e91
Packit 427e91
    if ((err=snd_ctl_elem_read(ctlhandle, control))<0)
Packit 427e91
      printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
     snd_ctl_elem_value_set_integer(control, channel, val);
Packit 427e91
     if ((err=snd_ctl_elem_write(ctlhandle, control))<0)
Packit 427e91
       printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
  } else if (vmixerId) {
Packit 427e91
    UpdateVMixerVolume(channel);
Packit 427e91
    UpdateMixerVolume(channel);
Packit 427e91
  } else {		// Otherwise we have to emulate it.
Packit 427e91
    UpdatePCMVolume(channel);
Packit 427e91
    UpdateMixerVolume(channel);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (Gang)
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(lineoutControl.adj[channel^1]), (gfloat)GTK_ADJUSTMENT(widget)->value);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Vmixer_volume_changed(GtkWidget *widget, gpointer ch) {
Packit 427e91
  char str[16];
Packit 427e91
  int val, rval, channel;
Packit 427e91
  int o, v;
Packit 427e91
Packit 427e91
  channel=(int)(long)ch;
Packit 427e91
  val=rval=INVERT((int)GTK_ADJUSTMENT(widget)->value);
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
  v=channel;
Packit 427e91
  o=vmixerControl.output;
Packit 427e91
#else
Packit 427e91
  v=vmixerControl.input;
Packit 427e91
  o=channel;
Packit 427e91
#endif
Packit 427e91
Packit 427e91
  // Emulate the line-out volume if this card can't do it in hw.
Packit 427e91
  if (!lineoutId) {
Packit 427e91
    rval=Add_dB(val, lineoutControl.Gain[o]);
Packit 427e91
    ClampOutputVolume(&rval);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  SetMixerGain(&vmixerControl.mixer[o][v], rval);
Packit 427e91
  vmixerControl.mixer[o][v].Gain=val;
Packit 427e91
Packit 427e91
  if (Gang) {
Packit 427e91
    SetMixerGain(&vmixerControl.mixer[o^1][v^1], rval);
Packit 427e91
    vmixerControl.mixer[o^1][v^1].Gain=val;
Packit 427e91
  }
Packit 427e91
  
Packit 427e91
  gtk_label_set_text(GTK_LABEL(vmixerControl.label[channel]), strOutGain(str, val));
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Vmixer_volume_clicked(GtkWidget *widget, gpointer ch) {
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
  vmixerControl.input=(int)(long)ch;
Packit 427e91
  UI_DEBUG(("Vmixer_volume_clicked vch=%d\n",vmixerControl.input));
Packit 427e91
#else
Packit 427e91
  vmixerControl.output=(int)(long)ch;
Packit 427e91
  UI_DEBUG(("Vmixer_volume_clicked out=%d\n",vmixerControl.output));
Packit 427e91
#endif
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
Packit 427e91
void Vmixer_output_selector_clicked(GtkWidget *widget, gpointer ch) {
Packit 427e91
  int c, val;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  if (vmixerControl.output==(int)ch)
Packit 427e91
    return;
Packit 427e91
  vmixerControl.output=(int)ch;
Packit 427e91
Packit 427e91
  UI_DEBUG(("Vmixer_selector_clicked out=%d\n",vmixerControl.output));
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  for (c=vmixerControl.inputs-1; c>=0; c--) {
Packit 427e91
    val=INVERT(vmixerControl.mixer[vmixerControl.output][c].Gain);
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[c]), (gfloat)val);
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
#else
Packit 427e91
Packit 427e91
void Vmixer_vchannel_selector_clicked(GtkWidget *widget, gpointer ch) {
Packit 427e91
  int c, val;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
Packit 427e91
  if (vmixerControl.input==(int)(long)ch)
Packit 427e91
    return;
Packit 427e91
  vmixerControl.input=(int)(long)ch;
Packit 427e91
Packit 427e91
  UI_DEBUG(("Vmixer_selector_clicked vch=%d\n",vmixerControl.input));
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  for (c=vmixerControl.outputs-1; c>=0; c--) {
Packit 427e91
    val=INVERT(vmixerControl.mixer[c][vmixerControl.input].Gain);
Packit 427e91
    gtk_adjustment_set_value(GTK_ADJUSTMENT(vmixerControl.adj[c]), (gfloat)val);
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
#endif
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Nominal_level_toggled(GtkWidget *widget, gpointer ch) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err, val, channel;
Packit 427e91
  struct NominalLevelControl_s *NominalLevel;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
Packit 427e91
  val=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
Packit 427e91
  if ((int)(long)ch
Packit 427e91
    channel=(int)(long)ch;
Packit 427e91
    NominalLevel=&NominalIn;
Packit 427e91
  } else {
Packit 427e91
    channel=(int)(long)ch-ECHO_MAXAUDIOINPUTS;
Packit 427e91
    NominalLevel=&NominalOut;
Packit 427e91
  }
Packit 427e91
  NominalLevel->Level[channel]=!val;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_set_numid(id, NominalLevel->id);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  if ((err=snd_ctl_elem_read(ctlhandle, control))<0)
Packit 427e91
    printf("Control %s element read error: %s\n", card, snd_strerror(err));
Packit 427e91
  snd_ctl_elem_value_set_integer(control, channel, !val);	// FALSE is +4
Packit 427e91
  if ((err=snd_ctl_elem_write(ctlhandle, control))<0)
Packit 427e91
    printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
  if (Gang)
Packit 427e91
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(NominalLevel->Button[channel^1]), val);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Switch_toggled(GtkWidget *widget, gpointer Ctl) {
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_value_t *control;
Packit 427e91
  int err;
Packit 427e91
  struct SwitchControl_s *Switch=(struct SwitchControl_s *)Ctl;
Packit 427e91
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_value_alloca(&control);
Packit 427e91
Packit 427e91
  Switch->value=gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
Packit 427e91
  snd_ctl_elem_id_set_interface(id, SND_CTL_ELEM_IFACE_CARD);
Packit 427e91
  snd_ctl_elem_id_set_numid(id, Switch->id);
Packit 427e91
  snd_ctl_elem_value_set_id(control, id);
Packit 427e91
  snd_ctl_elem_value_set_integer(control, 0, Switch->value);
Packit 427e91
  if ((err=snd_ctl_elem_write(ctlhandle, control))<0)
Packit 427e91
    printf("Control %s element write error: %s\n", card, snd_strerror(err));
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void AutoClock_toggled(GtkWidget *widget, gpointer unused) {
Packit 427e91
  char str[32];
Packit 427e91
Packit 427e91
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
Packit 427e91
    AutoClock=clocksrcVal;
Packit 427e91
    snprintf(str, 31, "Autoclock [%s]", clocksrcName[AutoClock]);
Packit 427e91
    str[31]=0;
Packit 427e91
    gtk_label_set_text(GTK_LABEL(GTK_BIN(widget)->child), str);
Packit 427e91
  } else {
Packit 427e91
    AutoClock=-1;
Packit 427e91
    gtk_label_set_text(GTK_LABEL(GTK_BIN(widget)->child), "Autoclock");
Packit 427e91
  }
Packit 427e91
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Digital_mode_activate(GtkWidget *widget, gpointer mode) {
Packit 427e91
  int adat;
Packit 427e91
Packit 427e91
  if (SetEnum(dmodeId, (int)(long)mode)<0) {
Packit 427e91
    // Restore old value if it failed
Packit 427e91
    gtk_option_menu_set_history(GTK_OPTION_MENU(dmodeOpt), dmodeVal);
Packit 427e91
    return;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  dmodeVal=(int)(long)mode;
Packit 427e91
  // When I change the digital mode, the clock source can change too
Packit 427e91
  clocksrcVal=GetEnum(clocksrcId);
Packit 427e91
  gtk_option_menu_set_history(GTK_OPTION_MENU(clocksrcOpt), clocksrcVal);
Packit 427e91
Packit 427e91
  adat=!memcmp(dmodeName[dmodeVal], "ADAT", 4);
Packit 427e91
  SetSensitivity(adat);
Packit 427e91
  if (adat) {
Packit 427e91
    GMixerSection.Inputs=nIn;
Packit 427e91
    GMixerSection.Outputs=nLOut;
Packit 427e91
  } else {
Packit 427e91
    GMixerSection.Inputs=fdIn+2;	// S/PDIF has only 2 channels
Packit 427e91
    GMixerSection.Outputs=fdOut+2;
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void Clock_source_activate(GtkWidget *widget, gpointer clk) {
Packit 427e91
  unsigned int source;
Packit 427e91
Packit 427e91
  source=(unsigned int)(long)clk & 0xff;
Packit 427e91
  if (SetEnum(clocksrcId, source)<0) {
Packit 427e91
    gtk_option_menu_set_history(GTK_OPTION_MENU(clocksrcOpt), clocksrcVal);
Packit 427e91
  } else {
Packit 427e91
    clocksrcVal=(int)(long)clk & 0xff;
Packit 427e91
    // Change only when the user triggers it
Packit 427e91
    if (((int)(long)clk & DONT_CHANGE)==0 && AutoClock>=0) {
Packit 427e91
      AutoClock=clocksrcVal;
Packit 427e91
      AutoClock_toggled(autoclockChkbutton, NULL);
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void SPDIF_mode_activate(GtkWidget *widget, gpointer mode) {
Packit 427e91
Packit 427e91
  SetEnum(spdifmodeId, (int)(long)mode);	// This one should never fail
Packit 427e91
  spdifmodeVal=(int)(long)mode;
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Create a new backing pixmap of the appropriate size
Packit 427e91
static gint VU_configure_event(GtkWidget *widget, GdkEventConfigure *event) {
Packit 427e91
Packit 427e91
  if (VUpixmap)
Packit 427e91
    gdk_pixmap_unref(VUpixmap);
Packit 427e91
  VUpixmap=gdk_pixmap_new(widget->window, widget->allocation.width, widget->allocation.height, -1);
Packit 427e91
  gdk_draw_rectangle(VUpixmap, widget->style->black_gc, TRUE, 0, 0, widget->allocation.width, widget->allocation.height);
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Redraw the screen from the backing pixmap
Packit 427e91
static gint VU_expose(GtkWidget *widget, GdkEventExpose *event) {
Packit 427e91
Packit 427e91
  if (VUpixmap)
Packit 427e91
    gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], VUpixmap,
Packit 427e91
                    event->area.x, event->area.y,
Packit 427e91
                    event->area.x, event->area.y,
Packit 427e91
                    event->area.width, event->area.height);
Packit 427e91
  return(FALSE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Create a new backing pixmap of the appropriate size
Packit 427e91
static gint Gmixer_configure_event(GtkWidget *widget, GdkEventConfigure *event) {
Packit 427e91
Packit 427e91
  if (Mixpixmap)
Packit 427e91
    gdk_pixmap_unref(Mixpixmap);
Packit 427e91
  Mixpixmap=gdk_pixmap_new(widget->window, widget->allocation.width, widget->allocation.height, -1);
Packit 427e91
  gdk_draw_rectangle(Mixpixmap, widget->style->black_gc, TRUE, 0, 0, widget->allocation.width, widget->allocation.height);
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Redraw the screen from the backing pixmap
Packit 427e91
static gint Gmixer_expose(GtkWidget *widget, GdkEventExpose *event) {
Packit 427e91
Packit 427e91
  if (Mixpixmap)
Packit 427e91
    gdk_draw_pixmap(widget->window, widget->style->fg_gc[GTK_WIDGET_STATE(widget)], Mixpixmap,
Packit 427e91
                    event->area.x, event->area.y,
Packit 427e91
                    event->area.x, event->area.y,
Packit 427e91
                    event->area.width, event->area.height);
Packit 427e91
  return(FALSE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
gint CloseWindow(GtkWidget *widget, GdkEvent *event, gpointer geom) {
Packit 427e91
  struct geometry *g=geom;
Packit 427e91
Packit 427e91
  gdk_window_get_root_origin(widget->window, &g->x, &g->y);
Packit 427e91
  gdk_window_get_size(widget->window, &g->w, &g->h);
Packit 427e91
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->toggler), FALSE);	// This hides the window
Packit 427e91
  //gtk_widget_set_uposition(widget, g->x, g->y);
Packit 427e91
  return(TRUE);		// Do not destroy it
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
gint Mainwindow_delete(GtkWidget *widget, GdkEvent *event, gpointer geom) {
Packit 427e91
  struct geometry *g=geom;
Packit 427e91
Packit 427e91
  if (VUwindow) {
Packit 427e91
    gdk_window_get_root_origin(VUwindow->window, &VUw_geom.x, &VUw_geom.y);
Packit 427e91
    gtk_widget_destroy(VUwindow);
Packit 427e91
  }
Packit 427e91
  if (GMwindow) {
Packit 427e91
    gdk_window_get_root_origin(GMwindow->window, &GMw_geom.x, &GMw_geom.y);
Packit 427e91
    gtk_widget_destroy(GMwindow);
Packit 427e91
  }
Packit 427e91
  gdk_window_get_root_origin(Mainwindow->window, &g->x, &g->y);
Packit 427e91
  gtk_main_quit();
Packit 427e91
  return(FALSE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
gint VUwindow_delete(GtkWidget *widget, GdkEvent *event, gpointer geom) {
Packit 427e91
  struct geometry *g=geom;
Packit 427e91
Packit 427e91
  gdk_window_get_root_origin(widget->window, &g->x, &g->y);
Packit 427e91
  g->st=0;
Packit 427e91
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->toggler), FALSE);
Packit 427e91
  return(FALSE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
gint VUwindow_destroy(GtkWidget *widget, gpointer unused) {
Packit 427e91
Packit 427e91
  SetVUmeters(0);
Packit 427e91
  gtk_timeout_remove(VUtimer);
Packit 427e91
  //@@@del gc and fnt
Packit 427e91
  VUwindow=0;
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
gint GMwindow_delete(GtkWidget *widget, GdkEvent *event, gpointer geom) {
Packit 427e91
  struct geometry *g=geom;
Packit 427e91
Packit 427e91
  gdk_window_get_root_origin(widget->window, &g->x, &g->y);
Packit 427e91
  g->st=0;
Packit 427e91
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(g->toggler), FALSE);
Packit 427e91
  return(FALSE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
gint GMwindow_destroy(GtkWidget *widget, gpointer unused) {
Packit 427e91
Packit 427e91
  SetVUmeters(0);
Packit 427e91
  gtk_timeout_remove(Mixtimer);
Packit 427e91
  //@@@del gc and fnt
Packit 427e91
  GMwindow=0;
Packit 427e91
  return(TRUE);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void VUmeters_button_click(GtkWidget *widget, gpointer unused) {
Packit 427e91
  char str[64];
Packit 427e91
Packit 427e91
  if (VUwindow && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
Packit 427e91
    VUw_geom.st=0;
Packit 427e91
    gtk_widget_destroy(VUwindow);
Packit 427e91
  } else if (!VUwindow && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
Packit 427e91
    // Create VU-meter window
Packit 427e91
    VUwidth=VU_XGRAF+(VU_BARWIDTH+VU_BARSEP)*(nIn+nLOut+1)+VU_BARSEP;
Packit 427e91
    VUheight=160;
Packit 427e91
    SetVUmeters(1);
Packit 427e91
    VUwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
    sprintf(str, "%s VU-meters", cardId);
Packit 427e91
    gtk_window_set_title (GTK_WINDOW (VUwindow), str);
Packit 427e91
    gtk_window_set_wmclass(GTK_WINDOW(VUwindow), "vumeters", "Emixer");
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(VUwindow), "destroy", GTK_SIGNAL_FUNC(VUwindow_destroy), NULL);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(VUwindow), "delete_event", GTK_SIGNAL_FUNC(VUwindow_delete), (gpointer)&VUw_geom);
Packit 427e91
    gtk_window_set_policy(GTK_WINDOW(VUwindow), FALSE, FALSE, TRUE);
Packit 427e91
    if (VUw_geom.st!=NOPOS)
Packit 427e91
      gtk_widget_set_uposition(VUwindow, VUw_geom.x, VUw_geom.y);
Packit 427e91
    gtk_widget_show(VUwindow);
Packit 427e91
Packit 427e91
    VUdarea=gtk_drawing_area_new();
Packit 427e91
    gtk_widget_set_events(VUdarea, GDK_EXPOSURE_MASK);
Packit 427e91
    gtk_drawing_area_size(GTK_DRAWING_AREA(VUdarea), VUwidth, VUheight);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(VUwindow), VUdarea);
Packit 427e91
Packit 427e91
    gtk_widget_show(VUdarea);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(VUdarea), "expose_event", (GtkSignalFunc)VU_expose, NULL);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(VUdarea), "configure_event", (GtkSignalFunc)VU_configure_event, NULL);
Packit 427e91
    VUtimer=gtk_timeout_add(30, DrawVUmeters, 0);	// The hw updates the meters about 30 times/s
Packit 427e91
    gdk_window_clear_area(VUdarea->window, 0, 0, VUwidth, VUheight);
Packit 427e91
    VUw_geom.st=1;
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void GMixer_button_click(GtkWidget *widget, gpointer unused) {
Packit 427e91
  char str[64];
Packit 427e91
Packit 427e91
  if (GMwindow && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
Packit 427e91
    GMw_geom.st=0;
Packit 427e91
    gtk_widget_destroy(GMwindow);
Packit 427e91
  } else if (!GMwindow && gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) {
Packit 427e91
    // Create graphic mixer window
Packit 427e91
    Mixwidth=XCELLTOT*(nLOut+1);
Packit 427e91
    Mixheight=YCELLTOT*(GMixerSection.LineOut+1)+9;
Packit 427e91
    SetVUmeters(1);
Packit 427e91
    GMwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
    sprintf(str, "%s Mixer", cardId);
Packit 427e91
    gtk_window_set_title (GTK_WINDOW (GMwindow), str);
Packit 427e91
    gtk_window_set_wmclass(GTK_WINDOW(GMwindow), "gridmixer", "Emixer");
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(GMwindow), "destroy", GTK_SIGNAL_FUNC(GMwindow_destroy), NULL);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(GMwindow), "delete_event", GTK_SIGNAL_FUNC(GMwindow_delete), (gpointer)&GMw_geom);
Packit 427e91
    gtk_window_set_policy(GTK_WINDOW(GMwindow), FALSE, FALSE, TRUE);
Packit 427e91
    if (GMw_geom.st!=NOPOS)
Packit 427e91
      gtk_widget_set_uposition(GMwindow, GMw_geom.x, GMw_geom.y);
Packit 427e91
    gtk_widget_show(GMwindow);
Packit 427e91
Packit 427e91
    Mixdarea=gtk_drawing_area_new();
Packit 427e91
    gtk_widget_set_events(Mixdarea, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK);
Packit 427e91
    gtk_drawing_area_size(GTK_DRAWING_AREA(Mixdarea), Mixwidth, Mixheight);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(GMwindow), Mixdarea);
Packit 427e91
Packit 427e91
    gtk_widget_show(Mixdarea);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(Mixdarea), "expose_event", (GtkSignalFunc)Gmixer_expose, NULL);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(Mixdarea), "configure_event", (GtkSignalFunc)Gmixer_configure_event, NULL);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(Mixdarea), "motion_notify_event", (GtkSignalFunc)Gmixer_motion_notify, NULL);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(Mixdarea), "button_press_event", (GtkSignalFunc)Gmixer_button_press, NULL);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(Mixdarea), "button_release_event", (GtkSignalFunc)Gmixer_button_release, NULL);
Packit 427e91
    Mixtimer=gtk_timeout_add(30, DrawMixer, 0);		// The hw updates the meters about 30 times/s
Packit 427e91
    gdk_window_clear_area(Mixdarea->window, 0, 0, Mixwidth, Mixheight);
Packit 427e91
    GMw_geom.st=1;
Packit 427e91
  }
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
void ToggleWindow(GtkWidget *widget, gpointer window) {
Packit 427e91
Packit 427e91
  if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
Packit 427e91
    gtk_widget_show(GTK_WIDGET(window));
Packit 427e91
  else
Packit 427e91
    gtk_widget_hide(GTK_WIDGET(window));
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
// Scan all controls and sets up the structures needed to access them.
Packit 427e91
int OpenControls(const char *card, const char *cardname) {
Packit 427e91
  int err, i, o;
Packit 427e91
  int numid, count, items, item;
Packit 427e91
  snd_hctl_t *handle;
Packit 427e91
  snd_hctl_elem_t *elem;
Packit 427e91
  snd_ctl_elem_id_t *id;
Packit 427e91
  snd_ctl_elem_info_t *info;
Packit 427e91
Packit 427e91
  pcmoutId=lineoutId=vmixerId=p4InId=p4OutId=dmodeId=clocksrcId=spdifmodeId=vuswitchId=vumetersId=mixerId=0;
Packit 427e91
  memset(&vmixerControl, 0, sizeof(vmixerControl));
Packit 427e91
  memset(&mixerControl, 0, sizeof(mixerControl));
Packit 427e91
  memset(&lineoutControl, 0, sizeof(struct VolumeControl_s));
Packit 427e91
  memset(&lineinControl, 0, sizeof(struct VolumeControl_s));
Packit 427e91
  memset(&pcmoutControl, 0, sizeof(struct VolumeControl_s));
Packit 427e91
  ndmodes=nclocksrc=nspdifmodes=0;
Packit 427e91
  snd_ctl_elem_id_alloca(&id);
Packit 427e91
  snd_ctl_elem_info_alloca(&info);
Packit 427e91
Packit 427e91
  if ((err=snd_hctl_open(&handle, card, 0))<0) {
Packit 427e91
    printf("Control %s open error: %s", card, snd_strerror(err));
Packit 427e91
    return err;
Packit 427e91
  }
Packit 427e91
  if ((err=snd_hctl_load(handle))<0) {
Packit 427e91
    printf("Control %s local error: %s\n", card, snd_strerror(err));
Packit 427e91
    return err;
Packit 427e91
  }
Packit 427e91
  for (elem=snd_hctl_first_elem(handle); elem; elem=snd_hctl_elem_next(elem)) {
Packit 427e91
    if ((err=snd_hctl_elem_info(elem, info))<0) {
Packit 427e91
      printf("Control %s snd_hctl_elem_info error: %s\n", card, snd_strerror(err));
Packit 427e91
      return err;
Packit 427e91
    }
Packit 427e91
    if (snd_ctl_elem_info_is_inactive(info))
Packit 427e91
      continue;
Packit 427e91
    snd_hctl_elem_get_id(elem, id);
Packit 427e91
    numid=snd_ctl_elem_id_get_numid(id);
Packit 427e91
    count=snd_ctl_elem_info_get_count(info);
Packit 427e91
    if (!strcmp("Monitor Mixer Volume", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      if (!mixerId) {
Packit 427e91
        mixerId=numid;
Packit 427e91
        CTLID_DEBUG(("First Mixer id=%d\n", mixerId));
Packit 427e91
      }
Packit 427e91
    } else if (!strcmp("VMixer Volume", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      if (!vmixerId) {
Packit 427e91
        vmixerId=vmixerControl.id=numid;
Packit 427e91
        CTLID_DEBUG(("First Vmixer id=%d\n", vmixerId));
Packit 427e91
      }
Packit 427e91
    } else if (!strcmp("PCM Playback Volume", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      pcmoutId=pcmoutControl.id=numid;
Packit 427e91
      CTLID_DEBUG(("PCM Playback Volume id=%d [%d]\n", pcmoutId, count));
Packit 427e91
    } else if (!strcmp("Line Playback Volume", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      lineoutId=numid;
Packit 427e91
      CTLID_DEBUG(("Line Volume id=%d\n", lineoutId));
Packit 427e91
    } else if (!strcmp("Line Capture Volume", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      lineinId=lineinControl.id=numid;
Packit 427e91
      CTLID_DEBUG(("Capture Volume id=%d [%d]\n", lineinId, count));
Packit 427e91
    } else if (!strcmp("Line Playback Switch (-10dBV)", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      p4OutId=NominalOut.id=numid;
Packit 427e91
      CTLID_DEBUG(("Playback nominal id=%d [%d]\n", p4OutId, count));
Packit 427e91
    } else if (!strcmp("Line Capture Switch (-10dBV)", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      p4InId=NominalIn.id=numid;
Packit 427e91
      CTLID_DEBUG(("Capture nominal id=%d [%d]\n", p4InId, count));
Packit 427e91
    } else if (!strcmp("Digital mode Switch", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      dmodeId=numid;
Packit 427e91
      items=snd_ctl_elem_info_get_items(info);
Packit 427e91
      ndmodes=items;
Packit 427e91
      for (item=0; item
Packit 427e91
        snd_ctl_elem_info_set_item(info, item);
Packit 427e91
        if ((err=snd_hctl_elem_info(elem, info)) < 0) {
Packit 427e91
          printf("Control %s element info error: %s\n", card, snd_strerror(err));
Packit 427e91
          exit(err);
Packit 427e91
        }
Packit 427e91
        strncpy(dmodeName[item], snd_ctl_elem_info_get_item_name(info), 63);
Packit 427e91
        dmodeName[item][63]=0;
Packit 427e91
        CTLID_DEBUG(("Digital Mode id=%d item #%u '%s'\n", numid, item, snd_ctl_elem_info_get_item_name(info)));
Packit 427e91
      }
Packit 427e91
    } else if (!strcmp("Sample Clock Source", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      clocksrcId=numid;
Packit 427e91
      items=snd_ctl_elem_info_get_items(info);
Packit 427e91
      nclocksrc=items;
Packit 427e91
      for (item=0; item
Packit 427e91
        snd_ctl_elem_info_set_item(info, item);
Packit 427e91
        if ((err=snd_hctl_elem_info(elem, info))<0) {
Packit 427e91
          printf("Control %s element info error: %s\n", card, snd_strerror(err));
Packit 427e91
          exit(err);
Packit 427e91
        }
Packit 427e91
        strncpy(clocksrcName[item], snd_ctl_elem_info_get_item_name(info), 63);
Packit 427e91
        clocksrcName[item][63]=0;
Packit 427e91
        CTLID_DEBUG(("Clock source id=%d item #%u '%s'\n", numid, item, snd_ctl_elem_info_get_item_name(info)));
Packit 427e91
      }
Packit 427e91
    } else if (!strcmp("S/PDIF mode Switch", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      spdifmodeId=numid;
Packit 427e91
      items=snd_ctl_elem_info_get_items(info);
Packit 427e91
      nspdifmodes=items;
Packit 427e91
      for (item=0; item
Packit 427e91
        snd_ctl_elem_info_set_item(info, item);
Packit 427e91
        if ((err=snd_hctl_elem_info(elem, info)) < 0) {
Packit 427e91
          printf("Control %s element info error: %s\n", card, snd_strerror(err));
Packit 427e91
        }
Packit 427e91
        strncpy(spdifmodeName[item], snd_ctl_elem_info_get_item_name(info), 63);
Packit 427e91
        spdifmodeName[item][63]=0;
Packit 427e91
        CTLID_DEBUG(("S/PDIF Mode id=%d item #%u '%s'\n", numid, item, snd_ctl_elem_info_get_item_name(info)));
Packit 427e91
      }
Packit 427e91
    } else if (!strcmp("Phantom power Switch", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      phantomId=PhantomPower.id=numid;
Packit 427e91
      CTLID_DEBUG(("Phantom power Switch id=%d\n", numid));
Packit 427e91
    } else if (!strcmp("Digital Capture Switch (automute)", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      automuteId=Automute.id=numid;
Packit 427e91
      CTLID_DEBUG(("Automute Switch id=%d\n", numid));
Packit 427e91
    } else if (!strcmp("VU-meters Switch", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      vuswitchId=numid;
Packit 427e91
      CTLID_DEBUG(("VU-meter switch id=%d\n", numid));
Packit 427e91
    } else if (!strcmp("VU-meters", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      vumetersId=numid;
Packit 427e91
      CTLID_DEBUG(("VU-meters id=%d\n", numid));
Packit 427e91
    } else if (!strcmp("Channels info", snd_ctl_elem_id_get_name(id))) {
Packit 427e91
      channelsId=numid;
Packit 427e91
      CTLID_DEBUG(("Channels info id=%d\n", numid));
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
  GetChannels();
Packit 427e91
  CTLID_DEBUG(("Input channels = %d (analog=%d digital=%d)\n", nIn, fdIn, nIn-fdIn));
Packit 427e91
  CTLID_DEBUG(("Output channels = %d (analog=%d digital=%d)\n", nLOut, fdOut, nLOut-fdOut));
Packit 427e91
  CTLID_DEBUG(("PCM channels out = %d\n", nPOut));
Packit 427e91
Packit 427e91
#ifndef REAL
Packit 427e91
vmixerId=1000;
Packit 427e91
vmixerControl.inputs=12;
Packit 427e91
vmixerControl.outputs=mixerControl.outputs=nLOut=10;
Packit 427e91
metersStreams=3;
Packit 427e91
metersNumber=16;
Packit 427e91
metersTypes=2;
Packit 427e91
nPOut=12;
Packit 427e91
fdOut=2;
Packit 427e91
nIn=10;
Packit 427e91
fdIn=2;
Packit 427e91
printf("nIn=%d fdIn=%d nLOut=%d nPOut=%d fdOut=%d\n", nIn,fdIn,nLOut,nPOut, fdOut);
Packit 427e91
#endif
Packit 427e91
Packit 427e91
  if (mixerId && (mixerControl.inputs!=nIn || mixerControl.outputs!=nLOut)) {
Packit 427e91
    printf("** Error - Mixer/channels mismatch !!  nIn=%d mnIn=%d    nLOut=%d mnLOut=%d\n", nIn, mixerControl.inputs, nLOut, mixerControl.outputs);
Packit 427e91
    return(1);
Packit 427e91
  }
Packit 427e91
  if (lineoutId && !vmixerId)
Packit 427e91
    printf("** Warning - Vmixer cards without LineOut volume control are not supported !\n");
Packit 427e91
Packit 427e91
  if (vmixerId) {
Packit 427e91
    if (vmixerControl.inputs!=nPOut || vmixerControl.outputs!=nLOut) {
Packit 427e91
      printf("** Error - vmixer/channels mismatch:  vmp=%d npo=%d    vmo=%d nlo=%d !!\n", vmixerControl.inputs, nPOut, vmixerControl.outputs, nLOut);
Packit 427e91
      return(1);
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (p4InId)
Packit 427e91
    NominalIn.Channels=fdIn;
Packit 427e91
Packit 427e91
  if (p4OutId)
Packit 427e91
    NominalOut.Channels=fdOut;
Packit 427e91
Packit 427e91
  //@ Assumes all mixer and vmixer controls are contiguous
Packit 427e91
  if (mixerId)
Packit 427e91
    for (o=0, numid=mixerId; o
Packit 427e91
      for (i=0; i
Packit 427e91
        mixerControl.mixer[o][i].id=numid++;
Packit 427e91
      }
Packit 427e91
    }
Packit 427e91
Packit 427e91
  if (vmixerId)
Packit 427e91
    for (o=0, numid=vmixerId; o
Packit 427e91
      for (i=0; i
Packit 427e91
        vmixerControl.mixer[o][i].id=numid++;
Packit 427e91
      }
Packit 427e91
    }
Packit 427e91
Packit 427e91
  snd_hctl_close(handle);
Packit 427e91
  return(0);
Packit 427e91
}
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
int main(int argc, char *argv[]) {
Packit 427e91
  gchar str[256];
Packit 427e91
  GtkWidget *hbox, *vbox;
Packit 427e91
  GtkWidget *mainbox;
Packit 427e91
  GtkWidget *vbsel, *frame, *button;
Packit 427e91
  GtkWidget *label, *menu, *menuitem;
Packit 427e91
  GSList *bgroup;
Packit 427e91
  int err, i, o, n, cardnum, value;
Packit 427e91
  char hwname[8], cardname[32], load, save;
Packit 427e91
  snd_ctl_card_info_t *hw_info;
Packit 427e91
Packit 427e91
  load=save=1;
Packit 427e91
Packit 427e91
  // Scans all installed cards
Packit 427e91
  snd_ctl_card_info_alloca(&hw_info);
Packit 427e91
  cardnum=-1;
Packit 427e91
  ctlhandle=0;
Packit 427e91
Packit 427e91
  if (argc>1)
Packit 427e91
    cardnum=atoi(argv[1])-1;
Packit 427e91
Packit 427e91
  while (snd_card_next(&cardnum)>=0 && cardnum>=0) {
Packit 427e91
    sprintf(hwname, "hw:%d", cardnum);
Packit 427e91
    if ((err=snd_ctl_open(&ctlhandle, hwname, 0))<0) {
Packit 427e91
      printf("snd_ctl_open(%s) Error: %s\n", hwname, snd_strerror(err));
Packit 427e91
      continue;
Packit 427e91
    }
Packit 427e91
    if ((err=snd_ctl_card_info(ctlhandle, hw_info))>=0) {
Packit 427e91
      if (!strncmp(snd_ctl_card_info_get_driver(hw_info), "Echo_", 5)) {
Packit 427e91
        strncpy(card, hwname, 7);
Packit 427e91
        hwname[7]=0;
Packit 427e91
        strncpy(cardname, snd_ctl_card_info_get_name(hw_info), 31);
Packit 427e91
        cardname[31]=0;
Packit 427e91
        strncpy(cardId, snd_ctl_card_info_get_name(hw_info), 15);
Packit 427e91
        cardId[15]=0;
Packit 427e91
        CTLID_DEBUG(("Card found: %s  (%s)\n", snd_ctl_card_info_get_longname(hw_info), hwname));
Packit 427e91
/*printf("card       = %d\n", snd_ctl_card_info_get_card(hw_info));
Packit 427e91
printf("id         = %s\n", snd_ctl_card_info_get_id(hw_info));
Packit 427e91
printf("driver     = %s\n", snd_ctl_card_info_get_driver(hw_info));
Packit 427e91
printf("name       = %s\n", snd_ctl_card_info_get_name(hw_info));
Packit 427e91
printf("longname   = %s\n", snd_ctl_card_info_get_longname(hw_info));
Packit 427e91
printf("mixername  = %s\n", snd_ctl_card_info_get_mixername(hw_info));
Packit 427e91
printf("components = %s\n", snd_ctl_card_info_get_components(hw_info));*/
Packit 427e91
        break;
Packit 427e91
      }
Packit 427e91
    } else {
Packit 427e91
      printf("snd_ctl_card_info(%s) Error: %s\n", hwname, snd_strerror(err));
Packit 427e91
    }
Packit 427e91
    snd_ctl_close(ctlhandle);
Packit 427e91
    ctlhandle=0;
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (!ctlhandle) {
Packit 427e91
    printf("No Echoaudio cards found, sorry.\n");
Packit 427e91
    return(0);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Reads available controls
Packit 427e91
  if (OpenControls(card, cardname))
Packit 427e91
    exit(1);
Packit 427e91
Packit 427e91
  mouseButton=0;
Packit 427e91
  Gang=0;		// Set the gang button off, because has annoying side effects during initialization
Packit 427e91
  Mainw_geom.st=NOPOS;
Packit 427e91
  PVw_geom.st=NOPOS;
Packit 427e91
  LVw_geom.st=NOPOS;
Packit 427e91
  VUw_geom.st=NOPOS;
Packit 427e91
  Mixerw_geom.st=NOPOS;
Packit 427e91
  Vmixerw_geom.st=NOPOS;
Packit 427e91
  VUwindow=GMwindow=0;
Packit 427e91
  GMixerSection.Inputs=nIn;	// The correct value is set by Digital_mode_activate()
Packit 427e91
  GMixerSection.Outputs=nLOut;
Packit 427e91
  GMixerSection.VmixerFirst=nIn;
Packit 427e91
  GMixerSection.VmixerLast=nIn+vmixerControl.inputs-1;
Packit 427e91
  GMixerSection.LineOut=GMixerSection.VmixerLast+1;
Packit 427e91
Packit 427e91
  // Read current mixer setting.
Packit 427e91
  if (mixerId)
Packit 427e91
    ReadMixer(&mixerControl);
Packit 427e91
  if (vmixerId)
Packit 427e91
    ReadMixer(&vmixerControl);
Packit 427e91
  if (pcmoutId)
Packit 427e91
    ReadControl(pcmoutControl.Gain, nPOut, pcmoutControl.id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  if (lineinId)
Packit 427e91
    ReadControl(lineinControl.Gain, nIn, lineinControl.id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  if (lineoutId)
Packit 427e91
    ReadControl(lineoutControl.Gain, nLOut, lineoutId, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
  if (p4InId)
Packit 427e91
    ReadNominalLevels(&NominalIn);
Packit 427e91
  if (p4OutId)
Packit 427e91
    ReadNominalLevels(&NominalOut);
Packit 427e91
Packit 427e91
  //@@ check the values
Packit 427e91
  if (load) {
Packit 427e91
    FILE *f;
Packit 427e91
    snprintf(str, 255, "%s/.Emixer_%s", getenv("HOME"), cardId);
Packit 427e91
    str[255]=0;
Packit 427e91
    if ((f=fopen(str, "r"))) {
Packit 427e91
      str[255]=0;
Packit 427e91
      while (fgets(str, 255, f)) {
Packit 427e91
        if (!strncmp("LineOut ", str, 8)) {
Packit 427e91
          sscanf(str+8, "%d %d", &o, &n);
Packit 427e91
          if (o>=0 && o
Packit 427e91
            lineoutControl.Gain[o]=n;
Packit 427e91
        } else if (!strncmp("LineIn ", str, 7)) {
Packit 427e91
          sscanf(str+7, "%d %d", &i, &n);
Packit 427e91
          if (i>=0 && i
Packit 427e91
            lineinControl.Gain[i]=n;
Packit 427e91
        } else if (!strncmp("PcmOut ", str, 7)) {
Packit 427e91
          sscanf(str+7, "%d %d", &o, &n);
Packit 427e91
          if (o>=0 && o
Packit 427e91
            pcmoutControl.Gain[o]=n;
Packit 427e91
        } else if (!strncmp("NominalOut ", str, 11)) {
Packit 427e91
          sscanf(str+11, "%d %d", &o, &n);
Packit 427e91
          if (o>=0 && o
Packit 427e91
            NominalOut.Level[o]=!!n;
Packit 427e91
        } else if (!strncmp("NominalIn ", str, 10)) {
Packit 427e91
          sscanf(str+10, "%d %d", &i, &n);
Packit 427e91
          if (i>=0 && i
Packit 427e91
            NominalIn.Level[i]=!!n;
Packit 427e91
        } else if (!strncmp("Mixer ", str, 6)) {
Packit 427e91
          sscanf(str+6, "%d %d %d", &o, &i, &n);
Packit 427e91
          if (o>=0 && o<nlout &&="" i="">=0 && i
Packit 427e91
            mixerControl.mixer[o][i].Gain=n;
Packit 427e91
        } else if (!strncmp("Vmixer ", str, 7)) {
Packit 427e91
          sscanf(str+7, "%d %d %d", &o, &i, &n);
Packit 427e91
          if (o>=0 && o<nlout &&="" i="">=0 && i
Packit 427e91
            vmixerControl.mixer[o][i].Gain=n;
Packit 427e91
        } else if (!strncmp("MainWindow ", str, 11)) {
Packit 427e91
          sscanf(str+11, "%d %d %d %d", &Mainw_geom.x, &Mainw_geom.y, &Mainw_geom.w, &Mainw_geom.h);
Packit 427e91
        } else if (!strncmp("VUmetersWindow ", str, 15)) {
Packit 427e91
          sscanf(str+15, "%d %d %d", &VUw_geom.x, &VUw_geom.y, &VUw_geom.st);
Packit 427e91
        } else if (!strncmp("GfxMixerWindow ", str, 15)) {
Packit 427e91
          sscanf(str+15, "%d %d %d", &GMw_geom.x, &GMw_geom.y, &GMw_geom.st);
Packit 427e91
        } else if (!strncmp("PcmVolumeWindow ", str, 16)) {
Packit 427e91
          sscanf(str+16, "%d %d %d %d %d", &PVw_geom.x, &PVw_geom.y, &PVw_geom.w, &PVw_geom.h, &PVw_geom.st);
Packit 427e91
        } else if (!strncmp("LineVolumeWindow ", str, 17)) {
Packit 427e91
          sscanf(str+17, "%d %d %d %d %d", &LVw_geom.x, &LVw_geom.y, &LVw_geom.w, &LVw_geom.h, &LVw_geom.st);
Packit 427e91
        } else if (!strncmp("MixerWindow ", str, 12)) {
Packit 427e91
          sscanf(str+12, "%d %d %d %d %d", &Mixerw_geom.x, &Mixerw_geom.y, &Mixerw_geom.w, &Mixerw_geom.h, &Mixerw_geom.st);
Packit 427e91
        } else if (!strncmp("VmixerWindow ", str, 13)) {
Packit 427e91
          sscanf(str+13, "%d %d %d %d %d", &Vmixerw_geom.x, &Vmixerw_geom.y, &Vmixerw_geom.w, &Vmixerw_geom.h, &Vmixerw_geom.st);
Packit 427e91
        } else if (!strncmp("MiscControlsWindow ", str, 19)) {
Packit 427e91
          sscanf(str+19, "%d %d %d %d %d", &Miscw_geom.x, &Miscw_geom.y, &Miscw_geom.w, &Miscw_geom.h, &Miscw_geom.st);
Packit 427e91
        }
Packit 427e91
      }
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
  gtk_init(&argc, &argv);
Packit 427e91
  fnt=gdk_font_load("-misc-fixed-medium-r-*-*-10-*-*-*-*-*-*-*");
Packit 427e91
  if (!fnt) {
Packit 427e91
    printf("Cannot find the font\n");
Packit 427e91
    exit(1);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  /* Now assemble the control windows */
Packit 427e91
Packit 427e91
Packit 427e91
  /* ********** Misc controls window ********** */
Packit 427e91
Packit 427e91
  Miscwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
  sprintf(str, "%s Misc controls", cardId);
Packit 427e91
  gtk_window_set_title(GTK_WINDOW(Miscwindow), str);
Packit 427e91
  gtk_window_set_wmclass(GTK_WINDOW(Miscwindow), "misc", "Emixer");
Packit 427e91
  gtk_signal_connect(GTK_OBJECT(Miscwindow), "delete_event", GTK_SIGNAL_FUNC(CloseWindow), (gpointer)&Miscw_geom);
Packit 427e91
  gtk_container_set_border_width(GTK_CONTAINER(Miscwindow), BORDER);
Packit 427e91
  if (Miscw_geom.st!=NOPOS) {
Packit 427e91
    gtk_widget_set_uposition(Miscwindow, Miscw_geom.x, Miscw_geom.y);
Packit 427e91
    gtk_window_set_default_size(GTK_WINDOW(Miscwindow), Miscw_geom.w, Miscw_geom.h);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  mainbox=gtk_vbox_new(FALSE, SPACING);
Packit 427e91
  gtk_widget_show(mainbox);
Packit 427e91
  gtk_container_add(GTK_CONTAINER(Miscwindow), mainbox);
Packit 427e91
Packit 427e91
Packit 427e91
  if (p4InId) {
Packit 427e91
    // Consumer/professional analog input switches
Packit 427e91
    frame=gtk_frame_new("Input +4dBu");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, FALSE, 0);
Packit 427e91
    hbox=gtk_hbox_new(FALSE, 0);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      sprintf(str, "%d", i);
Packit 427e91
      button=NominalIn.Button[i]=gtk_toggle_button_new_with_label(str);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 1);
Packit 427e91
      gtk_widget_show(button);
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), NominalIn.Level[i]);	// Forces handler call
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(Nominal_level_toggled), (gpointer)(long)i);
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), !NominalIn.Level[i]);
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
  if (p4OutId) {
Packit 427e91
    // Consumer/professional analog output switches
Packit 427e91
    frame=gtk_frame_new("Output +4dBu");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, FALSE, 0);
Packit 427e91
    hbox=gtk_hbox_new(FALSE, 0);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      sprintf(str, "%d", i);
Packit 427e91
      button=NominalOut.Button[i]=gtk_toggle_button_new_with_label(str);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 1);
Packit 427e91
      gtk_widget_show(button);
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), NominalOut.Level[i]);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(button), "toggled", GTK_SIGNAL_FUNC(Nominal_level_toggled), (gpointer)(long)(i+ECHO_MAXAUDIOINPUTS));
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), !NominalOut.Level[i]);
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
  if (dmodeId && ndmodes>1) {
Packit 427e91
    // Digital mode switch
Packit 427e91
    frame=gtk_frame_new("Digital mode");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, FALSE, 0);
Packit 427e91
    hbox=gtk_hbox_new(FALSE, 0);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    dmodeOpt=gtk_option_menu_new();
Packit 427e91
    gtk_widget_show(dmodeOpt);
Packit 427e91
    menu=gtk_menu_new();
Packit 427e91
    gtk_widget_show(menu);
Packit 427e91
    for (i=0; i
Packit 427e91
      menuitem=gtk_menu_item_new_with_label(dmodeName[i]);
Packit 427e91
      gtk_widget_show(menuitem);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(menuitem), "activate", Digital_mode_activate, (gpointer)(long)i);
Packit 427e91
      gtk_menu_append(GTK_MENU(menu), menuitem);
Packit 427e91
    }
Packit 427e91
    gtk_option_menu_set_menu(GTK_OPTION_MENU(dmodeOpt), menu);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), dmodeOpt, TRUE, TRUE, 0);
Packit 427e91
    gtk_option_menu_set_history(GTK_OPTION_MENU(dmodeOpt), dmodeVal=GetEnum(dmodeId));
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
  if (clocksrcId && nclocksrc>1) {
Packit 427e91
    // Clock source switch
Packit 427e91
    frame=gtk_frame_new("Clock source");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, FALSE, 0);
Packit 427e91
    hbox=gtk_hbox_new(FALSE, 0);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    clocksrcOpt=gtk_option_menu_new();
Packit 427e91
    gtk_widget_show(clocksrcOpt);
Packit 427e91
    menu=gtk_menu_new();
Packit 427e91
    gtk_widget_show(menu);
Packit 427e91
    for (i=0; i
Packit 427e91
      clocksrc_menuitem[i]=gtk_menu_item_new_with_label(clocksrcName[i]);
Packit 427e91
      gtk_widget_show(clocksrc_menuitem[i]);
Packit 427e91
      gtk_widget_set_sensitive(clocksrc_menuitem[i], FALSE);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(clocksrc_menuitem[i]), "activate", Clock_source_activate, (gpointer)(long)i);
Packit 427e91
      gtk_menu_append(GTK_MENU(menu), clocksrc_menuitem[i]);
Packit 427e91
    }
Packit 427e91
    gtk_option_menu_set_menu(GTK_OPTION_MENU(clocksrcOpt), menu);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), clocksrcOpt, TRUE, TRUE, 0);
Packit 427e91
    gtk_option_menu_set_history(GTK_OPTION_MENU(clocksrcOpt), clocksrcVal=GetEnum(clocksrcId));
Packit 427e91
    clocksrctimer=gtk_timeout_add(2000, CheckInputs, 0);
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
  if (spdifmodeId && nspdifmodes>1) {
Packit 427e91
    // S/PDIF mode switch
Packit 427e91
    frame=gtk_frame_new("S/PDIF mode");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, FALSE, 0);
Packit 427e91
    hbox=gtk_hbox_new(FALSE, 0);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    spdifmodeOpt=gtk_option_menu_new();
Packit 427e91
    gtk_widget_show(spdifmodeOpt);
Packit 427e91
    menu=gtk_menu_new();
Packit 427e91
    gtk_widget_show(menu);
Packit 427e91
    for (i=0; i
Packit 427e91
      menuitem=gtk_menu_item_new_with_label(spdifmodeName[i]);
Packit 427e91
      gtk_widget_show(menuitem);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(menuitem), "activate", SPDIF_mode_activate, (gpointer)(long)i);
Packit 427e91
      gtk_menu_append(GTK_MENU(menu), menuitem);
Packit 427e91
    }
Packit 427e91
    gtk_option_menu_set_menu(GTK_OPTION_MENU(spdifmodeOpt), menu);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), spdifmodeOpt, TRUE, TRUE, 0);
Packit 427e91
    gtk_option_menu_set_history(GTK_OPTION_MENU(spdifmodeOpt), spdifmodeVal=GetEnum(spdifmodeId));
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
  // Switches
Packit 427e91
  if (phantomId || clocksrcId) {
Packit 427e91
    frame=gtk_frame_new("Switches");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, FALSE, 0);
Packit 427e91
    hbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    if (phantomId) {
Packit 427e91
      // Phantom power switch
Packit 427e91
      button=gtk_check_button_new_with_label("Phantom power");
Packit 427e91
      gtk_widget_show(button);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
Packit 427e91
      ReadControl(&i, 1, PhantomPower.id, SND_CTL_ELEM_IFACE_MIXER);
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), i);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(button), "toggled", Switch_toggled, (gpointer)&PhantomPower);
Packit 427e91
      PhantomPower.Button=button;
Packit 427e91
    }
Packit 427e91
Packit 427e91
    if (automuteId) {
Packit 427e91
      // Digital input automute switch
Packit 427e91
      button=gtk_check_button_new_with_label("Automute");
Packit 427e91
      gtk_widget_show(button);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, FALSE, 0);
Packit 427e91
      ReadControl(&i, 1, Automute.id, SND_CTL_ELEM_IFACE_CARD);
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), i);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(button), "toggled", Switch_toggled, (gpointer)&Automute);
Packit 427e91
      Automute.Button=button;
Packit 427e91
    }
Packit 427e91
Packit 427e91
    // Auto clock switch
Packit 427e91
    if (clocksrcId) {
Packit 427e91
      autoclockChkbutton=gtk_check_button_new_with_label("Autoclock");
Packit 427e91
      gtk_widget_show(autoclockChkbutton);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(hbox), autoclockChkbutton, TRUE, FALSE, 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(autoclockChkbutton), "toggled", AutoClock_toggled, NULL);
Packit 427e91
      AutoClock=-1;
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
/* ********** PCM volume window ********** */
Packit 427e91
Packit 427e91
  pcmoutControl.window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
  sprintf(str, "%s PCM volume", cardId);
Packit 427e91
  gtk_window_set_title(GTK_WINDOW (pcmoutControl.window), str);
Packit 427e91
  gtk_window_set_wmclass(GTK_WINDOW(pcmoutControl.window), "pcm", "Emixer");
Packit 427e91
  gtk_signal_connect(GTK_OBJECT(pcmoutControl.window), "delete_event", GTK_SIGNAL_FUNC(CloseWindow), (gpointer)&PVw_geom);
Packit 427e91
  gtk_container_set_border_width(GTK_CONTAINER(pcmoutControl.window), BORDER);
Packit 427e91
  if (PVw_geom.st!=NOPOS) {
Packit 427e91
    gtk_widget_set_uposition(pcmoutControl.window, PVw_geom.x, PVw_geom.y);
Packit 427e91
    gtk_window_set_default_size(GTK_WINDOW(pcmoutControl.window), PVw_geom.w, PVw_geom.h);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  mainbox=gtk_hbox_new(FALSE, SPACING);
Packit 427e91
  gtk_widget_show(mainbox);
Packit 427e91
  gtk_container_add(GTK_CONTAINER(pcmoutControl.window), mainbox);
Packit 427e91
Packit 427e91
Packit 427e91
  if (pcmoutId) {
Packit 427e91
    // PCM Output volume widgets
Packit 427e91
    frame=gtk_frame_new("PCM Output volume");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
Packit 427e91
    hbox=gtk_hbox_new(TRUE, 1);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      vbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
      gtk_widget_show(vbox);
Packit 427e91
      gtk_container_add(GTK_CONTAINER(hbox), vbox);
Packit 427e91
      // Channel label
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "A%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "D%d", i-fdOut);
Packit 427e91
      label=gtk_label_new(str);
Packit 427e91
      gtk_widget_show(label);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
Packit 427e91
      // Volume
Packit 427e91
      value = INVERT(pcmoutControl.Gain[i]);
Packit 427e91
      pcmoutControl.adj[i]=gtk_adjustment_new(!value, ECHOGAIN_MINOUT, ECHOGAIN_MAXOUT, SHORTSTEP, LONGSTEP, 0);
Packit 427e91
      pcmoutControl.volume[i]=gtk_vscale_new(GTK_ADJUSTMENT(pcmoutControl.adj[i]));
Packit 427e91
      gtk_widget_show(pcmoutControl.volume[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), pcmoutControl.volume[i], TRUE, TRUE, 0);
Packit 427e91
      gtk_scale_set_draw_value(GTK_SCALE(pcmoutControl.volume[i]), 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(pcmoutControl.adj[i]), "value_changed", GTK_SIGNAL_FUNC(PCM_volume_changed), (gpointer)(long)(i+ECHO_MAXAUDIOINPUTS));
Packit 427e91
      // Value label
Packit 427e91
      pcmoutControl.label[i]=gtk_label_new("xxx");
Packit 427e91
      gtk_widget_show(pcmoutControl.label[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), pcmoutControl.label[i], FALSE, FALSE, 0);
Packit 427e91
      gtk_adjustment_set_value(GTK_ADJUSTMENT(pcmoutControl.adj[i]), value);
Packit 427e91
    }
Packit 427e91
    gtk_widget_set_usize(GTK_WIDGET(pcmoutControl.volume[0]), 0, 170);		// Set minimum y size
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
/* ********** Line volume window ********** */
Packit 427e91
Packit 427e91
  LVwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
  sprintf(str, "%s Line volume", cardId);
Packit 427e91
  gtk_window_set_title(GTK_WINDOW (LVwindow), str);
Packit 427e91
  gtk_window_set_wmclass(GTK_WINDOW(LVwindow), "line", "Emixer");
Packit 427e91
  gtk_signal_connect(GTK_OBJECT(LVwindow), "delete_event", GTK_SIGNAL_FUNC(CloseWindow), (gpointer)&LVw_geom);
Packit 427e91
  gtk_container_set_border_width(GTK_CONTAINER(LVwindow), BORDER);
Packit 427e91
  if (LVw_geom.st!=NOPOS) {
Packit 427e91
    gtk_widget_set_uposition(LVwindow, LVw_geom.x, LVw_geom.y);
Packit 427e91
    gtk_window_set_default_size(GTK_WINDOW(LVwindow), LVw_geom.w, LVw_geom.h);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  mainbox=gtk_hbox_new(FALSE, SPACING);
Packit 427e91
  gtk_widget_show(mainbox);
Packit 427e91
  gtk_container_add(GTK_CONTAINER(LVwindow), mainbox);
Packit 427e91
Packit 427e91
  // Line input volume widgets
Packit 427e91
  if (lineinId) {
Packit 427e91
    frame=gtk_frame_new("Analog input volume");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
Packit 427e91
    hbox=gtk_hbox_new(TRUE, 1);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      vbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
      gtk_widget_show(vbox);
Packit 427e91
      gtk_container_add(GTK_CONTAINER(hbox), vbox);
Packit 427e91
      // Channel label
Packit 427e91
      sprintf(str, "%d", i);
Packit 427e91
      label=gtk_label_new(str);
Packit 427e91
      gtk_widget_show(label);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
Packit 427e91
      // Volume (resolution is 0.5 dB)
Packit 427e91
      value = IN_INVERT(lineinControl.Gain[i]);
Packit 427e91
      lineinControl.adj[i]=gtk_adjustment_new(!value, ECHOGAIN_MININP, ECHOGAIN_MAXINP, SHORTSTEP, LONGSTEP*2, 0);
Packit 427e91
      lineinControl.volume[i]=gtk_vscale_new(GTK_ADJUSTMENT(lineinControl.adj[i]));
Packit 427e91
      gtk_widget_show(lineinControl.volume[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), lineinControl.volume[i], TRUE, TRUE, 0);
Packit 427e91
      gtk_scale_set_draw_value(GTK_SCALE(lineinControl.volume[i]), 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(lineinControl.adj[i]), "value_changed", GTK_SIGNAL_FUNC(PCM_volume_changed), (gpointer)(long)i);
Packit 427e91
      // Value label
Packit 427e91
      lineinControl.label[i]=gtk_label_new("xxx");
Packit 427e91
      gtk_widget_show(lineinControl.label[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), lineinControl.label[i], FALSE, FALSE, 0);
Packit 427e91
      gtk_adjustment_set_value(GTK_ADJUSTMENT(lineinControl.adj[i]), value);
Packit 427e91
    }
Packit 427e91
    gtk_widget_set_usize(GTK_WIDGET(lineinControl.volume[0]), 0, 170);	// Set minimum y size
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
  // Line output volume widgets
Packit 427e91
  if (1) {
Packit 427e91
    frame=gtk_frame_new("Line output volume");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
Packit 427e91
    hbox=gtk_hbox_new(TRUE, 1);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      vbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
      gtk_widget_show(vbox);
Packit 427e91
      gtk_container_add(GTK_CONTAINER(hbox), vbox);
Packit 427e91
      // Channel label
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "A%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "D%d", i-fdOut);
Packit 427e91
      label=gtk_label_new(str);
Packit 427e91
      gtk_widget_show(label);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
Packit 427e91
      // Volume
Packit 427e91
      value = INVERT(lineoutControl.Gain[i]);
Packit 427e91
      lineoutControl.adj[i]=gtk_adjustment_new(!value, ECHOGAIN_MINOUT, ECHOGAIN_MAXOUT, SHORTSTEP, LONGSTEP, 0);
Packit 427e91
      lineoutControl.volume[i]=gtk_vscale_new(GTK_ADJUSTMENT(lineoutControl.adj[i]));
Packit 427e91
      gtk_widget_show(lineoutControl.volume[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), lineoutControl.volume[i], TRUE, TRUE, 0);
Packit 427e91
      gtk_scale_set_draw_value(GTK_SCALE(lineoutControl.volume[i]), 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(lineoutControl.adj[i]), "value_changed", GTK_SIGNAL_FUNC(LineOut_volume_changed), (gpointer)(long)i);
Packit 427e91
      // Value label
Packit 427e91
      lineoutControl.label[i]=gtk_label_new("xxx");
Packit 427e91
      gtk_widget_show(lineoutControl.label[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), lineoutControl.label[i], FALSE, FALSE, 0);
Packit 427e91
      gtk_adjustment_set_value(GTK_ADJUSTMENT(lineoutControl.adj[i]), value);
Packit 427e91
    }
Packit 427e91
    gtk_widget_set_usize(GTK_WIDGET(lineoutControl.volume[0]), 0, 170);		// Set minimum y size
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
/* ********** Mixer window ********** */
Packit 427e91
Packit 427e91
  if (mixerId) {
Packit 427e91
    mixerControl.window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
    sprintf(str, "%s Monitor mixer", cardId);
Packit 427e91
    gtk_window_set_title(GTK_WINDOW(mixerControl.window), str);
Packit 427e91
    gtk_window_set_wmclass(GTK_WINDOW(mixerControl.window), "mixer", "Emixer");
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(mixerControl.window), "delete_event", GTK_SIGNAL_FUNC(CloseWindow), (gpointer)&Mixerw_geom);
Packit 427e91
    gtk_container_set_border_width(GTK_CONTAINER(mixerControl.window), BORDER);
Packit 427e91
    if (Mixerw_geom.st!=NOPOS) {
Packit 427e91
      gtk_widget_set_uposition(mixerControl.window, Mixerw_geom.x, Mixerw_geom.y);
Packit 427e91
      gtk_window_set_default_size(GTK_WINDOW(mixerControl.window), Mixerw_geom.w, Mixerw_geom.h);
Packit 427e91
//      gdk_window_move_resize(mixerControl.window->window, Mixerw_geom.x, Mixerw_geom.y, Mixerw_geom.w, Mixerw_geom.h);
Packit 427e91
/*      gtk_widget_set_usize(mixerControl.window, Mixerw_geom.w, Mixerw_geom.h);
Packit 427e91
      gtk_widget_set_usize(mixerControl.window, -1, -1);*/
Packit 427e91
    }
Packit 427e91
Packit 427e91
    mainbox=gtk_hbox_new(FALSE, SPACING);
Packit 427e91
    gtk_widget_show(mainbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(mixerControl.window), mainbox);
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
    // Mixer volume widgets
Packit 427e91
    frame=gtk_frame_new("Mixer input levels");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
Packit 427e91
    hbox=gtk_hbox_new(TRUE, 1);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      vbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
      gtk_widget_show(vbox);
Packit 427e91
      gtk_container_add(GTK_CONTAINER(hbox), vbox);
Packit 427e91
      // Channel label
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "A%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "D%d", i-fdIn);
Packit 427e91
      label=gtk_label_new(str);
Packit 427e91
      gtk_widget_show(label);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
Packit 427e91
      // Volume
Packit 427e91
      mixerControl.adj[i]=gtk_adjustment_new(0, ECHOGAIN_MINOUT, ECHOGAIN_MAXOUT, SHORTSTEP, LONGSTEP, 0);
Packit 427e91
      mixerControl.volume[i]=gtk_vscale_new(GTK_ADJUSTMENT(mixerControl.adj[i]));
Packit 427e91
      gtk_widget_show(mixerControl.volume[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), mixerControl.volume[i], TRUE, TRUE, 0);
Packit 427e91
      gtk_scale_set_draw_value(GTK_SCALE(mixerControl.volume[i]), 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(mixerControl.volume[i]), "grab_focus", GTK_SIGNAL_FUNC(Monitor_volume_clicked), (gpointer)i);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(mixerControl.adj[i]), "value_changed", GTK_SIGNAL_FUNC(Monitor_volume_changed), (gpointer)i);
Packit 427e91
      // Value label
Packit 427e91
      mixerControl.label[i]=gtk_label_new("xxx");
Packit 427e91
      gtk_widget_show(mixerControl.label[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), mixerControl.label[i], FALSE, FALSE, 0);
Packit 427e91
    }
Packit 427e91
    gtk_widget_set_usize(GTK_WIDGET(mixerControl.volume[0]), 0, 170);		// Set minimum y size
Packit 427e91
Packit 427e91
    // Output channel selectors
Packit 427e91
    frame=gtk_frame_new("Mixer output");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    vbsel=gtk_vbox_new(FALSE, 2);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, FALSE, FALSE, 0);
Packit 427e91
    gtk_widget_show(vbsel);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), vbsel);
Packit 427e91
Packit 427e91
    bgroup=0;
Packit 427e91
    for (i=n=0; i
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "An-%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "Di-%d", i-fdOut);
Packit 427e91
      if (i)
Packit 427e91
        bgroup=gtk_radio_button_group(GTK_RADIO_BUTTON(mixerControl.outsel[i-1]));
Packit 427e91
      mixerControl.outsel[i]=gtk_radio_button_new_with_label(bgroup, str);
Packit 427e91
      gtk_widget_show(mixerControl.outsel[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbsel), mixerControl.outsel[i], FALSE, FALSE, 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(mixerControl.outsel[i]), "toggled", GTK_SIGNAL_FUNC(Mixer_Output_selector_clicked), (gpointer)i);
Packit 427e91
    }
Packit 427e91
    mixerControl.input=0;
Packit 427e91
    mixerControl.output=-1;
Packit 427e91
    Mixer_Output_selector_clicked(0, 0);
Packit 427e91
Packit 427e91
#else // REVERSE
Packit 427e91
Packit 427e91
    // Input channel selectors
Packit 427e91
    frame=gtk_frame_new("Mixer input");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, FALSE, FALSE, 0);
Packit 427e91
    vbsel=gtk_vbox_new(FALSE, 2);
Packit 427e91
    gtk_widget_show(vbsel);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), vbsel);
Packit 427e91
Packit 427e91
    bgroup=0;
Packit 427e91
    for (i=n=0; i
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "An-%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "Di-%d", i-fdIn);
Packit 427e91
      if (i)
Packit 427e91
        bgroup=gtk_radio_button_group(GTK_RADIO_BUTTON(mixerControl.inpsel[i-1]));
Packit 427e91
      mixerControl.inpsel[i]=gtk_radio_button_new_with_label(bgroup, str);
Packit 427e91
      gtk_widget_show(mixerControl.inpsel[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbsel), mixerControl.inpsel[i], FALSE, FALSE, 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(mixerControl.inpsel[i]), "toggled", GTK_SIGNAL_FUNC(Mixer_Input_selector_clicked), (gpointer)(long)i);
Packit 427e91
    }
Packit 427e91
Packit 427e91
    // Mixer volume widgets
Packit 427e91
    frame=gtk_frame_new("Mixer output levels");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
Packit 427e91
    hbox=gtk_hbox_new(TRUE, 1);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      vbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
      gtk_widget_show(vbox);
Packit 427e91
      gtk_container_add(GTK_CONTAINER(hbox), vbox);
Packit 427e91
      // Channel label
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "A%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "D%d", i-fdOut);
Packit 427e91
      label=gtk_label_new(str);
Packit 427e91
      gtk_widget_show(label);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
Packit 427e91
      // Volume
Packit 427e91
      mixerControl.adj[i]=gtk_adjustment_new(0, ECHOGAIN_MINOUT, ECHOGAIN_MAXOUT, SHORTSTEP, LONGSTEP, 0);
Packit 427e91
      mixerControl.volume[i]=gtk_vscale_new(GTK_ADJUSTMENT(mixerControl.adj[i]));
Packit 427e91
      gtk_widget_show(mixerControl.volume[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), mixerControl.volume[i], TRUE, TRUE, 0);
Packit 427e91
      gtk_scale_set_draw_value(GTK_SCALE(mixerControl.volume[i]), 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(mixerControl.volume[i]), "grab_focus", GTK_SIGNAL_FUNC(Monitor_volume_clicked), (gpointer)(long)i);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(mixerControl.adj[i]), "value_changed", GTK_SIGNAL_FUNC(Monitor_volume_changed), (gpointer)(long)i);
Packit 427e91
      // Value label
Packit 427e91
      mixerControl.label[i]=gtk_label_new("xxx");
Packit 427e91
      gtk_widget_show(mixerControl.label[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), mixerControl.label[i], FALSE, FALSE, 0);
Packit 427e91
    }
Packit 427e91
    gtk_widget_set_usize(GTK_WIDGET(mixerControl.volume[0]), 0, 170);		// Set minimum y size
Packit 427e91
    mixerControl.input=-1;
Packit 427e91
    mixerControl.output=0;
Packit 427e91
    Mixer_Input_selector_clicked(0, 0);
Packit 427e91
#endif
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
/* ********** Vmixer window ********** */
Packit 427e91
Packit 427e91
  if (vmixerId) {
Packit 427e91
    vmixerControl.window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
    sprintf(str, "%s Vmixer", cardId);
Packit 427e91
    gtk_window_set_title(GTK_WINDOW(vmixerControl.window), str);
Packit 427e91
    gtk_window_set_wmclass(GTK_WINDOW(vmixerControl.window), "vmixer", "Emixer");
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(vmixerControl.window), "delete_event", GTK_SIGNAL_FUNC(CloseWindow), (gpointer)&Vmixerw_geom);
Packit 427e91
    gtk_container_set_border_width(GTK_CONTAINER(vmixerControl.window), BORDER);
Packit 427e91
    if (Vmixerw_geom.st!=NOPOS) {
Packit 427e91
      gtk_widget_set_uposition(vmixerControl.window, Vmixerw_geom.x, Vmixerw_geom.y);
Packit 427e91
      gtk_window_set_default_size(GTK_WINDOW(vmixerControl.window), Vmixerw_geom.w, Vmixerw_geom.h);
Packit 427e91
    }
Packit 427e91
Packit 427e91
    mainbox=gtk_hbox_new(FALSE, SPACING);
Packit 427e91
    gtk_widget_show(mainbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(vmixerControl.window), mainbox);
Packit 427e91
Packit 427e91
#ifdef REVERSE
Packit 427e91
Packit 427e91
    // Vmixer volume widgets
Packit 427e91
    frame=gtk_frame_new("Vmixer vchannels levels");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
Packit 427e91
    hbox=gtk_hbox_new(TRUE, 1);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      vbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
      gtk_widget_show(vbox);
Packit 427e91
      gtk_container_add(GTK_CONTAINER(hbox), vbox);
Packit 427e91
      // Channel label
Packit 427e91
      sprintf(str, "V%d", i);
Packit 427e91
      label=gtk_label_new(str);
Packit 427e91
      gtk_widget_show(label);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
Packit 427e91
      // Volume
Packit 427e91
      vmixerControl.adj[i]=gtk_adjustment_new(0, ECHOGAIN_MINOUT, ECHOGAIN_MAXOUT, SHORTSTEP, LONGSTEP, 0);
Packit 427e91
      vmixerControl.volume[i]=gtk_vscale_new(GTK_ADJUSTMENT(vmixerControl.adj[i]));
Packit 427e91
      gtk_widget_show(vmixerControl.volume[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), vmixerControl.volume[i], TRUE, TRUE, 0);
Packit 427e91
      gtk_scale_set_draw_value(GTK_SCALE(vmixerControl.volume[i]), 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(vmixerControl.volume[i]), "grab_focus", GTK_SIGNAL_FUNC(Vmixer_volume_clicked), (gpointer)i);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(vmixerControl.adj[i]), "value_changed", GTK_SIGNAL_FUNC(Vmixer_volume_changed), (gpointer)i);
Packit 427e91
      // Value label
Packit 427e91
      vmixerControl.label[i]=gtk_label_new("xxx");
Packit 427e91
      gtk_widget_show(vmixerControl.label[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), vmixerControl.label[i], FALSE, FALSE, 0);
Packit 427e91
    }
Packit 427e91
    gtk_widget_set_usize(GTK_WIDGET(vmixerControl.volume[0]), 0, 170);		// Set minimum y size
Packit 427e91
Packit 427e91
    // Input channel selectors
Packit 427e91
    frame=gtk_frame_new("Output");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, FALSE, FALSE, 0);
Packit 427e91
    vbsel=gtk_vbox_new(FALSE, 2);
Packit 427e91
    gtk_widget_show(vbsel);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), vbsel);
Packit 427e91
Packit 427e91
    bgroup=0;
Packit 427e91
    for (i=0; i
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "A%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "D%d", i);
Packit 427e91
      if (i)
Packit 427e91
        bgroup=gtk_radio_button_group(GTK_RADIO_BUTTON(vmixerControl.outsel[i-1]));
Packit 427e91
      vmixerControl.outsel[i]=gtk_radio_button_new_with_label(bgroup, str);
Packit 427e91
      gtk_widget_show(vmixerControl.outsel[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbsel), vmixerControl.outsel[i], FALSE, FALSE, 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(vmixerControl.outsel[i]), "toggled", GTK_SIGNAL_FUNC(Vmixer_output_selector_clicked), (gpointer)i);
Packit 427e91
    }
Packit 427e91
    vmixerControl.output=-1;
Packit 427e91
    Vmixer_output_selector_clicked(0, 0);
Packit 427e91
Packit 427e91
#else // REVERSE
Packit 427e91
Packit 427e91
    // Input channel selectors
Packit 427e91
    frame=gtk_frame_new("Vchannel");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, FALSE, FALSE, 0);
Packit 427e91
    vbsel=gtk_vbox_new(FALSE, 2);
Packit 427e91
    gtk_widget_show(vbsel);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), vbsel);
Packit 427e91
Packit 427e91
    bgroup=0;
Packit 427e91
    for (i=0; i
Packit 427e91
      sprintf(str, "V%d", i);
Packit 427e91
      if (i)
Packit 427e91
        bgroup=gtk_radio_button_group(GTK_RADIO_BUTTON(vmixerControl.vchsel[i-1]));
Packit 427e91
      vmixerControl.vchsel[i]=gtk_radio_button_new_with_label(bgroup, str);
Packit 427e91
      gtk_widget_show(vmixerControl.vchsel[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbsel), vmixerControl.vchsel[i], FALSE, FALSE, 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(vmixerControl.vchsel[i]), "toggled", GTK_SIGNAL_FUNC(Vmixer_vchannel_selector_clicked), (gpointer)(long)i);
Packit 427e91
    }
Packit 427e91
Packit 427e91
    // Vmixer volume widgets
Packit 427e91
    frame=gtk_frame_new("Vmixer output levels");
Packit 427e91
    gtk_widget_show(frame);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(mainbox), frame, TRUE, TRUE, 0);
Packit 427e91
    hbox=gtk_hbox_new(TRUE, 1);
Packit 427e91
    gtk_widget_show(hbox);
Packit 427e91
    gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
    for (i=0; i
Packit 427e91
      vbox=gtk_vbox_new(FALSE, 0);
Packit 427e91
      gtk_widget_show(vbox);
Packit 427e91
      gtk_container_add(GTK_CONTAINER(hbox), vbox);
Packit 427e91
      // Channel label
Packit 427e91
      if (i
Packit 427e91
        sprintf(str, "A%d", i);
Packit 427e91
      else
Packit 427e91
        sprintf(str, "D%d", i-fdOut);
Packit 427e91
      label=gtk_label_new(str);
Packit 427e91
      gtk_widget_show(label);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0);
Packit 427e91
      // Volume
Packit 427e91
      vmixerControl.adj[i]=gtk_adjustment_new(0, ECHOGAIN_MINOUT, ECHOGAIN_MAXOUT, SHORTSTEP, LONGSTEP, 0);
Packit 427e91
      vmixerControl.volume[i]=gtk_vscale_new(GTK_ADJUSTMENT(vmixerControl.adj[i]));
Packit 427e91
      gtk_widget_show(vmixerControl.volume[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), vmixerControl.volume[i], TRUE, TRUE, 0);
Packit 427e91
      gtk_scale_set_draw_value(GTK_SCALE(vmixerControl.volume[i]), 0);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(vmixerControl.volume[i]), "grab_focus", GTK_SIGNAL_FUNC(Vmixer_volume_clicked), (gpointer)(long)i);
Packit 427e91
      gtk_signal_connect(GTK_OBJECT(vmixerControl.adj[i]), "value_changed", GTK_SIGNAL_FUNC(Vmixer_volume_changed), (gpointer)(long)i);
Packit 427e91
      // Value label
Packit 427e91
      vmixerControl.label[i]=gtk_label_new("xxx");
Packit 427e91
      gtk_widget_show(vmixerControl.label[i]);
Packit 427e91
      gtk_box_pack_start(GTK_BOX(vbox), vmixerControl.label[i], FALSE, FALSE, 0);
Packit 427e91
    }
Packit 427e91
    gtk_widget_set_usize(GTK_WIDGET(vmixerControl.volume[0]), 0, 170);		// Set minimum y size
Packit 427e91
    vmixerControl.input=-1;
Packit 427e91
    Vmixer_vchannel_selector_clicked(0, 0);
Packit 427e91
#endif
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
/* ********** Main window ********** */
Packit 427e91
Packit 427e91
  Mainwindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
Packit 427e91
  sprintf(str, EM_VERSION, cardId);
Packit 427e91
  gtk_window_set_title(GTK_WINDOW(Mainwindow), str);
Packit 427e91
  gtk_window_set_wmclass(GTK_WINDOW(Mainwindow), "emixer", "Emixer");
Packit 427e91
  gtk_signal_connect(GTK_OBJECT(Mainwindow), "delete_event", GTK_SIGNAL_FUNC(Mainwindow_delete), (gpointer)&Mainw_geom);
Packit 427e91
  gtk_container_set_border_width(GTK_CONTAINER(Mainwindow), BORDER);
Packit 427e91
  gtk_widget_show(Mainwindow);
Packit 427e91
  if (Mainw_geom.x!=NOPOS) {
Packit 427e91
    gtk_widget_set_uposition(Mainwindow, Mainw_geom.x, Mainw_geom.y);
Packit 427e91
    gtk_window_set_default_size(GTK_WINDOW(Mainwindow), Mainw_geom.w, Mainw_geom.h);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  mainbox=gtk_hbox_new(FALSE, SPACING);
Packit 427e91
  gtk_widget_show(mainbox);
Packit 427e91
  gtk_container_add(GTK_CONTAINER(Mainwindow), mainbox);
Packit 427e91
Packit 427e91
Packit 427e91
  // Gang button and its frame
Packit 427e91
  frame=gtk_frame_new("Gang");
Packit 427e91
  gtk_widget_show(frame);
Packit 427e91
  gtk_box_pack_start(GTK_BOX(mainbox), frame, FALSE, FALSE, 0);
Packit 427e91
  hbox=gtk_hbox_new(FALSE, 0);
Packit 427e91
  gtk_widget_show(hbox);
Packit 427e91
  gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
  button=gtk_toggle_button_new_with_label("On");
Packit 427e91
  gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
Packit 427e91
  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), 1);
Packit 427e91
  gtk_widget_show(button);
Packit 427e91
  gtk_signal_connect(GTK_OBJECT(button), "toggled", Gang_button_toggled, 0);
Packit 427e91
Packit 427e91
  // Controls frame
Packit 427e91
  frame=gtk_frame_new("Controls");
Packit 427e91
  gtk_widget_show(frame);
Packit 427e91
  gtk_box_pack_end(GTK_BOX(mainbox), frame, FALSE, FALSE, 0);
Packit 427e91
  hbox=gtk_hbox_new(FALSE, 0);
Packit 427e91
  gtk_widget_show(hbox);
Packit 427e91
  gtk_container_add(GTK_CONTAINER(frame), hbox);
Packit 427e91
Packit 427e91
  // VUmeters button
Packit 427e91
  if (vumetersId && vuswitchId) {
Packit 427e91
    button=gtk_toggle_button_new_with_label("VU");
Packit 427e91
    gtk_widget_show(button);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(button), "toggled", VUmeters_button_click, 0);
Packit 427e91
    VUw_geom.toggler=button;
Packit 427e91
    if (VUw_geom.st==1)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  // Line volume button
Packit 427e91
  button=gtk_toggle_button_new_with_label("Line");
Packit 427e91
  gtk_widget_show(button);
Packit 427e91
  gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
Packit 427e91
  gtk_signal_connect(GTK_OBJECT(button), "toggled", ToggleWindow, (gpointer)LVwindow);
Packit 427e91
  LVw_geom.toggler=button;
Packit 427e91
  if (LVw_geom.st==1)
Packit 427e91
    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
Packit 427e91
Packit 427e91
  // Misc controls button
Packit 427e91
  if (p4InId || p4OutId || phantomId || (dmodeId && ndmodes>1) || (clocksrcId && nclocksrc>1) || (spdifmodeId && nspdifmodes>1)) {
Packit 427e91
    button=gtk_toggle_button_new_with_label("Misc");
Packit 427e91
    gtk_widget_show(button);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(button), "toggled", ToggleWindow, (gpointer)Miscwindow);
Packit 427e91
    Miscw_geom.toggler=button;
Packit 427e91
    if (Miscw_geom.st==1)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (mixerId) {
Packit 427e91
    // Graphical mixer button
Packit 427e91
    button=gtk_toggle_button_new_with_label("GrMix");
Packit 427e91
    gtk_widget_show(button);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(button), "toggled", GMixer_button_click, 0);
Packit 427e91
    GMw_geom.toggler=button;
Packit 427e91
    if (GMw_geom.st==1)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
Packit 427e91
Packit 427e91
    // Mixer button
Packit 427e91
    button=gtk_toggle_button_new_with_label("Mixer");
Packit 427e91
    gtk_widget_show(button);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(button), "toggled", ToggleWindow, (gpointer)mixerControl.window);
Packit 427e91
    Mixerw_geom.toggler=button;
Packit 427e91
    if (Mixerw_geom.st==1)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (vmixerId) {
Packit 427e91
    // Vmixer button
Packit 427e91
    button=gtk_toggle_button_new_with_label("Vmixer");
Packit 427e91
    gtk_widget_show(button);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(button), "toggled", ToggleWindow, (gpointer)vmixerControl.window);
Packit 427e91
    Vmixerw_geom.toggler=button;
Packit 427e91
    if (Vmixerw_geom.st==1)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (pcmoutId) {
Packit 427e91
    // PCM volume button
Packit 427e91
    button=gtk_toggle_button_new_with_label("PCM");
Packit 427e91
    gtk_widget_show(button);
Packit 427e91
    gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 1);
Packit 427e91
    gtk_signal_connect(GTK_OBJECT(button), "toggled", ToggleWindow, (gpointer)pcmoutControl.window);
Packit 427e91
    PVw_geom.toggler=button;
Packit 427e91
    if (PVw_geom.st==1)
Packit 427e91
      gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
Packit 427e91
  }
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
/* ********** GTK-main ********** */
Packit 427e91
Packit 427e91
  Gang=1;
Packit 427e91
  if (dmodeId)
Packit 427e91
    Digital_mode_activate(dmodeOpt, (gpointer)(long)dmodeVal);	// Also calls SetSensitivity()
Packit 427e91
  gtk_widget_show(Mainwindow);
Packit 427e91
  gtk_main();
Packit 427e91
Packit 427e91
  if (save) {
Packit 427e91
    FILE *f;
Packit 427e91
    if (snprintf(str, 255, "%s/.Emixer_%s", getenv("HOME"), cardId)>0) {
Packit 427e91
      str[255]=0;
Packit 427e91
      if ((f=fopen(str, "w"))) {
Packit 427e91
        fprintf(f, "-- LineOut <channel> <gain>\n");
Packit 427e91
        for (i=0; i
Packit 427e91
          fprintf(f, "LineOut %2d %d\n", i, lineoutControl.Gain[i]);
Packit 427e91
        fprintf(f, "-- LineIn <channel> <gain>\n");
Packit 427e91
        for (i=0; i
Packit 427e91
          fprintf(f, "LineIn %2d %d\n", i, lineinControl.Gain[i]);
Packit 427e91
        fprintf(f, "-- PcmOut <channel> <gain>\n");
Packit 427e91
        for (i=0; i
Packit 427e91
          fprintf(f, "PcmOut %2d %d\n", i, pcmoutControl.Gain[i]);
Packit 427e91
        if (p4InId) {
Packit 427e91
          fprintf(f, "-- NominalIn <channel> <consumer level="" enabled="">\n");
Packit 427e91
          for (i=0; i
Packit 427e91
            fprintf(f, "NominalIn %2d %d\n", i, NominalIn.Level[i]);
Packit 427e91
        }
Packit 427e91
        if (p4OutId) {
Packit 427e91
          fprintf(f, "-- NominalOut <channel> <consumer level="" enabled="">\n");
Packit 427e91
          for (o=0; o
Packit 427e91
            fprintf(f, "NominalOut %2d %d\n", o, NominalOut.Level[o]);
Packit 427e91
        }
Packit 427e91
        if (mixerId) {
Packit 427e91
          fprintf(f, "-- Mixer <output> <input> <gain>\n");
Packit 427e91
          for (o=0; o
Packit 427e91
            for (i=0; i
Packit 427e91
              fprintf(f, "Mixer %2d %2d %d\n", o, i, mixerControl.mixer[o][i].Gain);
Packit 427e91
        }
Packit 427e91
        if (vmixerId) {
Packit 427e91
          fprintf(f, "-- Vmixer <output> <vchannel> <gain>\n");
Packit 427e91
          for (o=0; o
Packit 427e91
            for (i=0; i
Packit 427e91
              fprintf(f, "Vmixer %2d %2d %d\n", o, i, vmixerControl.mixer[o][i].Gain);
Packit 427e91
        }
Packit 427e91
        fprintf(f, "-- xxWindow <x> <y> <width> <height> <visible>\n");
Packit 427e91
        fprintf(f, "MainWindow %d %d %d %d\n", Mainw_geom.x, Mainw_geom.y, Mainw_geom.w, Mainw_geom.h);
Packit 427e91
        if (VUwindow)
Packit 427e91
          gdk_window_get_root_origin(VUwindow->window, &VUw_geom.x, &VUw_geom.y);
Packit 427e91
        fprintf(f, "VUmetersWindow %d %d %d\n", VUw_geom.x, VUw_geom.y, VUw_geom.st);
Packit 427e91
        if (GMwindow)
Packit 427e91
          gdk_window_get_root_origin(GMwindow->window, &VUw_geom.x, &VUw_geom.y);
Packit 427e91
        fprintf(f, "GfxMixerWindow %d %d %d\n", GMw_geom.x, GMw_geom.y, GMw_geom.st);
Packit 427e91
        if (pcmoutId) {
Packit 427e91
          if (pcmoutControl.window->window) {
Packit 427e91
            gdk_window_get_root_origin(pcmoutControl.window->window, &PVw_geom.x, &PVw_geom.y);
Packit 427e91
            gdk_window_get_size(pcmoutControl.window->window, &PVw_geom.w, &PVw_geom.h);
Packit 427e91
          }
Packit 427e91
          fprintf(f, "PcmVolumeWindow %d %d %d %d %d\n", PVw_geom.x, PVw_geom.y, PVw_geom.w, PVw_geom.h, !!GTK_WIDGET_VISIBLE(pcmoutControl.window));
Packit 427e91
        }
Packit 427e91
        if (LVwindow->window) {
Packit 427e91
          gdk_window_get_root_origin(LVwindow->window, &LVw_geom.x, &LVw_geom.y);
Packit 427e91
          gdk_window_get_size(LVwindow->window, &LVw_geom.w, &LVw_geom.h);
Packit 427e91
        }
Packit 427e91
        fprintf(f, "LineVolumeWindow %d %d %d %d %d\n", LVw_geom.x, LVw_geom.y, LVw_geom.w, LVw_geom.h, !!GTK_WIDGET_VISIBLE(LVwindow));
Packit 427e91
        if (Miscwindow->window) {
Packit 427e91
          gdk_window_get_root_origin(Miscwindow->window, &Miscw_geom.x, &Miscw_geom.y);
Packit 427e91
          gdk_window_get_size(Miscwindow->window, &Miscw_geom.w, &Miscw_geom.h);
Packit 427e91
        }
Packit 427e91
        fprintf(f, "MiscControlsWindow %d %d %d %d %d\n", Miscw_geom.x, Miscw_geom.y, Miscw_geom.w, Miscw_geom.h, !!GTK_WIDGET_VISIBLE(Miscwindow));
Packit 427e91
        if (mixerId) {
Packit 427e91
          if (mixerControl.window->window) {
Packit 427e91
            gdk_window_get_root_origin(mixerControl.window->window, &Mixerw_geom.x, &Mixerw_geom.y);
Packit 427e91
            gdk_window_get_size(mixerControl.window->window, &Mixerw_geom.w, &Mixerw_geom.h);
Packit 427e91
          }
Packit 427e91
          fprintf(f, "MixerWindow %d %d %d %d %d\n", Mixerw_geom.x, Mixerw_geom.y, Mixerw_geom.w, Mixerw_geom.h, !!GTK_WIDGET_VISIBLE(mixerControl.window));
Packit 427e91
        }
Packit 427e91
        if (vmixerId) {
Packit 427e91
          if (vmixerControl.window->window) {
Packit 427e91
            gdk_window_get_root_origin(vmixerControl.window->window, &Vmixerw_geom.x, &Vmixerw_geom.y);
Packit 427e91
            gdk_window_get_size(vmixerControl.window->window, &Vmixerw_geom.w, &Vmixerw_geom.h);
Packit 427e91
          }
Packit 427e91
          fprintf(f, "VmixerWindow %d %d %d %d %d\n", Vmixerw_geom.x, Vmixerw_geom.y, Vmixerw_geom.w, Vmixerw_geom.h, !!GTK_WIDGET_VISIBLE(vmixerControl.window));
Packit 427e91
        }
Packit 427e91
        fprintf(f, "\n");
Packit 427e91
        fclose(f);
Packit 427e91
      }
Packit 427e91
    }
Packit 427e91
  }
Packit 427e91
Packit 427e91
  if (VUwindow) {
Packit 427e91
    SetVUmeters(0);
Packit 427e91
    gtk_timeout_remove(VUtimer);
Packit 427e91
  }
Packit 427e91
  if (GMwindow) {
Packit 427e91
    SetVUmeters(0);
Packit 427e91
    gtk_timeout_remove(Mixtimer);
Packit 427e91
  }
Packit 427e91
  snd_ctl_close(ctlhandle);
Packit 427e91
  return(0);
Packit 427e91
}
Packit 427e91