public String setMidiOut(int id)
    {
        if(_synthesizer != null)
        {
            _synthesizer.close();
            _synthesizer = null;
            _midiDevices.setSynthesizer(_synthesizer);
        }

        if(id > _midiDevices.getNumberOfDevices())
        {
            return "<midi-out>" + id + "</midi-out>";
        }

        if(id == -1)
        {
            return "<midi-out>" + id + "</midi-out>";
        }

        try
        {
            _synthesizer = _midiDevices.getDevice(id);//hw output
        }
        catch(ArrayIndexOutOfBoundsException e1)
        {
            return "<error id='setOutPort'>" + e1 + "</error><midi-out>-1</midi-out>";
        }

        try
        {
            _synthesizer.open();
        }
        catch(MidiUnavailableException e2)
        {
            return "<error id='setOutPort'>" + e2 + "</error><midi-out>-1</midi-out>";
        }

        if(_keyboard == null || !_keyboard.isOpen())
        {
            _midiDevices.setSynthesizer(_synthesizer);
            return "<message id='setOutPort'>no keyboard</message><midi-out>" + id + "</midi-out>";
        }

        Transmitter trans2 = null;

        try
        {
            trans2 = _keyboard.getTransmitter();
            trans2.setReceiver(_synthesizer.getReceiver());
        }
        catch(MidiUnavailableException e)
        {
            return "<error id='setOutPort'>" + e + "</error><midi-out>-1</midi-out>";
        }
        
        _midiDevices.setSynthesizer(_synthesizer);
        return "<midi-out>" + id + "</midi-out>";
    }