protected void populateMidiMenu() {
    JMenuItem rbMenuItem;
    
    // midiMenuInitialized = true; // just to be quickeer XXX
    
    midiMenu.removeAll();
    boolean empty = true;
    
    MidiUploader uploader = new MidiUploader();
    
    rbMenuItem = new JMenuItem("Rescan MIDI Ports");
    rbMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
          SwingUtilities.invokeLater(new Runnable() {
              public void run() {
                midiMenuInitialized = false;
                populateMidiMenu();
              }
            });
        }
      });
    midiMenu.add(rbMenuItem);
    midiMenu.addSeparator();
    
    if (midiInputMenu != null) {
      midiInputMenu.removeAll();
    } else {
      midiInputMenu = new JMenu("Input port");
    }
    if (midiOutputMenu != null) {
      midiOutputMenu.removeAll();
    } else {
      midiOutputMenu = new JMenu("Output port");
    }
    
    String ports[];
    
    ports = uploader.getMidiInputPorts();
    
    if (ports != null) {
      System.out.println("ports input " + ports.length);
      for (int i = 0; i < ports.length; i++) {
        String curport = ports[i];
        rbMenuItem = new JCheckBoxMenuItem(curport, curport.equals(Preferences.get("midi.inputport")));
        rbMenuItem.addActionListener(midiInputMenuListener);
        //serialGroup.add(rbMenuItem);
        midiInputMenu.add(rbMenuItem);
        empty = false;
      }
    }
    
    try {
      Thread.sleep(1000); // sleep to catch midi weirdness under macosx
    } catch (Exception e) {
    }
    
    ports = uploader.getMidiOutputPorts();
    if (ports != null) {
      System.out.println("ports output " + ports.length);
      for (int i = 0; i < ports.length; i++) {
        String curport = ports[i];
        rbMenuItem = new JCheckBoxMenuItem(curport, curport.equals(Preferences.get("midi.outputport")));
        rbMenuItem.addActionListener(midiOutputMenuListener);
        //serialGroup.add(rbMenuItem);
        midiOutputMenu.add(rbMenuItem);
        empty = false;
      }
    }
    
    midiMenu.add(midiInputMenu);
    midiMenu.add(midiOutputMenu);
    
    midiMenu.setEnabled(true);
    midiMenuInitialized = true;
  }