Re: [gtk-list] gdk_input_{add,remove} ??
- From: Paul Barton-Davis <pbd op net>
- To: gtk-list redhat com
- Cc: topper virginia edu
- Subject: Re: [gtk-list] gdk_input_{add,remove} ??
- Date: Thu, 11 Mar 1999 23:28:52 -0500
In message <36E7E7D4.1B66694C@virginia.edu>you write:
>Hey folks,
>
>I'm trying to hook in data that will read from my MIDI device, without
>using pthreads and whatanot. Someone mentioned:
>
> gdk_input_{add,remove}
>
>But I'm at a loss to find documentation on how to use it.
As the suggestor, here is a fragment of my actual code:
MidiPort *MidiInputPort;
int
UI::init ()
{
.
.
.
theMain = new Gtk_Main (argc, argv);
.
.
.
gdk_input_add (MidiInputPort->fd(),
GDK_INPUT_READ,
MidiInputPort->read_callback (),
(void *) MidiInputPort);
.
.
.
}
where the MidiInputPort object/struct (C++) contains the following
static member function:
static void read_callback (void *arg, int fd, GdkInputCondition cond)
{
MidiPort *port = (MidiInputPort *) arg;
/* assume that cond == GDK_INPUT_READ since we set up
the callback only for that condition, and ignore the
file descriptor since the port argument has its
own references to that.
*/
port->read ();
}
You could do this trivially in C as well:
void c_midi_read_callback (void *arg, int fd, GdkInputCondition cond)
{
unsigned char midibuffer[SOME_SIZE];
int nread;
nread = read (fd, midibuffer, SOME_SIZE);
.... do something with contents of midibuffer ...
}
Let me know if you have questions. If you're working in C++, you're
welcome to use my C++ MIDI library that comes with SoftWerk and Xphat
(at http://www.op.net/~pbd/{softwerk,xphat} respectively). It has its
own internal callback system for handling every type of MIDI message,
you can register any number of callbacks for each message (or even every
byte) if you want. etc. etc. At some point, I might convert this to
use Gtk--'s signal mechanism.
--p
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]