OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libjava/] [classpath/] [gnu/] [javax/] [sound/] [midi/] [dssi/] [DSSIMidiDeviceProvider.java] - Blame information for rev 14

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 14 jlechner
/* DSSIMidiDeviceProvider.java -- DSSI Device Provider
2
   Copyright (C) 2005 Free Software Foundation, Inc.
3
 
4
This file is part of GNU Classpath.
5
 
6
GNU Classpath is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2, or (at your option)
9
any later version.
10
 
11
GNU Classpath is distributed in the hope that it will be useful, but
12
WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with GNU Classpath; see the file COPYING.  If not, write to the
18
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19
02110-1301 USA.
20
 
21
Linking this library statically or dynamically with other modules is
22
making a combined work based on this library.  Thus, the terms and
23
conditions of the GNU General Public License cover the whole
24
combination.
25
 
26
As a special exception, the copyright holders of this library give you
27
permission to link this library with independent modules to produce an
28
executable, regardless of the license terms of these independent
29
modules, and to copy and distribute the resulting executable under
30
terms of your choice, provided that you also meet, for each linked
31
independent module, the terms and conditions of the license of that
32
module.  An independent module is a module which is not derived from
33
or based on this library.  If you modify this library, you may extend
34
this exception to your version of the library, but you are not
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version. */
37
 
38
 
39
package gnu.javax.sound.midi.dssi;
40
 
41
import java.util.ArrayList;
42
import java.util.List;
43
import java.io.File;
44
import java.io.FilenameFilter;
45
 
46
import gnu.classpath.Configuration;
47
import gnu.javax.sound.midi.alsa.AlsaMidiSequencerDevice;
48
 
49
import javax.sound.midi.MidiDevice;
50
import javax.sound.midi.MidiDevice.Info;
51
import javax.sound.midi.spi.MidiDeviceProvider;
52
 
53
/**
54
 * A DSSI MIDI device provider.
55
 *
56
 * DSSI (pronounced "dizzy") is an API for audio plugins, with particular
57
 * application for software synthesis plugins with native user interfaces.
58
 *
59
 * Read about DSSI at http://dssi.sourceforge.net
60
 *
61
 * @author Anthony Green (green@redhat.com)
62
 *
63
 */
64
public class DSSIMidiDeviceProvider extends MidiDeviceProvider
65
{
66
  /**
67
   * The MidiDevice.Info specialized for DSSI synthesizers.
68
   *
69
   * @author Anthony Green (green@redhat.com)
70
   *
71
   */
72
  private static class DSSIInfo extends Info
73
  {
74
    String soname;
75
    long index;
76
 
77
    public DSSIInfo(String name, String vendor, String description,
78
                    String version, String soname, long index)
79
    {
80
      super(name, vendor, description, version);
81
      this.soname = soname;
82
      this.index = index;
83
    }
84
  }
85
 
86
  static native long dlopen_(String soname);
87
  static native void dlclose_(long sohandle);
88
  static native long getDSSIHandle_(long sohandle, long index);
89
  static native String getDSSIName_(long handle);
90
  static native String getDSSICopyright_(long handle);
91
  static native String getDSSIVendor_(long handle);
92
  static native String getDSSILabel_(long handle);
93
 
94
  private static List examineLibrary(String soname)
95
  {
96
     List list = new ArrayList();
97
     long index = 0;
98
     long handle;
99
 
100
     long sohandle = dlopen_(soname);
101
     if (sohandle == 0)
102
       return list;
103
     do
104
     {
105
       handle = getDSSIHandle_(sohandle, index);
106
       if (handle == 0)
107
         break;
108
       String name = getDSSILabel_(handle);
109
       String copyright = getDSSICopyright_(handle);
110
       String label = getDSSIName_(handle);
111
       String vendor = getDSSIVendor_(handle);
112
       list.add(new DSSIInfo(name, vendor, label,
113
                             "DSSI-1", soname, index));
114
       index++;
115
     } while (true);
116
 
117
     // Close the library and free memory
118
     dlclose_(sohandle);
119
 
120
     return list;
121
  }
122
 
123
  private static DSSIInfo[] infos;
124
 
125
  static
126
  {
127
    if (Configuration.INIT_LOAD_LIBRARY)
128
      System.loadLibrary("gjsmdssi");
129
 
130
    File dssidir = new File("/usr/lib/dssi/");
131
    String sofiles[] = dssidir.list(new FilenameFilter()
132
                                    {
133
                                      public boolean accept(File dir, String n)
134
                                      {
135
                                        return n.endsWith(".so");
136
                                      }
137
                                    });
138
    List ilist = new ArrayList();
139
    for (int i = 0; i < sofiles.length; i++)
140
      ilist.addAll(examineLibrary(new File(dssidir, sofiles[i]).getAbsolutePath()));
141
    infos = (DSSIInfo[]) ilist.toArray(new DSSIInfo[ilist.size()]);
142
  }
143
 
144
  public DSSIMidiDeviceProvider()
145
  {
146
    // Empty.
147
  }
148
 
149
  /* Return the Info array.
150
   * @see javax.sound.midi.spi.MidiDeviceProvider#getDeviceInfo()
151
   */
152
  public Info[] getDeviceInfo()
153
  {
154
    return infos;
155
  }
156
 
157
  /* Get a MIDI Device for info.
158
   * @see javax.sound.midi.spi.MidiDeviceProvider#getDevice(javax.sound.midi.MidiDevice.Info)
159
   */
160
  public MidiDevice getDevice(Info info)
161
  {
162
    for (int i = 0; i < infos.length; i++)
163
    {
164
      if (info.equals(infos[i]))
165
      {
166
          return new DSSISynthesizer(infos[i],
167
                                     infos[i].soname,
168
                                     infos[i].index);
169
      }
170
    }
171
    throw new IllegalArgumentException("Don't recognize MIDI device " + info);
172
  }
173
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.