[9297] in The GTK GIMP ToolKit mailing list archive

home help back first fref pref prev next nref lref last post

[gtk-list] gpointer and callbacks

daemon@ATHENA.MIT.EDU (dross)
Wed Oct 14 16:04:35 1998

Date: Wed, 14 Oct 1998 20:08:26 +0000
From: dross <dross@melbpc.org.au>
To: gtk-list@redhat.com
Resent-From: gtk-list@redhat.com
Reply-To: gtk-list@redhat.com



I'm trying to write a simple audio interface, and am setting sliders to
adjust the volume and mic levels. I have a callback function that I would
like to pass an integer identifier, identifing the device I want to change
the level for. The problem is I can't seem to pass an integer to this function.

I am new to gtk and I don't quite understand what a gpointer is, and in all the

examples I found only strings where used. Can you pass any type using gpointer?

void adjust_level (GtkAdjustment * adj, gpointer data)
{
  int volume = adj->value, rvolume;

  /* equalise left and right channels */
  rvolume = (volume & 0x000000ff) << 8;
  volume = (volume & 0x000000ff) | rvolume;
  if (ioctl (fd_mixer, MIXER_WRITE (*(int*)data), &volume) < 0)
    {
      perror ("Can't set current volume settings");
    }
}

void setup_window (GtkWidget * parent)
{
  GtkWidget *vbox, *hbox;
  GtkWidget *button;
  GtkWidget *hscale;
  int volume = 0;
  int device, *ptr;
  ptr = &device;
 .
 .
 .
  /* Set the initial volume to the left chanel */
  device = SOUND_MIXER_VOLUME;
  volume = get_level(device);
  vol_adj = (GtkAdjustment*)gtk_adjustment_new ((volume & 0x000000ff),
0, 100, 1, 1, 0);
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (vol_adj));
  gtk_signal_connect (GTK_OBJECT (vol_adj), "value_changed",
        GTK_SIGNAL_FUNC (adjust_level), (gpointer)&device);
 gtk_box_pack_start (GTK_BOX (hbox), hscale, TRUE, TRUE, 0);
  gtk_widget_show (hscale);

  /* Set the initial volume to the left chanel */
  device = SOUND_MIXER_MIC;
  volume = get_level(device);
  mic_adj = (GtkAdjustment*)gtk_adjustment_new ((volume & 0x000000ff),
0, 100, 1, 1, 0);
  hscale = gtk_hscale_new (GTK_ADJUSTMENT (mic_adj));
  gtk_signal_connect (GTK_OBJECT (mic_adj), "value_changed",
        GTK_SIGNAL_FUNC (adjust_level), (gpointer)&device);

 .
 .
 .
}

Thanks

Darryl Ross


-- 
To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null


home help back first fref pref prev next nref lref last post