void ConfigureMIDIOut::refreshList() { QTreeWidgetItem* item; MIDIDevice* dev; int i = 1; m_list->clear(); QListIterator <MIDIDevice*> it(m_plugin->m_devices); while (it.hasNext() == true) { dev = it.next(); item = new QTreeWidgetItem(m_list); item->setText(KColumnNumber, QString("%1").arg(i++)); item->setText(KColumnName, dev->name()); item->setText(KColumnMIDIChannel, QString("%1").arg(dev->midiChannel() + 1)); item->setText(KColumnMode, MIDIDevice::modeToString(dev->mode())); } }
void MIDIOut::rescanDevices() { snd_seq_client_info_t* clientInfo = NULL; snd_seq_port_info_t* portInfo = NULL; /* Don't do anything if the ALSA sequencer interface is not open */ if (m_alsa == NULL) return; /* Copy all device pointers to a destroy list */ QList <MIDIDevice*> destroyList(m_devices); /* Allocate these from stack */ snd_seq_client_info_alloca(&clientInfo); snd_seq_port_info_alloca(&portInfo); /* Find out what kinds of clients and ports there are */ snd_seq_client_info_set_client(clientInfo, 0); // TODO: -1 ????? while (snd_seq_query_next_client(m_alsa, clientInfo) == 0) { int client; /* Get the client ID */ client = snd_seq_client_info_get_client(clientInfo); /* Ignore our own client */ if (m_address->client == client) continue; /* Go thru all available ports in the client */ snd_seq_port_info_set_client(portInfo, client); snd_seq_port_info_set_port(portInfo, -1); while (snd_seq_query_next_port(m_alsa, portInfo) == 0) { const snd_seq_addr_t* address; MIDIDevice* dev; address = snd_seq_port_info_get_addr(portInfo); if (address == NULL) continue; dev = device(address); if (dev == NULL) { /* New address. Create a new device for it. */ dev = new MIDIDevice(this, address); Q_ASSERT(dev != NULL); /* Don't show QLC's internal ALSA ports */ if (dev->name().contains("__QLC__") == false) addDevice(dev); else delete dev; } else { /* This device is still alive. Do not destroy it at the end of this function. */ destroyList.removeAll(dev); } } } /* All devices that were not found during rescan are clearly no longer in our presence and must be destroyed. */ while (destroyList.isEmpty() == false) removeDevice(destroyList.takeFirst()); }