Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
public static void main(String[] args) {
Info[] devices = MidiSystem.getMidiDeviceInfo();
System.out.println(devices.length + " device(s) available:");
for (int i = 0; i < devices.length; i++) {
System.out.println("Device #" + i);
System.out.println("Name: " + devices[i].getName());
System.out.println("Version: " + devices[i].getVersion());
System.out.println("Vendor: " + devices[i].getVendor());
System.out.println("Description: " + devices[i].getDescription());
System.out.println();
}
}
4 device(s) available:
Device #0
Name: Microsoft MIDI-Mapper
Version: 5.0
Vendor: Unknown vendor
Description: Windows MIDI_MAPPER
Device #1
Name: Microsoft GS Wavetable SW Synth
Version: 5.10
Vendor: Unknown vendor
Description: Internal software synthesizer
Device #2
Name: Real Time Sequencer
Version: Version 1.0
Vendor: Sun Microsystems
Description: Software sequencer
Device #3
Name: Java Sound Synthesizer
Version: Version 1.0
Vendor: Sun Microsystems
Description: Software wavetable synthesizer and receiver
package gui;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.sound.midi.*;
public class MidiOutDialog extends JDialog{
private JComboBox midiDevices = new JComboBox();
private MidiDevice actualMidiDevice;
private JLabel label = new JLabel("Bitte das gewünschte Gerät auswählen");
private JButton ok_button = new JButton("OK");
private GridBagLayout gbl = new GridBagLayout();
private GridBagConstraints gbc;
private int driverNumber =0;
public MidiOutDialog(){
super.setTitle("Midigerät wählen");
initMidiDevice();
midiDevices.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
performSelection(midiDevices.getSelectedItem());
}
});
ok_button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
closeFrame();
}
});
this.setLayout(gbl);
gbc = new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=0;
gbc.gridwidth=1;
gbl.addLayoutComponent(label, gbc);
this.add(label);
gbc = new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=1;
gbc.gridwidth=1;
gbl.addLayoutComponent(midiDevices, gbc);
this.add(midiDevices);
gbc = new GridBagConstraints();
gbc.gridx=0;
gbc.gridy=2;
gbc.gridwidth=2;
gbl.addLayoutComponent(ok_button, gbc);
this.add(ok_button);
this.setModal(true);
this.setBounds(100, 100, 330, 300);
}
private void initMidiDevice(){
int anzahl = MidiSystem.getMidiDeviceInfo().length;
for (int i = 0; i<anzahl; i++){
midiDevices.addItem(MidiSystem.getMidiDeviceInfo()[i].getName());
}
}
private void performSelection(Object selected) {
try {
actualMidiDevice = MidiSystem.getMidiDevice(MidiSystem.getMidiDeviceInfo()[midiDevices.getSelectedIndex()]);
driverNumber = midiDevices.getSelectedIndex();
System.out.println(actualMidiDevice.getDeviceInfo().getName());
} catch (MidiUnavailableException e) {
throwMidiUnavailable();
e.printStackTrace();
}
}
public MidiDevice returnMidiDeviceNumber(){
return actualMidiDevice;
}
private void closeFrame(){
this.setVisible(false);
}
public int returnSelectedDriver(){
return driverNumber;
}
private void throwMidiUnavailable(){
JOptionPane.showMessageDialog(this,"Keine Midischnittstelle vorhanden!"
,"Midifehler!", JOptionPane.ERROR_MESSAGE);
}
}