Dead
[official-gcc.git] / gomp-20050608-branch / libjava / classpath / gnu / javax / sound / midi / dssi / DSSIMidiDeviceProvider.java
blobbaf61732d1867be2735ffeaea092fb4743324799
1 /* DSSIMidiDeviceProvider.java -- DSSI Device Provider
2 Copyright (C) 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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.
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.
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.
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.
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. */
39 package gnu.javax.sound.midi.dssi;
41 import java.util.ArrayList;
42 import java.util.List;
43 import java.io.File;
44 import java.io.FilenameFilter;
46 import gnu.classpath.Configuration;
47 import gnu.javax.sound.midi.alsa.AlsaMidiSequencerDevice;
49 import javax.sound.midi.MidiDevice;
50 import javax.sound.midi.MidiDevice.Info;
51 import javax.sound.midi.spi.MidiDeviceProvider;
53 /**
54 * A DSSI MIDI device provider.
56 * DSSI (pronounced "dizzy") is an API for audio plugins, with particular
57 * application for software synthesis plugins with native user interfaces.
59 * Read about DSSI at http://dssi.sourceforge.net
61 * @author Anthony Green (green@redhat.com)
64 public class DSSIMidiDeviceProvider extends MidiDeviceProvider
66 /**
67 * The MidiDevice.Info specialized for DSSI synthesizers.
69 * @author Anthony Green (green@redhat.com)
72 private static class DSSIInfo extends Info
74 String soname;
75 long index;
77 public DSSIInfo(String name, String vendor, String description,
78 String version, String soname, long index)
80 super(name, vendor, description, version);
81 this.soname = soname;
82 this.index = index;
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);
94 private static List examineLibrary(String soname)
96 List list = new ArrayList();
97 long index = 0;
98 long handle;
100 long sohandle = dlopen_(soname);
101 if (sohandle == 0)
102 return list;
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);
117 // Close the library and free memory
118 dlclose_(sohandle);
120 return list;
123 private static DSSIInfo[] infos;
125 static
127 if (Configuration.INIT_LOAD_LIBRARY)
128 System.loadLibrary("gjsmdssi");
130 File dssidir = new File("/usr/lib/dssi/");
131 String sofiles[] = dssidir.list(new FilenameFilter()
133 public boolean accept(File dir, String n)
135 return n.endsWith(".so");
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()]);
144 public DSSIMidiDeviceProvider()
146 // Empty.
149 /* Return the Info array.
150 * @see javax.sound.midi.spi.MidiDeviceProvider#getDeviceInfo()
152 public Info[] getDeviceInfo()
154 return infos;
157 /* Get a MIDI Device for info.
158 * @see javax.sound.midi.spi.MidiDeviceProvider#getDevice(javax.sound.midi.MidiDevice.Info)
160 public MidiDevice getDevice(Info info)
162 for (int i = 0; i < infos.length; i++)
164 if (info.equals(infos[i]))
166 return new DSSISynthesizer(infos[i],
167 infos[i].soname,
168 infos[i].index);
171 throw new IllegalArgumentException("Don't recognize MIDI device " + info);