~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to modules/controller_midi.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* LIBGIMP - The GIMP Library
2
 
 * Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
 
1
/* GIMP - The GNU Image Manipulation Program
 
2
 * Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * controller_midi.c
5
 
 * Copyright (C) 2004 Michael Natterer <mitch@gimp.org>
6
 
 *
7
 
 * This library is free software; you can redistribute it and/or
8
 
 * modify it under the terms of the GNU Lesser General Public
9
 
 * License as published by the Free Software Foundation; either
10
 
 * version 2 of the License, or (at your option) any later version.
11
 
 *
12
 
 * This library is distributed in the hope that it will be useful,
 
5
 * Copyright (C) 2004-2007 Michael Natterer <mitch@gimp.org>
 
6
 *
 
7
 * This program is free software; you can redistribute it and/or modify
 
8
 * it under the terms of the GNU General Public License as published by
 
9
 * the Free Software Foundation; either version 2 of the License, or
 
10
 * (at your option) any later version.
 
11
 *
 
12
 * This program is distributed in the hope that it will be useful,
13
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
 * Lesser General Public License for more details.
 
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
 * GNU General Public License for more details.
16
16
 *
17
 
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with this library; if not, write to the
19
 
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
 * Boston, MA 02111-1307, USA.
 
17
 * You should have received a copy of the GNU General Public License
 
18
 * along with this program; if not, write to the Free Software
 
19
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21
20
 */
22
21
 
23
22
#include "config.h"
24
23
 
 
24
#define _GNU_SOURCE  /* the ALSA headers need this */
 
25
 
25
26
#include <errno.h>
26
27
#include <fcntl.h>
27
28
#include <string.h>
29
30
#include <sys/types.h>
30
31
#include <time.h>
31
32
 
 
33
#include <glib/gstdio.h>
 
34
 
32
35
#ifdef HAVE_ALSA
33
36
#include <alsa/asoundlib.h>
34
37
#endif
35
38
 
36
39
#include <gtk/gtk.h>
37
40
 
 
41
#include "libgimpconfig/gimpconfig.h"
38
42
#include "libgimpmodule/gimpmodule.h"
39
43
#include "libgimpwidgets/gimpwidgets.h"
40
44
 
162
166
  GIMP_MODULE_ABI_VERSION,
163
167
  N_("MIDI event controller"),
164
168
  "Michael Natterer <mitch@gimp.org>",
165
 
  "v0.1",
166
 
  "(c) 2004, released under the GPL",
167
 
  "June 2004"
 
169
  "v0.2",
 
170
  "(c) 2004-2007, released under the GPL",
 
171
  "2004-2007"
168
172
};
169
173
 
170
174
 
194
198
{
195
199
  if (! controller_type)
196
200
    {
197
 
      static const GTypeInfo controller_info =
 
201
      const GTypeInfo controller_info =
198
202
      {
199
203
        sizeof (ControllerMidiClass),
200
204
        (GBaseInitFunc) NULL,
241
245
                                                        _("Device:"),
242
246
                                                        blurb,
243
247
                                                        NULL,
244
 
                                                        G_PARAM_READWRITE |
245
 
                                                        G_PARAM_CONSTRUCT |
246
 
                                                        GIMP_MODULE_PARAM_SERIALIZE));
 
248
                                                        GIMP_CONFIG_PARAM_FLAGS));
247
249
 
248
250
  g_free (blurb);
249
251
 
252
254
                                                     _("Channel:"),
253
255
                                                     _("The MIDI channel to read events from. Set to -1 for reading from all MIDI channels."),
254
256
                                                     -1, 15, -1,
255
 
                                                     G_PARAM_READWRITE |
256
 
                                                     G_PARAM_CONSTRUCT |
257
 
                                                     GIMP_MODULE_PARAM_SERIALIZE));
 
257
                                                     GIMP_CONFIG_PARAM_FLAGS));
258
258
 
259
259
  controller_class->name            = _("MIDI");
260
260
  controller_class->help_id         = "gimp-controller-midi";
 
261
  controller_class->stock_id        = GIMP_STOCK_CONTROLLER_MIDI;
261
262
 
262
263
  controller_class->get_n_events    = midi_get_n_events;
263
264
  controller_class->get_event_name  = midi_get_event_name;
379
380
      if (! midi_events[event_id].blurb)
380
381
        {
381
382
          if (event_id <= 127)
382
 
            midi_events[event_id].blurb = g_strdup_printf ("Note %02x on",
 
383
            midi_events[event_id].blurb = g_strdup_printf (_("Note %02x on"),
383
384
                                                           event_id);
384
385
          else if (event_id <= 255)
385
 
            midi_events[event_id].blurb = g_strdup_printf ("Note %02x off",
 
386
            midi_events[event_id].blurb = g_strdup_printf (_("Note %02x off"),
386
387
                                                           event_id - 128);
387
388
          else if (event_id <= 383)
388
 
            midi_events[event_id].blurb = g_strdup_printf ("Controller %03d",
 
389
            midi_events[event_id].blurb = g_strdup_printf (_("Controller %03d"),
389
390
                                                           event_id - 256);
390
391
        }
391
392
 
441
442
#ifdef HAVE_ALSA
442
443
      if (! g_ascii_strcasecmp (midi->device, "alsa"))
443
444
        {
444
 
          GAlsaSource *event_source;
445
 
          gchar       *alsa;
446
 
          gchar       *state;
447
 
          gint         ret;
 
445
          GSource *event_source;
 
446
          gchar   *alsa;
 
447
          gchar   *state;
 
448
          gint     ret;
448
449
 
449
450
          ret = snd_seq_open (&midi->sequencer, "default",
450
451
                              SND_SEQ_OPEN_INPUT, 0);
451
452
          if (ret >= 0)
452
453
            {
453
 
              snd_seq_set_client_name (midi->sequencer, "The GIMP");
 
454
              snd_seq_set_client_name (midi->sequencer, _("GIMP"));
454
455
              ret = snd_seq_create_simple_port (midi->sequencer,
455
 
                                                "The GIMP midi controller",
 
456
                                                _("GIMP MIDI Input Controller"),
456
457
                                                SND_SEQ_PORT_CAP_WRITE |
457
458
                                                SND_SEQ_PORT_CAP_SUBS_WRITE,
458
459
                                                SND_SEQ_PORT_TYPE_APPLICATION);
484
485
          g_object_set (midi, "state", state, NULL);
485
486
          g_free (state);
486
487
 
487
 
          event_source = (GAlsaSource *) g_source_new (&alsa_source_funcs,
488
 
                                                       sizeof (GAlsaSource));
489
 
          event_source->controller = midi;
490
 
          midi->seq_id = g_source_attach ((GSource *) event_source, NULL);
 
488
          event_source = g_source_new (&alsa_source_funcs,
 
489
                                       sizeof (GAlsaSource));
 
490
 
 
491
          ((GAlsaSource *) event_source)->controller = midi;
 
492
 
 
493
          midi->seq_id = g_source_attach (event_source, NULL);
 
494
          g_source_unref (event_source);
491
495
 
492
496
          return TRUE;
493
497
        }
494
498
#endif /* HAVE_ALSA */
495
499
 
496
500
#ifdef G_OS_WIN32
497
 
      fd = open (midi->device, O_RDONLY);
 
501
      fd = g_open (midi->device, O_RDONLY, 0);
498
502
#else
499
 
      fd = open (midi->device, O_RDONLY | O_NONBLOCK);
 
503
      fd = g_open (midi->device, O_RDONLY | O_NONBLOCK, 0);
500
504
#endif
501
505
 
502
506
      if (fd >= 0)